Path: blob/main/src/vs/editor/test/node/diffing/defaultLinesDiffComputer.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 { Range } from '../../../common/core/range.js';7import { getLineRangeMapping, RangeMapping } from '../../../common/diff/rangeMapping.js';8import { OffsetRange } from '../../../common/core/ranges/offsetRange.js';9import { LinesSliceCharSequence } from '../../../common/diff/defaultLinesDiffComputer/linesSliceCharSequence.js';10import { MyersDiffAlgorithm } from '../../../common/diff/defaultLinesDiffComputer/algorithms/myersDiffAlgorithm.js';11import { DynamicProgrammingDiffing } from '../../../common/diff/defaultLinesDiffComputer/algorithms/dynamicProgrammingDiffing.js';12import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../base/test/common/utils.js';13import { ArrayText } from '../../../common/core/text/abstractText.js';1415suite('myers', () => {16ensureNoDisposablesAreLeakedInTestSuite();1718test('1', () => {19const s1 = new LinesSliceCharSequence(['hello world'], new Range(1, 1, 1, Number.MAX_SAFE_INTEGER), true);20const s2 = new LinesSliceCharSequence(['hallo welt'], new Range(1, 1, 1, Number.MAX_SAFE_INTEGER), true);2122const a = true ? new MyersDiffAlgorithm() : new DynamicProgrammingDiffing();23a.compute(s1, s2);24});25});2627suite('lineRangeMapping', () => {28ensureNoDisposablesAreLeakedInTestSuite();2930test('Simple', () => {31assert.deepStrictEqual(32getLineRangeMapping(33new RangeMapping(34new Range(2, 1, 3, 1),35new Range(2, 1, 2, 1)36),37new ArrayText([38'const abc = "helloworld".split("");',39'',40''41]),42new ArrayText([43'const asciiLower = "helloworld".split("");',44''45])46).toString(),47"{[2,3)->[2,2)}"48);49});5051test('Empty Lines', () => {52assert.deepStrictEqual(53getLineRangeMapping(54new RangeMapping(55new Range(2, 1, 2, 1),56new Range(2, 1, 4, 1),57),58new ArrayText([59'',60'',61]),62new ArrayText([63'',64'',65'',66'',67])68).toString(),69"{[2,2)->[2,4)}"70);71});72});7374suite('LinesSliceCharSequence', () => {75ensureNoDisposablesAreLeakedInTestSuite();7677const sequence = new LinesSliceCharSequence(78[79'line1: foo',80'line2: fizzbuzz',81'line3: barr',82'line4: hello world',83'line5: bazz',84],85new Range(2, 1, 5, 1), true86);8788test('translateOffset', () => {89assert.deepStrictEqual(90{ result: OffsetRange.ofLength(sequence.length).map(offset => sequence.translateOffset(offset).toString()) },91({92result: [93"(2,1)", "(2,2)", "(2,3)", "(2,4)", "(2,5)", "(2,6)", "(2,7)", "(2,8)", "(2,9)", "(2,10)", "(2,11)",94"(2,12)", "(2,13)", "(2,14)", "(2,15)", "(2,16)",9596"(3,1)", "(3,2)", "(3,3)", "(3,4)", "(3,5)", "(3,6)", "(3,7)", "(3,8)", "(3,9)", "(3,10)", "(3,11)", "(3,12)",9798"(4,1)", "(4,2)", "(4,3)", "(4,4)", "(4,5)", "(4,6)", "(4,7)", "(4,8)", "(4,9)",99"(4,10)", "(4,11)", "(4,12)", "(4,13)", "(4,14)", "(4,15)", "(4,16)", "(4,17)",100"(4,18)", "(4,19)"101]102})103);104});105106test('extendToFullLines', () => {107assert.deepStrictEqual(108{ result: sequence.getText(sequence.extendToFullLines(new OffsetRange(20, 25))) },109({ result: "line3: barr\n" })110);111112assert.deepStrictEqual(113{ result: sequence.getText(sequence.extendToFullLines(new OffsetRange(20, 45))) },114({ result: "line3: barr\nline4: hello world\n" })115);116});117});118119120