Incremental parser tests should verify the same set of diagnostics are produced.

This commit is contained in:
Cyrus Najmabadi
2014-12-10 19:07:36 -08:00
parent fc27f72324
commit 563b234240

View File

@@ -21,6 +21,26 @@ module ts {
return createLanguageServiceSourceFile(/*fileName:*/ "", text, ScriptTarget.ES5, version, /*isOpen:*/ true, /*setNodeParents:*/ true)
}
function assertSameDiagnostics(file1: SourceFile, file2: SourceFile) {
var diagnostics1 = file1.getSyntacticDiagnostics();
var diagnostics2 = file2.getSyntacticDiagnostics();
assert.equal(diagnostics1.length, diagnostics2.length, "diagnostics1.length !== diagnostics2.length");
for (var i = 0, n = diagnostics1.length; i < n; i++) {
var d1 = diagnostics1[i];
var d2 = diagnostics2[i];
assert.equal(d1.file, file1, "d1.file !== file1");
assert.equal(d2.file, file2, "d2.file !== file2");
assert.equal(d1.start, d2.start, "d1.start !== d2.start");
assert.equal(d1.length, d2.length, "d1.length !== d2.length");
assert.equal(d1.messageText, d2.messageText, "d1.messageText !== d2.messageText");
assert.equal(d1.category, d2.category, "d1.category !== d2.category");
assert.equal(d1.code, d2.code, "d1.code !== d2.code");
assert.equal(d1.isEarly, d2.isEarly, "d1.isEarly !== d2.isEarly");
}
}
// NOTE: 'reusedElements' is the expected count of elements reused from the old tree to the new
// tree. It may change as we tweak the parser. If the count increases then that should always
// be a good thing. If it decreases, that's not great (less reusability), but that may be
@@ -41,6 +61,9 @@ module ts {
// We should get the same tree when doign a full or incremental parse.
assertStructuralEquals(newTree, incrementalNewTree);
// We should also get the exact same set of diagnostics.
assertSameDiagnostics(newTree, incrementalNewTree);
// There should be no reused nodes between two trees that are fully parsed.
assert.isTrue(reusedElements(oldTree, newTree) === 0);
@@ -694,6 +717,42 @@ module m3 { }\
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0);
});
it('Class to interface',() => {
var source = "class A { public M1() { } public M2() { } public M3() { } p1 = 0; p2 = 0; p3 = 0 }"
var oldText = ScriptSnapshot.fromString(source);
var newTextAndChange = withChange(oldText, 0, "class".length, "interface");
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0);
});
it('Interface to class',() => {
var source = "interface A { M1?(); M2?(); M3?(); p1?; p2?; p3? }"
var oldText = ScriptSnapshot.fromString(source);
var newTextAndChange = withChange(oldText, 0, "interface".length, "class");
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0);
});
it('Surrounding function declarations with block',() => {
var source = "declare function F1() { } export function F2() { } declare export function F3() { }"
var oldText = ScriptSnapshot.fromString(source);
var newTextAndChange = withInsert(oldText, 0, "{");
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0);
});
it('Removing block around function declarations',() => {
var source = "{ declare function F1() { } export function F2() { } declare export function F3() { }"
var oldText = ScriptSnapshot.fromString(source);
var newTextAndChange = withDelete(oldText, 0, "{".length);
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0);
});
// Simulated typing tests.
it('Type extends clause 1',() => {