Skip to content

Commit 3079607

Browse files
author
Yui T
committed
Update verification function to be able to test that the only symbol with certain kind, document, and text is the completion list
1 parent 7747ad4 commit 3079607

File tree

4 files changed

+56
-5
lines changed

4 files changed

+56
-5
lines changed

src/harness/fourslash.ts

+45-3
Original file line numberDiff line numberDiff line change
@@ -704,13 +704,55 @@ module FourSlash {
704704
}
705705
}
706706

707-
public verifyCompletionListDoesNotContain(symbol: string) {
707+
/**
708+
* Verfiy that the completion list does NOT contain the given symbol. If text, or documentation, or kind are provided,
709+
* the list contains the symbol all given parameters must matched. When any parameter is omitted, the parameters is ignored during comparison.
710+
*/
711+
public verifyCompletionListDoesNotContain(symbol: string, expectedText?: string, expectedDocumentation?: string, expectedKind?: string) {
712+
let that = this;
713+
function filterByTextOrDocumentation(entry: ts.CompletionEntry) {
714+
let details = that.getCompletionEntryDetails(entry.name);
715+
let documentation = ts.displayPartsToString(details.documentation);
716+
let text = ts.displayPartsToString(details.displayParts);
717+
if (expectedText && expectedDocumentation) {
718+
return (documentation === expectedDocumentation && text === expectedText) ? true : false;
719+
}
720+
else if (expectedText && !expectedDocumentation) {
721+
return text === expectedText ? true : false;
722+
}
723+
else if (expectedDocumentation && !expectedText) {
724+
return documentation === expectedDocumentation ? true : false;
725+
}
726+
// Because expectedText and expectedDocumentation are undefined, we assume that
727+
// users don't care to compare them so we will treat that entry as if the entry has matching text and documentation
728+
// and keep it in the list of filtered entry.
729+
return true;
730+
}
708731
this.scenarioActions.push('<ShowCompletionList />');
709732
this.scenarioActions.push('<VerifyCompletionDoesNotContainItem ItemName="' + escapeXmlAttributeValue(symbol) + '" />');
710733

711734
var completions = this.getCompletionListAtCaret();
712-
if (completions && completions.entries.filter(e => e.name === symbol).length !== 0) {
713-
this.raiseError('Completion list did contain ' + symbol);
735+
if (completions) {
736+
let filterCompletions = completions.entries.filter(e => e.name === symbol);
737+
filterCompletions = expectedKind ? filterCompletions.filter(e => e.kind === expectedKind) : filterCompletions;
738+
filterCompletions = filterCompletions.filter(filterByTextOrDocumentation);
739+
if (filterCompletions.length !== 0) {
740+
// After filtered using all present criterion, if there are still symbol left in the list
741+
// then these symbols must meet the criterion for Not supposed to be in the list. So we
742+
// raise an error
743+
let error = "Completion list did contain \'" + symbol + "\'.";
744+
let details = this.getCompletionEntryDetails(filterCompletions[0].name);
745+
if (expectedText) {
746+
error += "Expected text: " + expectedText + " to equal: " + ts.displayPartsToString(details.displayParts) + ".";
747+
}
748+
if (expectedDocumentation) {
749+
error += "Expected documentation: " + expectedDocumentation + " to equal: " + ts.displayPartsToString(details.documentation) + ".";
750+
}
751+
if (expectedKind) {
752+
error += "Expected kind: " + expectedKind + " to equal: " + filterCompletions[0].kind + "."
753+
}
754+
this.raiseError(error);
755+
}
714756
}
715757
}
716758

tests/cases/fourslash/completionListInNamedClassExpressionWithShadowing.ts

+6
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,24 @@
1717

1818
goTo.marker("0");
1919
verify.completionListContains("myClass", "class myClass", /*documentation*/ undefined, "class");
20+
verify.not.completionListContains("myClass", "(local class) myClass", /*documentation*/ undefined, "local class");
2021

2122
goTo.marker("1");
2223
verify.completionListContains("myClass", "class myClass", /*documentation*/ undefined, "class");
24+
verify.not.completionListContains("myClass", "(local class) myClass", /*documentation*/ undefined, "local class");
2325

2426
goTo.marker("2");
2527
verify.completionListContains("myClass", "(local class) myClass", /*documentation*/ undefined, "local class");
28+
verify.not.completionListContains("myClass", "class myClass", /*documentation*/ undefined, "class");
2629

2730
goTo.marker("3");
2831
verify.completionListContains("myClass", "(local class) myClass", /*documentation*/ undefined, "local class");
32+
verify.not.completionListContains("myClass", "class myClass", /*documentation*/ undefined, "class");
2933

3034
goTo.marker("4");
3135
verify.completionListContains("myClass", "class myClass", /*documentation*/ undefined, "class");
36+
verify.not.completionListContains("myClass", "(local class) myClass", /*documentation*/ undefined, "local class");
3237

3338
goTo.marker("5");
3439
verify.completionListContains("myClass", "class myClass", /*documentation*/ undefined, "class");
40+
verify.not.completionListContains("myClass", "(local class) myClass", /*documentation*/ undefined, "local class");

tests/cases/fourslash/completionListInNamedFunctionExpressionWithShadowing.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111

1212
goTo.marker("0");
1313
verify.completionListContains("foo", "function foo(): void", /*documentation*/ undefined, "function");
14+
verify.not.completionListContains("foo", "(local function) foo(): void", /*documentation*/ undefined, "local function");;
1415

1516
goTo.marker("1");
1617
verify.completionListContains("foo", "(local function) foo(): void", /*documentation*/ undefined, "local function");
18+
verify.not.completionListContains("foo", "function foo(): void", /*documentation*/ undefined, "function");;
1719

1820
goTo.marker("2");
19-
verify.completionListContains("foo", "function foo(): void", /*documentation*/ undefined, "function")
21+
verify.completionListContains("foo", "function foo(): void", /*documentation*/ undefined, "function")
22+
verify.not.completionListContains("foo", "(local function) foo(): void", /*documentation*/ undefined, "local function");;

tests/cases/fourslash/fourslash.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ module FourSlashInterface {
169169
// completion list is brought up if necessary
170170
public completionListContains(symbol: string, text?: string, documentation?: string, kind?: string) {
171171
if (this.negative) {
172-
FourSlash.currentTestState.verifyCompletionListDoesNotContain(symbol);
172+
FourSlash.currentTestState.verifyCompletionListDoesNotContain(symbol, text, documentation, kind);
173173
} else {
174174
FourSlash.currentTestState.verifyCompletionListContains(symbol, text, documentation, kind);
175175
}

0 commit comments

Comments
 (0)