Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/base/test/browser/highlightedLabel.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 { HighlightedLabel } from '../../browser/ui/highlightedlabel/highlightedLabel.js';
8
import { ensureNoDisposablesAreLeakedInTestSuite } from '../common/utils.js';
9
10
suite('HighlightedLabel', () => {
11
let label: HighlightedLabel;
12
13
setup(() => {
14
label = new HighlightedLabel(document.createElement('div'), { supportIcons: true });
15
});
16
17
test('empty label', function () {
18
assert.strictEqual(label.element.innerHTML, '');
19
});
20
21
test('no decorations', function () {
22
label.set('hello');
23
assert.strictEqual(label.element.innerHTML, 'hello');
24
});
25
26
test('escape html', function () {
27
label.set('hel<lo');
28
assert.strictEqual(label.element.innerHTML, 'hel&lt;lo');
29
});
30
31
test('everything highlighted', function () {
32
label.set('hello', [{ start: 0, end: 5 }]);
33
assert.strictEqual(label.element.innerHTML, '<span class="highlight">hello</span>');
34
});
35
36
test('beginning highlighted', function () {
37
label.set('hellothere', [{ start: 0, end: 5 }]);
38
assert.strictEqual(label.element.innerHTML, '<span class="highlight">hello</span>there');
39
});
40
41
test('ending highlighted', function () {
42
label.set('goodbye', [{ start: 4, end: 7 }]);
43
assert.strictEqual(label.element.innerHTML, 'good<span class="highlight">bye</span>');
44
});
45
46
test('middle highlighted', function () {
47
label.set('foobarfoo', [{ start: 3, end: 6 }]);
48
assert.strictEqual(label.element.innerHTML, 'foo<span class="highlight">bar</span>foo');
49
});
50
51
test('escapeNewLines', () => {
52
53
let highlights = [{ start: 0, end: 5 }, { start: 7, end: 9 }, { start: 11, end: 12 }];// before,after,after
54
let escaped = HighlightedLabel.escapeNewLines('ACTION\r\n_TYPE2', highlights);
55
assert.strictEqual(escaped, 'ACTION\u23CE_TYPE2');
56
assert.deepStrictEqual(highlights, [{ start: 0, end: 5 }, { start: 6, end: 8 }, { start: 10, end: 11 }]);
57
58
highlights = [{ start: 5, end: 9 }, { start: 11, end: 12 }];//overlap,after
59
escaped = HighlightedLabel.escapeNewLines('ACTION\r\n_TYPE2', highlights);
60
assert.strictEqual(escaped, 'ACTION\u23CE_TYPE2');
61
assert.deepStrictEqual(highlights, [{ start: 5, end: 8 }, { start: 10, end: 11 }]);
62
});
63
64
teardown(() => {
65
label.dispose();
66
});
67
68
ensureNoDisposablesAreLeakedInTestSuite();
69
});
70
71