|
1 | 1 | 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'; |
2 | 17 |
|
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 | +} |
7 | 73 |
|
8 | 74 | 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[]>; |
10 | 86 |
|
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); |
14 | 90 | }); |
15 | 91 | }); |
0 commit comments