Skip to content

Commit 4764672

Browse files
authored
Use patience diff algorithm (microsoft#891)
1 parent 6cd5949 commit 4764672

File tree

20,791 files changed

+195377
-180167
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

20,791 files changed

+195377
-180167
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/dlclark/regexp2 v1.11.5
77
github.com/go-json-experiment/json v0.0.0-20250517221953-25912455fbc8
88
github.com/google/go-cmp v0.7.0
9-
github.com/pkg/diff v0.0.0-20241224192749-4e6772a4315c
9+
github.com/peter-evans/patience v0.3.0
1010
golang.org/x/sync v0.14.0
1111
golang.org/x/sys v0.33.0
1212
gotest.tools/v3 v3.5.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
1212
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
1313
github.com/matryer/moq v0.5.3 h1:4femQCFmBUwFPYs8VfM5ID7AI67/DTEDRBbTtSWy7GU=
1414
github.com/matryer/moq v0.5.3/go.mod h1:8288Qkw7gMZhUP3cIN86GG7g5p9jRuZH8biXLW4RXvQ=
15-
github.com/pkg/diff v0.0.0-20241224192749-4e6772a4315c h1:8TRxBMS/YsupXoOiGKHr9ZOXo+5DezGWPgBAhBHEHto=
16-
github.com/pkg/diff v0.0.0-20241224192749-4e6772a4315c/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
15+
github.com/peter-evans/patience v0.3.0 h1:rX0JdJeepqdQl1Sk9c9uvorjYYzL2TfgLX1adqYm9cA=
16+
github.com/peter-evans/patience v0.3.0/go.mod h1:Kmxu5sY1NmBLFSStvXjX1wS9mIv7wMcP/ubucyMOAu0=
1717
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1818
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
1919
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=

internal/testutil/baseline/baseline.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import (
1111

1212
"github.com/microsoft/typescript-go/internal/core"
1313
"github.com/microsoft/typescript-go/internal/repo"
14+
"github.com/microsoft/typescript-go/internal/stringutil"
1415
"github.com/microsoft/typescript-go/internal/tspath"
15-
"github.com/pkg/diff"
16+
"github.com/peter-evans/patience"
1617
"gotest.tools/v3/assert"
1718
)
1819

@@ -102,21 +103,27 @@ func readFileOrNoContent(fileName string) string {
102103
return string(content)
103104
}
104105

106+
func diffText(oldName string, newName string, expected string, actual string) string {
107+
lines := patience.Diff(stringutil.SplitLines(expected), stringutil.SplitLines(actual))
108+
return patience.UnifiedDiffTextWithOptions(lines, patience.UnifiedDiffOptions{
109+
Precontext: 3,
110+
Postcontext: 3,
111+
SrcHeader: oldName,
112+
DstHeader: newName,
113+
})
114+
}
115+
105116
func getBaselineDiff(t *testing.T, actual string, expected string, fileName string, fixupOld func(string) string) string {
106117
if fixupOld != nil {
107118
expected = fixupOld(expected)
108119
}
109120
if actual == expected {
110121
return NoContent
111122
}
112-
var b strings.Builder
113-
if err := diff.Text("old."+fileName, "new."+fileName, expected, actual, &b); err != nil {
114-
return fmt.Sprintf("failed to diff the actual and expected content: %v\n", err)
115-
}
123+
s := diffText("old."+fileName, "new."+fileName, expected, actual)
116124

117125
// Remove line numbers from unified diff headers; this avoids adding/deleting
118126
// lines in our baselines from causing knock-on header changes later in the diff.
119-
s := b.String()
120127

121128
aCurLine := 1
122129
bCurLine := 1

testdata/baselines/reference/submodule/compiler/2dArrays.js.diff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
+++ new.2dArrays.js
33
@@= skipped -17, +17 lines =@@
44
}
5-
5+
66
//// [2dArrays.js]
77
-var Cell = /** @class */ (function () {
88
- function Cell() {
@@ -32,4 +32,4 @@
3232
- return Board;
3333
-}());
3434
+ }
35-
+}
35+
+}

testdata/baselines/reference/submodule/compiler/2dArrays.symbols.diff

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,29 @@
22
+++ new.2dArrays.symbols
33
@@= skipped -8, +8 lines =@@
44
>Ship : Symbol(Ship, Decl(2dArrays.ts, 1, 1))
5-
5+
66
isSunk: boolean;
77
->isSunk : Symbol(Ship.isSunk, Decl(2dArrays.ts, 3, 12))
88
+>isSunk : Symbol(isSunk, Decl(2dArrays.ts, 3, 12))
99
}
10-
10+
1111
class Board {
1212
>Board : Symbol(Board, Decl(2dArrays.ts, 5, 1))
13-
13+
1414
ships: Ship[];
1515
->ships : Symbol(Board.ships, Decl(2dArrays.ts, 7, 13))
1616
+>ships : Symbol(ships, Decl(2dArrays.ts, 7, 13))
1717
>Ship : Symbol(Ship, Decl(2dArrays.ts, 1, 1))
18-
18+
1919
cells: Cell[];
2020
->cells : Symbol(Board.cells, Decl(2dArrays.ts, 8, 18))
2121
+>cells : Symbol(cells, Decl(2dArrays.ts, 8, 18))
2222
>Cell : Symbol(Cell, Decl(2dArrays.ts, 0, 0))
23-
23+
2424
private allShipsSunk() {
2525
->allShipsSunk : Symbol(Board.allShipsSunk, Decl(2dArrays.ts, 9, 18))
2626
+>allShipsSunk : Symbol(allShipsSunk, Decl(2dArrays.ts, 9, 18))
27-
27+
2828
return this.ships.every(function (val) { return val.isSunk; });
2929
->this.ships.every : Symbol(Array.every, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
3030
->this.ships : Symbol(Board.ships, Decl(2dArrays.ts, 7, 13))
@@ -33,13 +33,15 @@
3333
>this : Symbol(Board, Decl(2dArrays.ts, 5, 1))
3434
->ships : Symbol(Board.ships, Decl(2dArrays.ts, 7, 13))
3535
->every : Symbol(Array.every, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
36+
->val : Symbol(val, Decl(2dArrays.ts, 12, 42))
37+
->val.isSunk : Symbol(Ship.isSunk, Decl(2dArrays.ts, 3, 12))
38+
->val : Symbol(val, Decl(2dArrays.ts, 12, 42))
39+
->isSunk : Symbol(Ship.isSunk, Decl(2dArrays.ts, 3, 12))
3640
+>ships : Symbol(ships, Decl(2dArrays.ts, 7, 13))
3741
+>every : Symbol(every, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
38-
>val : Symbol(val, Decl(2dArrays.ts, 12, 42))
39-
->val.isSunk : Symbol(Ship.isSunk, Decl(2dArrays.ts, 3, 12))
42+
+>val : Symbol(val, Decl(2dArrays.ts, 12, 42))
4043
+>val.isSunk : Symbol(isSunk, Decl(2dArrays.ts, 3, 12))
41-
>val : Symbol(val, Decl(2dArrays.ts, 12, 42))
42-
->isSunk : Symbol(Ship.isSunk, Decl(2dArrays.ts, 3, 12))
44+
+>val : Symbol(val, Decl(2dArrays.ts, 12, 42))
4345
+>isSunk : Symbol(isSunk, Decl(2dArrays.ts, 3, 12))
4446
}
45-
}
47+
}

testdata/baselines/reference/submodule/compiler/APILibCheck.errors.txt.diff

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
--- old.APILibCheck.errors.txt
22
+++ new.APILibCheck.errors.txt
3-
@@= skipped -0, +-1 lines =@@
3+
@@= skipped -0, +0 lines =@@
44
-<no content>
5-
@@= skipped --1, +1 lines =@@
65
+index.ts(1,21): error TS2307: Cannot find module 'typescript' or its corresponding type declarations.
76
+index.ts(2,29): error TS2307: Cannot find module 'typescript-internal' or its corresponding type declarations.
87
+index.ts(3,34): error TS2307: Cannot find module 'tsserverlibrary' or its corresponding type declarations.
@@ -46,4 +45,4 @@
4645
+ "name": "tsserverlibrary-internal",
4746
+ "types": "/.ts/tsserverlibrary.internal.d.ts"
4847
+ }
49-
+
48+
+

testdata/baselines/reference/submodule/compiler/APISample_Watch.errors.txt.diff

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
--- old.APISample_Watch.errors.txt
22
+++ new.APISample_Watch.errors.txt
3-
@@= skipped -0, +-1 lines =@@
3+
@@= skipped -0, +0 lines =@@
44
-<no content>
5-
@@= skipped --1, +1 lines =@@
65
+APISample_Watch.ts(11,21): error TS2307: Cannot find module 'typescript' or its corresponding type declarations.
76
+APISample_Watch.ts(14,27): error TS7006: Parameter 'path' implicitly has an 'any' type.
87
+APISample_Watch.ts(45,61): error TS7006: Parameter 'options' implicitly has an 'any' type.
@@ -104,4 +103,4 @@
104103
+ "name": "typescript",
105104
+ "types": "/.ts/typescript.d.ts"
106105
+ }
107-
+
106+
+

testdata/baselines/reference/submodule/compiler/APISample_Watch.js.diff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--- old.APISample_Watch.js
22
+++ new.APISample_Watch.js
33
@@= skipped -84, +84 lines =@@
4-
4+
55
//// [APISample_Watch.js]
66
"use strict";
77
-/*
@@ -47,4 +47,4 @@
4747
+ host.afterProgramCreate = program => {
4848
console.log("** We finished making the program! **");
4949
origPostProgramCreate(program);
50-
};
50+
};

testdata/baselines/reference/submodule/compiler/APISample_WatchWithDefaults.errors.txt.diff

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
--- old.APISample_WatchWithDefaults.errors.txt
22
+++ new.APISample_WatchWithDefaults.errors.txt
3-
@@= skipped -0, +-1 lines =@@
3+
@@= skipped -0, +0 lines =@@
44
-<no content>
5-
@@= skipped --1, +1 lines =@@
65
+APISample_WatchWithDefaults.ts(8,21): error TS2307: Cannot find module 'typescript' or its corresponding type declarations.
76
+APISample_WatchWithDefaults.ts(32,27): error TS7006: Parameter 'rootNames' implicitly has an 'any' type.
87
+APISample_WatchWithDefaults.ts(32,38): error TS7006: Parameter 'options' implicitly has an 'any' type.
@@ -77,4 +76,4 @@
7776
+ "name": "typescript",
7877
+ "types": "/.ts/typescript.d.ts"
7978
+ }
80-
+
79+
+

testdata/baselines/reference/submodule/compiler/APISample_WatchWithDefaults.js.diff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--- old.APISample_WatchWithDefaults.js
22
+++ new.APISample_WatchWithDefaults.js
33
@@= skipped -57, +57 lines =@@
4-
4+
55
//// [APISample_WatchWithDefaults.js]
66
"use strict";
77
-/*
@@ -38,4 +38,4 @@
3838
+ host.afterProgramCreate = program => {
3939
console.log("** We finished making the program! **");
4040
origPostProgramCreate(program);
41-
};
41+
};

testdata/baselines/reference/submodule/compiler/APISample_WatchWithOwnWatchHost.errors.txt.diff

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
--- old.APISample_WatchWithOwnWatchHost.errors.txt
22
+++ new.APISample_WatchWithOwnWatchHost.errors.txt
3-
@@= skipped -0, +-1 lines =@@
3+
@@= skipped -0, +0 lines =@@
44
-<no content>
5-
@@= skipped --1, +1 lines =@@
65
+APISample_WatchWithOwnWatchHost.ts(8,21): error TS2307: Cannot find module 'typescript' or its corresponding type declarations.
76
+APISample_WatchWithOwnWatchHost.ts(22,32): error TS7006: Parameter 'options' implicitly has an 'any' type.
87
+APISample_WatchWithOwnWatchHost.ts(39,27): error TS7006: Parameter 'rootNames' implicitly has an 'any' type.
@@ -87,4 +86,4 @@
8786
+ "name": "typescript",
8887
+ "types": "/.ts/typescript.d.ts"
8988
+ }
90-
+
89+
+

testdata/baselines/reference/submodule/compiler/APISample_WatchWithOwnWatchHost.js.diff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--- old.APISample_WatchWithOwnWatchHost.js
22
+++ new.APISample_WatchWithOwnWatchHost.js
33
@@= skipped -64, +64 lines =@@
4-
4+
55
//// [APISample_WatchWithOwnWatchHost.js]
66
"use strict";
77
-/*
@@ -49,4 +49,4 @@
4949
+ host.afterProgramCreate = program => {
5050
console.log("** We finished making the program! **");
5151
origPostProgramCreate(program);
52-
};
52+
};

testdata/baselines/reference/submodule/compiler/APISample_compile.errors.txt.diff

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
--- old.APISample_compile.errors.txt
22
+++ new.APISample_compile.errors.txt
3-
@@= skipped -0, +-1 lines =@@
3+
@@= skipped -0, +0 lines =@@
44
-<no content>
5-
@@= skipped --1, +1 lines =@@
65
+APISample_compile.ts(11,21): error TS2307: Cannot find module 'typescript' or its corresponding type declarations.
76
+APISample_compile.ts(19,28): error TS7006: Parameter 'diagnostic' implicitly has an 'any' type.
87
+
@@ -55,4 +54,4 @@
5554
+ "name": "typescript",
5655
+ "types": "/.ts/typescript.d.ts"
5756
+ }
58-
+
57+
+

testdata/baselines/reference/submodule/compiler/APISample_compile.js.diff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--- old.APISample_compile.js
22
+++ new.APISample_compile.js
33
@@= skipped -47, +47 lines =@@
4-
4+
55
//// [APISample_compile.js]
66
"use strict";
77
-/*
@@ -34,4 +34,4 @@
3434
+ console.log(`Process exiting with code '${exitCode}'.`);
3535
process.exit(exitCode);
3636
}
37-
compile(process.argv.slice(2), {
37+
compile(process.argv.slice(2), {

testdata/baselines/reference/submodule/compiler/APISample_jsdoc.errors.txt.diff

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
--- old.APISample_jsdoc.errors.txt
22
+++ new.APISample_jsdoc.errors.txt
3-
@@= skipped -0, +-1 lines =@@
3+
@@= skipped -0, +0 lines =@@
44
-<no content>
5-
@@= skipped --1, +1 lines =@@
65
+APISample_jsdoc.ts(10,21): error TS2307: Cannot find module 'typescript' or its corresponding type declarations.
76
+APISample_jsdoc.ts(26,47): error TS7006: Parameter 'comment' implicitly has an 'any' type.
87
+APISample_jsdoc.ts(31,20): error TS7006: Parameter 'doc' implicitly has an 'any' type.
@@ -133,4 +132,4 @@
133132
+ tags.push(ts.getJSDocTemplateTag(node));
134133
+ return tags;
135134
+ }
136-
+
135+
+

testdata/baselines/reference/submodule/compiler/APISample_jsdoc.js.diff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--- old.APISample_jsdoc.js
22
+++ new.APISample_jsdoc.js
33
@@= skipped -122, +122 lines =@@
4-
4+
55
//// [APISample_jsdoc.js]
66
"use strict";
77
-/*
@@ -104,4 +104,4 @@
104104
+ const type = ts.getJSDocTypeTag(node);
105105
if (type) {
106106
tags.push(type);
107-
}
107+
}

testdata/baselines/reference/submodule/compiler/APISample_linter.errors.txt.diff

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
--- old.APISample_linter.errors.txt
22
+++ new.APISample_linter.errors.txt
3-
@@= skipped -0, +-1 lines =@@
3+
@@= skipped -0, +0 lines =@@
44
-<no content>
5-
@@= skipped --1, +1 lines =@@
65
+APISample_linter.ts(11,21): error TS2307: Cannot find module 'typescript' or its corresponding type declarations.
76
+
87
+
@@ -78,4 +77,4 @@
7877
+ // delint it
7978
+ delint(sourceFile);
8079
+ });
81-
+
80+
+

testdata/baselines/reference/submodule/compiler/APISample_linter.js.diff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--- old.APISample_linter.js
22
+++ new.APISample_linter.js
33
@@= skipped -73, +73 lines =@@
4-
4+
55
//// [APISample_linter.js]
66
"use strict";
77
-/*
@@ -53,4 +53,4 @@
5353
+ let sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES2015, /*setParentNodes */ true);
5454
// delint it
5555
delint(sourceFile);
56-
});
56+
});

testdata/baselines/reference/submodule/compiler/APISample_parseConfig.errors.txt.diff

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
--- old.APISample_parseConfig.errors.txt
22
+++ new.APISample_parseConfig.errors.txt
3-
@@= skipped -0, +-1 lines =@@
3+
@@= skipped -0, +0 lines =@@
44
-<no content>
5-
@@= skipped --1, +1 lines =@@
65
+APISample_parseConfig.ts(11,21): error TS2307: Cannot find module 'typescript' or its corresponding type declarations.
76
+
87
+
@@ -50,4 +49,4 @@
5049
+ "name": "typescript",
5150
+ "types": "/.ts/typescript.d.ts"
5251
+ }
53-
+
52+
+

testdata/baselines/reference/submodule/compiler/APISample_parseConfig.js.diff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--- old.APISample_parseConfig.js
22
+++ new.APISample_parseConfig.js
33
@@= skipped -45, +45 lines =@@
4-
4+
55
//// [APISample_parseConfig.js]
66
"use strict";
77
-/*
@@ -37,4 +37,4 @@
3737
+ for (const err of settings.errors) {
3838
printError(err);
3939
}
40-
return undefined;
40+
return undefined;

0 commit comments

Comments
 (0)