mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
clean up tests
This commit is contained in:
parent
959e1e2106
commit
15f97e8355
|
@ -7,10 +7,37 @@
|
|||
import * as assert from 'assert';
|
||||
import * as path from 'path';
|
||||
import { providePathSuggestions } from '../../modes/pathCompletion';
|
||||
import { CompletionItemKind, Range, Position } from 'vscode-languageserver-types';
|
||||
import { CompletionItemKind, Range, Position, CompletionItem, TextEdit } from 'vscode-languageserver-types';
|
||||
|
||||
const fixtureRoot = path.resolve(__dirname, '../../../test/pathCompletionFixtures');
|
||||
|
||||
function toRange(line: number, startChar: number, endChar: number) {
|
||||
return Range.create(Position.create(line, startChar), Position.create(line, endChar));
|
||||
}
|
||||
|
||||
interface PathSuggestion {
|
||||
label?: string;
|
||||
kind?: CompletionItemKind;
|
||||
textEdit?: TextEdit;
|
||||
}
|
||||
|
||||
function assertSuggestions( actual: CompletionItem[], expected: PathSuggestion[]) {
|
||||
assert.equal(actual.length, expected.length, 'Suggestions should have expected length');
|
||||
|
||||
for (let i = 0; i < expected.length; i++) {
|
||||
if (expected[i].label) {
|
||||
assert.equal(actual[i].label, expected[i].label, `Suggestion ${actual[i].label} should have label ${expected[i].label}`);
|
||||
}
|
||||
if (expected[i].kind) {
|
||||
assert.equal(actual[i].kind, expected[i].kind, `Suggestion ${actual[i].label} has type ${CompletionItemKind[actual[i].kind]} but should have label ${CompletionItemKind[expected[i].kind]}`);
|
||||
}
|
||||
if (expected[i].textEdit) {
|
||||
assert.equal(actual[i].textEdit.newText, expected[i].textEdit.newText);
|
||||
assert.deepEqual(actual[i].textEdit.range, expected[i].textEdit.range);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suite('Path Completion - Relative Path', () => {
|
||||
const mockRange = Range.create(Position.create(0, 3), Position.create(0, 5));
|
||||
|
||||
|
@ -19,14 +46,11 @@ suite('Path Completion - Relative Path', () => {
|
|||
const activeFileFsPath = path.resolve(fixtureRoot, 'index.html');
|
||||
const suggestions = providePathSuggestions(value, mockRange, activeFileFsPath);
|
||||
|
||||
assert.equal(suggestions.length, 3);
|
||||
assert.equal(suggestions[0].label, 'about');
|
||||
assert.equal(suggestions[1].label, 'index.html');
|
||||
assert.equal(suggestions[2].label, 'src');
|
||||
|
||||
assert.equal(suggestions[0].kind, CompletionItemKind.Folder);
|
||||
assert.equal(suggestions[1].kind, CompletionItemKind.File);
|
||||
assert.equal(suggestions[2].kind, CompletionItemKind.Folder);
|
||||
assertSuggestions(suggestions, [
|
||||
{ label: 'about', kind: CompletionItemKind.Folder },
|
||||
{ label: 'index.html', kind: CompletionItemKind.File },
|
||||
{ label: 'src', kind: CompletionItemKind.Folder }
|
||||
]);
|
||||
});
|
||||
|
||||
test('Parent Folder', () => {
|
||||
|
@ -34,14 +58,11 @@ suite('Path Completion - Relative Path', () => {
|
|||
const activeFileFsPath = path.resolve(fixtureRoot, 'about/about.html');
|
||||
const suggestions = providePathSuggestions(value, mockRange, activeFileFsPath);
|
||||
|
||||
assert.equal(suggestions.length, 3);
|
||||
assert.equal(suggestions[0].label, 'about');
|
||||
assert.equal(suggestions[1].label, 'index.html');
|
||||
assert.equal(suggestions[2].label, 'src');
|
||||
|
||||
assert.equal(suggestions[0].kind, CompletionItemKind.Folder);
|
||||
assert.equal(suggestions[1].kind, CompletionItemKind.File);
|
||||
assert.equal(suggestions[2].kind, CompletionItemKind.Folder);
|
||||
assertSuggestions(suggestions, [
|
||||
{ label: 'about', kind: CompletionItemKind.Folder },
|
||||
{ label: 'index.html', kind: CompletionItemKind.File },
|
||||
{ label: 'src', kind: CompletionItemKind.Folder }
|
||||
]);
|
||||
});
|
||||
|
||||
test('Adjacent Folder', () => {
|
||||
|
@ -49,15 +70,11 @@ suite('Path Completion - Relative Path', () => {
|
|||
const activeFileFsPath = path.resolve(fixtureRoot, 'about/about.html');
|
||||
const suggestions = providePathSuggestions(value, mockRange, activeFileFsPath);
|
||||
|
||||
assert.equal(suggestions.length, 2);
|
||||
assert.equal(suggestions[0].label, 'feature.js');
|
||||
assert.equal(suggestions[1].label, 'test.js');
|
||||
|
||||
assert.equal(suggestions[0].kind, CompletionItemKind.File);
|
||||
assert.equal(suggestions[1].kind, CompletionItemKind.File);
|
||||
assertSuggestions(suggestions, [
|
||||
{ label: 'feature.js', kind: CompletionItemKind.File },
|
||||
{ label: 'test.js', kind: CompletionItemKind.File }
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
suite('Path Completion - Absolute Path', () => {
|
||||
|
@ -72,13 +89,11 @@ suite('Path Completion - Absolute Path', () => {
|
|||
const suggestions2 = providePathSuggestions(value, mockRange, activeFileFsPath2, fixtureRoot);
|
||||
|
||||
const verify = (suggestions) => {
|
||||
assert.equal(suggestions[0].label, 'about');
|
||||
assert.equal(suggestions[1].label, 'index.html');
|
||||
assert.equal(suggestions[2].label, 'src');
|
||||
|
||||
assert.equal(suggestions[0].kind, CompletionItemKind.Folder);
|
||||
assert.equal(suggestions[1].kind, CompletionItemKind.File);
|
||||
assert.equal(suggestions[2].kind, CompletionItemKind.Folder);
|
||||
assertSuggestions(suggestions, [
|
||||
{ label: 'about', kind: CompletionItemKind.Folder },
|
||||
{ label: 'index.html', kind: CompletionItemKind.File },
|
||||
{ label: 'src', kind: CompletionItemKind.Folder }
|
||||
]);
|
||||
};
|
||||
|
||||
verify(suggestions1);
|
||||
|
@ -90,12 +105,10 @@ suite('Path Completion - Absolute Path', () => {
|
|||
const activeFileFsPath = path.resolve(fixtureRoot, 'about/about.html');
|
||||
const suggestions = providePathSuggestions(value, mockRange, activeFileFsPath, fixtureRoot);
|
||||
|
||||
assert.equal(suggestions.length, 2);
|
||||
assert.equal(suggestions[0].label, 'feature.js');
|
||||
assert.equal(suggestions[1].label, 'test.js');
|
||||
|
||||
assert.equal(suggestions[0].kind, CompletionItemKind.File);
|
||||
assert.equal(suggestions[1].kind, CompletionItemKind.File);
|
||||
assertSuggestions(suggestions, [
|
||||
{ label: 'feature.js', kind: CompletionItemKind.File },
|
||||
{ label: 'test.js', kind: CompletionItemKind.File }
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -107,12 +120,10 @@ suite('Path Completion - Incomplete Path at End', () => {
|
|||
const activeFileFsPath = path.resolve(fixtureRoot, 'about/about.html');
|
||||
const suggestions = providePathSuggestions(value, mockRange, activeFileFsPath, fixtureRoot);
|
||||
|
||||
assert.equal(suggestions.length, 2);
|
||||
assert.equal(suggestions[0].label, 'feature.js');
|
||||
assert.equal(suggestions[1].label, 'test.js');
|
||||
|
||||
assert.equal(suggestions[0].kind, CompletionItemKind.File);
|
||||
assert.equal(suggestions[1].kind, CompletionItemKind.File);
|
||||
assertSuggestions(suggestions, [
|
||||
{ label: 'feature.js', kind: CompletionItemKind.File },
|
||||
{ label: 'test.js', kind: CompletionItemKind.File }
|
||||
]);
|
||||
});
|
||||
|
||||
test('Incomplete Path that does not start with slash', () => {
|
||||
|
@ -120,12 +131,10 @@ suite('Path Completion - Incomplete Path at End', () => {
|
|||
const activeFileFsPath = path.resolve(fixtureRoot, 'about/about.html');
|
||||
const suggestions = providePathSuggestions(value, mockRange, activeFileFsPath, fixtureRoot);
|
||||
|
||||
assert.equal(suggestions.length, 2);
|
||||
assert.equal(suggestions[0].label, 'feature.js');
|
||||
assert.equal(suggestions[1].label, 'test.js');
|
||||
|
||||
assert.equal(suggestions[0].kind, CompletionItemKind.File);
|
||||
assert.equal(suggestions[1].kind, CompletionItemKind.File);
|
||||
assertSuggestions(suggestions, [
|
||||
{ label: 'feature.js', kind: CompletionItemKind.File },
|
||||
{ label: 'test.js', kind: CompletionItemKind.File }
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -133,19 +142,15 @@ suite('Path Completion - TextEdit', () => {
|
|||
test('TextEdit has correct replace text and range', () => {
|
||||
const value = './';
|
||||
const activeFileFsPath = path.resolve(fixtureRoot, 'index.html');
|
||||
const range = Range.create(Position.create(0, 3), Position.create(0, 5));
|
||||
const range = toRange(0, 3, 5);
|
||||
const expectedReplaceRange = toRange(0, 4, 4);
|
||||
|
||||
const suggestions = providePathSuggestions(value, range, activeFileFsPath);
|
||||
|
||||
assert.equal(suggestions[0].textEdit.newText, 'about');
|
||||
assert.equal(suggestions[1].textEdit.newText, 'index.html');
|
||||
assert.equal(suggestions[2].textEdit.newText, 'src');
|
||||
|
||||
assert.equal(suggestions[0].textEdit.range.start.character, 4);
|
||||
assert.equal(suggestions[1].textEdit.range.start.character, 4);
|
||||
assert.equal(suggestions[2].textEdit.range.start.character, 4);
|
||||
|
||||
assert.equal(suggestions[0].textEdit.range.end.character, 4);
|
||||
assert.equal(suggestions[1].textEdit.range.end.character, 4);
|
||||
assert.equal(suggestions[2].textEdit.range.end.character, 4);
|
||||
assertSuggestions(suggestions, [
|
||||
{ textEdit: TextEdit.replace(expectedReplaceRange, 'about') },
|
||||
{ textEdit: TextEdit.replace(expectedReplaceRange, 'index.html') },
|
||||
{ textEdit: TextEdit.replace(expectedReplaceRange, 'src') },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue