Skip to content

Commit f1f7ff4

Browse files
committed
Added first test
1 parent eaffd2f commit f1f7ff4

File tree

3 files changed

+98
-10
lines changed

3 files changed

+98
-10
lines changed

package-lock.json

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,4 @@
7373
"webpack": "^5.9.0",
7474
"webpack-cli": "^4.2.0"
7575
}
76-
}
76+
}

src/test/suite/extension.test.ts

Lines changed: 84 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,91 @@
11
import * as assert from 'assert';
2+
import { ClassCompletionItemProvider } from '../../extension';
3+
import {
4+
window,
5+
TextDocument,
6+
Position,
7+
CancellationToken,
8+
Event,
9+
CompletionContext,
10+
CompletionTriggerKind,
11+
EndOfLine,
12+
Range,
13+
TextLine,
14+
Uri,
15+
CompletionItem
16+
} from 'vscode';
217

3-
// You can import and use all API from the 'vscode' module
4-
// as well as import your extension to test it
5-
import * as vscode from 'vscode';
6-
// import * as myExtension from '../../extension';
18+
class MockCancellationToken implements CancellationToken {
19+
isCancellationRequested: boolean;
20+
onCancellationRequested!: Event<any>;
21+
22+
constructor(isCancellationRequested: boolean) {
23+
this.isCancellationRequested = isCancellationRequested;
24+
}
25+
}
26+
27+
class MockCompletionContext implements CompletionContext {
28+
triggerKind = CompletionTriggerKind.Invoke;
29+
triggerCharacter?: string | undefined;
30+
}
31+
32+
class MockTextDocument implements TextDocument {
33+
uri!: Uri;
34+
fileName!: string;
35+
isUntitled!: boolean;
36+
languageId!: string;
37+
version!: number;
38+
isDirty!: boolean;
39+
isClosed!: boolean;
40+
eol!: EndOfLine;
41+
lineCount!: number;
42+
readonly #text: string;
43+
44+
constructor(text: string) {
45+
this.#text = text;
46+
}
47+
48+
getText(range?: Range): string {
49+
return this.#text;
50+
}
51+
save(): Thenable<boolean> {
52+
throw new Error('Method not implemented.');
53+
}
54+
lineAt(position: Position | number | any): TextLine | any {
55+
throw new Error('Method not implemented.');
56+
}
57+
offsetAt(position: Position): number {
58+
throw new Error('Method not implemented.');
59+
}
60+
positionAt(offset: number): Position {
61+
throw new Error('Method not implemented.');
62+
}
63+
getWordRangeAtPosition(position: Position, regex?: RegExp): Range | undefined {
64+
throw new Error('Method not implemented.');
65+
}
66+
validateRange(range: Range): Range {
67+
throw new Error('Method not implemented.');
68+
}
69+
validatePosition(position: Position): Position {
70+
throw new Error('Method not implemented.');
71+
}
72+
}
773

874
suite('Extension Test Suite', () => {
9-
vscode.window.showInformationMessage('Start all tests.');
75+
window.showInformationMessage('Start all tests.');
76+
77+
test('Completes empty document with no items.', done => {
78+
const provider = new ClassCompletionItemProvider();
79+
80+
const document = new MockTextDocument("");
81+
const position = new Position(0, 0);
82+
const token = new MockCancellationToken(false);
83+
const context = new MockCompletionContext();
84+
85+
const result = provider.provideCompletionItems(document, position, token, context) as Thenable<CompletionItem[]>;
1086

11-
test('Sample test', () => {
12-
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
13-
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
87+
result.then((items) => {
88+
assert.strictEqual(items.length, 0);
89+
}, done);
1490
});
1591
});

0 commit comments

Comments
 (0)