mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-11 02:32:35 -05:00
Merge from vscode ad407028575a77ea387eb7cc219b323dc017b686
This commit is contained in:
committed by
Anthony Dresser
parent
404260b8a0
commit
4ad73d381c
@@ -3,7 +3,7 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { compareFileNames, compareFileExtensions, compareFileNamesNumeric, compareFileExtensionsNumeric } from 'vs/base/common/comparers';
|
||||
import { compareFileNames, compareFileExtensions, compareFileNamesDefault, compareFileExtensionsDefault } from 'vs/base/common/comparers';
|
||||
import * as assert from 'assert';
|
||||
|
||||
const compareLocale = (a: string, b: string) => a.localeCompare(b);
|
||||
@@ -15,7 +15,7 @@ suite('Comparers', () => {
|
||||
test('compareFileNames', () => {
|
||||
|
||||
//
|
||||
// Comparisons with the same results as compareFileNamesNumeric
|
||||
// Comparisons with the same results as compareFileNamesDefault
|
||||
//
|
||||
|
||||
// name-only comparisons
|
||||
@@ -28,6 +28,7 @@ suite('Comparers', () => {
|
||||
|
||||
// name plus extension comparisons
|
||||
assert(compareFileNames('bbb.aaa', 'aaa.bbb') > 0, 'files with extensions are compared first by filename');
|
||||
assert(compareFileNames('aggregate.go', 'aggregate_repo.go') > 0, 'compares the whole name all at once by locale');
|
||||
|
||||
// dotfile comparisons
|
||||
assert(compareFileNames('.abc', '.abc') === 0, 'equal dotfile names should be equal');
|
||||
@@ -52,7 +53,7 @@ suite('Comparers', () => {
|
||||
assert(compareFileNames('abc1.10.txt', 'abc1.2.txt') > 0, 'numbers with dots between them are treated as two separate numbers, not one decimal number');
|
||||
|
||||
//
|
||||
// Comparisons with different results than compareFileNamesNumeric
|
||||
// Comparisons with different results than compareFileNamesDefault
|
||||
//
|
||||
|
||||
// name-only comparisons
|
||||
@@ -61,9 +62,6 @@ suite('Comparers', () => {
|
||||
assert.notDeepEqual(['artichoke', 'Artichoke', 'art', 'Art'].sort(compareFileNames), ['artichoke', 'Artichoke', 'art', 'Art'].sort(compareLocale), 'words with the same root and different cases do not sort in locale order');
|
||||
assert.notDeepEqual(['email', 'Email', 'émail', 'Émail'].sort(compareFileNames), ['email', 'Email', 'émail', 'Émail'].sort(compareLocale), 'the same base characters with different case or accents do not sort in locale order');
|
||||
|
||||
// name plus extension comparisons
|
||||
assert(compareFileNames('aggregate.go', 'aggregate_repo.go') > 0, 'compares the whole name all at once by locale');
|
||||
|
||||
// numeric comparisons
|
||||
assert(compareFileNames('abc02.txt', 'abc002.txt') > 0, 'filenames with equivalent numbers and leading zeros sort in unicode order');
|
||||
assert(compareFileNames('abc.txt1', 'abc.txt01') > 0, 'same name plus extensions with equal numbers sort in unicode order');
|
||||
@@ -75,7 +73,7 @@ suite('Comparers', () => {
|
||||
test('compareFileExtensions', () => {
|
||||
|
||||
//
|
||||
// Comparisons with the same results as compareFileExtensionsNumeric
|
||||
// Comparisons with the same results as compareFileExtensionsDefault
|
||||
//
|
||||
|
||||
// name-only comparisons
|
||||
@@ -118,12 +116,8 @@ suite('Comparers', () => {
|
||||
assert(compareFileExtensions('a.ext1', 'b.ext1') < 0, 'if equal extensions with numbers, filenames should be compared');
|
||||
assert(compareFileExtensions('a10.txt', 'A2.txt') > 0, 'filenames with number and case differences compare numerically');
|
||||
|
||||
// Same extension comparison that has the same result as compareFileExtensionsNumeric, but a different result than compareFileNames
|
||||
// This is an edge case caused by compareFileNames comparing the whole name all at once instead of the name and then the extension.
|
||||
assert(compareFileExtensions('aggregate.go', 'aggregate_repo.go') < 0, 'when extensions are equal, names sort in dictionary order');
|
||||
|
||||
//
|
||||
// Comparisons with different results from compareFileExtensionsNumeric
|
||||
// Comparisons with different results from compareFileExtensionsDefault
|
||||
//
|
||||
|
||||
// name-only comparisions
|
||||
@@ -135,6 +129,7 @@ suite('Comparers', () => {
|
||||
// name plus extension comparisons
|
||||
assert(compareFileExtensions('a.MD', 'a.md') !== compareLocale('MD', 'md'), 'case differences in extensions do not sort by locale');
|
||||
assert(compareFileExtensions('a.md', 'A.md') !== compareLocale('a', 'A'), 'case differences in names do not sort by locale');
|
||||
assert(compareFileExtensions('aggregate.go', 'aggregate_repo.go') < 0, 'when extensions are equal, names sort in dictionary order');
|
||||
|
||||
// dotfile comparisons
|
||||
assert(compareFileExtensions('.env', '.aaa.env') < 0, 'a dotfile with an extension is treated as a name plus an extension - equal extensions');
|
||||
@@ -152,145 +147,139 @@ suite('Comparers', () => {
|
||||
|
||||
});
|
||||
|
||||
test('compareFileNamesNumeric', () => {
|
||||
test('compareFileNamesDefault', () => {
|
||||
|
||||
//
|
||||
// Comparisons with the same results as compareFileNames
|
||||
//
|
||||
|
||||
// name-only comparisons
|
||||
assert(compareFileNamesNumeric(null, null) === 0, 'null should be equal');
|
||||
assert(compareFileNamesNumeric(null, 'abc') < 0, 'null should be come before real values');
|
||||
assert(compareFileNamesNumeric('', '') === 0, 'empty should be equal');
|
||||
assert(compareFileNamesNumeric('abc', 'abc') === 0, 'equal names should be equal');
|
||||
assert(compareFileNamesNumeric('z', 'A') > 0, 'z comes is after A regardless of case');
|
||||
assert(compareFileNamesNumeric('Z', 'a') > 0, 'Z comes after a regardless of case');
|
||||
assert(compareFileNamesDefault(null, null) === 0, 'null should be equal');
|
||||
assert(compareFileNamesDefault(null, 'abc') < 0, 'null should be come before real values');
|
||||
assert(compareFileNamesDefault('', '') === 0, 'empty should be equal');
|
||||
assert(compareFileNamesDefault('abc', 'abc') === 0, 'equal names should be equal');
|
||||
assert(compareFileNamesDefault('z', 'A') > 0, 'z comes is after A regardless of case');
|
||||
assert(compareFileNamesDefault('Z', 'a') > 0, 'Z comes after a regardless of case');
|
||||
|
||||
// name plus extension comparisons
|
||||
assert(compareFileNamesNumeric('file.ext', 'file.ext') === 0, 'equal full names should be equal');
|
||||
assert(compareFileNamesNumeric('a.ext', 'b.ext') < 0, 'if equal extensions, filenames should be compared');
|
||||
assert(compareFileNamesNumeric('file.aaa', 'file.bbb') < 0, 'files with equal names should be compared by extensions');
|
||||
assert(compareFileNamesNumeric('bbb.aaa', 'aaa.bbb') > 0, 'files should be compared by names even if extensions compare differently');
|
||||
assert(compareFileNamesDefault('file.ext', 'file.ext') === 0, 'equal full names should be equal');
|
||||
assert(compareFileNamesDefault('a.ext', 'b.ext') < 0, 'if equal extensions, filenames should be compared');
|
||||
assert(compareFileNamesDefault('file.aaa', 'file.bbb') < 0, 'files with equal names should be compared by extensions');
|
||||
assert(compareFileNamesDefault('bbb.aaa', 'aaa.bbb') > 0, 'files should be compared by names even if extensions compare differently');
|
||||
assert(compareFileNamesDefault('aggregate.go', 'aggregate_repo.go') > 0, 'compares the whole filename in locale order');
|
||||
|
||||
// dotfile comparisons
|
||||
assert(compareFileNamesNumeric('.abc', '.abc') === 0, 'equal dotfile names should be equal');
|
||||
assert(compareFileNamesNumeric('.env.', '.gitattributes') < 0, 'filenames starting with dots and with extensions should still sort properly');
|
||||
assert(compareFileNamesNumeric('.env', '.aaa.env') > 0, 'dotfiles sort alphabetically when they contain multiple dots');
|
||||
assert(compareFileNamesNumeric('.env', '.env.aaa') < 0, 'dotfiles with the same root sort shortest first');
|
||||
assert(compareFileNamesNumeric('.aaa_env', '.aaa.env') < 0, 'and underscore in a dotfile name will sort before a dot');
|
||||
assert(compareFileNamesDefault('.abc', '.abc') === 0, 'equal dotfile names should be equal');
|
||||
assert(compareFileNamesDefault('.env.', '.gitattributes') < 0, 'filenames starting with dots and with extensions should still sort properly');
|
||||
assert(compareFileNamesDefault('.env', '.aaa.env') > 0, 'dotfiles sort alphabetically when they contain multiple dots');
|
||||
assert(compareFileNamesDefault('.env', '.env.aaa') < 0, 'dotfiles with the same root sort shortest first');
|
||||
assert(compareFileNamesDefault('.aaa_env', '.aaa.env') < 0, 'and underscore in a dotfile name will sort before a dot');
|
||||
|
||||
// dotfile vs non-dotfile comparisons
|
||||
assert(compareFileNamesNumeric(null, '.abc') < 0, 'null should come before dotfiles');
|
||||
assert(compareFileNamesNumeric('.env', 'aaa') < 0, 'dotfiles come before filenames without extensions');
|
||||
assert(compareFileNamesNumeric('.env', 'aaa.env') < 0, 'dotfiles come before filenames with extensions');
|
||||
assert(compareFileNamesNumeric('.md', 'A.MD') < 0, 'dotfiles sort before uppercase files');
|
||||
assert(compareFileNamesNumeric('.MD', 'a.md') < 0, 'dotfiles sort before lowercase files');
|
||||
assert(compareFileNamesDefault(null, '.abc') < 0, 'null should come before dotfiles');
|
||||
assert(compareFileNamesDefault('.env', 'aaa') < 0, 'dotfiles come before filenames without extensions');
|
||||
assert(compareFileNamesDefault('.env', 'aaa.env') < 0, 'dotfiles come before filenames with extensions');
|
||||
assert(compareFileNamesDefault('.md', 'A.MD') < 0, 'dotfiles sort before uppercase files');
|
||||
assert(compareFileNamesDefault('.MD', 'a.md') < 0, 'dotfiles sort before lowercase files');
|
||||
|
||||
// numeric comparisons
|
||||
assert(compareFileNamesNumeric('1', '1') === 0, 'numerically equal full names should be equal');
|
||||
assert(compareFileNamesNumeric('abc1.txt', 'abc1.txt') === 0, 'equal filenames with numbers should be equal');
|
||||
assert(compareFileNamesNumeric('abc1.txt', 'abc2.txt') < 0, 'filenames with numbers should be in numerical order, not alphabetical order');
|
||||
assert(compareFileNamesNumeric('abc2.txt', 'abc10.txt') < 0, 'filenames with numbers should be in numerical order even when they are multiple digits long');
|
||||
assert(compareFileNamesNumeric('abc02.txt', 'abc010.txt') < 0, 'filenames with numbers that have leading zeros sort numerically');
|
||||
assert(compareFileNamesNumeric('abc1.10.txt', 'abc1.2.txt') > 0, 'numbers with dots between them are treated as two separate numbers, not one decimal number');
|
||||
assert(compareFileNamesDefault('1', '1') === 0, 'numerically equal full names should be equal');
|
||||
assert(compareFileNamesDefault('abc1.txt', 'abc1.txt') === 0, 'equal filenames with numbers should be equal');
|
||||
assert(compareFileNamesDefault('abc1.txt', 'abc2.txt') < 0, 'filenames with numbers should be in numerical order, not alphabetical order');
|
||||
assert(compareFileNamesDefault('abc2.txt', 'abc10.txt') < 0, 'filenames with numbers should be in numerical order even when they are multiple digits long');
|
||||
assert(compareFileNamesDefault('abc02.txt', 'abc010.txt') < 0, 'filenames with numbers that have leading zeros sort numerically');
|
||||
assert(compareFileNamesDefault('abc1.10.txt', 'abc1.2.txt') > 0, 'numbers with dots between them are treated as two separate numbers, not one decimal number');
|
||||
|
||||
//
|
||||
// Comparisons with different results than compareFileNames
|
||||
//
|
||||
|
||||
// name-only comparisons
|
||||
assert(compareFileNamesNumeric('a', 'A') === compareLocale('a', 'A'), 'the same letter sorts by locale');
|
||||
assert(compareFileNamesNumeric('â', 'Â') === compareLocale('â', 'Â'), 'the same accented letter sorts by locale');
|
||||
assert.deepEqual(['artichoke', 'Artichoke', 'art', 'Art'].sort(compareFileNamesNumeric), ['artichoke', 'Artichoke', 'art', 'Art'].sort(compareLocale), 'words with the same root and different cases sort in locale order');
|
||||
assert.deepEqual(['email', 'Email', 'émail', 'Émail'].sort(compareFileNamesNumeric), ['email', 'Email', 'émail', 'Émail'].sort(compareLocale), 'the same base characters with different case or accents sort in locale order');
|
||||
|
||||
// name plus extensions comparisons
|
||||
assert(compareFileNamesNumeric('aggregate.go', 'aggregate_repo.go') < 0, 'compares the name first, then the extension');
|
||||
assert(compareFileNamesDefault('a', 'A') === compareLocale('a', 'A'), 'the same letter sorts by locale');
|
||||
assert(compareFileNamesDefault('â', 'Â') === compareLocale('â', 'Â'), 'the same accented letter sorts by locale');
|
||||
assert.deepEqual(['artichoke', 'Artichoke', 'art', 'Art'].sort(compareFileNamesDefault), ['artichoke', 'Artichoke', 'art', 'Art'].sort(compareLocale), 'words with the same root and different cases sort in locale order');
|
||||
assert.deepEqual(['email', 'Email', 'émail', 'Émail'].sort(compareFileNamesDefault), ['email', 'Email', 'émail', 'Émail'].sort(compareLocale), 'the same base characters with different case or accents sort in locale order');
|
||||
|
||||
// numeric comparisons
|
||||
assert(compareFileNamesNumeric('abc02.txt', 'abc002.txt') < 0, 'filenames with equivalent numbers and leading zeros sort shortest number first');
|
||||
assert(compareFileNamesNumeric('abc.txt1', 'abc.txt01') < 0, 'same name plus extensions with equal numbers sort shortest number first');
|
||||
assert(compareFileNamesNumeric('art01', 'Art01') === compareLocaleNumeric('art01', 'Art01'), 'a numerically equivalent word of a different case compares numerically based on locale');
|
||||
assert(compareFileNamesDefault('abc02.txt', 'abc002.txt') < 0, 'filenames with equivalent numbers and leading zeros sort shortest number first');
|
||||
assert(compareFileNamesDefault('abc.txt1', 'abc.txt01') < 0, 'same name plus extensions with equal numbers sort shortest number first');
|
||||
assert(compareFileNamesDefault('art01', 'Art01') === compareLocaleNumeric('art01', 'Art01'), 'a numerically equivalent word of a different case compares numerically based on locale');
|
||||
|
||||
});
|
||||
|
||||
test('compareFileExtensionsNumeric', () => {
|
||||
test('compareFileExtensionsDefault', () => {
|
||||
|
||||
//
|
||||
// Comparisons with the same result as compareFileExtensions
|
||||
//
|
||||
|
||||
// name-only comparisons
|
||||
assert(compareFileExtensionsNumeric(null, null) === 0, 'null should be equal');
|
||||
assert(compareFileExtensionsNumeric(null, 'abc') < 0, 'null should come before real files without extensions');
|
||||
assert(compareFileExtensionsNumeric('', '') === 0, 'empty should be equal');
|
||||
assert(compareFileExtensionsNumeric('abc', 'abc') === 0, 'equal names should be equal');
|
||||
assert(compareFileExtensionsNumeric('z', 'A') > 0, 'z comes after A');
|
||||
assert(compareFileExtensionsNumeric('Z', 'a') > 0, 'Z comes after a');
|
||||
assert(compareFileExtensionsDefault(null, null) === 0, 'null should be equal');
|
||||
assert(compareFileExtensionsDefault(null, 'abc') < 0, 'null should come before real files without extensions');
|
||||
assert(compareFileExtensionsDefault('', '') === 0, 'empty should be equal');
|
||||
assert(compareFileExtensionsDefault('abc', 'abc') === 0, 'equal names should be equal');
|
||||
assert(compareFileExtensionsDefault('z', 'A') > 0, 'z comes after A');
|
||||
assert(compareFileExtensionsDefault('Z', 'a') > 0, 'Z comes after a');
|
||||
|
||||
// name plus extension comparisons
|
||||
assert(compareFileExtensionsNumeric('file.ext', 'file.ext') === 0, 'equal full filenames should be equal');
|
||||
assert(compareFileExtensionsNumeric('a.ext', 'b.ext') < 0, 'if equal extensions, filenames should be compared');
|
||||
assert(compareFileExtensionsNumeric('file.aaa', 'file.bbb') < 0, 'files with equal names should be compared by extensions');
|
||||
assert(compareFileExtensionsNumeric('bbb.aaa', 'aaa.bbb') < 0, 'files should be compared by extension first');
|
||||
assert(compareFileExtensionsNumeric('agg.go', 'aggrepo.go') < 0, 'shorter names sort before longer names');
|
||||
assert(compareFileExtensionsNumeric('agg.go', 'agg_repo.go') < 0, 'shorter names short before longer names even when the longer name contains an underscore');
|
||||
assert(compareFileExtensionsNumeric('a.MD', 'b.md') < 0, 'when extensions are the same except for case, the files sort by name');
|
||||
assert(compareFileExtensionsDefault('file.ext', 'file.ext') === 0, 'equal full filenames should be equal');
|
||||
assert(compareFileExtensionsDefault('a.ext', 'b.ext') < 0, 'if equal extensions, filenames should be compared');
|
||||
assert(compareFileExtensionsDefault('file.aaa', 'file.bbb') < 0, 'files with equal names should be compared by extensions');
|
||||
assert(compareFileExtensionsDefault('bbb.aaa', 'aaa.bbb') < 0, 'files should be compared by extension first');
|
||||
assert(compareFileExtensionsDefault('agg.go', 'aggrepo.go') < 0, 'shorter names sort before longer names');
|
||||
assert(compareFileExtensionsDefault('a.MD', 'b.md') < 0, 'when extensions are the same except for case, the files sort by name');
|
||||
|
||||
// dotfile comparisons
|
||||
assert(compareFileExtensionsNumeric('.abc', '.abc') === 0, 'equal dotfiles should be equal');
|
||||
assert(compareFileExtensionsNumeric('.md', '.Gitattributes') > 0, 'dotfiles sort alphabetically regardless of case');
|
||||
assert(compareFileExtensionsDefault('.abc', '.abc') === 0, 'equal dotfiles should be equal');
|
||||
assert(compareFileExtensionsDefault('.md', '.Gitattributes') > 0, 'dotfiles sort alphabetically regardless of case');
|
||||
|
||||
// dotfile vs non-dotfile comparisons
|
||||
assert(compareFileExtensionsNumeric(null, '.abc') < 0, 'null should come before dotfiles');
|
||||
assert(compareFileExtensionsNumeric('.env', 'aaa.env') < 0, 'dotfiles come before filenames with extensions');
|
||||
assert(compareFileExtensionsNumeric('.MD', 'a.md') < 0, 'dotfiles sort before lowercase files');
|
||||
assert(compareFileExtensionsDefault(null, '.abc') < 0, 'null should come before dotfiles');
|
||||
assert(compareFileExtensionsDefault('.env', 'aaa.env') < 0, 'dotfiles come before filenames with extensions');
|
||||
assert(compareFileExtensionsDefault('.MD', 'a.md') < 0, 'dotfiles sort before lowercase files');
|
||||
|
||||
// numeric comparisons
|
||||
assert(compareFileExtensionsNumeric('1', '1') === 0, 'numerically equal full names should be equal');
|
||||
assert(compareFileExtensionsNumeric('abc1.txt', 'abc1.txt') === 0, 'equal filenames with numbers should be equal');
|
||||
assert(compareFileExtensionsNumeric('abc1.txt', 'abc2.txt') < 0, 'filenames with numbers should be in numerical order, not alphabetical order');
|
||||
assert(compareFileExtensionsNumeric('abc2.txt', 'abc10.txt') < 0, 'filenames with numbers should be in numerical order');
|
||||
assert(compareFileExtensionsNumeric('abc02.txt', 'abc010.txt') < 0, 'filenames with numbers that have leading zeros sort numerically');
|
||||
assert(compareFileExtensionsNumeric('abc1.10.txt', 'abc1.2.txt') > 0, 'numbers with dots between them are treated as two separate numbers, not one decimal number');
|
||||
assert(compareFileExtensionsNumeric('abc2.txt2', 'abc1.txt10') < 0, 'extensions with numbers should be in numerical order, not alphabetical order');
|
||||
assert(compareFileExtensionsNumeric('txt.abc1', 'txt.abc1') === 0, 'equal extensions with numbers should be equal');
|
||||
assert(compareFileExtensionsNumeric('txt.abc1', 'txt.abc2') < 0, 'extensions with numbers should be in numerical order, not alphabetical order');
|
||||
assert(compareFileExtensionsNumeric('txt.abc2', 'txt.abc10') < 0, 'extensions with numbers should be in numerical order even when they are multiple digits long');
|
||||
assert(compareFileExtensionsNumeric('a.ext1', 'b.ext1') < 0, 'if equal extensions with numbers, filenames should be compared');
|
||||
assert(compareFileExtensionsNumeric('a10.txt', 'A2.txt') > 0, 'filenames with number and case differences compare numerically');
|
||||
|
||||
// Same extension comparison that has the same result as compareFileExtensions, but a different result than compareFileNames
|
||||
// This is an edge case caused by compareFileNames comparing the whole name all at once instead of the name and then the extension.
|
||||
assert(compareFileExtensionsNumeric('aggregate.go', 'aggregate_repo.go') < 0, 'when extensions are equal, names sort in dictionary order');
|
||||
assert(compareFileExtensionsDefault('1', '1') === 0, 'numerically equal full names should be equal');
|
||||
assert(compareFileExtensionsDefault('abc1.txt', 'abc1.txt') === 0, 'equal filenames with numbers should be equal');
|
||||
assert(compareFileExtensionsDefault('abc1.txt', 'abc2.txt') < 0, 'filenames with numbers should be in numerical order, not alphabetical order');
|
||||
assert(compareFileExtensionsDefault('abc2.txt', 'abc10.txt') < 0, 'filenames with numbers should be in numerical order');
|
||||
assert(compareFileExtensionsDefault('abc02.txt', 'abc010.txt') < 0, 'filenames with numbers that have leading zeros sort numerically');
|
||||
assert(compareFileExtensionsDefault('abc1.10.txt', 'abc1.2.txt') > 0, 'numbers with dots between them are treated as two separate numbers, not one decimal number');
|
||||
assert(compareFileExtensionsDefault('abc2.txt2', 'abc1.txt10') < 0, 'extensions with numbers should be in numerical order, not alphabetical order');
|
||||
assert(compareFileExtensionsDefault('txt.abc1', 'txt.abc1') === 0, 'equal extensions with numbers should be equal');
|
||||
assert(compareFileExtensionsDefault('txt.abc1', 'txt.abc2') < 0, 'extensions with numbers should be in numerical order, not alphabetical order');
|
||||
assert(compareFileExtensionsDefault('txt.abc2', 'txt.abc10') < 0, 'extensions with numbers should be in numerical order even when they are multiple digits long');
|
||||
assert(compareFileExtensionsDefault('a.ext1', 'b.ext1') < 0, 'if equal extensions with numbers, filenames should be compared');
|
||||
assert(compareFileExtensionsDefault('a10.txt', 'A2.txt') > 0, 'filenames with number and case differences compare numerically');
|
||||
|
||||
//
|
||||
// Comparisons with different results than compareFileExtensions
|
||||
//
|
||||
|
||||
// name-only comparisons
|
||||
assert(compareFileExtensionsNumeric('a', 'A') === compareLocale('a', 'A'), 'the same letter of different case sorts by locale');
|
||||
assert(compareFileExtensionsNumeric('â', 'Â') === compareLocale('â', 'Â'), 'the same accented letter of different case sorts by locale');
|
||||
assert.deepEqual(['artichoke', 'Artichoke', 'art', 'Art'].sort(compareFileExtensionsNumeric), ['artichoke', 'Artichoke', 'art', 'Art'].sort(compareLocale), 'words with the same root and different cases sort in locale order');
|
||||
assert.deepEqual(['email', 'Email', 'émail', 'Émail'].sort(compareFileExtensionsNumeric), ['email', 'Email', 'émail', 'Émail'].sort((a, b) => a.localeCompare(b)), 'the same base characters with different case or accents sort in locale order');
|
||||
assert(compareFileExtensionsDefault('a', 'A') === compareLocale('a', 'A'), 'the same letter of different case sorts by locale');
|
||||
assert(compareFileExtensionsDefault('â', 'Â') === compareLocale('â', 'Â'), 'the same accented letter of different case sorts by locale');
|
||||
assert.deepEqual(['artichoke', 'Artichoke', 'art', 'Art'].sort(compareFileExtensionsDefault), ['artichoke', 'Artichoke', 'art', 'Art'].sort(compareLocale), 'words with the same root and different cases sort in locale order');
|
||||
assert.deepEqual(['email', 'Email', 'émail', 'Émail'].sort(compareFileExtensionsDefault), ['email', 'Email', 'émail', 'Émail'].sort((a, b) => a.localeCompare(b)), 'the same base characters with different case or accents sort in locale order');
|
||||
|
||||
// name plus extension comparisons
|
||||
assert(compareFileExtensionsNumeric('a.MD', 'a.md') === compareLocale('MD', 'md'), 'case differences in extensions sort by locale');
|
||||
assert(compareFileExtensionsNumeric('a.md', 'A.md') === compareLocale('a', 'A'), 'case differences in names sort by locale');
|
||||
assert(compareFileExtensionsDefault('a.MD', 'a.md') === compareLocale('MD', 'md'), 'case differences in extensions sort by locale');
|
||||
assert(compareFileExtensionsDefault('a.md', 'A.md') === compareLocale('a', 'A'), 'case differences in names sort by locale');
|
||||
assert(compareFileExtensionsDefault('aggregate.go', 'aggregate_repo.go') > 0, 'names with the same extension sort in full filename locale order');
|
||||
|
||||
// dotfile comparisons
|
||||
assert(compareFileExtensionsNumeric('.env', '.aaa.env') > 0, 'dotfiles sort alphabetically when they contain multiple dots');
|
||||
assert(compareFileExtensionsNumeric('.env', '.env.aaa') < 0, 'dotfiles with the same root sort shortest first');
|
||||
assert(compareFileExtensionsDefault('.env', '.aaa.env') > 0, 'dotfiles sort alphabetically when they contain multiple dots');
|
||||
assert(compareFileExtensionsDefault('.env', '.env.aaa') < 0, 'dotfiles with the same root sort shortest first');
|
||||
|
||||
// dotfile vs non-dotfile comparisons
|
||||
assert(compareFileExtensionsNumeric('.env', 'aaa') < 0, 'dotfiles come before filenames without extensions');
|
||||
assert(compareFileExtensionsNumeric('.md', 'A.MD') < 0, 'dotfiles sort before uppercase files');
|
||||
assert(compareFileExtensionsDefault('.env', 'aaa') < 0, 'dotfiles come before filenames without extensions');
|
||||
assert(compareFileExtensionsDefault('.md', 'A.MD') < 0, 'dotfiles sort before uppercase files');
|
||||
|
||||
// numeric comparisons
|
||||
assert(compareFileExtensionsNumeric('abc.txt01', 'abc.txt1') > 0, 'extensions with equal numbers should be in shortest-first order');
|
||||
assert(compareFileExtensionsNumeric('art01', 'Art01') === compareLocaleNumeric('art01', 'Art01'), 'a numerically equivalent word of a different case compares numerically based on locale');
|
||||
assert(compareFileExtensionsNumeric('abc02.txt', 'abc002.txt') < 0, 'filenames with equivalent numbers and leading zeros sort shortest string first');
|
||||
assert(compareFileExtensionsNumeric('txt.abc01', 'txt.abc1') > 0, 'extensions with equivalent numbers sort shortest extension first');
|
||||
assert(compareFileExtensionsDefault('abc.txt01', 'abc.txt1') > 0, 'extensions with equal numbers should be in shortest-first order');
|
||||
assert(compareFileExtensionsDefault('art01', 'Art01') === compareLocaleNumeric('art01', 'Art01'), 'a numerically equivalent word of a different case compares numerically based on locale');
|
||||
assert(compareFileExtensionsDefault('abc02.txt', 'abc002.txt') < 0, 'filenames with equivalent numbers and leading zeros sort shortest string first');
|
||||
assert(compareFileExtensionsDefault('txt.abc01', 'txt.abc1') > 0, 'extensions with equivalent numbers sort shortest extension first');
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@@ -93,6 +93,22 @@ suite('dom', () => {
|
||||
assert(!div.firstChild);
|
||||
});
|
||||
|
||||
test('should buld nodes with id', () => {
|
||||
const div = $('div#foo');
|
||||
assert(div);
|
||||
assert(div instanceof HTMLElement);
|
||||
assert.equal(div.tagName, 'DIV');
|
||||
assert.equal(div.id, 'foo');
|
||||
});
|
||||
|
||||
test('should buld nodes with class-name', () => {
|
||||
const div = $('div.foo');
|
||||
assert(div);
|
||||
assert(div instanceof HTMLElement);
|
||||
assert.equal(div.tagName, 'DIV');
|
||||
assert.equal(div.className, 'foo');
|
||||
});
|
||||
|
||||
test('should build nodes with attributes', () => {
|
||||
let div = $('div', { class: 'test' });
|
||||
assert.equal(div.className, 'test');
|
||||
@@ -111,5 +127,12 @@ suite('dom', () => {
|
||||
|
||||
assert.equal(div.firstChild && div.firstChild.textContent, 'hello');
|
||||
});
|
||||
|
||||
test('should build nodes with text children', () => {
|
||||
let div = $('div', undefined, 'foobar');
|
||||
let firstChild = div.firstChild as HTMLElement;
|
||||
assert.equal(firstChild.tagName, undefined);
|
||||
assert.equal(firstChild.textContent, 'foobar');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -18,7 +18,6 @@ suite('MarkdownRenderer', () => {
|
||||
const result: HTMLElement = renderMarkdown(markdown);
|
||||
const renderer = new marked.Renderer();
|
||||
const imageFromMarked = marked(markdown.value, {
|
||||
sanitize: true,
|
||||
renderer
|
||||
}).trim();
|
||||
assert.strictEqual(result.innerHTML, imageFromMarked);
|
||||
@@ -29,7 +28,6 @@ suite('MarkdownRenderer', () => {
|
||||
const result: HTMLElement = renderMarkdown(markdown);
|
||||
const renderer = new marked.Renderer();
|
||||
const imageFromMarked = marked(markdown.value, {
|
||||
sanitize: true,
|
||||
renderer
|
||||
}).trim();
|
||||
assert.strictEqual(result.innerHTML, imageFromMarked);
|
||||
|
||||
@@ -110,10 +110,10 @@ suite('Fuzzy Scorer', () => {
|
||||
scores.push(_doScore(target, 'hw', true)); // direct mix-case prefix (multiple)
|
||||
scores.push(_doScore(target, 'H', true)); // direct case prefix
|
||||
scores.push(_doScore(target, 'h', true)); // direct mix-case prefix
|
||||
scores.push(_doScore(target, 'ld', true)); // in-string mix-case match (consecutive, avoids scattered hit)
|
||||
scores.push(_doScore(target, 'W', true)); // direct case word prefix
|
||||
scores.push(_doScore(target, 'w', true)); // direct mix-case word prefix
|
||||
scores.push(_doScore(target, 'Ld', true)); // in-string case match (multiple)
|
||||
scores.push(_doScore(target, 'ld', true)); // in-string mix-case match (consecutive, avoids scattered hit)
|
||||
scores.push(_doScore(target, 'w', true)); // direct mix-case word prefix
|
||||
scores.push(_doScore(target, 'L', true)); // in-string case match
|
||||
scores.push(_doScore(target, 'l', true)); // in-string mix-case match
|
||||
scores.push(_doScore(target, '4', true)); // no match
|
||||
@@ -123,13 +123,13 @@ suite('Fuzzy Scorer', () => {
|
||||
assert.deepEqual(scores, sortedScores);
|
||||
|
||||
// Assert scoring positions
|
||||
let positions = scores[0][1];
|
||||
assert.equal(positions.length, 'HelLo-World'.length);
|
||||
// let positions = scores[0][1];
|
||||
// assert.equal(positions.length, 'HelLo-World'.length);
|
||||
|
||||
positions = scores[2][1];
|
||||
assert.equal(positions.length, 'HW'.length);
|
||||
assert.equal(positions[0], 0);
|
||||
assert.equal(positions[1], 6);
|
||||
// positions = scores[2][1];
|
||||
// assert.equal(positions.length, 'HW'.length);
|
||||
// assert.equal(positions[0], 0);
|
||||
// assert.equal(positions[1], 6);
|
||||
});
|
||||
|
||||
test('score (non fuzzy)', function () {
|
||||
@@ -626,6 +626,21 @@ suite('Fuzzy Scorer', () => {
|
||||
assert.equal(res[1], resourceA);
|
||||
});
|
||||
|
||||
test('compareFilesByScore - prefer camel case matches', function () {
|
||||
const resourceA = URI.file('config/test/NullPointerException.java');
|
||||
const resourceB = URI.file('config/test/nopointerexception.java');
|
||||
|
||||
for (const query of ['npe', 'NPE']) {
|
||||
let res = [resourceA, resourceB].sort((r1, r2) => compareItemsByScore(r1, r2, query, true, ResourceAccessor));
|
||||
assert.equal(res[0], resourceA);
|
||||
assert.equal(res[1], resourceB);
|
||||
|
||||
res = [resourceB, resourceA].sort((r1, r2) => compareItemsByScore(r1, r2, query, true, ResourceAccessor));
|
||||
assert.equal(res[0], resourceA);
|
||||
assert.equal(res[1], resourceB);
|
||||
}
|
||||
});
|
||||
|
||||
test('compareFilesByScore - prefer more compact camel case matches', function () {
|
||||
const resourceA = URI.file('config/test/openthisAnythingHandler.js');
|
||||
const resourceB = URI.file('config/test/openthisisnotsorelevantforthequeryAnyHand.js');
|
||||
@@ -925,6 +940,91 @@ suite('Fuzzy Scorer', () => {
|
||||
assert.equal(res[0], resourceB);
|
||||
});
|
||||
|
||||
test('compareFilesByScore - prefer shorter match (bug #103052) - foo bar', function () {
|
||||
const resourceA = URI.file('app/emails/foo.bar.js');
|
||||
const resourceB = URI.file('app/emails/other-footer.other-bar.js');
|
||||
|
||||
for (const query of ['foo bar', 'foobar']) {
|
||||
let res = [resourceA, resourceB].sort((r1, r2) => compareItemsByScore(r1, r2, query, true, ResourceAccessor));
|
||||
assert.equal(res[0], resourceA);
|
||||
assert.equal(res[1], resourceB);
|
||||
|
||||
res = [resourceB, resourceA].sort((r1, r2) => compareItemsByScore(r1, r2, query, true, ResourceAccessor));
|
||||
assert.equal(res[0], resourceA);
|
||||
assert.equal(res[1], resourceB);
|
||||
}
|
||||
});
|
||||
|
||||
test('compareFilesByScore - prefer shorter match (bug #103052) - payment model', function () {
|
||||
const resourceA = URI.file('app/components/payment/payment.model.js');
|
||||
const resourceB = URI.file('app/components/online-payments-history/online-payments-history.model.js');
|
||||
|
||||
for (const query of ['payment model', 'paymentmodel']) {
|
||||
let res = [resourceA, resourceB].sort((r1, r2) => compareItemsByScore(r1, r2, query, true, ResourceAccessor));
|
||||
assert.equal(res[0], resourceA);
|
||||
assert.equal(res[1], resourceB);
|
||||
|
||||
res = [resourceB, resourceA].sort((r1, r2) => compareItemsByScore(r1, r2, query, true, ResourceAccessor));
|
||||
assert.equal(res[0], resourceA);
|
||||
assert.equal(res[1], resourceB);
|
||||
}
|
||||
});
|
||||
|
||||
test('compareFilesByScore - prefer shorter match (bug #103052) - color', function () {
|
||||
const resourceA = URI.file('app/constants/color.js');
|
||||
const resourceB = URI.file('app/components/model/input/pick-avatar-color.js');
|
||||
|
||||
for (const query of ['color js', 'colorjs']) {
|
||||
let res = [resourceA, resourceB].sort((r1, r2) => compareItemsByScore(r1, r2, query, true, ResourceAccessor));
|
||||
assert.equal(res[0], resourceA);
|
||||
assert.equal(res[1], resourceB);
|
||||
|
||||
res = [resourceB, resourceA].sort((r1, r2) => compareItemsByScore(r1, r2, query, true, ResourceAccessor));
|
||||
assert.equal(res[0], resourceA);
|
||||
assert.equal(res[1], resourceB);
|
||||
}
|
||||
});
|
||||
|
||||
test('compareFilesByScore - prefer strict case prefix', function () {
|
||||
const resourceA = URI.file('app/constants/color.js');
|
||||
const resourceB = URI.file('app/components/model/input/Color.js');
|
||||
|
||||
let query = 'Color';
|
||||
|
||||
let res = [resourceA, resourceB].sort((r1, r2) => compareItemsByScore(r1, r2, query, true, ResourceAccessor));
|
||||
assert.equal(res[0], resourceB);
|
||||
assert.equal(res[1], resourceA);
|
||||
|
||||
res = [resourceB, resourceA].sort((r1, r2) => compareItemsByScore(r1, r2, query, true, ResourceAccessor));
|
||||
assert.equal(res[0], resourceB);
|
||||
assert.equal(res[1], resourceA);
|
||||
|
||||
query = 'color';
|
||||
|
||||
res = [resourceA, resourceB].sort((r1, r2) => compareItemsByScore(r1, r2, query, true, ResourceAccessor));
|
||||
assert.equal(res[0], resourceA);
|
||||
assert.equal(res[1], resourceB);
|
||||
|
||||
res = [resourceB, resourceA].sort((r1, r2) => compareItemsByScore(r1, r2, query, true, ResourceAccessor));
|
||||
assert.equal(res[0], resourceA);
|
||||
assert.equal(res[1], resourceB);
|
||||
});
|
||||
|
||||
test('compareFilesByScore - prefer prefix (bug #103052)', function () {
|
||||
const resourceA = URI.file('test/smoke/src/main.ts');
|
||||
const resourceB = URI.file('src/vs/editor/common/services/semantikTokensProviderStyling.ts');
|
||||
|
||||
let query = 'smoke main.ts';
|
||||
|
||||
let res = [resourceA, resourceB].sort((r1, r2) => compareItemsByScore(r1, r2, query, true, ResourceAccessor));
|
||||
assert.equal(res[0], resourceA);
|
||||
assert.equal(res[1], resourceB);
|
||||
|
||||
res = [resourceB, resourceA].sort((r1, r2) => compareItemsByScore(r1, r2, query, true, ResourceAccessor));
|
||||
assert.equal(res[0], resourceA);
|
||||
assert.equal(res[1], resourceB);
|
||||
});
|
||||
|
||||
test('prepareQuery', () => {
|
||||
assert.equal(scorer.prepareQuery(' f*a ').normalized, 'fa');
|
||||
assert.equal(scorer.prepareQuery('model Tester.ts').original, 'model Tester.ts');
|
||||
|
||||
@@ -32,12 +32,18 @@ suite('Hash', () => {
|
||||
assert.equal(hash([1, 2, 3]), hash([1, 2, 3]));
|
||||
assert.equal(hash(['foo', 'bar']), hash(['foo', 'bar']));
|
||||
assert.equal(hash([]), hash([]));
|
||||
assert.equal(hash([]), hash(new Array()));
|
||||
assert.notEqual(hash(['foo', 'bar']), hash(['bar', 'foo']));
|
||||
assert.notEqual(hash(['foo', 'bar']), hash(['bar', 'foo', null]));
|
||||
assert.notEqual(hash(['foo', 'bar', null]), hash(['bar', 'foo', null]));
|
||||
assert.notEqual(hash(['foo', 'bar']), hash(['bar', 'foo', undefined]));
|
||||
assert.notEqual(hash(['foo', 'bar', undefined]), hash(['bar', 'foo', undefined]));
|
||||
assert.notEqual(hash(['foo', 'bar', null]), hash(['foo', 'bar', undefined]));
|
||||
});
|
||||
|
||||
test('object', () => {
|
||||
assert.equal(hash({}), hash({}));
|
||||
assert.equal(hash({}), hash(Object.create(null)));
|
||||
assert.equal(hash({ 'foo': 'bar' }), hash({ 'foo': 'bar' }));
|
||||
assert.equal(hash({ 'foo': 'bar', 'foo2': undefined }), hash({ 'foo2': undefined, 'foo': 'bar' }));
|
||||
assert.notEqual(hash({ 'foo': 'bar' }), hash({ 'foo': 'bar2' }));
|
||||
@@ -45,14 +51,26 @@ suite('Hash', () => {
|
||||
});
|
||||
|
||||
test('array - unexpected collision', function () {
|
||||
this.skip();
|
||||
const a = hash([undefined, undefined, undefined, undefined, undefined]);
|
||||
const b = hash([undefined, undefined, 'HHHHHH', [{ line: 0, character: 0 }, { line: 0, character: 0 }], undefined]);
|
||||
// console.log(a);
|
||||
// console.log(b);
|
||||
assert.notEqual(a, b);
|
||||
});
|
||||
|
||||
test('all different', () => {
|
||||
const candidates: any[] = [
|
||||
null, undefined, {}, [], 0, false, true, '', ' ', [null], [undefined], [undefined, undefined], { '': undefined }, { [' ']: undefined },
|
||||
'ab', 'ba', ['ab']
|
||||
];
|
||||
const hashes: number[] = candidates.map(hash);
|
||||
for (let i = 0; i < hashes.length; i++) {
|
||||
assert.equal(hashes[i], hash(candidates[i])); // verify that repeated invocation returns the same hash
|
||||
for (let k = i + 1; k < hashes.length; k++) {
|
||||
assert.notEqual(hashes[i], hashes[k], `Same hash ${hashes[i]} for ${JSON.stringify(candidates[i])} and ${JSON.stringify(candidates[k])}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
function checkSHA1(strings: string[], expected: string) {
|
||||
const hash = new StringSHA1();
|
||||
for (const str of strings) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import * as assert from 'assert';
|
||||
import { IDisposable, dispose, ReferenceCollection } from 'vs/base/common/lifecycle';
|
||||
import { DisposableStore, dispose, IDisposable, MultiDisposeError, ReferenceCollection, toDisposable } from 'vs/base/common/lifecycle';
|
||||
|
||||
class Disposable implements IDisposable {
|
||||
isDisposed = false;
|
||||
@@ -49,6 +49,48 @@ suite('Lifecycle', () => {
|
||||
assert(disposable2.isDisposed);
|
||||
});
|
||||
|
||||
test('dispose array should dispose all if a child throws on dispose', () => {
|
||||
const disposedValues = new Set<number>();
|
||||
|
||||
let thrownError: any;
|
||||
try {
|
||||
dispose([
|
||||
toDisposable(() => { disposedValues.add(1); }),
|
||||
toDisposable(() => { throw new Error('I am error'); }),
|
||||
toDisposable(() => { disposedValues.add(3); }),
|
||||
]);
|
||||
} catch (e) {
|
||||
thrownError = e;
|
||||
}
|
||||
|
||||
assert.ok(disposedValues.has(1));
|
||||
assert.ok(disposedValues.has(3));
|
||||
assert.strictEqual(thrownError.message, 'I am error');
|
||||
});
|
||||
|
||||
test('dispose array should rethrow composite error if multiple entries throw on dispose', () => {
|
||||
const disposedValues = new Set<number>();
|
||||
|
||||
let thrownError: any;
|
||||
try {
|
||||
dispose([
|
||||
toDisposable(() => { disposedValues.add(1); }),
|
||||
toDisposable(() => { throw new Error('I am error 1'); }),
|
||||
toDisposable(() => { throw new Error('I am error 2'); }),
|
||||
toDisposable(() => { disposedValues.add(4); }),
|
||||
]);
|
||||
} catch (e) {
|
||||
thrownError = e;
|
||||
}
|
||||
|
||||
assert.ok(disposedValues.has(1));
|
||||
assert.ok(disposedValues.has(4));
|
||||
assert.ok(thrownError instanceof MultiDisposeError);
|
||||
assert.strictEqual((thrownError as MultiDisposeError).errors.length, 2);
|
||||
assert.strictEqual((thrownError as MultiDisposeError).errors[0].message, 'I am error 1');
|
||||
assert.strictEqual((thrownError as MultiDisposeError).errors[1].message, 'I am error 2');
|
||||
});
|
||||
|
||||
test('Action bar has broken accessibility #100273', function () {
|
||||
let array = [{ dispose() { } }, { dispose() { } }];
|
||||
let array2 = dispose(array);
|
||||
@@ -61,7 +103,52 @@ suite('Lifecycle', () => {
|
||||
let setValues = set.values();
|
||||
let setValues2 = dispose(setValues);
|
||||
assert.ok(setValues === setValues2);
|
||||
});
|
||||
});
|
||||
|
||||
suite('DisposableStore', () => {
|
||||
test('dispose should call all child disposes even if a child throws on dispose', () => {
|
||||
const disposedValues = new Set<number>();
|
||||
|
||||
const store = new DisposableStore();
|
||||
store.add(toDisposable(() => { disposedValues.add(1); }));
|
||||
store.add(toDisposable(() => { throw new Error('I am error'); }));
|
||||
store.add(toDisposable(() => { disposedValues.add(3); }));
|
||||
|
||||
let thrownError: any;
|
||||
try {
|
||||
store.dispose();
|
||||
} catch (e) {
|
||||
thrownError = e;
|
||||
}
|
||||
|
||||
assert.ok(disposedValues.has(1));
|
||||
assert.ok(disposedValues.has(3));
|
||||
assert.strictEqual(thrownError.message, 'I am error');
|
||||
});
|
||||
|
||||
test('dispose should throw composite error if multiple children throw on dispose', () => {
|
||||
const disposedValues = new Set<number>();
|
||||
|
||||
const store = new DisposableStore();
|
||||
store.add(toDisposable(() => { disposedValues.add(1); }));
|
||||
store.add(toDisposable(() => { throw new Error('I am error 1'); }));
|
||||
store.add(toDisposable(() => { throw new Error('I am error 2'); }));
|
||||
store.add(toDisposable(() => { disposedValues.add(4); }));
|
||||
|
||||
let thrownError: any;
|
||||
try {
|
||||
store.dispose();
|
||||
} catch (e) {
|
||||
thrownError = e;
|
||||
}
|
||||
|
||||
assert.ok(disposedValues.has(1));
|
||||
assert.ok(disposedValues.has(4));
|
||||
assert.ok(thrownError instanceof MultiDisposeError);
|
||||
assert.strictEqual((thrownError as MultiDisposeError).errors.length, 2);
|
||||
assert.strictEqual((thrownError as MultiDisposeError).errors[0].message, 'I am error 1');
|
||||
assert.strictEqual((thrownError as MultiDisposeError).errors[1].message, 'I am error 2');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -224,7 +224,6 @@ suite('PFS', function () {
|
||||
}
|
||||
catch (error) {
|
||||
assert.fail(error);
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user