Skip to content

Commit

Permalink
Add a test for all CompletionItem properties
Browse files Browse the repository at this point in the history
  • Loading branch information
DanTup committed Apr 8, 2019
1 parent 900cfec commit 95008a2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
22 changes: 22 additions & 0 deletions test/dart_only/providers/completion_item_provider.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as assert from "assert";
import * as vs from "vscode";
import { acceptFirstSuggestion, activate, currentDoc, ensureCompletion, ensureTestContent, ensureTestContentWithCursorPos, ensureTestContentWithSelection, everythingFile, extApi, getCompletionsAt, helloWorldCompletionFile, helloWorldPartFile, helloWorldPartWrapperFile, openFile, rangeOf, select, setTestContent } from "../../helpers";

Expand Down Expand Up @@ -55,6 +56,27 @@ describe("completion_item_provider", () => {
ensureCompletion(completions, vs.CompletionItemKind.Keyword, "final", "final");
});

it("full populates a completion", async () => {
await openFile(everythingFile);
const completions = await getCompletionsAt(`^return str`);

const cl = ensureCompletion(completions, vs.CompletionItemKind.Method, "methodWithArgsAndReturnValue(…)", "methodWithArgsAndReturnValue");
assert.equal(cl.additionalTextEdits, undefined); // Tested in the unimported imports test.
assert.equal(cl.command, undefined); // Tested in the unimported imports in part-file test.
assert.equal(cl.commitCharacters, undefined); // TODO: ??
assert.equal(cl.detail, "(int i) → int");
assert.equal((cl.documentation as vs.MarkdownString).value, "This is my method taking arguments and returning a value.");
assert.equal(cl.filterText, "methodWithArgsAndReturnValue");
assert.equal((cl.insertText as vs.SnippetString).value, "methodWithArgsAndReturnValue(${1:i})");
assert.equal(cl.keepWhitespace, true);
assert.equal(cl.kind, vs.CompletionItemKind.Method);
assert.equal(cl.label, "methodWithArgsAndReturnValue(…)");
assert.notEqual(cl.preselect, true);
assert.equal(cl.range.isEqual(rangeOf("|return| str")), true);
assert.equal(cl.sortText, "998943methodWithArgsAndReturnValue(…)"); // TODO: This may be fragile...
assert.equal(cl.textEdit, undefined); // We don't use this (we use insertText and range).
});

it("sorts completions by relevance", async () => {
throw new Error("NYI");
});
Expand Down
5 changes: 3 additions & 2 deletions test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ export async function getSnippetCompletionsAt(searchText: string, triggerCharact
return completions.filter((c) => c.kind === vs.CompletionItemKind.Snippet);
}

export function ensureCompletion(items: vs.CompletionItem[], kind: vs.CompletionItemKind, label: string, filterText?: string, documentation?: string): void {
export function ensureCompletion(items: vs.CompletionItem[], kind: vs.CompletionItemKind, label: string, filterText?: string, documentation?: string): vs.CompletionItem {
let completion = items.find((item) =>
item.label === label
&& item.filterText === filterText
Expand All @@ -505,8 +505,9 @@ export function ensureCompletion(items: vs.CompletionItem[], kind: vs.Completion
);
completion = completion!;
if (documentation) {
assert.equal(((completion.documentation as any).value as string).trim(), documentation);
assert.equal((completion.documentation as any).value.trim(), documentation);
}
return completion;
}

export function ensureSnippet(items: vs.CompletionItem[], label: string, filterText: string, documentation?: string): void {
Expand Down
5 changes: 5 additions & 0 deletions test/test_projects/hello_world/lib/everything.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ class MyClass {

/// This is my method taking a function.
void methodTakingFunction(void Function(String) myFunc) {}

/// This is my method taking arguments and returning a value.
int methodWithArgsAndReturnValue(int i) {
return i;
}
}

@deprecated
Expand Down

0 comments on commit 95008a2

Please sign in to comment.