Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/test/common/viewModel/glyphLanesModel.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 { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../base/test/common/utils.js';
8
import { GlyphMarginLanesModel, } from '../../../common/viewModel/glyphLanesModel.js';
9
import { Range } from '../../../common/core/range.js';
10
import { GlyphMarginLane } from '../../../common/model.js';
11
12
suite('GlyphLanesModel', () => {
13
let model: GlyphMarginLanesModel;
14
15
ensureNoDisposablesAreLeakedInTestSuite();
16
17
const lineRange = (startLineNumber: number, endLineNumber: number) => new Range(startLineNumber, 1, endLineNumber, 1);
18
const assertLines = (fromLine: number, n: number, expected: GlyphMarginLane[][]) => {
19
const result: GlyphMarginLane[][] = [];
20
for (let i = 0; i < n; i++) {
21
result.push(model.getLanesAtLine(fromLine + i));
22
}
23
assert.deepStrictEqual(result, expected, `fromLine: ${fromLine}, n: ${n}`);
24
};
25
26
setup(() => {
27
model = new GlyphMarginLanesModel(10);
28
});
29
30
test('handles empty', () => {
31
assert.equal(model.requiredLanes, 1);
32
assertLines(1, 1, [
33
[GlyphMarginLane.Center],
34
]);
35
});
36
37
test('works with a single line range', () => {
38
model.push(GlyphMarginLane.Left, lineRange(2, 3));
39
assert.equal(model.requiredLanes, 1);
40
assertLines(1, 5, [
41
[GlyphMarginLane.Center], // 1
42
[GlyphMarginLane.Left], // 2
43
[GlyphMarginLane.Left], // 3
44
[GlyphMarginLane.Center], // 4
45
[GlyphMarginLane.Center], // 5
46
]);
47
});
48
49
test('persists ranges', () => {
50
model.push(GlyphMarginLane.Left, lineRange(2, 3), true);
51
assert.equal(model.requiredLanes, 1);
52
assertLines(1, 5, [
53
[GlyphMarginLane.Left], // 1
54
[GlyphMarginLane.Left], // 2
55
[GlyphMarginLane.Left], // 3
56
[GlyphMarginLane.Left], // 4
57
[GlyphMarginLane.Left], // 5
58
]);
59
});
60
61
test('handles overlaps', () => {
62
model.push(GlyphMarginLane.Left, lineRange(6, 9));
63
model.push(GlyphMarginLane.Right, lineRange(5, 7));
64
model.push(GlyphMarginLane.Center, lineRange(7, 8));
65
assert.equal(model.requiredLanes, 3);
66
assertLines(5, 6, [
67
[GlyphMarginLane.Right], // 5
68
[GlyphMarginLane.Left, GlyphMarginLane.Right], // 6
69
[GlyphMarginLane.Left, GlyphMarginLane.Center, GlyphMarginLane.Right], // 7
70
[GlyphMarginLane.Left, GlyphMarginLane.Center], // 8
71
[GlyphMarginLane.Left], // 9
72
[GlyphMarginLane.Center], // 10
73
]);
74
});
75
});
76
77