Path: blob/main/src/vs/workbench/contrib/editTelemetry/test/common/arcTracker.test.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import assert from 'assert';6import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';7import { StringText } from '../../../../../editor/common/core/text/abstractText.js';8import { computeStringDiff } from '../../../../../editor/common/services/editorWebWorker.js';9import { ArcTracker } from '../../common/arcTracker.js';1011suite('ArcTracker', () => {12ensureNoDisposablesAreLeakedInTestSuite();1314test('https://github.com/microsoft/vscode/issues/264048 - Line number count should decrease', () => {1516const states = [17`TODO: Add Charlie18Alpha19Bravo20Delta`,21`Alpha22Bravo23Delta24Charlie`,25`* Alpha26* Bravo27* Delta28* Charlie`,29`ICAO spelling alphabet:30* Alpha31* Bravo32* Delta33* Charlie`34];3536const edits = compareAdjacentItems(states, (a, b) => computeStringDiff(a, b, { maxComputationTimeMs: 0 }, 'advanced'));3738const t = new ArcTracker(39new StringText(states[0]),40edits[0]41);4243const data: unknown[] = [];44data.push(t.getLineCountInfo());4546for (let i = 1; i < edits.length; i++) {47t.handleEdits(edits[i]);48data.push(t.getLineCountInfo());49}50assert.deepStrictEqual(data, ([51{52deletedLineCounts: 1,53insertedLineCounts: 154},55{56deletedLineCounts: 0,57insertedLineCounts: 158},59{60deletedLineCounts: 0,61insertedLineCounts: 162}63]));64});65});6667function compareAdjacentItems<T, TResult>(arr: T[], comparator: (a: T, b: T) => TResult): TResult[] {68const result: TResult[] = [];69for (let i = 0; i < arr.length - 1; i++) {70result.push(comparator(arr[i], arr[i + 1]));71}72return result;73}747576