Add cursor position check to jsDocCompletionTest
This commit is contained in:
parent
2b7e6ab2fd
commit
87b6d03182
|
@ -3,12 +3,11 @@
|
||||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||||
*--------------------------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
import * as assert from 'assert';
|
|
||||||
import 'mocha';
|
import 'mocha';
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import { disposeAll } from '../utils/dispose';
|
import { disposeAll } from '../utils/dispose';
|
||||||
import { acceptFirstSuggestion } from './suggestTestHelpers';
|
import { acceptFirstSuggestion } from './suggestTestHelpers';
|
||||||
import { Config, createTestEditor, joinLines, updateConfig, VsCodeConfiguration, wait } from './testUtils';
|
import { assertEditorContents, Config, createTestEditor, CURSOR, enumerateConfig, insertModesValues, joinLines, updateConfig, VsCodeConfiguration, wait } from './testUtils';
|
||||||
|
|
||||||
const testDocumentUri = vscode.Uri.parse('untitled:test.ts');
|
const testDocumentUri = vscode.Uri.parse('untitled:test.ts');
|
||||||
|
|
||||||
|
@ -38,21 +37,25 @@ suite('JSDoc Completions', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Should complete jsdoc inside single line comment', async () => {
|
test('Should complete jsdoc inside single line comment', async () => {
|
||||||
await createTestEditor(testDocumentUri,
|
await enumerateConfig(testDocumentUri, Config.insertMode, insertModesValues, async config => {
|
||||||
`/**$0 */`,
|
|
||||||
`function abcdef(x, y) { }`,
|
|
||||||
);
|
|
||||||
|
|
||||||
const document = await acceptFirstSuggestion(testDocumentUri, _disposables);
|
const editor = await createTestEditor(testDocumentUri,
|
||||||
assert.strictEqual(
|
`/**$0 */`,
|
||||||
document.getText(),
|
|
||||||
joinLines(
|
|
||||||
`/**`,
|
|
||||||
` * `,
|
|
||||||
` * @param x `,
|
|
||||||
` * @param y `,
|
|
||||||
` */`,
|
|
||||||
`function abcdef(x, y) { }`,
|
`function abcdef(x, y) { }`,
|
||||||
));
|
);
|
||||||
|
|
||||||
|
await acceptFirstSuggestion(testDocumentUri, _disposables);
|
||||||
|
|
||||||
|
assertEditorContents(editor,
|
||||||
|
joinLines(
|
||||||
|
`/**`,
|
||||||
|
` * `,
|
||||||
|
` * @param x ${CURSOR}`,
|
||||||
|
` * @param y `,
|
||||||
|
` */`,
|
||||||
|
`function abcdef(x, y) { }`,
|
||||||
|
),
|
||||||
|
`Config: ${config}`);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -74,14 +74,9 @@ export const joinLines = (...args: string[]) => args.join('\n');
|
||||||
|
|
||||||
export async function createTestEditor(uri: vscode.Uri, ...lines: string[]) {
|
export async function createTestEditor(uri: vscode.Uri, ...lines: string[]) {
|
||||||
const document = await vscode.workspace.openTextDocument(uri);
|
const document = await vscode.workspace.openTextDocument(uri);
|
||||||
await vscode.window.showTextDocument(document);
|
const editor = await vscode.window.showTextDocument(document);
|
||||||
const activeEditor = vscode.window.activeTextEditor;
|
await editor.insertSnippet(new vscode.SnippetString(joinLines(...lines)), new vscode.Range(0, 0, 1000, 0));
|
||||||
if (!activeEditor) {
|
return editor;
|
||||||
throw new Error('no active editor');
|
|
||||||
}
|
|
||||||
|
|
||||||
await activeEditor.insertSnippet(new vscode.SnippetString(joinLines(...lines)), new vscode.Range(0, 0, 1000, 0));
|
|
||||||
return activeEditor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function assertEditorContents(editor: vscode.TextEditor, expectedDocContent: string, message?: string): void {
|
export function assertEditorContents(editor: vscode.TextEditor, expectedDocContent: string, message?: string): void {
|
||||||
|
@ -94,15 +89,11 @@ export function assertEditorContents(editor: vscode.TextEditor, expectedDocConte
|
||||||
|
|
||||||
if (cursorIndex >= 0) {
|
if (cursorIndex >= 0) {
|
||||||
const expectedCursorPos = editor.document.positionAt(cursorIndex);
|
const expectedCursorPos = editor.document.positionAt(cursorIndex);
|
||||||
assert.strictEqual(
|
assert.deepEqual(
|
||||||
editor.selection.active.line,
|
{ line: editor.selection.active.line, character: editor.selection.active.line },
|
||||||
expectedCursorPos.line
|
{ line: expectedCursorPos.line, character: expectedCursorPos.line },
|
||||||
|
'Cursor position'
|
||||||
);
|
);
|
||||||
assert.strictEqual(
|
|
||||||
editor.selection.active.character,
|
|
||||||
expectedCursorPos.character
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +111,6 @@ export async function updateConfig(documentUri: vscode.Uri, newConfig: VsCodeCon
|
||||||
return oldConfig;
|
return oldConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const Config = Object.freeze({
|
export const Config = Object.freeze({
|
||||||
autoClosingBrackets: 'editor.autoClosingBrackets',
|
autoClosingBrackets: 'editor.autoClosingBrackets',
|
||||||
completeFunctionCalls: 'typescript.suggest.completeFunctionCalls',
|
completeFunctionCalls: 'typescript.suggest.completeFunctionCalls',
|
||||||
|
@ -128,3 +118,18 @@ export const Config = Object.freeze({
|
||||||
snippetSuggestions: 'editor.snippetSuggestions',
|
snippetSuggestions: 'editor.snippetSuggestions',
|
||||||
suggestSelection: 'editor.suggestSelection',
|
suggestSelection: 'editor.suggestSelection',
|
||||||
} as const);
|
} as const);
|
||||||
|
|
||||||
|
export const insertModesValues = Object.freeze(['insert', 'replace']);
|
||||||
|
|
||||||
|
export async function enumerateConfig(
|
||||||
|
documentUri: vscode.Uri,
|
||||||
|
configKey: string,
|
||||||
|
values: readonly string[],
|
||||||
|
f: (message: string) => Promise<void>
|
||||||
|
): Promise<void> {
|
||||||
|
for (const value of values) {
|
||||||
|
const newConfig = { [configKey]: value };
|
||||||
|
await updateConfig(documentUri, newConfig);
|
||||||
|
await f(JSON.stringify(newConfig));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue