提交 6e52a9f0 编写于 作者: J Joao Moreno

fixes #13298

上级 527f8bb6
......@@ -7,22 +7,26 @@
import scorer = require('vs/base/common/scorer');
import strings = require('vs/base/common/strings');
const FileNameMatch = /^(.*)\.([^.]*)|([^.]+)$/;
const FileNameMatch = /^([^.]*)(\.(.*))?$/;
export function compareFileNames(one: string, other: string): number {
let oneMatch = FileNameMatch.exec(one.toLowerCase());
let otherMatch = FileNameMatch.exec(other.toLowerCase());
let oneName = oneMatch[1] || oneMatch[3] || '';
let oneExtension = oneMatch[2] || '';
let oneName = oneMatch[1] || '';
let oneExtension = oneMatch[3] || '';
let otherName = otherMatch[1] || otherMatch[3] || '';
let otherExtension = otherMatch[2] || '';
let otherName = otherMatch[1] || '';
let otherExtension = otherMatch[3] || '';
if (oneName !== otherName) {
return oneName < otherName ? -1 : 1;
}
if (oneExtension === otherExtension) {
return 0;
}
return oneExtension < otherExtension ? -1 : 1;
}
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { compareFileNames } from 'vs/base/common/Comparers';
import * as assert from 'assert';
suite('Comparers', () => {
test('compareFileNames', () => {
assert(compareFileNames('', '') === 0, 'empty should be equal');
assert(compareFileNames('abc', 'abc') === 0, 'equal names should be equal');
assert(compareFileNames('.abc', '.abc') === 0, 'equal full names should be equal');
assert(compareFileNames('.env', '.env.example') < 0);
assert(compareFileNames('.env.example', '.gitattributes') < 0);
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册