Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/contrib/folding/test/browser/indentFold.test.ts
4780 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
import assert from 'assert';
6
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';
7
import { computeRanges } from '../../browser/indentRangeProvider.js';
8
import { createTextModel } from '../../../../test/common/testTextModel.js';
9
10
interface IndentRange {
11
start: number;
12
end: number;
13
}
14
15
suite('Indentation Folding', () => {
16
ensureNoDisposablesAreLeakedInTestSuite();
17
18
function r(start: number, end: number): IndentRange {
19
return { start, end };
20
}
21
22
test('Limit by indent', () => {
23
24
25
const lines = [
26
/* 1*/ 'A',
27
/* 2*/ ' A',
28
/* 3*/ ' A',
29
/* 4*/ ' A',
30
/* 5*/ ' A',
31
/* 6*/ ' A',
32
/* 7*/ ' A',
33
/* 8*/ ' A',
34
/* 9*/ ' A',
35
/* 10*/ ' A',
36
/* 11*/ ' A',
37
/* 12*/ ' A',
38
/* 13*/ ' A',
39
/* 14*/ ' A',
40
/* 15*/ 'A',
41
/* 16*/ ' A'
42
];
43
const r1 = r(1, 14); //0
44
const r2 = r(3, 11); //1
45
const r3 = r(4, 5); //2
46
const r4 = r(6, 11); //2
47
const r5 = r(8, 9); //3
48
const r6 = r(10, 11); //3
49
const r7 = r(12, 14); //1
50
const r8 = r(13, 14);//4
51
const r9 = r(15, 16);//0
52
53
const model = createTextModel(lines.join('\n'));
54
55
function assertLimit(maxEntries: number, expectedRanges: IndentRange[], message: string) {
56
let reported: number | false = false;
57
const indentRanges = computeRanges(model, true, undefined, { limit: maxEntries, update: (computed, limited) => reported = limited });
58
assert.ok(indentRanges.length <= maxEntries, 'max ' + message);
59
const actual: IndentRange[] = [];
60
for (let i = 0; i < indentRanges.length; i++) {
61
actual.push({ start: indentRanges.getStartLineNumber(i), end: indentRanges.getEndLineNumber(i) });
62
}
63
assert.deepStrictEqual(actual, expectedRanges, message);
64
assert.equal(reported, 9 <= maxEntries ? false : maxEntries, 'limited');
65
}
66
67
assertLimit(1000, [r1, r2, r3, r4, r5, r6, r7, r8, r9], '1000');
68
assertLimit(9, [r1, r2, r3, r4, r5, r6, r7, r8, r9], '9');
69
assertLimit(8, [r1, r2, r3, r4, r5, r6, r7, r9], '8');
70
assertLimit(7, [r1, r2, r3, r4, r5, r7, r9], '7');
71
assertLimit(6, [r1, r2, r3, r4, r7, r9], '6');
72
assertLimit(5, [r1, r2, r3, r7, r9], '5');
73
assertLimit(4, [r1, r2, r7, r9], '4');
74
assertLimit(3, [r1, r2, r9], '3');
75
assertLimit(2, [r1, r9], '2');
76
assertLimit(1, [r1], '1');
77
assertLimit(0, [], '0');
78
79
model.dispose();
80
});
81
82
});
83
84