Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/editTelemetry/test/common/arcTracker.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 { StringText } from '../../../../../editor/common/core/text/abstractText.js';
9
import { computeStringDiff } from '../../../../../editor/common/services/editorWebWorker.js';
10
import { ArcTracker } from '../../common/arcTracker.js';
11
12
suite('ArcTracker', () => {
13
ensureNoDisposablesAreLeakedInTestSuite();
14
15
test('https://github.com/microsoft/vscode/issues/264048 - Line number count should decrease', () => {
16
17
const states = [
18
`TODO: Add Charlie
19
Alpha
20
Bravo
21
Delta`,
22
`Alpha
23
Bravo
24
Delta
25
Charlie`,
26
`* Alpha
27
* Bravo
28
* Delta
29
* Charlie`,
30
`ICAO spelling alphabet:
31
* Alpha
32
* Bravo
33
* Delta
34
* Charlie`
35
];
36
37
const edits = compareAdjacentItems(states, (a, b) => computeStringDiff(a, b, { maxComputationTimeMs: 0 }, 'advanced'));
38
39
const t = new ArcTracker(
40
new StringText(states[0]),
41
edits[0]
42
);
43
44
const data: unknown[] = [];
45
data.push(t.getLineCountInfo());
46
47
for (let i = 1; i < edits.length; i++) {
48
t.handleEdits(edits[i]);
49
data.push(t.getLineCountInfo());
50
}
51
assert.deepStrictEqual(data, ([
52
{
53
deletedLineCounts: 1,
54
insertedLineCounts: 1
55
},
56
{
57
deletedLineCounts: 0,
58
insertedLineCounts: 1
59
},
60
{
61
deletedLineCounts: 0,
62
insertedLineCounts: 1
63
}
64
]));
65
});
66
});
67
68
function compareAdjacentItems<T, TResult>(arr: T[], comparator: (a: T, b: T) => TResult): TResult[] {
69
const result: TResult[] = [];
70
for (let i = 0; i < arr.length - 1; i++) {
71
result.push(comparator(arr[i], arr[i + 1]));
72
}
73
return result;
74
}
75
76