mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-25 12:40:05 -05:00
Update verification function to be able to test that the only symbol with certain kind, document, and text is the completion list
This commit is contained in:
@@ -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('<ShowCompletionList />');
|
||||
this.scenarioActions.push('<VerifyCompletionDoesNotContainItem ItemName="' + escapeXmlAttributeValue(symbol) + '" />');
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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")
|
||||
verify.completionListContains("foo", "function foo(): void", /*documentation*/ undefined, "function")
|
||||
verify.not.completionListContains("foo", "(local function) foo(): void", /*documentation*/ undefined, "local function");;
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user