Skip to content

Commit 38016f9

Browse files
author
Andy
authored
Implement feedback on "Improve completions testing" (microsoft#23842)
1 parent bad3a44 commit 38016f9

68 files changed

Lines changed: 171 additions & 168 deletions

File tree

Some content is hidden

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

src/harness/fourslash.ts

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
namespace FourSlash {
2424
ts.disableIncrementalParsing = false;
2525

26-
import Many = FourSlashInterface.Many;
26+
import ArrayOrSingle = FourSlashInterface.Many;
2727

2828
// Represents a parsed source file with metadata
2929
interface FourSlashFile {
@@ -627,11 +627,11 @@ namespace FourSlash {
627627
}
628628
}
629629

630-
public verifyGoToDefinitionIs(endMarker: Many<string>) {
630+
public verifyGoToDefinitionIs(endMarker: ArrayOrSingle<string>) {
631631
this.verifyGoToXWorker(toArray(endMarker), () => this.getGoToDefinition());
632632
}
633633

634-
public verifyGoToDefinition(arg0: any, endMarkerNames?: Many<string>) {
634+
public verifyGoToDefinition(arg0: any, endMarkerNames?: ArrayOrSingle<string>) {
635635
this.verifyGoToX(arg0, endMarkerNames, () => this.getGoToDefinitionAndBoundSpan());
636636
}
637637

@@ -643,23 +643,23 @@ namespace FourSlash {
643643
return this.languageService.getDefinitionAndBoundSpan(this.activeFile.fileName, this.currentCaretPosition);
644644
}
645645

646-
public verifyGoToType(arg0: any, endMarkerNames?: Many<string>) {
646+
public verifyGoToType(arg0: any, endMarkerNames?: ArrayOrSingle<string>) {
647647
this.verifyGoToX(arg0, endMarkerNames, () =>
648648
this.languageService.getTypeDefinitionAtPosition(this.activeFile.fileName, this.currentCaretPosition));
649649
}
650650

651-
private verifyGoToX(arg0: any, endMarkerNames: Many<string> | undefined, getDefs: () => ts.DefinitionInfo[] | ts.DefinitionInfoAndBoundSpan | undefined) {
651+
private verifyGoToX(arg0: any, endMarkerNames: ArrayOrSingle<string> | undefined, getDefs: () => ts.DefinitionInfo[] | ts.DefinitionInfoAndBoundSpan | undefined) {
652652
if (endMarkerNames) {
653653
this.verifyGoToXPlain(arg0, endMarkerNames, getDefs);
654654
}
655655
else if (ts.isArray(arg0)) {
656-
const pairs = arg0 as ReadonlyArray<[Many<string>, Many<string>]>;
656+
const pairs = arg0 as ReadonlyArray<[ArrayOrSingle<string>, ArrayOrSingle<string>]>;
657657
for (const [start, end] of pairs) {
658658
this.verifyGoToXPlain(start, end, getDefs);
659659
}
660660
}
661661
else {
662-
const obj: { [startMarkerName: string]: Many<string> } = arg0;
662+
const obj: { [startMarkerName: string]: ArrayOrSingle<string> } = arg0;
663663
for (const startMarkerName in obj) {
664664
if (ts.hasProperty(obj, startMarkerName)) {
665665
this.verifyGoToXPlain(startMarkerName, obj[startMarkerName], getDefs);
@@ -668,7 +668,7 @@ namespace FourSlash {
668668
}
669669
}
670670

671-
private verifyGoToXPlain(startMarkerNames: Many<string>, endMarkerNames: Many<string>, getDefs: () => ts.DefinitionInfo[] | ts.DefinitionInfoAndBoundSpan | undefined) {
671+
private verifyGoToXPlain(startMarkerNames: ArrayOrSingle<string>, endMarkerNames: ArrayOrSingle<string>, getDefs: () => ts.DefinitionInfo[] | ts.DefinitionInfoAndBoundSpan | undefined) {
672672
for (const start of toArray(startMarkerNames)) {
673673
this.verifyGoToXSingle(start, endMarkerNames, getDefs);
674674
}
@@ -680,7 +680,7 @@ namespace FourSlash {
680680
}
681681
}
682682

683-
private verifyGoToXSingle(startMarkerName: string, endMarkerNames: Many<string>, getDefs: () => ReadonlyArray<ts.DefinitionInfo> | ts.DefinitionInfoAndBoundSpan | undefined) {
683+
private verifyGoToXSingle(startMarkerName: string, endMarkerNames: ArrayOrSingle<string>, getDefs: () => ReadonlyArray<ts.DefinitionInfo> | ts.DefinitionInfoAndBoundSpan | undefined) {
684684
this.goToMarker(startMarkerName);
685685
this.verifyGoToXWorker(toArray(endMarkerNames), getDefs, startMarkerName);
686686
}
@@ -843,19 +843,21 @@ namespace FourSlash {
843843
}
844844

845845
public verifyCompletions(options: FourSlashInterface.VerifyCompletionsOptions) {
846-
if (options.at !== undefined) {
847-
if (typeof options.at === "string") {
848-
this.goToMarker(options.at);
849-
}
850-
else {
851-
for (const a of options.at) this.verifyCompletions({ ...options, at: a });
852-
return;
846+
if (options.marker === undefined) {
847+
this.verifyCompletionsWorker(options);
848+
}
849+
else {
850+
for (const marker of toArray(options.marker)) {
851+
this.goToMarker(marker);
852+
this.verifyCompletionsWorker(options);
853853
}
854854
}
855+
}
855856

857+
private verifyCompletionsWorker(options: FourSlashInterface.VerifyCompletionsOptions): void {
856858
const actualCompletions = this.getCompletionListAtCaret({ ...options.preferences, triggerCharacter: options.triggerCharacter });
857859
if (!actualCompletions) {
858-
if (options.are === undefined) return;
860+
if (options.exact === undefined) return;
859861
this.raiseError(`No completions at position '${this.currentCaretPosition}'.`);
860862
}
861863

@@ -874,9 +876,10 @@ namespace FourSlash {
874876
}
875877
}
876878

877-
if ("are" in options) {
878-
if (options.are === undefined) this.raiseError("Expected no completions");
879-
this.verifyCompletionsAreExactly(actualCompletions.entries, toArray(options.are));
879+
if ("exact" in options) {
880+
ts.Debug.assert(!("includes" in options) && !("excludes" in options));
881+
if (options.exact === undefined) this.raiseError("Expected no completions");
882+
this.verifyCompletionsAreExactly(actualCompletions.entries, toArray(options.exact));
880883
}
881884
else {
882885
if (options.includes) {
@@ -887,7 +890,7 @@ namespace FourSlash {
887890
this.verifyCompletionEntry(found, include);
888891
}
889892
}
890-
else {
893+
if (options.excludes) {
891894
for (const exclude of toArray(options.excludes)) {
892895
if (typeof exclude === "string") {
893896
if (actualByName.has(exclude)) {
@@ -954,7 +957,7 @@ namespace FourSlash {
954957
}
955958

956959
public verifyCompletionsAt(markerName: string | ReadonlyArray<string>, expected: ReadonlyArray<FourSlashInterface.ExpectedCompletionEntry>, options?: FourSlashInterface.CompletionsAtOptions) {
957-
this.verifyCompletions({ at: markerName, are: expected, isNewIdentifierLocation: options && options.isNewIdentifierLocation, preferences: options, triggerCharacter: options && options.triggerCharacter });
960+
this.verifyCompletions({ marker: markerName, exact: expected, isNewIdentifierLocation: options && options.isNewIdentifierLocation, preferences: options, triggerCharacter: options && options.triggerCharacter });
958961
}
959962

960963
public verifyCompletionListContains(entryId: ts.Completions.CompletionEntryIdentifier, text?: string, documentation?: string, kind?: string | { kind?: string, kindModifiers?: string }, spanIndex?: number, hasAction?: boolean, options?: FourSlashInterface.VerifyCompletionListContainsOptions) {
@@ -1190,7 +1193,7 @@ namespace FourSlash {
11901193
}
11911194
}
11921195

1193-
public verifyReferenceGroups(starts: Many<string> | Many<Range>, parts: ReadonlyArray<FourSlashInterface.ReferenceGroup> | undefined): void {
1196+
public verifyReferenceGroups(starts: ArrayOrSingle<string> | ArrayOrSingle<Range>, parts: ReadonlyArray<FourSlashInterface.ReferenceGroup> | undefined): void {
11941197
interface ReferenceGroupJson {
11951198
definition: string | { text: string, range: ts.TextSpan };
11961199
references: ts.ReferenceEntry[];
@@ -1425,7 +1428,7 @@ Actual: ${stringify(fullActual)}`);
14251428
}
14261429
}
14271430

1428-
public verifyRenameLocations(startRanges: Many<Range>, options: Range[] | { findInStrings?: boolean, findInComments?: boolean, ranges: Range[] }) {
1431+
public verifyRenameLocations(startRanges: ArrayOrSingle<Range>, options: Range[] | { findInStrings?: boolean, findInComments?: boolean, ranges: Range[] }) {
14291432
let findInStrings: boolean, findInComments: boolean, ranges: Range[];
14301433
if (ts.isArray(options)) {
14311434
findInStrings = findInComments = false;
@@ -3815,7 +3818,7 @@ ${code}
38153818
return ts.arrayFrom(set.keys());
38163819
}
38173820

3818-
function toArray<T>(x: Many<T>): ReadonlyArray<T> {
3821+
function toArray<T>(x: ArrayOrSingle<T>): ReadonlyArray<T> {
38193822
return ts.isArray(x) ? x : [x];
38203823
}
38213824

@@ -4763,9 +4766,9 @@ namespace FourSlashInterface {
47634766
}
47644767

47654768
export interface VerifyCompletionsOptions {
4766-
readonly at?: Many<string>;
4769+
readonly marker?: Many<string>;
47674770
readonly isNewIdentifierLocation?: boolean;
4768-
readonly are?: Many<ExpectedCompletionEntry>;
4771+
readonly exact?: Many<ExpectedCompletionEntry>;
47694772
readonly includes?: Many<ExpectedCompletionEntry>;
47704773
readonly excludes?: Many<string | { readonly name: string, readonly source: string }>;
47714774
readonly preferences: ts.UserPreferences;

tests/cases/fourslash/augmentedTypesClass1.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
////var r = new c5b();
77
////r./*2*/
88

9-
verify.completions({ at: "1", includes: { name: "prototype", text: '(property) c5b.prototype: c5b' } });
9+
verify.completions({ marker: "1", includes: { name: "prototype", text: '(property) c5b.prototype: c5b' } });
1010
edit.insert('y;');
11-
verify.completions({ at: "2", includes: { name: "foo", text: '(method) c5b.foo(): void' } });
11+
verify.completions({ marker: "2", includes: { name: "foo", text: '(method) c5b.foo(): void' } });

tests/cases/fourslash/augmentedTypesModule6.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88
////var r2: m3f.I = r;
99
////r2./*6*/
1010

11-
verify.completions({ at: "1", includes: "I", excludes: "foo" });
11+
verify.completions({ marker: "1", includes: "I", excludes: "foo" });
1212
edit.insert('I;');
1313

14-
verify.completions({ at: "2", includes: "m3f" });
14+
verify.completions({ marker: "2", includes: "m3f" });
1515

1616
goTo.marker('3');
1717
verify.currentSignatureHelpIs('m3f(): m3f');
1818

1919
verify.quickInfoAt("4", "var r: m3f");
2020

21-
verify.completions({ at: "5", includes: "foo" });
21+
verify.completions({ marker: "5", includes: "foo" });
2222
edit.insert('foo(1)');
2323

24-
verify.completions({ at: "6", includes: "foo" });
24+
verify.completions({ marker: "6", includes: "foo" });
2525
edit.insert('foo(');
2626
verify.currentSignatureHelpIs('foo(): void');

tests/cases/fourslash/cloduleAsBaseClass2.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
////d./*1*/
2929
////D./*2*/
3030

31-
verify.completions({ at: "1", are: ["foo2", "foo"] });
31+
verify.completions({ marker: "1", exact: ["foo2", "foo"] });
3232
edit.insert('foo()');
3333

34-
verify.completions({ at: "2", includes: ["bar", "bar2", "baz", "x"], excludes: ["foo", "foo2"] });
34+
verify.completions({ marker: "2", includes: ["bar", "bar2", "baz", "x"], excludes: ["foo", "foo2"] });
3535
edit.insert('bar()');
3636

3737
verify.noErrors();

tests/cases/fourslash/cloduleTypeOf1.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
//// }
1515
////}
1616

17-
verify.completions({ at: "1", includes: ["f", "foo"] });
17+
verify.completions({ marker: "1", includes: ["f", "foo"] });
1818
edit.insert('foo(1);');
1919

20-
verify.completions({ at: "2", includes: "x" });
20+
verify.completions({ marker: "2", includes: "x" });
2121

2222
verify.quickInfoAt("3", "(local var) r: C<number>");
2323

24-
verify.completions({ at: "4", includes: "x" });
24+
verify.completions({ marker: "4", includes: "x" });
2525
edit.insert('x;');
2626

2727
verify.quickInfoAt("5", "(local var) r2: number");

tests/cases/fourslash/commentsEnums.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ verify.quickInfos({
1818
});
1919

2020
verify.completions({
21-
at: "5",
21+
marker: "5",
2222
includes: { name: "Colors", text: "enum Colors", documentation: "Enum of colors" },
2323
isNewIdentifierLocation: true,
2424
});
@@ -28,8 +28,8 @@ const completions = [
2828
{ name: "Cornflower", text: "(enum member) Colors.Cornflower = 0", documentation: "Fancy name for 'blue'" },
2929
{ name: "FancyPink", text: "(enum member) Colors.FancyPink = 1", documentation: "Fancy name for 'pink'" },
3030
];
31-
verify.completions({ at: "6", includes: completions });
31+
verify.completions({ marker: "6", includes: completions });
3232
verify.quickInfoIs("(enum member) Colors.Cornflower = 0", "Fancy name for 'blue'");
3333

34-
verify.completions({ at: "7", includes: completions });
34+
verify.completions({ marker: "7", includes: completions });
3535
verify.quickInfoIs("(enum member) Colors.FancyPink = 1", "Fancy name for 'pink'");

tests/cases/fourslash/commentsImportDeclaration.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ verify.quickInfos({
2929
3: ['import extMod = require("./commentsImportDeclaration_file0")', "Import declaration"]
3030
});
3131

32-
verify.completions({ at: "6", are: [{ name: "m1", text: "namespace extMod.m1", documentation: "NamespaceComment" }] });
32+
verify.completions({ marker: "6", exact: [{ name: "m1", text: "namespace extMod.m1", documentation: "NamespaceComment" }] });
3333

3434
verify.completions({
35-
at: "7",
36-
are: [
35+
marker: "7",
36+
exact: [
3737
{ name: "fooExport", text: "function extMod.m1.fooExport(): number", documentation: "exported function" },
3838
{ name: "b", text: "var extMod.m1.b: number", documentation: "b's comment" },
3939
{ name: "m2", text: "namespace extMod.m1.m2", documentation: "m2 comments" },
@@ -48,8 +48,8 @@ verify.quickInfos({
4848
});
4949

5050
verify.completions({
51-
at: "10",
52-
are: [
51+
marker: "10",
52+
exact: [
5353
{ name: "c", text: "constructor extMod.m1.m2.c(): extMod.m1.m2.c" },
5454
{ name: "i", text: "var extMod.m1.m2.i: extMod.m1.m2.c", documentation: "i" },
5555
],

tests/cases/fourslash/commentsVariables.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,18 @@ verify.quickInfoAt("1", "var myVariable: number", "This is my variable");
4545

4646
verify.completions(
4747
{
48-
at: "2",
48+
marker: "2",
4949
includes: { name: "myVariable", text: "var myVariable: number", documentation: "This is my variable" },
5050
},
5151
{
52-
at: "3",
52+
marker: "3",
5353
includes: [
5454
{ name: "myVariable", text: "var myVariable: number", documentation: "This is my variable" },
5555
{ name: "d", text: "var d: number", documentation: "d variable" }
5656
],
5757
},
5858
{
59-
at: "4",
59+
marker: "4",
6060
includes: [
6161
{ name: "foo", text: "function foo(): void", documentation: "foos comment" },
6262
{ name: "fooVar", text: "var fooVar: () => void", documentation:"fooVar comment" },
@@ -73,7 +73,7 @@ verify.currentSignatureHelpDocCommentIs("fooVar comment");
7373
verify.quickInfoAt("6q", "var fooVar: () => void", "fooVar comment");
7474

7575
verify.completions({
76-
at: "7",
76+
marker: "7",
7777
includes: [
7878
{ name: "foo", text: "function foo(): void", documentation: "foos comment" },
7979
{ name: "fooVar", text: "var fooVar: () => void", documentation:"fooVar comment" },
@@ -91,8 +91,8 @@ verify.quickInfos({
9191
"9aq": ["var fooVar: () => void", "fooVar comment"]
9292
});
9393

94-
verify.completions({ at: "10", includes: { name: "i", text: "var i: c", documentation: "instance comment" } });
95-
verify.completions({ at: "11", includes: { name: "i1_i", text: "var i1_i: i1", documentation: "interface instance comments" } });
94+
verify.completions({ marker: "10", includes: { name: "i", text: "var i: c", documentation: "instance comment" } });
95+
verify.completions({ marker: "11", includes: { name: "i1_i", text: "var i1_i: i1", documentation: "interface instance comments" } });
9696

9797
verify.quickInfos({
9898
12: ["var fooVar: () => void", "fooVar comment"],

tests/cases/fourslash/completionForStringLiteralNonrelativeImport10.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424
// @Filename: dir1/dir2/dir3/node_modules/fake-module3/ts.ts
2525
////
2626

27-
verify.completions({ at: test.markerNames(), are: [], isNewIdentifierLocation: true });
27+
verify.completions({ marker: test.markerNames(), exact: [], isNewIdentifierLocation: true });

tests/cases/fourslash/completionForStringLiteralNonrelativeImport11.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
const kinds = ["import_as", "import_equals", "require"];
2525
verify.completions(
2626
{
27-
at: kinds.map(k => `${k}0`),
28-
are: "module",
27+
marker: kinds.map(k => `${k}0`),
28+
exact: "module",
2929
isNewIdentifierLocation: true,
3030
},
3131
{
32-
at: kinds.map(k => `${k}1`),
33-
are: "index",
32+
marker: kinds.map(k => `${k}1`),
33+
exact: "index",
3434
isNewIdentifierLocation: true,
3535
},
3636
)

0 commit comments

Comments
 (0)