Merge from vscode c58aaab8a1cc22a7139b761166a0d4f37d41e998 (#7880)

* Merge from vscode c58aaab8a1cc22a7139b761166a0d4f37d41e998

* fix pipelines

* fix strict-null-checks

* add missing files
This commit is contained in:
Anthony Dresser
2019-10-21 22:12:22 -07:00
committed by GitHub
parent 7c9be74970
commit 1e22f47304
913 changed files with 18898 additions and 16536 deletions

View File

@@ -4,21 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { LcsDiff, IDiffChange, ISequence } from 'vs/base/common/diff/diff';
class StringDiffSequence implements ISequence {
constructor(private source: string) {
}
getLength() {
return this.source.length;
}
getElementAtIndex(i: number) {
return this.source.charCodeAt(i);
}
}
import { LcsDiff, IDiffChange, StringDiffSequence } from 'vs/base/common/diff/diff';
function createArray<T>(length: number, value: T): T[] {
const r: T[] = [];
@@ -71,9 +57,9 @@ function assertAnswer(originalStr: string, modifiedStr: string, changes: IDiffCh
}
}
function lcsInnerTest(Algorithm: any, originalStr: string, modifiedStr: string, answerStr: string, onlyLength: boolean = false): void {
let diff = new Algorithm(new StringDiffSequence(originalStr), new StringDiffSequence(modifiedStr));
let changes = diff.ComputeDiff();
function lcsInnerTest(originalStr: string, modifiedStr: string, answerStr: string, onlyLength: boolean = false): void {
let diff = new LcsDiff(new StringDiffSequence(originalStr), new StringDiffSequence(modifiedStr));
let changes = diff.ComputeDiff(false).changes;
assertAnswer(originalStr, modifiedStr, changes, answerStr, onlyLength);
}
@@ -85,32 +71,28 @@ function stringPower(str: string, power: number): string {
return r;
}
function lcsTest(Algorithm: any, originalStr: string, modifiedStr: string, answerStr: string) {
lcsInnerTest(Algorithm, originalStr, modifiedStr, answerStr);
function lcsTest(originalStr: string, modifiedStr: string, answerStr: string) {
lcsInnerTest(originalStr, modifiedStr, answerStr);
for (let i = 2; i <= 5; i++) {
lcsInnerTest(Algorithm, stringPower(originalStr, i), stringPower(modifiedStr, i), stringPower(answerStr, i), true);
lcsInnerTest(stringPower(originalStr, i), stringPower(modifiedStr, i), stringPower(answerStr, i), true);
}
}
function lcsTests(Algorithm: any) {
lcsTest(Algorithm, 'heLLo world', 'hello orlando', 'heo orld');
lcsTest(Algorithm, 'abcde', 'acd', 'acd'); // simple
lcsTest(Algorithm, 'abcdbce', 'bcede', 'bcde'); // skip
lcsTest(Algorithm, 'abcdefgabcdefg', 'bcehafg', 'bceafg'); // long
lcsTest(Algorithm, 'abcde', 'fgh', ''); // no match
lcsTest(Algorithm, 'abcfabc', 'fabc', 'fabc');
lcsTest(Algorithm, '0azby0', '9axbzby9', 'azby');
lcsTest(Algorithm, '0abc00000', '9a1b2c399999', 'abc');
lcsTest(Algorithm, 'fooBar', 'myfooBar', 'fooBar'); // all insertions
lcsTest(Algorithm, 'fooBar', 'fooMyBar', 'fooBar'); // all insertions
lcsTest(Algorithm, 'fooBar', 'fooBar', 'fooBar'); // identical sequences
}
suite('Diff', () => {
test('LcsDiff - different strings tests', function () {
this.timeout(10000);
lcsTests(LcsDiff);
lcsTest('heLLo world', 'hello orlando', 'heo orld');
lcsTest('abcde', 'acd', 'acd'); // simple
lcsTest('abcdbce', 'bcede', 'bcde'); // skip
lcsTest('abcdefgabcdefg', 'bcehafg', 'bceafg'); // long
lcsTest('abcde', 'fgh', ''); // no match
lcsTest('abcfabc', 'fabc', 'fabc');
lcsTest('0azby0', '9axbzby9', 'azby');
lcsTest('0abc00000', '9a1b2c399999', 'abc');
lcsTest('fooBar', 'myfooBar', 'fooBar'); // all insertions
lcsTest('fooBar', 'fooMyBar', 'fooBar'); // all insertions
lcsTest('fooBar', 'fooBar', 'fooBar'); // identical sequences
});
});
@@ -123,18 +105,17 @@ suite('Diff - Ported from VS', () => {
// doesn't get there first.
let predicateCallCount = 0;
let diff = new LcsDiff(new StringDiffSequence(left), new StringDiffSequence(right), function (leftIndex, leftSequence, longestMatchSoFar) {
let diff = new LcsDiff(new StringDiffSequence(left), new StringDiffSequence(right), function (leftIndex, longestMatchSoFar) {
assert.equal(predicateCallCount, 0);
predicateCallCount++;
assert.equal(leftSequence.getLength(), left.length);
assert.equal(leftIndex, 1);
// cancel processing
return false;
});
let changes = diff.ComputeDiff(true);
let changes = diff.ComputeDiff(true).changes;
assert.equal(predicateCallCount, 1);
@@ -144,26 +125,26 @@ suite('Diff - Ported from VS', () => {
// Cancel after the first match ('c')
diff = new LcsDiff(new StringDiffSequence(left), new StringDiffSequence(right), function (leftIndex, leftSequence, longestMatchSoFar) {
diff = new LcsDiff(new StringDiffSequence(left), new StringDiffSequence(right), function (leftIndex, longestMatchSoFar) {
assert(longestMatchSoFar <= 1); // We never see a match of length > 1
// Continue processing as long as there hasn't been a match made.
return longestMatchSoFar < 1;
});
changes = diff.ComputeDiff(true);
changes = diff.ComputeDiff(true).changes;
assertAnswer(left, right, changes, 'abcf');
// Cancel after the second match ('d')
diff = new LcsDiff(new StringDiffSequence(left), new StringDiffSequence(right), function (leftIndex, leftSequence, longestMatchSoFar) {
diff = new LcsDiff(new StringDiffSequence(left), new StringDiffSequence(right), function (leftIndex, longestMatchSoFar) {
assert(longestMatchSoFar <= 2); // We never see a match of length > 2
// Continue processing as long as there hasn't been a match made.
return longestMatchSoFar < 2;
});
changes = diff.ComputeDiff(true);
changes = diff.ComputeDiff(true).changes;
assertAnswer(left, right, changes, 'abcdf');
@@ -171,7 +152,7 @@ suite('Diff - Ported from VS', () => {
// Cancel *one iteration* after the second match ('d')
let hitSecondMatch = false;
diff = new LcsDiff(new StringDiffSequence(left), new StringDiffSequence(right), function (leftIndex, leftSequence, longestMatchSoFar) {
diff = new LcsDiff(new StringDiffSequence(left), new StringDiffSequence(right), function (leftIndex, longestMatchSoFar) {
assert(longestMatchSoFar <= 2); // We never see a match of length > 2
let hitYet = hitSecondMatch;
@@ -179,20 +160,20 @@ suite('Diff - Ported from VS', () => {
// Continue processing as long as there hasn't been a match made.
return !hitYet;
});
changes = diff.ComputeDiff(true);
changes = diff.ComputeDiff(true).changes;
assertAnswer(left, right, changes, 'abcdf');
// Cancel after the third and final match ('e')
diff = new LcsDiff(new StringDiffSequence(left), new StringDiffSequence(right), function (leftIndex, leftSequence, longestMatchSoFar) {
diff = new LcsDiff(new StringDiffSequence(left), new StringDiffSequence(right), function (leftIndex, longestMatchSoFar) {
assert(longestMatchSoFar <= 3); // We never see a match of length > 3
// Continue processing as long as there hasn't been a match made.
return longestMatchSoFar < 3;
});
changes = diff.ComputeDiff(true);
changes = diff.ComputeDiff(true).changes;
assertAnswer(left, right, changes, 'abcdef');
});