Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/base/test/common/iconLabels.test.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import assert from 'assert';
7
import { IMatch } from '../../common/filters.js';
8
import { escapeIcons, getCodiconAriaLabel, IParsedLabelWithIcons, markdownEscapeEscapedIcons, matchesFuzzyIconAware, parseLabelWithIcons, stripIcons } from '../../common/iconLabels.js';
9
import { ensureNoDisposablesAreLeakedInTestSuite } from './utils.js';
10
11
interface IIconFilter {
12
// Returns null if word doesn't match.
13
(query: string, target: IParsedLabelWithIcons): IMatch[] | null;
14
}
15
16
function filterOk(filter: IIconFilter, word: string, target: IParsedLabelWithIcons, highlights?: { start: number; end: number }[]) {
17
const r = filter(word, target);
18
assert(r);
19
if (highlights) {
20
assert.deepStrictEqual(r, highlights);
21
}
22
}
23
24
suite('Icon Labels', () => {
25
test('Can get proper aria labels', () => {
26
// note, the spaces in the results are important
27
const testCases = new Map<string, string>([
28
['', ''],
29
['asdf', 'asdf'],
30
['asdf$(squirrel)asdf', 'asdf squirrel asdf'],
31
['asdf $(squirrel) asdf', 'asdf squirrel asdf'],
32
['$(rocket)asdf', 'rocket asdf'],
33
['$(rocket) asdf', 'rocket asdf'],
34
['$(rocket)$(rocket)$(rocket)asdf', 'rocket rocket rocket asdf'],
35
['$(rocket) asdf $(rocket)', 'rocket asdf rocket'],
36
['$(rocket)asdf$(rocket)', 'rocket asdf rocket'],
37
]);
38
39
for (const [input, expected] of testCases) {
40
assert.strictEqual(getCodiconAriaLabel(input), expected);
41
}
42
});
43
44
test('matchesFuzzyIconAware', () => {
45
46
// Camel Case
47
48
filterOk(matchesFuzzyIconAware, 'ccr', parseLabelWithIcons('$(codicon)CamelCaseRocks$(codicon)'), [
49
{ start: 10, end: 11 },
50
{ start: 15, end: 16 },
51
{ start: 19, end: 20 }
52
]);
53
54
filterOk(matchesFuzzyIconAware, 'ccr', parseLabelWithIcons('$(codicon) CamelCaseRocks $(codicon)'), [
55
{ start: 11, end: 12 },
56
{ start: 16, end: 17 },
57
{ start: 20, end: 21 }
58
]);
59
60
filterOk(matchesFuzzyIconAware, 'iut', parseLabelWithIcons('$(codicon) Indent $(octico) Using $(octic) Tpaces'), [
61
{ start: 11, end: 12 },
62
{ start: 28, end: 29 },
63
{ start: 43, end: 44 },
64
]);
65
66
// Prefix
67
68
filterOk(matchesFuzzyIconAware, 'using', parseLabelWithIcons('$(codicon) Indent Using Spaces'), [
69
{ start: 18, end: 23 },
70
]);
71
72
// Broken Codicon
73
74
filterOk(matchesFuzzyIconAware, 'codicon', parseLabelWithIcons('This $(codicon Indent Using Spaces'), [
75
{ start: 7, end: 14 },
76
]);
77
78
filterOk(matchesFuzzyIconAware, 'indent', parseLabelWithIcons('This $codicon Indent Using Spaces'), [
79
{ start: 14, end: 20 },
80
]);
81
82
// Testing #59343
83
filterOk(matchesFuzzyIconAware, 'unt', parseLabelWithIcons('$(primitive-dot) $(file-text) Untitled-1'), [
84
{ start: 30, end: 33 },
85
]);
86
87
// Testing #136172
88
filterOk(matchesFuzzyIconAware, 's', parseLabelWithIcons('$(loading~spin) start'), [
89
{ start: 16, end: 17 },
90
]);
91
});
92
93
test('stripIcons', () => {
94
assert.strictEqual(stripIcons('Hello World'), 'Hello World');
95
assert.strictEqual(stripIcons('$(Hello World'), '$(Hello World');
96
assert.strictEqual(stripIcons('$(Hello) World'), ' World');
97
assert.strictEqual(stripIcons('$(Hello) W$(oi)rld'), ' Wrld');
98
});
99
100
101
test('escapeIcons', () => {
102
assert.strictEqual(escapeIcons('Hello World'), 'Hello World');
103
assert.strictEqual(escapeIcons('$(Hello World'), '$(Hello World');
104
assert.strictEqual(escapeIcons('$(Hello) World'), '\\$(Hello) World');
105
assert.strictEqual(escapeIcons('\\$(Hello) W$(oi)rld'), '\\$(Hello) W\\$(oi)rld');
106
});
107
108
test('markdownEscapeEscapedIcons', () => {
109
assert.strictEqual(markdownEscapeEscapedIcons('Hello World'), 'Hello World');
110
assert.strictEqual(markdownEscapeEscapedIcons('$(Hello) World'), '$(Hello) World');
111
assert.strictEqual(markdownEscapeEscapedIcons('\\$(Hello) World'), '\\\\$(Hello) World');
112
});
113
114
ensureNoDisposablesAreLeakedInTestSuite();
115
});
116
117