From 307e28a8a1b78cbe1b5394aa033bf18b621949de Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 13 Oct 2014 14:38:18 -0700 Subject: [PATCH] Enable infrastructure to test the symbol display parts returned by quickInfo --- src/harness/fourslash.ts | 17 +++++++- src/services/services.ts | 5 ++- tests/cases/fourslash/fourslash.ts | 12 +++++- .../fourslash/quicklInfoDisplayPartsClass.ts | 39 +++++++++++++++++++ 4 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 tests/cases/fourslash/quicklInfoDisplayPartsClass.ts diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 6a4e13b22e3..e6bca42ea64 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -765,7 +765,7 @@ module FourSlash { return "\nActual " + name + ":\n\t" + actualValue + "\nExpected value:\n\t" + expectedValue; } - public verifyQuickInfo(negative: boolean, expectedText?: string, expectedDocumentation?: string) { + public quickInfoIs(negative: boolean, expectedText?: string, expectedDocumentation?: string) { [expectedText, expectedDocumentation].forEach(str => { if (str) { this.scenarioActions.push(''); @@ -794,6 +794,21 @@ module FourSlash { } } + + public verifyQuickInfo(kind: string, kindModifiers: string, textSpan: { start: number; length: number; }, + displayParts: { text: string; kind: string; }[], + documentation: { text: string; kind: string; }[]) { + this.scenarioActions.push(''); + this.scenarioActions.push(''); + + var actualQuickInfo = this.languageService.getQuickInfoAtPosition(this.activeFile.fileName, this.currentCaretPosition); + assert.equal(actualQuickInfo.kind, kind, this.messageAtLastKnownMarker("QuickInfo kind")); + assert.equal(actualQuickInfo.kindModifiers, kindModifiers, this.messageAtLastKnownMarker("QuickInfo kindModifiers")); + assert.equal(JSON.stringify(actualQuickInfo.textSpan), JSON.stringify(textSpan), this.messageAtLastKnownMarker("QuickInfo textSpan")); + assert.equal(JSON.stringify(actualQuickInfo.displayParts), JSON.stringify(displayParts), this.messageAtLastKnownMarker("QuickInfo displayParts")); + assert.equal(JSON.stringify(actualQuickInfo.documentation), JSON.stringify(documentation), this.messageAtLastKnownMarker("QuickInfo documentation")); + } + public verifyRenameLocations(findInStrings: boolean, findInComments: boolean) { var renameInfo = this.languageService.getRenameInfo(this.activeFile.fileName, this.currentCaretPosition); if (renameInfo.canRename) { diff --git a/src/services/services.ts b/src/services/services.ts index 618026408fe..237c0ca9f1c 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1317,7 +1317,10 @@ module ts { function writeIndent() { if (lineStart) { - displayParts.push(displayPart(getIndentString(indent), SymbolDisplayPartKind.space)); + var indentString = getIndentString(indent); + if (indentString) { + displayParts.push(displayPart(indentString, SymbolDisplayPartKind.space)); + } lineStart = false; } } diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 7be7dd63c92..eef259065ca 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -83,6 +83,10 @@ module FourSlashInterface { public ranges(): Range[] { return FourSlash.currentTestState.getRanges(); } + + public markerByName(s: string): Marker { + return FourSlash.currentTestState.getMarkerByName(s); + } } export class diagnostics { @@ -223,7 +227,7 @@ module FourSlashInterface { } public quickInfoIs(expectedText?: string, expectedDocumentation?: string) { - FourSlash.currentTestState.verifyQuickInfo(this.negative, expectedText, expectedDocumentation); + FourSlash.currentTestState.quickInfoIs(this.negative, expectedText, expectedDocumentation); } public quickInfoExists() { @@ -420,6 +424,12 @@ module FourSlashInterface { public renameLocations(findInStrings: boolean, findInComments: boolean) { FourSlash.currentTestState.verifyRenameLocations(findInStrings, findInComments); } + + public verifyQuickInfo(kind: string, kindModifiers: string, textSpan: { start: number; length: number; }, + displayParts: { text: string; kind: string; }[], + documentation: { text: string; kind: string; }[]) { + FourSlash.currentTestState.verifyQuickInfo(kind, kindModifiers, textSpan, displayParts, documentation); + } } export class edit { diff --git a/tests/cases/fourslash/quicklInfoDisplayPartsClass.ts b/tests/cases/fourslash/quicklInfoDisplayPartsClass.ts new file mode 100644 index 00000000000..8e4dc346cbc --- /dev/null +++ b/tests/cases/fourslash/quicklInfoDisplayPartsClass.ts @@ -0,0 +1,39 @@ +/// + +////class /*1*/c { +////} +////var /*2*/cInstance = new /*3*/c(); +////var /*4*/cVal = /*5*/c; + +goTo.marker('1'); +verify.verifyQuickInfo("class", "", { start: test.markerByName("1").position, length: "c".length }, + [{ text: "class", kind: "keyword" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); + +goTo.marker('2'); +verify.verifyQuickInfo("var", "", { start: test.markerByName("2").position, length: "cInstance".length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "cInstance", kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); + +goTo.marker('3'); +verify.verifyQuickInfo("constructor", "", { start: test.markerByName("3").position, length: "c".length }, + [{ text: "(", kind: "punctuation" }, { text: "constructor", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "c", kind: "className" }, + { text: "(", kind: "punctuation" }, { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); + +goTo.marker('4'); +verify.verifyQuickInfo("var", "", { start: test.markerByName("4").position, length: "cVal".length }, + [{ text: "(", kind: "punctuation" }, { text: "var", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "cVal", kind: "localName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, + { text: "typeof", kind: "keyword" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); + +goTo.marker('5'); +verify.verifyQuickInfo("class", "", { start: test.markerByName("5").position, length: "c".length }, + [{ text: "class", kind: "keyword" }, { text: " ", kind: "space" }, { text: "c", kind: "className" }], + []); \ No newline at end of file