Skip to content

Commit 5e3e0d6

Browse files
authored
Merge pull request #10900 from Microsoft/quick_info_tests
Simplify quick-info tests
2 parents ab98dcf + 695410c commit 5e3e0d6

File tree

211 files changed

+1730
-2880
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

211 files changed

+1730
-2880
lines changed

src/harness/fourslash.ts

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -955,23 +955,35 @@ namespace FourSlash {
955955
assert.equal(actual, expected);
956956
}
957957

958-
public verifyQuickInfoString(negative: boolean, expectedText: string, expectedDocumentation?: string) {
959-
const actualQuickInfo = this.languageService.getQuickInfoAtPosition(this.activeFile.fileName, this.currentCaretPosition);
960-
const actualQuickInfoText = actualQuickInfo ? ts.displayPartsToString(actualQuickInfo.displayParts) : "";
961-
const actualQuickInfoDocumentation = actualQuickInfo ? ts.displayPartsToString(actualQuickInfo.documentation) : "";
958+
public verifyQuickInfoAt(markerName: string, expectedText: string, expectedDocumentation?: string) {
959+
this.goToMarker(markerName);
960+
this.verifyQuickInfoString(expectedText, expectedDocumentation);
961+
}
962962

963-
if (negative) {
964-
assert.notEqual(actualQuickInfoText, expectedText, this.messageAtLastKnownMarker("quick info text"));
965-
if (expectedDocumentation !== undefined) {
966-
assert.notEqual(actualQuickInfoDocumentation, expectedDocumentation, this.messageAtLastKnownMarker("quick info doc comment"));
963+
public verifyQuickInfos(namesAndTexts: { [name: string]: string | [string, string] }) {
964+
ts.forEachProperty(ts.createMap(namesAndTexts), (text, name) => {
965+
if (text instanceof Array) {
966+
assert(text.length === 2);
967+
const [expectedText, expectedDocumentation] = text;
968+
this.verifyQuickInfoAt(name, expectedText, expectedDocumentation);
967969
}
968-
}
969-
else {
970-
assert.equal(actualQuickInfoText, expectedText, this.messageAtLastKnownMarker("quick info text"));
971-
if (expectedDocumentation !== undefined) {
972-
assert.equal(actualQuickInfoDocumentation, expectedDocumentation, this.assertionMessageAtLastKnownMarker("quick info doc"));
970+
else {
971+
this.verifyQuickInfoAt(name, text);
973972
}
973+
});
974+
}
975+
976+
public verifyQuickInfoString(expectedText: string, expectedDocumentation?: string) {
977+
if (expectedDocumentation === "") {
978+
throw new Error("Use 'undefined' instead");
974979
}
980+
981+
const actualQuickInfo = this.languageService.getQuickInfoAtPosition(this.activeFile.fileName, this.currentCaretPosition);
982+
const actualQuickInfoText = actualQuickInfo ? ts.displayPartsToString(actualQuickInfo.displayParts) : "";
983+
const actualQuickInfoDocumentation = actualQuickInfo ? ts.displayPartsToString(actualQuickInfo.documentation) : "";
984+
985+
assert.equal(actualQuickInfoText, expectedText, this.messageAtLastKnownMarker("quick info text"));
986+
assert.equal(actualQuickInfoDocumentation, expectedDocumentation || "", this.assertionMessageAtLastKnownMarker("quick info doc"));
975987
}
976988

977989
public verifyQuickInfoDisplayParts(kind: string, kindModifiers: string, textSpan: { start: number; length: number; },
@@ -2964,10 +2976,6 @@ namespace FourSlashInterface {
29642976
this.state.verifyErrorExistsAfterMarker(markerName, !this.negative, /*after*/ false);
29652977
}
29662978

2967-
public quickInfoIs(expectedText: string, expectedDocumentation?: string) {
2968-
this.state.verifyQuickInfoString(this.negative, expectedText, expectedDocumentation);
2969-
}
2970-
29712979
public quickInfoExists() {
29722980
this.state.verifyQuickInfoExists(this.negative);
29732981
}
@@ -2986,6 +2994,18 @@ namespace FourSlashInterface {
29862994
super(state);
29872995
}
29882996

2997+
public quickInfoIs(expectedText: string, expectedDocumentation?: string) {
2998+
this.state.verifyQuickInfoString(expectedText, expectedDocumentation);
2999+
}
3000+
3001+
public quickInfoAt(markerName: string, expectedText?: string, expectedDocumentation?: string) {
3002+
this.state.verifyQuickInfoAt(markerName, expectedText, expectedDocumentation);
3003+
}
3004+
3005+
public quickInfos(namesAndTexts: { [name: string]: string }) {
3006+
this.state.verifyQuickInfos(namesAndTexts);
3007+
}
3008+
29893009
public caretAtMarker(markerName?: string) {
29903010
this.state.verifyCaretAtMarker(markerName);
29913011
}

tests/cases/fourslash/addInterfaceMemberAboveClass.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@
1010
//// }
1111
//// }
1212

13-
goTo.marker('className');
14-
verify.quickInfoIs('class Sphere');
13+
verify.quickInfoAt("className", "class Sphere");
1514

1615
goTo.marker('insertHere');
1716
edit.insert("ray: Ray;");
1817

19-
goTo.marker('className');
20-
21-
verify.quickInfoIs('class Sphere');
18+
verify.quickInfoAt("className", "class Sphere");

tests/cases/fourslash/addMemberToInterface.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@
1010

1111
edit.disableFormatting();
1212

13-
goTo.marker('check');
14-
verify.quickInfoIs('namespace Mod');
13+
verify.quickInfoAt("check", "namespace Mod");
1514

1615
goTo.marker('insert');
1716
edit.insert("x: number;\n");
1817

19-
goTo.marker('check');
20-
verify.quickInfoIs('namespace Mod');
18+
verify.quickInfoAt("check", "namespace Mod");

tests/cases/fourslash/aliasMergingWithNamespace.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
////namespace bar { }
44
////import bar = bar/**/;
55

6-
goTo.marker();
7-
verify.quickInfoIs(
6+
verify.quickInfoAt("",
87
`namespace bar
9-
import bar = bar`);
8+
import bar = bar`);

tests/cases/fourslash/ambientShorthandGotoDefinition.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,22 @@
1010
/////*importBang*/import /*idBang*/bang = require("jquery");
1111
////foo/*useFoo*/(bar/*useBar*/, baz/*useBaz*/, bang/*useBang*/);
1212

13-
goTo.marker("useFoo");
14-
verify.quickInfoIs("import foo");
13+
verify.quickInfoAt("useFoo", "import foo");
1514
verify.goToDefinition({
1615
useFoo: "importFoo",
1716
importFoo: "module"
1817
});
1918

20-
goTo.marker("useBar");
21-
verify.quickInfoIs("import bar");
19+
verify.quickInfoAt("useBar", "import bar");
2220
verify.goToDefinition("useBar", "module");
2321

24-
goTo.marker("useBaz");
25-
verify.quickInfoIs("import baz");
22+
verify.quickInfoAt("useBaz", "import baz");
2623
verify.goToDefinition({
2724
useBaz: "importBaz",
2825
idBaz: "module"
2926
});
3027

31-
goTo.marker("useBang");
32-
verify.quickInfoIs("import bang = require(\"jquery\")");
28+
verify.quickInfoAt("useBang", "import bang = require(\"jquery\")");
3329
verify.goToDefinition({
3430
useBang: "importBang",
3531
idBang: "module"

tests/cases/fourslash/arrayCallAndConstructTypings.ts

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,15 @@
1111
////var a/*9*/9 = Array<boolean>(1);
1212
////var a/*10*/10 = Array("s");
1313

14-
15-
goTo.marker('1');
16-
verify.quickInfoIs('var a1: any[]');
17-
18-
goTo.marker('2');
19-
verify.quickInfoIs('var a2: any[]');
20-
21-
goTo.marker('3');
22-
verify.quickInfoIs('var a3: boolean[]');
23-
24-
goTo.marker('4');
25-
verify.quickInfoIs('var a4: boolean[]');
26-
27-
goTo.marker('5');
28-
verify.quickInfoIs('var a5: string[]');
29-
30-
goTo.marker('6');
31-
verify.quickInfoIs('var a6: any[]');
32-
33-
goTo.marker('7');
34-
verify.quickInfoIs('var a7: any[]');
35-
36-
goTo.marker('8');
37-
verify.quickInfoIs('var a8: boolean[]');
38-
39-
goTo.marker('9');
40-
verify.quickInfoIs('var a9: boolean[]');
41-
42-
goTo.marker('10');
43-
verify.quickInfoIs('var a10: string[]');
14+
verify.quickInfos({
15+
1: "var a1: any[]",
16+
2: "var a2: any[]",
17+
3: "var a3: boolean[]",
18+
4: "var a4: boolean[]",
19+
5: "var a5: string[]",
20+
6: "var a6: any[]",
21+
7: "var a7: any[]",
22+
8: "var a8: boolean[]",
23+
9: "var a9: boolean[]",
24+
10: "var a10: string[]"
25+
});

tests/cases/fourslash/assertContextualType.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22

33
////<(aa: number) =>void >(function myFn(b/**/b) { });
44

5-
goTo.marker();
6-
verify.quickInfoIs('(parameter) bb: number');
5+
verify.quickInfoAt("", "(parameter) bb: number");

tests/cases/fourslash/augmentedTypesClass3.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
////namespace c/*2*/5b { export var y = 2; } // should be ok
55
/////*3*/
66

7-
goTo.marker('1');
8-
verify.quickInfoIs("class c5b\nnamespace c5b");
9-
10-
goTo.marker('2');
11-
verify.quickInfoIs("class c5b\nnamespace c5b");
7+
verify.quickInfos({
8+
1: "class c5b\nnamespace c5b",
9+
2: "class c5b\nnamespace c5b"
10+
});
1211

1312
goTo.marker('3');
1413
verify.completionListContains("c5b", "class c5b\nnamespace c5b");

tests/cases/fourslash/augmentedTypesModule1.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@ goTo.marker('1');
1111
verify.completionListContains('I');
1212
verify.not.completionListContains('foo');
1313

14-
goTo.marker('2');
15-
verify.quickInfoIs('var r: number');
14+
verify.quickInfoAt("2", "var r: number");

tests/cases/fourslash/augmentedTypesModule2.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
////var x: m2f./*1*/
66
////var /*2*/r = m2f/*3*/;
77

8-
goTo.marker('11');
9-
verify.quickInfoIs('function m2f(x: number): void\nnamespace m2f');
8+
verify.quickInfoAt("11", "function m2f(x: number): void\nnamespace m2f");
109

1110
goTo.marker('1');
1211
verify.completionListContains('I');
@@ -15,8 +14,7 @@ edit.insert('I.');
1514
verify.not.completionListContains('foo');
1615
edit.backspace(1);
1716

18-
goTo.marker('2');
19-
verify.quickInfoIs('var r: (x: number) => void');
17+
verify.quickInfoAt("2", "var r: (x: number) => void");
2018

2119
goTo.marker('3');
2220
edit.insert('(');

0 commit comments

Comments
 (0)