Start fixing fourslash tests

This commit is contained in:
Sheetal Nandi 2019-05-24 16:29:27 -07:00
parent fd86f40d05
commit 1d830ffe7a
2 changed files with 10 additions and 6 deletions

View file

@ -955,14 +955,18 @@ namespace FourSlash {
const fullExpected = ts.map<FourSlashInterface.ReferenceGroup, ReferenceGroupJson>(parts, ({ definition, ranges }) => ({ const fullExpected = ts.map<FourSlashInterface.ReferenceGroup, ReferenceGroupJson>(parts, ({ definition, ranges }) => ({
definition: typeof definition === "string" ? definition : { ...definition, range: ts.createTextSpanFromRange(definition.range) }, definition: typeof definition === "string" ? definition : { ...definition, range: ts.createTextSpanFromRange(definition.range) },
references: ranges.map<ts.ReferenceEntry>(r => { references: ranges.map<ts.ReferenceEntry>(r => {
const { isWriteAccess = false, isDefinition = false, isInString } = (r.marker && r.marker.data || {}) as { isWriteAccess?: boolean, isDefinition?: boolean, isInString?: true }; const { isWriteAccess = false, isDefinition = false, isInString, declarationRange } = (r.marker && r.marker.data || {}) as { isWriteAccess?: boolean, isDefinition?: boolean, isInString?: true, declarationRange?: number };
return { const result: ts.ReferenceEntry = {
fileName: r.fileName, fileName: r.fileName,
textSpan: ts.createTextSpanFromRange(r), textSpan: ts.createTextSpanFromRange(r),
isWriteAccess, isWriteAccess,
isDefinition, isDefinition,
...(isInString ? { isInString: true } : undefined), ...(isInString ? { isInString: true } : undefined),
}; };
if (declarationRange !== undefined) {
result.declarationSpan = ts.createTextSpanFromRange(this.getRanges()[declarationRange]);
}
return result;
}), }),
})); }));
@ -1011,7 +1015,7 @@ Actual: ${stringify(fullActual)}`);
}; };
if ((actual === undefined) !== (expected === undefined)) { if ((actual === undefined) !== (expected === undefined)) {
fail(`Expected ${expected}, got ${actual}`); fail(`Expected ${stringify(expected)}, got ${stringify(actual)}`);
} }
for (const key in actual) { for (const key in actual) {
@ -1021,7 +1025,7 @@ Actual: ${stringify(fullActual)}`);
recur(ak, ek, path ? path + "." + key : key); recur(ak, ek, path ? path + "." + key : key);
} }
else if (ak !== ek) { else if (ak !== ek) {
fail(`Expected '${key}' to be '${ek}', got '${ak}'`); fail(`Expected '${key}' to be '${stringify(ek)}', got '${stringify(ak)}'`);
} }
} }
} }

View file

@ -4,7 +4,7 @@
////{} ////{}
// @Filename: a.ts // @Filename: a.ts
////import /*foo*/[|{| "isWriteAccess": true, "isDefinition": true |}foo|] from /*fooModule*/"[|{| "isInString": true |}foo|]"; ////[|import /*foo*/[|{| "isWriteAccess": true, "isDefinition": true, "declarationRange": 0 |}foo|] from /*fooModule*/"[|{| "isInString": true |}foo|]";|]
////[|foo|](); ////[|foo|]();
goTo.file("a.ts"); goTo.file("a.ts");
@ -13,7 +13,7 @@ verify.numberOfErrorsInCurrentFile(0);
goTo.marker("fooModule"); goTo.marker("fooModule");
verify.goToDefinitionIs([]); verify.goToDefinitionIs([]);
verify.quickInfoIs(""); verify.quickInfoIs("");
const [r0, r1, r2] = test.ranges(); const [r00, r0, r1, r2] = test.ranges();
verify.singleReferenceGroup('"foo"', [r1]); verify.singleReferenceGroup('"foo"', [r1]);
goTo.marker("foo"); goTo.marker("foo");