This commit is contained in:
Luke Hoban 2015-12-14 13:55:14 -08:00
Родитель 16a4f4f306
Коммит 43a9d7741b
1 изменённых файлов: 46 добавлений и 15 удалений

Просмотреть файл

@ -4,16 +4,19 @@ import * as fs from 'fs-extra';
import * as path from 'path';
import * as vscode from 'vscode';
import { GoHoverProvider } from '../src/goExtraInfo';
// setup:
// Fixture path: $GOPATH/src/___testrepo/test/testfixture/test.go
// Fixture file: test.go
// Contents:
import { GoCompletionItemProvider } from '../src/goSuggest';
var fixtureSrc =
`package main
`package main
import (
"fmt"
)
func print(txt string) {
fmt.Println(txt)
}
func main() {
main()
print("Hello")
}`;
suite("Go Extension Tests", () => {
@ -35,17 +38,45 @@ suite("Go Extension Tests", () => {
test("Test Hover Provider", (done) => {
let provider = new GoHoverProvider();
let position = new vscode.Position(1, 6);
let testCases: [vscode.Position, string][] = [
[new vscode.Position(3,3), '/usr/local/go/src/fmt'],
[new vscode.Position(8,6), 'main func()'],
[new vscode.Position(6,2), 'import (fmt "fmt")'],
[new vscode.Position(6,6), 'Println func(a ...interface{}) (n int, err error)'],
[new vscode.Position(9,3), 'print func(txt string)']
];
let uri = vscode.Uri.file(fixture);
vscode.workspace.openTextDocument(uri).then((textDocument) => {
provider.provideHover(textDocument, position, null).then(value => {
assert.equal(value.contents.length, 1);
assert.equal('main func()', (<{ language: string; value: string }>value.contents[0]).value, 'hover text does not match');
done();
});
let promises = testCases.map(([position, expected]) =>
provider.provideHover(textDocument, position, null).then(res => {
assert.equal(res.contents.length, 1);
assert.equal(expected, (<{ language: string; value: string }>res.contents[0]).value);
})
);
return Promise.all(promises);
}, (err) => {
assert.ok(false, `error in OpenTextDocument ${err}`);
});
}).then(() => done(),done);
});
test("Test Completion", (done) => {
let provider = new GoCompletionItemProvider();
let testCases: [vscode.Position, string[]][] = [
[new vscode.Position(1,0), []],
[new vscode.Position(4,1), ['main', 'print', 'fmt']],
[new vscode.Position(6,4), ['fmt']],
[new vscode.Position(7,0), ['main', 'print', 'fmt', 'txt']]
];
let uri = vscode.Uri.file(fixture);
vscode.workspace.openTextDocument(uri).then((textDocument) => {
let promises = testCases.map(([position, expected]) =>
provider.provideCompletionItems(textDocument, position, null).then(items => {
assert.deepEqual(expected, items.map(x => x.label));
})
);
return Promise.all(promises);
}, (err) => {
assert.ok(false, `error in OpenTextDocument ${err}`);
}).then(() => done(),done);
});
});