diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts
index 0717ed68e83..9a07482e60d 100644
--- a/src/harness/fourslash.ts
+++ b/src/harness/fourslash.ts
@@ -704,13 +704,55 @@ module FourSlash {
}
}
- public verifyCompletionListDoesNotContain(symbol: string) {
+ /**
+ * Verfiy that the completion list does NOT contain the given symbol. If text, or documentation, or kind are provided,
+ * the list contains the symbol all given parameters must matched. When any parameter is omitted, the parameters is ignored during comparison.
+ */
+ public verifyCompletionListDoesNotContain(symbol: string, expectedText?: string, expectedDocumentation?: string, expectedKind?: string) {
+ let that = this;
+ function filterByTextOrDocumentation(entry: ts.CompletionEntry) {
+ let details = that.getCompletionEntryDetails(entry.name);
+ let documentation = ts.displayPartsToString(details.documentation);
+ let text = ts.displayPartsToString(details.displayParts);
+ if (expectedText && expectedDocumentation) {
+ return (documentation === expectedDocumentation && text === expectedText) ? true : false;
+ }
+ else if (expectedText && !expectedDocumentation) {
+ return text === expectedText ? true : false;
+ }
+ else if (expectedDocumentation && !expectedText) {
+ return documentation === expectedDocumentation ? true : false;
+ }
+ // Because expectedText and expectedDocumentation are undefined, we assume that
+ // users don't care to compare them so we will treat that entry as if the entry has matching text and documentation
+ // and keep it in the list of filtered entry.
+ return true;
+ }
this.scenarioActions.push('');
this.scenarioActions.push('');
var completions = this.getCompletionListAtCaret();
- if (completions && completions.entries.filter(e => e.name === symbol).length !== 0) {
- this.raiseError('Completion list did contain ' + symbol);
+ if (completions) {
+ let filterCompletions = completions.entries.filter(e => e.name === symbol);
+ filterCompletions = expectedKind ? filterCompletions.filter(e => e.kind === expectedKind) : filterCompletions;
+ filterCompletions = filterCompletions.filter(filterByTextOrDocumentation);
+ if (filterCompletions.length !== 0) {
+ // After filtered using all present criterion, if there are still symbol left in the list
+ // then these symbols must meet the criterion for Not supposed to be in the list. So we
+ // raise an error
+ let error = "Completion list did contain \'" + symbol + "\'.";
+ let details = this.getCompletionEntryDetails(filterCompletions[0].name);
+ if (expectedText) {
+ error += "Expected text: " + expectedText + " to equal: " + ts.displayPartsToString(details.displayParts) + ".";
+ }
+ if (expectedDocumentation) {
+ error += "Expected documentation: " + expectedDocumentation + " to equal: " + ts.displayPartsToString(details.documentation) + ".";
+ }
+ if (expectedKind) {
+ error += "Expected kind: " + expectedKind + " to equal: " + filterCompletions[0].kind + "."
+ }
+ this.raiseError(error);
+ }
}
}
diff --git a/tests/cases/fourslash/completionListInNamedClassExpressionWithShadowing.ts b/tests/cases/fourslash/completionListInNamedClassExpressionWithShadowing.ts
index b1f7f1ca3f0..e1274e6f592 100644
--- a/tests/cases/fourslash/completionListInNamedClassExpressionWithShadowing.ts
+++ b/tests/cases/fourslash/completionListInNamedClassExpressionWithShadowing.ts
@@ -17,18 +17,24 @@
goTo.marker("0");
verify.completionListContains("myClass", "class myClass", /*documentation*/ undefined, "class");
+verify.not.completionListContains("myClass", "(local class) myClass", /*documentation*/ undefined, "local class");
goTo.marker("1");
verify.completionListContains("myClass", "class myClass", /*documentation*/ undefined, "class");
+verify.not.completionListContains("myClass", "(local class) myClass", /*documentation*/ undefined, "local class");
goTo.marker("2");
verify.completionListContains("myClass", "(local class) myClass", /*documentation*/ undefined, "local class");
+verify.not.completionListContains("myClass", "class myClass", /*documentation*/ undefined, "class");
goTo.marker("3");
verify.completionListContains("myClass", "(local class) myClass", /*documentation*/ undefined, "local class");
+verify.not.completionListContains("myClass", "class myClass", /*documentation*/ undefined, "class");
goTo.marker("4");
verify.completionListContains("myClass", "class myClass", /*documentation*/ undefined, "class");
+verify.not.completionListContains("myClass", "(local class) myClass", /*documentation*/ undefined, "local class");
goTo.marker("5");
verify.completionListContains("myClass", "class myClass", /*documentation*/ undefined, "class");
+verify.not.completionListContains("myClass", "(local class) myClass", /*documentation*/ undefined, "local class");
diff --git a/tests/cases/fourslash/completionListInNamedFunctionExpressionWithShadowing.ts b/tests/cases/fourslash/completionListInNamedFunctionExpressionWithShadowing.ts
index 7d441acb7d7..14965253e84 100644
--- a/tests/cases/fourslash/completionListInNamedFunctionExpressionWithShadowing.ts
+++ b/tests/cases/fourslash/completionListInNamedFunctionExpressionWithShadowing.ts
@@ -11,9 +11,12 @@
goTo.marker("0");
verify.completionListContains("foo", "function foo(): void", /*documentation*/ undefined, "function");
+verify.not.completionListContains("foo", "(local function) foo(): void", /*documentation*/ undefined, "local function");;
goTo.marker("1");
verify.completionListContains("foo", "(local function) foo(): void", /*documentation*/ undefined, "local function");
+verify.not.completionListContains("foo", "function foo(): void", /*documentation*/ undefined, "function");;
goTo.marker("2");
-verify.completionListContains("foo", "function foo(): void", /*documentation*/ undefined, "function")
\ No newline at end of file
+verify.completionListContains("foo", "function foo(): void", /*documentation*/ undefined, "function")
+verify.not.completionListContains("foo", "(local function) foo(): void", /*documentation*/ undefined, "local function");;
\ No newline at end of file
diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts
index 07a1fc4de40..a0463073d8c 100644
--- a/tests/cases/fourslash/fourslash.ts
+++ b/tests/cases/fourslash/fourslash.ts
@@ -169,7 +169,7 @@ module FourSlashInterface {
// completion list is brought up if necessary
public completionListContains(symbol: string, text?: string, documentation?: string, kind?: string) {
if (this.negative) {
- FourSlash.currentTestState.verifyCompletionListDoesNotContain(symbol);
+ FourSlash.currentTestState.verifyCompletionListDoesNotContain(symbol, text, documentation, kind);
} else {
FourSlash.currentTestState.verifyCompletionListContains(symbol, text, documentation, kind);
}