Skip to content

Commit 5237ed7

Browse files
Merge pull request microsoft#1482 from Microsoft/typingHighFidelity
Move test helpers into the harness Utils module.
2 parents c3ad5b2 + b09e92e commit 5237ed7

29 files changed

+172
-296
lines changed

Jakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ function deleteTemporaryProjectOutput() {
485485
}
486486
}
487487

488-
var testTimeout = 5000;
488+
var testTimeout = 20000;
489489
desc("Runs the tests using the built run.js file. Syntax is jake runtests. Optional parameters 'host=', 'tests=[regex], reporter=[list|spec|json|<more>]'.");
490490
task("runtests", ["tests", builtLocalDirectory], function() {
491491
cleanTestDirs();

src/harness/fourslash.ts

Lines changed: 59 additions & 119 deletions
Large diffs are not rendered by default.

src/harness/harness.ts

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,64 @@ module Utils {
290290
return o;
291291
}
292292
}
293+
294+
export function assertStructuralEquals(node1: ts.Node, node2: ts.Node) {
295+
if (node1 === node2) {
296+
return;
297+
}
298+
299+
assert(node1, "node1");
300+
assert(node2, "node2");
301+
assert.equal(node1.pos, node2.pos, "node1.pos !== node2.pos");
302+
assert.equal(node1.end, node2.end, "node1.end !== node2.end");
303+
assert.equal(node1.kind, node2.kind, "node1.kind !== node2.kind");
304+
assert.equal(node1.flags, node2.flags, "node1.flags !== node2.flags");
305+
306+
// call this on both nodes to ensure all propagated flags have been set (and thus can be
307+
// compared).
308+
assert.equal(ts.containsParseError(node1), ts.containsParseError(node2));
309+
assert.equal(node1.parserContextFlags, node2.parserContextFlags, "node1.parserContextFlags !== node2.parserContextFlags");
310+
311+
ts.forEachChild(node1,
312+
child1 => {
313+
var childName = findChildName(node1, child1);
314+
var child2: ts.Node = (<any>node2)[childName];
315+
316+
assertStructuralEquals(child1, child2);
317+
},
318+
(array1: ts.NodeArray<ts.Node>) => {
319+
var childName = findChildName(node1, array1);
320+
var array2: ts.NodeArray<ts.Node> = (<any>node2)[childName];
321+
322+
assertArrayStructuralEquals(array1, array2);
323+
});
324+
}
325+
326+
function assertArrayStructuralEquals(array1: ts.NodeArray<ts.Node>, array2: ts.NodeArray<ts.Node>) {
327+
if (array1 === array2) {
328+
return;
329+
}
330+
331+
assert(array1, "array1");
332+
assert(array2, "array2");
333+
assert.equal(array1.pos, array2.pos, "array1.pos !== array2.pos");
334+
assert.equal(array1.end, array2.end, "array1.end !== array2.end");
335+
assert.equal(array1.length, array2.length, "array1.length !== array2.length");
336+
337+
for (var i = 0, n = array1.length; i < n; i++) {
338+
assertStructuralEquals(array1[i], array2[i]);
339+
}
340+
}
341+
342+
function findChildName(parent: any, child: any) {
343+
for (var name in parent) {
344+
if (parent.hasOwnProperty(name) && parent[name] === child) {
345+
return name;
346+
}
347+
}
348+
349+
throw new Error("Could not find child in parent");
350+
}
293351
}
294352

295353
module Harness.Path {
@@ -772,7 +830,7 @@ module Harness {
772830
writeFile,
773831
getCanonicalFileName,
774832
useCaseSensitiveFileNames: () => useCaseSensitiveFileNames,
775-
getNewLine: ()=> ts.sys.newLine
833+
getNewLine: () => ts.sys.newLine
776834
};
777835
}
778836

@@ -814,7 +872,7 @@ module Harness {
814872
}
815873

816874
public emitAll(ioHost?: IEmitterIOHost) {
817-
this.compileFiles(this.inputFiles, [], (result) => {
875+
this.compileFiles(this.inputFiles, [],(result) => {
818876
result.files.forEach(file => {
819877
ioHost.writeFile(file.fileName, file.code, false);
820878
});
@@ -824,7 +882,7 @@ module Harness {
824882
result.sourceMaps.forEach(file => {
825883
ioHost.writeFile(file.fileName, file.code, false);
826884
});
827-
}, () => { }, this.compileOptions);
885+
},() => { }, this.compileOptions);
828886
}
829887

830888
public compileFiles(inputFiles: { unitName: string; content: string }[],
@@ -962,7 +1020,7 @@ module Harness {
9621020
break;
9631021

9641022
case 'includebuiltfile':
965-
inputFiles.push({ unitName: setting.value, content: IO.readFile(libFolder + setting.value)});
1023+
inputFiles.push({ unitName: setting.value, content: IO.readFile(libFolder + setting.value) });
9661024
break;
9671025

9681026
default:
@@ -1071,7 +1129,7 @@ module Harness {
10711129
return ts.removeFileExtension(sourceFileName) + ".d.ts";
10721130
}
10731131
});
1074-
1132+
10751133
return ts.forEach(result.declFilesCode, declFile => declFile.fileName === dTsFileName ? declFile : undefined);
10761134
}
10771135

@@ -1584,4 +1642,4 @@ module Harness {
15841642
}
15851643

15861644
// TODO: not sure why Utils.evalFile isn't working with this, eventually will concat it like old compiler instead of eval
1587-
eval(Harness.tcServicesFile);
1645+
eval(Harness.tcServicesFile);

tests/cases/fourslash/addMemberToInterface.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
//// }
1010

1111
edit.disableFormatting();
12-
diagnostics.setEditValidation(IncrementalEditValidation.SyntacticOnly);
1312

1413
goTo.marker('check');
1514
verify.quickInfoIs('module Mod');
Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
/// <reference path="fourslash.ts" />
2-
1+
/// <reference path="fourslash.ts" />
2+
33
////module A {
44
//// /*var*/
55
////}
66
////module /*check*/A {
77
//// var p;
8-
////}
9-
10-
diagnostics.setEditValidation(IncrementalEditValidation.SyntacticOnly);
11-
12-
goTo.marker('check');
13-
verify.quickInfoExists();
14-
15-
goTo.marker('var');
16-
edit.insert('var o;');
17-
18-
goTo.marker('check');
19-
verify.quickInfoExists();
20-
8+
////}
9+
10+
goTo.marker('check');
11+
verify.quickInfoExists();
12+
13+
goTo.marker('var');
14+
edit.insert('var o;');
15+
16+
goTo.marker('check');
17+
verify.quickInfoExists();
18+

tests/cases/fourslash/cancellationWhenfindingAllRefsOnDefinition.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
////second.start();
2424
////second.stop();
2525

26-
diagnostics.setEditValidation(IncrementalEditValidation.None);
27-
2826
goTo.file("findAllRefsOnDefinition-import.ts");
2927
goTo.marker("1");
3028

@@ -38,4 +36,3 @@ verifyOperationIsCancelled(() => verify.referencesCountIs(0) );
3836
cancellation.resetCancelled();
3937
goTo.marker("1");
4038
verify.referencesCountIs(2);
41-

tests/cases/fourslash/cloduleAsBaseClass.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
// this line triggers a semantic/syntactic error check, remove line when 788570 is fixed
2727
edit.insert('');
2828

29-
diagnostics.setTypingFidelity(TypingFidelity.High);
30-
3129
goTo.marker('1');
3230
verify.completionListContains('foo');
3331
verify.completionListContains('foo2');

tests/cases/fourslash/cloduleAsBaseClass2.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
// this line triggers a semantic/syntactic error check, remove line when 788570 is fixed
3232
edit.insert('');
33-
diagnostics.setTypingFidelity(TypingFidelity.High);
3433

3534
goTo.marker('1');
3635
verify.completionListContains('foo');

tests/cases/fourslash/completionBeforeSemanticDiagnosticsInArrowFunction1.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
//// var f4 = <T>(x: T/**/ ) => {
44
//// }
55

6-
// Turn off edit validation. We don't want semantic diagnostics to run until we explicit call it.
7-
fs.diagnostics.setEditValidation(IncrementalEditValidation.None);
8-
96
fs.goTo.marker();
107

118
// Replace the "T" type with the non-existent type 'V'.

tests/cases/fourslash/completionEntryForPrimitive.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
////var x = Object.create(/**/
44

5-
diagnostics.setEditValidation(IncrementalEditValidation.None);
65
goTo.marker();
76
verify.not.completionListIsEmpty();
87
edit.insert("nu");

0 commit comments

Comments
 (0)