From 8039909913be85531b09cef6cc31a61542cc5408 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 16 Nov 2015 10:36:13 -0800 Subject: [PATCH] remove Tao generation --- src/harness/fourslash.ts | 282 +++++---------------------------- src/harness/fourslashRunner.ts | 50 ------ 2 files changed, 37 insertions(+), 295 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index f62e1c58412..88458beaba4 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -48,12 +48,6 @@ namespace FourSlash { ranges: Range[]; } - export interface TestXmlData { - invalidReason: string; - originalName: string; - actions: string[]; - } - interface MemberListData { result: { maybeInaccurate: boolean; @@ -84,14 +78,14 @@ namespace FourSlash { marker?: Marker; } - interface ILocationInformation { + interface LocationInformation { position: number; sourcePosition: number; sourceLine: number; sourceColumn: number; } - interface IRangeLocationInformation extends ILocationInformation { + interface RangeLocationInformation extends LocationInformation { marker?: Marker; } @@ -134,11 +128,6 @@ namespace FourSlash { return settings; } - export let currentTestState: TestState = null; - function assertionMessage(msg: string) { - return "\nMarker: " + currentTestState.lastKnownMarker + "\nChecking: " + msg + "\n\n"; - } - export class TestCancellationToken implements ts.HostCancellationToken { // 0 - cancelled // >0 - not cancelled @@ -216,9 +205,6 @@ namespace FourSlash { public formatCodeOptions: ts.FormatCodeOptions; - private scenarioActions: string[] = []; - private taoInvalidReason: string = null; - private inputFiles: ts.Map = {}; // Map between inputFile's fileName and its content for easily looking up when resolving references // Add input file which has matched file name with the given reference-file path. @@ -338,7 +324,6 @@ namespace FourSlash { this.testData.files.forEach(file => { const fileName = file.fileName.replace(Harness.IO.directoryName(file.fileName), "").substr(1); const fileNameWithoutExtension = fileName.substr(0, fileName.lastIndexOf(".")); - this.scenarioActions.push(""); }); // Open the first file by default @@ -367,21 +352,11 @@ namespace FourSlash { public goToPosition(pos: number) { this.currentCaretPosition = pos; - - const lineStarts = ts.computeLineStarts(this.getFileContent(this.activeFile.fileName)); - const lineCharPos = ts.computeLineAndCharacterOfPosition(lineStarts, pos); - this.scenarioActions.push(``); } public moveCaretRight(count = 1) { this.currentCaretPosition += count; this.currentCaretPosition = Math.min(this.currentCaretPosition, this.getFileContent(this.activeFile.fileName).length); - if (count > 0) { - this.scenarioActions.push(``); - } - else { - this.scenarioActions.push(``); - } } // Opens a file given its 0-based index or fileName @@ -391,9 +366,6 @@ namespace FourSlash { const fileToOpen: FourSlashFile = this.findFile(indexOrName); fileToOpen.fileName = ts.normalizeSlashes(fileToOpen.fileName); this.activeFile = fileToOpen; - const fileName = fileToOpen.fileName.replace(Harness.IO.directoryName(fileToOpen.fileName), "").substr(1); - this.scenarioActions.push(``); - // Let the host know that this file is now open this.languageServiceAdapterHost.openFile(fileToOpen.fileName, content); } @@ -407,8 +379,6 @@ namespace FourSlash { const exists = this.anyErrorInRange(predicate, startMarker, endMarker); - this.taoInvalidReason = "verifyErrorExistsBetweenMarkers NYI"; - if (exists !== negative) { this.printErrorLog(negative, this.getAllDiagnostics()); throw new Error("Failure between markers: " + startMarkerName + ", " + endMarkerName); @@ -421,7 +391,11 @@ namespace FourSlash { } private messageAtLastKnownMarker(message: string) { - return "Marker: " + currentTestState.lastKnownMarker + "\n" + message; + return "Marker: " + this.lastKnownMarker + "\n" + message; + } + + private assertionMessageAtLastKnownMarker(msg: string) { + return "\nMarker: " + this.lastKnownMarker + "\nChecking: " + msg + "\n\n"; } private getDiagnostics(fileName: string): ts.Diagnostic[] { @@ -461,8 +435,6 @@ namespace FourSlash { }; } - this.taoInvalidReason = "verifyErrorExistsAfterMarker NYI"; - const exists = this.anyErrorInRange(predicate, marker); const diagnostics = this.getAllDiagnostics(); @@ -511,8 +483,6 @@ namespace FourSlash { const errors = this.getDiagnostics(this.activeFile.fileName); const actual = errors.length; - this.scenarioActions.push(``); - if (actual !== expected) { this.printErrorLog(/*expectErrors*/ false, errors); const errorMsg = "Actual number of errors (" + actual + ") does not match expected number (" + expected + ")"; @@ -527,8 +497,6 @@ namespace FourSlash { throw new Error("Expected exactly one output from emit of " + this.activeFile.fileName); } - this.taoInvalidReason = "verifyEval impossible"; - const evaluation = new Function(`${emit.outputFiles[0].text};\r\nreturn (${expr});`)(); if (evaluation !== value) { this.raiseError(`Expected evaluation of expression "${expr}" to equal "${value}", but got "${evaluation}"`); @@ -540,7 +508,6 @@ namespace FourSlash { if (emit.outputFiles.length !== 1) { throw new Error("Expected exactly one output from emit of " + this.activeFile.fileName); } - this.taoInvalidReason = "verifyGetEmitOutputForCurrentFile impossible"; const actual = emit.outputFiles[0].text; if (actual !== expected) { this.raiseError(`Expected emit output to be "${expected}", but got "${actual}"`); @@ -548,13 +515,6 @@ namespace FourSlash { } public verifyMemberListContains(symbol: string, text?: string, documentation?: string, kind?: string) { - this.scenarioActions.push(""); - this.scenarioActions.push(``); - - if (text || documentation || kind) { - this.taoInvalidReason = "verifyMemberListContains only supports the \"symbol\" parameter"; - } - const members = this.getMemberListAtCaret(); if (members) { this.assertItemInCompletionList(members.entries, symbol, text, documentation, kind); @@ -565,18 +525,9 @@ namespace FourSlash { } public verifyMemberListCount(expectedCount: number, negative: boolean) { - if (expectedCount === 0) { - if (negative) { - this.verifyMemberListIsEmpty(/*negative*/ false); - return; - } - else { - this.scenarioActions.push(""); - } - } - else { - this.scenarioActions.push(""); - this.scenarioActions.push(``); + if (expectedCount === 0 && negative) { + this.verifyMemberListIsEmpty(/*negative*/ false); + return; } const members = this.getMemberListAtCaret(); @@ -594,9 +545,6 @@ namespace FourSlash { } public verifyMemberListDoesNotContain(symbol: string) { - this.scenarioActions.push(""); - this.scenarioActions.push(``); - const members = this.getMemberListAtCaret(); if (members && members.entries.filter(e => e.name === symbol).length !== 0) { this.raiseError(`Member list did contain ${symbol}`); @@ -604,8 +552,6 @@ namespace FourSlash { } public verifyCompletionListItemsCountIsGreaterThan(count: number, negative: boolean) { - this.taoInvalidReason = "verifyCompletionListItemsCountIsGreaterThan NYI"; - const completions = this.getCompletionListAtCaret(); const itemsCount = completions.entries.length; @@ -622,13 +568,6 @@ namespace FourSlash { } public verifyMemberListIsEmpty(negative: boolean) { - if (negative) { - this.scenarioActions.push(""); - } - else { - this.scenarioActions.push(""); - } - const members = this.getMemberListAtCaret(); if ((!members || members.entries.length === 0) && negative) { this.raiseError("Member list is empty at Caret"); @@ -647,8 +586,6 @@ namespace FourSlash { } public verifyCompletionListIsEmpty(negative: boolean) { - this.scenarioActions.push(""); - const completions = this.getCompletionListAtCaret(); if ((!completions || completions.entries.length === 0) && negative) { this.raiseError("Completion list is empty at caret at position " + this.activeFile.fileName + " " + this.currentCaretPosition); @@ -716,8 +653,6 @@ namespace FourSlash { // and keep it in the list of filtered entry. return true; } - this.scenarioActions.push(""); - this.scenarioActions.push(``); const completions = this.getCompletionListAtCaret(); if (completions) { @@ -745,24 +680,20 @@ namespace FourSlash { } public verifyCompletionEntryDetails(entryName: string, expectedText: string, expectedDocumentation?: string, kind?: string) { - this.taoInvalidReason = "verifyCompletionEntryDetails NYI"; - const details = this.getCompletionEntryDetails(entryName); - assert.equal(ts.displayPartsToString(details.displayParts), expectedText, assertionMessage("completion entry details text")); + assert.equal(ts.displayPartsToString(details.displayParts), expectedText, this.assertionMessageAtLastKnownMarker("completion entry details text")); if (expectedDocumentation !== undefined) { - assert.equal(ts.displayPartsToString(details.documentation), expectedDocumentation, assertionMessage("completion entry documentation")); + assert.equal(ts.displayPartsToString(details.documentation), expectedDocumentation, this.assertionMessageAtLastKnownMarker("completion entry documentation")); } if (kind !== undefined) { - assert.equal(details.kind, kind, assertionMessage("completion entry kind")); + assert.equal(details.kind, kind, this.assertionMessageAtLastKnownMarker("completion entry kind")); } } public verifyReferencesAtPositionListContains(fileName: string, start: number, end: number, isWriteAccess?: boolean) { - this.taoInvalidReason = "verifyReferencesAtPositionListContains NYI"; - const references = this.getReferencesAtCaret(); if (!references || references.length === 0) { @@ -784,8 +715,6 @@ namespace FourSlash { } public verifyReferencesCountIs(count: number, localFilesOnly = true) { - this.taoInvalidReason = "verifyReferences NYI"; - const references = this.getReferencesAtCaret(); let referencesCount = 0; @@ -845,13 +774,6 @@ namespace FourSlash { } public verifyQuickInfoString(negative: boolean, expectedText?: string, expectedDocumentation?: string) { - [expectedText, expectedDocumentation].forEach(str => { - if (str) { - this.scenarioActions.push(""); - this.scenarioActions.push(``); - } - }); - const actualQuickInfo = this.languageService.getQuickInfoAtPosition(this.activeFile.fileName, this.currentCaretPosition); const actualQuickInfoText = actualQuickInfo ? ts.displayPartsToString(actualQuickInfo.displayParts) : ""; const actualQuickInfoDocumentation = actualQuickInfo ? ts.displayPartsToString(actualQuickInfo.documentation) : ""; @@ -871,7 +793,7 @@ namespace FourSlash { } // TODO: should be '==='? if (expectedDocumentation != undefined) { - assert.equal(actualQuickInfoDocumentation, expectedDocumentation, assertionMessage("quick info doc")); + assert.equal(actualQuickInfoDocumentation, expectedDocumentation, this.assertionMessageAtLastKnownMarker("quick info doc")); } } } @@ -879,8 +801,6 @@ namespace FourSlash { public verifyQuickInfoDisplayParts(kind: string, kindModifiers: string, textSpan: { start: number; length: number; }, displayParts: ts.SymbolDisplayPart[], documentation: ts.SymbolDisplayPart[]) { - this.scenarioActions.push(""); - this.scenarioActions.push(``); function getDisplayPartsJson(displayParts: ts.SymbolDisplayPart[]) { let result = ""; @@ -947,8 +867,6 @@ namespace FourSlash { } public verifyQuickInfoExists(negative: boolean) { - this.taoInvalidReason = "verifyQuickInfoExists NYI"; - const actualQuickInfo = this.languageService.getQuickInfoAtPosition(this.activeFile.fileName, this.currentCaretPosition); if (negative) { if (actualQuickInfo) { @@ -963,8 +881,6 @@ namespace FourSlash { } public verifyCurrentSignatureHelpIs(expected: string) { - this.taoInvalidReason = "verifyCurrentSignatureHelpIs NYI"; - const help = this.getActiveSignatureHelpItem(); assert.equal( ts.displayPartsToString(help.prefixDisplayParts) + @@ -973,75 +889,51 @@ namespace FourSlash { } public verifyCurrentParameterIsletiable(isVariable: boolean) { - this.taoInvalidReason = "verifyCurrentParameterIsletiable NYI"; - const signature = this.getActiveSignatureHelpItem(); assert.isNotNull(signature); assert.equal(isVariable, signature.isVariadic); } public verifyCurrentParameterHelpName(name: string) { - this.taoInvalidReason = "verifyCurrentParameterHelpName NYI"; - const activeParameter = this.getActiveParameter(); const activeParameterName = activeParameter.name; assert.equal(activeParameterName, name); } public verifyCurrentParameterSpanIs(parameter: string) { - this.taoInvalidReason = "verifyCurrentParameterSpanIs NYI"; - const activeSignature = this.getActiveSignatureHelpItem(); const activeParameter = this.getActiveParameter(); assert.equal(ts.displayPartsToString(activeParameter.displayParts), parameter); } public verifyCurrentParameterHelpDocComment(docComment: string) { - this.taoInvalidReason = "verifyCurrentParameterHelpDocComment NYI"; - const activeParameter = this.getActiveParameter(); const activeParameterDocComment = activeParameter.documentation; - assert.equal(ts.displayPartsToString(activeParameterDocComment), docComment, assertionMessage("current parameter Help DocComment")); + assert.equal(ts.displayPartsToString(activeParameterDocComment), docComment, this.assertionMessageAtLastKnownMarker("current parameter Help DocComment")); } public verifyCurrentSignatureHelpParameterCount(expectedCount: number) { - this.taoInvalidReason = "verifyCurrentSignatureHelpParameterCount NYI"; - assert.equal(this.getActiveSignatureHelpItem().parameters.length, expectedCount); } - public verifyCurrentSignatureHelpTypeParameterCount(expectedCount: number) { - this.taoInvalidReason = "verifyCurrentSignatureHelpTypeParameterCount NYI"; - - // assert.equal(this.getActiveSignatureHelpItem().typeParameters.length, expectedCount); - } - public verifyCurrentSignatureHelpDocComment(docComment: string) { - this.taoInvalidReason = "verifyCurrentSignatureHelpDocComment NYI"; - const actualDocComment = this.getActiveSignatureHelpItem().documentation; - assert.equal(ts.displayPartsToString(actualDocComment), docComment, assertionMessage("current signature help doc comment")); + assert.equal(ts.displayPartsToString(actualDocComment), docComment, this.assertionMessageAtLastKnownMarker("current signature help doc comment")); } public verifySignatureHelpCount(expected: number) { - this.scenarioActions.push(""); - this.scenarioActions.push(``); - const help = this.languageService.getSignatureHelpItems(this.activeFile.fileName, this.currentCaretPosition); const actual = help && help.items ? help.items.length : 0; assert.equal(actual, expected); } public verifySignatureHelpArgumentCount(expected: number) { - this.taoInvalidReason = "verifySignatureHelpArgumentCount NYI"; const signatureHelpItems = this.languageService.getSignatureHelpItems(this.activeFile.fileName, this.currentCaretPosition); const actual = signatureHelpItems.argumentCount; assert.equal(actual, expected); } public verifySignatureHelpPresent(shouldBePresent = true) { - this.taoInvalidReason = "verifySignatureHelpPresent NYI"; - const actual = this.languageService.getSignatureHelpItems(this.activeFile.fileName, this.currentCaretPosition); if (shouldBePresent) { if (!actual) { @@ -1184,13 +1076,10 @@ namespace FourSlash { } public getBreakpointStatementLocation(pos: number) { - this.taoInvalidReason = "getBreakpointStatementLocation NYI"; return this.languageService.getBreakpointStatementAtPosition(this.activeFile.fileName, pos); } public baselineCurrentFileBreakpointLocations() { - this.taoInvalidReason = "baselineCurrentFileBreakpointLocations impossible"; - Harness.Baseline.runBaseline( "Breakpoint Locations for " + this.activeFile.fileName, this.testData.globalOptions[metadataOptionNames.baselineFile], @@ -1201,7 +1090,6 @@ namespace FourSlash { } public baselineGetEmitOutput() { - this.taoInvalidReason = "baselineGetEmitOutput impossible"; // Find file to be emitted const emitFiles: FourSlashFile[] = []; // List of FourSlashFile that has emitThisFile flag on @@ -1327,8 +1215,6 @@ namespace FourSlash { } public deleteChar(count = 1) { - this.scenarioActions.push(``); - let offset = this.currentCaretPosition; const ch = ""; @@ -1340,7 +1226,7 @@ namespace FourSlash { this.updateMarkersForEdit(this.activeFile.fileName, offset, offset + 1, ch); if (i % checkCadence === 0) { - this.checkPostEditInletiants(); + this.checkPostEditInvariants(); } // Handle post-keystroke formatting @@ -1357,20 +1243,16 @@ namespace FourSlash { this.currentCaretPosition = offset; this.fixCaretPosition(); - this.checkPostEditInletiants(); + this.checkPostEditInvariants(); } public replace(start: number, length: number, text: string) { - this.taoInvalidReason = "replace NYI"; - this.languageServiceAdapterHost.editScript(this.activeFile.fileName, start, start + length, text); this.updateMarkersForEdit(this.activeFile.fileName, start, start + length, text); - this.checkPostEditInletiants(); + this.checkPostEditInvariants(); } public deleteCharBehindMarker(count = 1) { - this.scenarioActions.push(``); - let offset = this.currentCaretPosition; const ch = ""; const checkCadence = (count >> 2) + 1; @@ -1382,7 +1264,7 @@ namespace FourSlash { this.updateMarkersForEdit(this.activeFile.fileName, offset, offset + 1, ch); if (i % checkCadence === 0) { - this.checkPostEditInletiants(); + this.checkPostEditInvariants(); } // Handle post-keystroke formatting @@ -1398,18 +1280,11 @@ namespace FourSlash { this.currentCaretPosition = offset; this.fixCaretPosition(); - this.checkPostEditInletiants(); + this.checkPostEditInvariants(); } // Enters lines of text at the current caret position public type(text: string) { - if (text === "") { - this.taoInvalidReason = "Test used empty-insert workaround."; - } - else { - this.scenarioActions.push(``); - } - return this.typeHighFidelity(text); } @@ -1440,7 +1315,7 @@ namespace FourSlash { } if (i % checkCadence === 0) { - this.checkPostEditInletiants(); + this.checkPostEditInvariants(); // this.languageService.getSyntacticDiagnostics(this.activeFile.fileName); // this.languageService.getSemanticDiagnostics(this.activeFile.fileName); } @@ -1459,18 +1334,16 @@ namespace FourSlash { this.currentCaretPosition = offset; this.fixCaretPosition(); - this.checkPostEditInletiants(); + this.checkPostEditInvariants(); } // Enters text as if the user had pasted it public paste(text: string) { - this.scenarioActions.push(``); - const start = this.currentCaretPosition; let offset = this.currentCaretPosition; this.languageServiceAdapterHost.editScript(this.activeFile.fileName, offset, offset, text); this.updateMarkersForEdit(this.activeFile.fileName, offset, offset, text); - this.checkPostEditInletiants(); + this.checkPostEditInvariants(); offset += text.length; // Handle formatting @@ -1478,7 +1351,7 @@ namespace FourSlash { const edits = this.languageService.getFormattingEditsForRange(this.activeFile.fileName, start, offset, this.formatCodeOptions); if (edits.length) { offset += this.applyEdits(this.activeFile.fileName, edits, /*isFormattingEdit*/ true); - this.checkPostEditInletiants(); + this.checkPostEditInvariants(); } } @@ -1486,10 +1359,10 @@ namespace FourSlash { this.currentCaretPosition = offset; this.fixCaretPosition(); - this.checkPostEditInletiants(); + this.checkPostEditInvariants(); } - private checkPostEditInletiants() { + private checkPostEditInvariants() { if (this.testType !== FourSlashTestType.Native) { // getSourcefile() results can not be serialized. Only perform these verifications // if running against a native LS object. @@ -1560,16 +1433,12 @@ namespace FourSlash { } public formatDocument() { - this.scenarioActions.push(""); - const edits = this.languageService.getFormattingEditsForDocument(this.activeFile.fileName, this.formatCodeOptions); this.currentCaretPosition += this.applyEdits(this.activeFile.fileName, edits, /*isFormattingEdit*/ true); this.fixCaretPosition(); } public formatSelection(start: number, end: number) { - this.taoInvalidReason = "formatSelection NYI"; - const edits = this.languageService.getFormattingEditsForRange(this.activeFile.fileName, start, end, this.formatCodeOptions); this.currentCaretPosition += this.applyEdits(this.activeFile.fileName, edits, /*isFormattingEdit*/ true); this.fixCaretPosition(); @@ -1603,13 +1472,6 @@ namespace FourSlash { } public goToDefinition(definitionIndex: number) { - if (definitionIndex === 0) { - this.scenarioActions.push(""); - } - else { - this.taoInvalidReason = "GoToDefinition not supported for non-zero definition indices"; - } - const definitions = this.languageService.getDefinitionAtPosition(this.activeFile.fileName, this.currentCaretPosition); if (!definitions || !definitions.length) { this.raiseError("goToDefinition failed - expected to at least one definition location but got 0"); @@ -1625,13 +1487,6 @@ namespace FourSlash { } public goToTypeDefinition(definitionIndex: number) { - if (definitionIndex === 0) { - this.scenarioActions.push(""); - } - else { - this.taoInvalidReason = "GoToTypeDefinition not supported for non-zero definition indices"; - } - const definitions = this.languageService.getTypeDefinitionAtPosition(this.activeFile.fileName, this.currentCaretPosition); if (!definitions || !definitions.length) { this.raiseError("goToTypeDefinition failed - expected to at least one definition location but got 0"); @@ -1647,8 +1502,6 @@ namespace FourSlash { } public verifyDefinitionLocationExists(negative: boolean) { - this.taoInvalidReason = "verifyDefinitionLocationExists NYI"; - const definitions = this.languageService.getDefinitionAtPosition(this.activeFile.fileName, this.currentCaretPosition); const foundDefinitions = definitions && definitions.length; @@ -1680,8 +1533,6 @@ namespace FourSlash { } public verifyDefinitionsName(negative: boolean, expectedName: string, expectedContainerName: string) { - this.taoInvalidReason = "verifyDefinititionsInfo NYI"; - const definitions = this.languageService.getDefinitionAtPosition(this.activeFile.fileName, this.currentCaretPosition); const actualDefinitionName = definitions && definitions.length ? definitions[0].name : ""; const actualDefinitionContainerName = definitions && definitions.length ? definitions[0].containerName : ""; @@ -1706,8 +1557,6 @@ namespace FourSlash { } public verifyCaretAtMarker(markerName = "") { - this.taoInvalidReason = "verifyCaretAtMarker NYI"; - const pos = this.getMarkerByName(markerName); if (pos.fileName !== this.activeFile.fileName) { throw new Error(`verifyCaretAtMarker failed - expected to be in file "${pos.fileName}", but was in file "${this.activeFile.fileName}"`); @@ -1726,8 +1575,6 @@ namespace FourSlash { } public verifyIndentationAtCurrentPosition(numberOfSpaces: number, indentStyle: ts.IndentStyle = ts.IndentStyle.Smart) { - this.taoInvalidReason = "verifyIndentationAtCurrentPosition NYI"; - const actual = this.getIndentation(this.activeFile.fileName, this.currentCaretPosition, indentStyle); const lineCol = this.getLineColStringAtPosition(this.currentCaretPosition); if (actual !== numberOfSpaces) { @@ -1736,8 +1583,6 @@ namespace FourSlash { } public verifyIndentationAtPosition(fileName: string, position: number, numberOfSpaces: number, indentStyle: ts.IndentStyle = ts.IndentStyle.Smart) { - this.taoInvalidReason = "verifyIndentationAtPosition NYI"; - const actual = this.getIndentation(fileName, position, indentStyle); const lineCol = this.getLineColStringAtPosition(position); if (actual !== numberOfSpaces) { @@ -1746,8 +1591,6 @@ namespace FourSlash { } public verifyCurrentLineContent(text: string) { - this.taoInvalidReason = "verifyCurrentLineContent NYI"; - const actual = this.getCurrentLineContent(); if (actual !== text) { throw new Error("verifyCurrentLineContent\n" + @@ -1757,8 +1600,6 @@ namespace FourSlash { } public verifyCurrentFileContent(text: string) { - this.taoInvalidReason = "verifyCurrentFileContent NYI"; - const actual = this.getFileContent(this.activeFile.fileName); const replaceNewlines = (str: string) => str.replace(/\r\n/g, "\n"); if (replaceNewlines(actual) !== replaceNewlines(text)) { @@ -1769,8 +1610,6 @@ namespace FourSlash { } public verifyTextAtCaretIs(text: string) { - this.taoInvalidReason = "verifyCurrentFileContent NYI"; - const actual = this.getFileContent(this.activeFile.fileName).substring(this.currentCaretPosition, this.currentCaretPosition + text.length); if (actual !== text) { throw new Error("verifyTextAtCaretIs\n" + @@ -1780,8 +1619,6 @@ namespace FourSlash { } public verifyCurrentNameOrDottedNameSpanText(text: string) { - this.taoInvalidReason = "verifyCurrentNameOrDottedNameSpanText NYI"; - const span = this.languageService.getNameOrDottedNameSpan(this.activeFile.fileName, this.currentCaretPosition, this.currentCaretPosition); if (!span) { this.raiseError("verifyCurrentNameOrDottedNameSpanText\n" + @@ -1798,13 +1635,10 @@ namespace FourSlash { } private getNameOrDottedNameSpan(pos: number) { - this.taoInvalidReason = "getNameOrDottedNameSpan NYI"; return this.languageService.getNameOrDottedNameSpan(this.activeFile.fileName, pos, pos); } public baselineCurrentFileNameOrDottedNameSpans() { - this.taoInvalidReason = "baselineCurrentFileNameOrDottedNameSpans impossible"; - Harness.Baseline.runBaseline( "Name OrDottedNameSpans for " + this.activeFile.fileName, this.testData.globalOptions[metadataOptionNames.baselineFile], @@ -1898,8 +1732,6 @@ namespace FourSlash { } public verifyOutliningSpans(spans: TextSpan[]) { - this.taoInvalidReason = "verifyOutliningSpans NYI"; - const actual = this.languageService.getOutliningSpans(this.activeFile.fileName); if (actual.length !== spans.length) { @@ -1968,8 +1800,6 @@ namespace FourSlash { } public verifyMatchingBracePosition(bracePosition: number, expectedMatchPosition: number) { - this.taoInvalidReason = "verifyMatchingBracePosition NYI"; - const actual = this.languageService.getBraceMatchingAtPosition(this.activeFile.fileName, bracePosition); if (actual.length !== 2) { @@ -1993,8 +1823,6 @@ namespace FourSlash { } public verifyNoMatchingBracePosition(bracePosition: number) { - this.taoInvalidReason = "verifyNoMatchingBracePosition NYI"; - const actual = this.languageService.getBraceMatchingAtPosition(this.activeFile.fileName, bracePosition); if (actual.length !== 0) { @@ -2007,8 +1835,6 @@ namespace FourSlash { Report an error if expected value and actual value do not match. */ public verifyNavigationItemsCount(expected: number, searchValue: string, matchKind?: string) { - this.taoInvalidReason = "verifyNavigationItemsCount NYI"; - const items = this.languageService.getNavigateToItems(searchValue); let actual = 0; let item: ts.NavigateToItem = null; @@ -2037,8 +1863,6 @@ namespace FourSlash { matchKind: string, fileName?: string, parentName?: string) { - this.taoInvalidReason = "verifyNavigationItemsListContains NYI"; - const items = this.languageService.getNavigateToItems(searchValue); if (!items || items.length === 0) { @@ -2063,8 +1887,6 @@ namespace FourSlash { } public verifyGetScriptLexicalStructureListCount(expected: number) { - this.taoInvalidReason = "verifyNavigationItemsListContains impossible"; - const items = this.languageService.getNavigationBarItems(this.activeFile.fileName); const actual = this.getNavigationBarItemsCount(items); @@ -2086,8 +1908,6 @@ namespace FourSlash { } public verifyGetScriptLexicalStructureListContains(name: string, kind: string) { - this.taoInvalidReason = "verifyGetScriptLexicalStructureListContains impossible"; - const items = this.languageService.getNavigationBarItems(this.activeFile.fileName); if (!items || items.length === 0) { @@ -2148,8 +1968,6 @@ namespace FourSlash { } public verifyOccurrencesAtPositionListContains(fileName: string, start: number, end: number, isWriteAccess?: boolean) { - this.taoInvalidReason = "verifyOccurrencesAtPositionListContains NYI"; - const occurrences = this.getOccurrencesAtCurrentPosition(); if (!occurrences || occurrences.length === 0) { @@ -2170,8 +1988,6 @@ namespace FourSlash { } public verifyOccurrencesAtPositionListCount(expectedCount: number) { - this.taoInvalidReason = "verifyOccurrencesAtPositionListCount NYI"; - const occurrences = this.getOccurrencesAtCurrentPosition(); const actualCount = occurrences ? occurrences.length : 0; if (expectedCount !== actualCount) { @@ -2185,8 +2001,6 @@ namespace FourSlash { } public verifyDocumentHighlightsAtPositionListContains(fileName: string, start: number, end: number, fileNamesToSearch: string[], kind?: string) { - this.taoInvalidReason = "verifyDocumentHighlightsAtPositionListContains NYI"; - const documentHighlights = this.getDocumentHighlightsAtCurrentPosition(fileNamesToSearch); if (!documentHighlights || documentHighlights.length === 0) { @@ -2213,8 +2027,6 @@ namespace FourSlash { } public verifyDocumentHighlightsAtPositionListCount(expectedCount: number, fileNamesToSearch: string[]) { - this.taoInvalidReason = "verifyDocumentHighlightsAtPositionListCount NYI"; - const documentHighlights = this.getDocumentHighlightsAtCurrentPosition(fileNamesToSearch); const actualCount = documentHighlights ? documentHighlights.reduce((currentCount, { highlightSpans }) => currentCount + highlightSpans.length, 0) @@ -2255,13 +2067,6 @@ namespace FourSlash { } private assertItemInCompletionList(items: ts.CompletionEntry[], name: string, text?: string, documentation?: string, kind?: string) { - this.scenarioActions.push(""); - this.scenarioActions.push(``); - - if (text || documentation || kind) { - this.taoInvalidReason = "assertItemInCompletionList only supports the \"name\" parameter"; - } - for (let i = 0; i < items.length; i++) { const item = items[i]; if (item.name === name) { @@ -2269,15 +2074,15 @@ namespace FourSlash { const details = this.getCompletionEntryDetails(item.name); if (documentation !== undefined) { - assert.equal(ts.displayPartsToString(details.documentation), documentation, assertionMessage("completion item documentation for " + name)); + assert.equal(ts.displayPartsToString(details.documentation), documentation, this.assertionMessageAtLastKnownMarker("completion item documentation for " + name)); } if (text !== undefined) { - assert.equal(ts.displayPartsToString(details.displayParts), text, assertionMessage("completion item detail text for " + name)); + assert.equal(ts.displayPartsToString(details.displayParts), text, this.assertionMessageAtLastKnownMarker("completion item detail text for " + name)); } } if (kind !== undefined) { - assert.equal(item.kind, kind, assertionMessage("completion item kind for " + name)); + assert.equal(item.kind, kind, this.assertionMessageAtLastKnownMarker("completion item kind for " + name)); } return; @@ -2352,14 +2157,6 @@ namespace FourSlash { return text.replace(/ /g, "\u00B7").replace(/\r/g, "\u00B6").replace(/\n/g, "\u2193\n").replace(/\t/g, "\u2192\ "); } - public getTestXmlData(): TestXmlData { - return { - actions: this.scenarioActions, - invalidReason: this.taoInvalidReason, - originalName: "" - }; - } - public setCancelled(numberOfCalls: number): void { this.cancellationToken.setCancelled(numberOfCalls); } @@ -2372,11 +2169,9 @@ namespace FourSlash { // TOOD: should these just use the Harness's stdout/stderr? const fsOutput = new Harness.Compiler.WriterAggregator(); const fsErrors = new Harness.Compiler.WriterAggregator(); - export let xmlData: TestXmlData[] = []; export function runFourSlashTest(basePath: string, testType: FourSlashTestType, fileName: string) { const content = Harness.IO.readFile(fileName); - const xml = runFourSlashTestContent(basePath, testType, content, fileName); - xmlData.push(xml); + runFourSlashTestContent(basePath, testType, content, fileName); } // We don't want to recompile 'fourslash.ts' for every test, so @@ -2398,7 +2193,8 @@ namespace FourSlash { program.emit(host.getSourceFile(Harness.Compiler.fourslashFileName, ts.ScriptTarget.ES3)); } - export function runFourSlashTestContent(basePath: string, testType: FourSlashTestType, content: string, fileName: string): TestXmlData { + export let currentTestState: TestState; + export function runFourSlashTestContent(basePath: string, testType: FourSlashTestType, content: string, fileName: string): void { // Parse out the files and their metadata const testData = parseTestData(basePath, content, fileName); @@ -2437,10 +2233,6 @@ namespace FourSlash { result = fourslashJsOutput + "\r\n" + result; runCode(result); - - const xmlData = currentTestState.getTestXmlData(); - xmlData.originalName = fileName; - return xmlData; } function runCode(code: string): void { @@ -2619,7 +2411,7 @@ namespace FourSlash { throw new Error(errorMessage); } - function recordObjectMarker(fileName: string, location: ILocationInformation, text: string, markerMap: MarkerMap, markers: Marker[]): Marker { + function recordObjectMarker(fileName: string, location: LocationInformation, text: string, markerMap: MarkerMap, markers: Marker[]): Marker { let markerValue: any = undefined; try { // Attempt to parse the marker value as JSON @@ -2650,7 +2442,7 @@ namespace FourSlash { return marker; } - function recordMarker(fileName: string, location: ILocationInformation, name: string, markerMap: MarkerMap, markers: Marker[]): Marker { + function recordMarker(fileName: string, location: LocationInformation, name: string, markerMap: MarkerMap, markers: Marker[]): Marker { const marker: Marker = { fileName: fileName, position: location.position @@ -2679,10 +2471,10 @@ namespace FourSlash { let output = ""; /// The current marker (or maybe multi-line comment?) we're parsing, possibly - let openMarker: ILocationInformation = null; + let openMarker: LocationInformation = null; /// A stack of the open range markers that are still unclosed - const openRanges: IRangeLocationInformation[] = []; + const openRanges: RangeLocationInformation[] = []; /// A list of ranges we've collected so far */ let localRanges: Range[] = []; diff --git a/src/harness/fourslashRunner.ts b/src/harness/fourslashRunner.ts index 7228f06c20f..84e352359c4 100644 --- a/src/harness/fourslashRunner.ts +++ b/src/harness/fourslashRunner.ts @@ -58,56 +58,6 @@ class FourSlashRunner extends RunnerBase { } }); }); - - describe("Generate Tao XML", () => { - const invalidReasons: any = {}; - FourSlash.xmlData.forEach(xml => { - if (xml.invalidReason !== null) { - invalidReasons[xml.invalidReason] = (invalidReasons[xml.invalidReason] || 0) + 1; - } - }); - const invalidReport: { reason: string; count: number }[] = []; - for (const reason in invalidReasons) { - if (invalidReasons.hasOwnProperty(reason)) { - invalidReport.push({ reason: reason, count: invalidReasons[reason] }); - } - } - invalidReport.sort((lhs, rhs) => lhs.count > rhs.count ? -1 : lhs.count === rhs.count ? 0 : 1); - - const lines: string[] = []; - lines.push(""); - lines.push(""); - lines.push(" "); - lines.push(" "); - lines.push(" "); - lines.push(" "); - FourSlash.xmlData.forEach(xml => { - if (xml.invalidReason !== null) { - lines.push(""); - } - else { - lines.push(" "); - xml.actions.forEach(action => { - lines.push(" " + action); - }); - lines.push(" "); - } - }); - lines.push(" "); - lines.push(" "); - lines.push(" "); - lines.push(" "); - lines.push(" "); - lines.push(" "); - lines.push(" "); - lines.push(" "); - lines.push(""); - Harness.IO.writeFile("built/local/fourslash.xml", lines.join("\r\n")); - }); }); } }