Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/test/node/diffing/defaultLinesDiffComputer.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 { Range } from '../../../common/core/range.js';
8
import { getLineRangeMapping, RangeMapping } from '../../../common/diff/rangeMapping.js';
9
import { OffsetRange } from '../../../common/core/ranges/offsetRange.js';
10
import { LinesSliceCharSequence } from '../../../common/diff/defaultLinesDiffComputer/linesSliceCharSequence.js';
11
import { MyersDiffAlgorithm } from '../../../common/diff/defaultLinesDiffComputer/algorithms/myersDiffAlgorithm.js';
12
import { DynamicProgrammingDiffing } from '../../../common/diff/defaultLinesDiffComputer/algorithms/dynamicProgrammingDiffing.js';
13
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../base/test/common/utils.js';
14
import { ArrayText } from '../../../common/core/text/abstractText.js';
15
16
suite('myers', () => {
17
ensureNoDisposablesAreLeakedInTestSuite();
18
19
test('1', () => {
20
const s1 = new LinesSliceCharSequence(['hello world'], new Range(1, 1, 1, Number.MAX_SAFE_INTEGER), true);
21
const s2 = new LinesSliceCharSequence(['hallo welt'], new Range(1, 1, 1, Number.MAX_SAFE_INTEGER), true);
22
23
const a = true ? new MyersDiffAlgorithm() : new DynamicProgrammingDiffing();
24
a.compute(s1, s2);
25
});
26
});
27
28
suite('lineRangeMapping', () => {
29
ensureNoDisposablesAreLeakedInTestSuite();
30
31
test('Simple', () => {
32
assert.deepStrictEqual(
33
getLineRangeMapping(
34
new RangeMapping(
35
new Range(2, 1, 3, 1),
36
new Range(2, 1, 2, 1)
37
),
38
new ArrayText([
39
'const abc = "helloworld".split("");',
40
'',
41
''
42
]),
43
new ArrayText([
44
'const asciiLower = "helloworld".split("");',
45
''
46
])
47
).toString(),
48
"{[2,3)->[2,2)}"
49
);
50
});
51
52
test('Empty Lines', () => {
53
assert.deepStrictEqual(
54
getLineRangeMapping(
55
new RangeMapping(
56
new Range(2, 1, 2, 1),
57
new Range(2, 1, 4, 1),
58
),
59
new ArrayText([
60
'',
61
'',
62
]),
63
new ArrayText([
64
'',
65
'',
66
'',
67
'',
68
])
69
).toString(),
70
"{[2,2)->[2,4)}"
71
);
72
});
73
});
74
75
suite('LinesSliceCharSequence', () => {
76
ensureNoDisposablesAreLeakedInTestSuite();
77
78
const sequence = new LinesSliceCharSequence(
79
[
80
'line1: foo',
81
'line2: fizzbuzz',
82
'line3: barr',
83
'line4: hello world',
84
'line5: bazz',
85
],
86
new Range(2, 1, 5, 1), true
87
);
88
89
test('translateOffset', () => {
90
assert.deepStrictEqual(
91
{ result: OffsetRange.ofLength(sequence.length).map(offset => sequence.translateOffset(offset).toString()) },
92
({
93
result: [
94
"(2,1)", "(2,2)", "(2,3)", "(2,4)", "(2,5)", "(2,6)", "(2,7)", "(2,8)", "(2,9)", "(2,10)", "(2,11)",
95
"(2,12)", "(2,13)", "(2,14)", "(2,15)", "(2,16)",
96
97
"(3,1)", "(3,2)", "(3,3)", "(3,4)", "(3,5)", "(3,6)", "(3,7)", "(3,8)", "(3,9)", "(3,10)", "(3,11)", "(3,12)",
98
99
"(4,1)", "(4,2)", "(4,3)", "(4,4)", "(4,5)", "(4,6)", "(4,7)", "(4,8)", "(4,9)",
100
"(4,10)", "(4,11)", "(4,12)", "(4,13)", "(4,14)", "(4,15)", "(4,16)", "(4,17)",
101
"(4,18)", "(4,19)"
102
]
103
})
104
);
105
});
106
107
test('extendToFullLines', () => {
108
assert.deepStrictEqual(
109
{ result: sequence.getText(sequence.extendToFullLines(new OffsetRange(20, 25))) },
110
({ result: "line3: barr\n" })
111
);
112
113
assert.deepStrictEqual(
114
{ result: sequence.getText(sequence.extendToFullLines(new OffsetRange(20, 45))) },
115
({ result: "line3: barr\nline4: hello world\n" })
116
);
117
});
118
});
119
120