Assert that Extract* baselines are syntactically valid

This commit is contained in:
Andrew Casey 2017-09-28 14:31:35 -07:00
parent 0d5d5cdf28
commit a73a553f58

View file

@ -108,23 +108,16 @@ namespace ts {
it(`${caption} [${extension}]`, () => runBaseline(extension))); it(`${caption} [${extension}]`, () => runBaseline(extension)));
function runBaseline(extension: Extension) { function runBaseline(extension: Extension) {
const f = { const path = "/a" + extension;
path: "/a" + extension, const program = makeProgram({ path, content: t.source });
content: t.source
};
const host = projectSystem.createServerHost([f, projectSystem.libFile]);
const projectService = projectSystem.createProjectService(host);
projectService.openClientFile(f.path);
const program = projectService.inferredProjects[0].getLanguageService().getProgram();
// Don't bother generating JS baselines for inputs that aren't valid JS. if (hasSyntacticDiagnostics(program)) {
const diags = program.getSyntacticDiagnostics(); // Don't bother generating JS baselines for inputs that aren't valid JS.
if (diags && diags.length) {
assert.equal(Extension.Js, extension); assert.equal(Extension.Js, extension);
return; return;
} }
const sourceFile = program.getSourceFile(f.path); const sourceFile = program.getSourceFile(path);
const context: RefactorContext = { const context: RefactorContext = {
cancellationToken: { throwIfCancellationRequested() { }, isCancellationRequested() { return false; } }, cancellationToken: { throwIfCancellationRequested() { }, isCancellationRequested() { return false; } },
newLineCharacter, newLineCharacter,
@ -150,10 +143,26 @@ namespace ts {
const newText = textChanges.applyChanges(sourceFile.text, edits[0].textChanges); const newText = textChanges.applyChanges(sourceFile.text, edits[0].textChanges);
const newTextWithRename = newText.slice(0, renameLocation) + "/*RENAME*/" + newText.slice(renameLocation); const newTextWithRename = newText.slice(0, renameLocation) + "/*RENAME*/" + newText.slice(renameLocation);
data.push(newTextWithRename); data.push(newTextWithRename);
const diagProgram = makeProgram({ path, content: newText });
assert.isFalse(hasSyntacticDiagnostics(diagProgram));
} }
return data.join(newLineCharacter); return data.join(newLineCharacter);
}); });
} }
function makeProgram(f: {path: string, content: string }) {
const host = projectSystem.createServerHost([f, projectSystem.libFile]);
const projectService = projectSystem.createProjectService(host);
projectService.openClientFile(f.path);
const program = projectService.inferredProjects[0].getLanguageService().getProgram();
return program;
}
function hasSyntacticDiagnostics(program: Program) {
const diags = program.getSyntacticDiagnostics();
return length(diags) > 0;
}
} }
export function testExtractSymbolFailed(caption: string, text: string, description: DiagnosticMessage) { export function testExtractSymbolFailed(caption: string, text: string, description: DiagnosticMessage) {