mirror of
https://github.com/Microsoft/vscode
synced 2024-10-30 06:25:37 +00:00
adding more tests
This commit is contained in:
parent
85eea4a9b2
commit
88d546e778
2 changed files with 174 additions and 90 deletions
|
@ -273,7 +273,7 @@ suite('Change Indentation to Tabs - TypeScript/Javascript', () => {
|
|||
});
|
||||
});
|
||||
|
||||
suite('`Full` Auto Indent On Paste - TypeScript/JavaScript', () => {
|
||||
suite('Auto Indent On Paste - TypeScript/JavaScript', () => {
|
||||
|
||||
const languageId = 'ts-test';
|
||||
let disposables: DisposableStore;
|
||||
|
@ -366,6 +366,84 @@ suite('`Full` Auto Indent On Paste - TypeScript/JavaScript', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('issue #29803: do not indent when pasting text with only one line', () => {
|
||||
|
||||
// https://github.com/microsoft/vscode/issues/29803
|
||||
|
||||
const model = createTextModel([
|
||||
'const linkHandler = new Class(a, b, c,',
|
||||
' d)'
|
||||
].join('\n'), languageId, {});
|
||||
disposables.add(model);
|
||||
|
||||
withTestCodeEditor(model, { autoIndent: 'full' }, (editor, viewModel, instantiationService) => {
|
||||
registerLanguage(instantiationService, languageId, Language.TypeScript, disposables);
|
||||
editor.setSelection(new Selection(2, 6, 2, 6));
|
||||
const text = ', null';
|
||||
viewModel.paste(text, true, undefined, 'keyboard');
|
||||
const autoIndentOnPasteController = editor.registerAndInstantiateContribution(AutoIndentOnPaste.ID, AutoIndentOnPaste);
|
||||
autoIndentOnPasteController.trigger(new Range(2, 6, 2, 11));
|
||||
assert.strictEqual(model.getValue(), [
|
||||
'const linkHandler = new Class(a, b, c,',
|
||||
' d, null)'
|
||||
].join('\n'));
|
||||
});
|
||||
});
|
||||
|
||||
test('issue #29753: incorrect indentation after comment', () => {
|
||||
|
||||
// https://github.com/microsoft/vscode/issues/29753
|
||||
|
||||
const model = createTextModel([
|
||||
'class A {',
|
||||
' /**',
|
||||
' * used only for debug purposes.',
|
||||
' */',
|
||||
' private _codeInfo: KeyMapping[];',
|
||||
'}',
|
||||
].join('\n'), languageId, {});
|
||||
disposables.add(model);
|
||||
|
||||
withTestCodeEditor(model, { autoIndent: 'full' }, (editor, viewModel, instantiationService) => {
|
||||
registerLanguage(instantiationService, languageId, Language.TypeScript, disposables);
|
||||
editor.setSelection(new Selection(5, 24, 5, 34));
|
||||
const text = 'IMacLinuxKeyMapping';
|
||||
viewModel.paste(text, true, undefined, 'keyboard');
|
||||
const autoIndentOnPasteController = editor.registerAndInstantiateContribution(AutoIndentOnPaste.ID, AutoIndentOnPaste);
|
||||
autoIndentOnPasteController.trigger(new Range(5, 24, 5, 43));
|
||||
assert.strictEqual(model.getValue(), [
|
||||
'class A {',
|
||||
' /**',
|
||||
' * used only for debug purposes.',
|
||||
' */',
|
||||
' private _codeInfo: IMacLinuxKeyMapping[];',
|
||||
'}',
|
||||
].join('\n'));
|
||||
});
|
||||
});
|
||||
|
||||
test('issue #29753: incorrect indentation of header comment', () => {
|
||||
|
||||
// https://github.com/microsoft/vscode/issues/29753
|
||||
|
||||
const model = createTextModel('', languageId, {});
|
||||
disposables.add(model);
|
||||
|
||||
withTestCodeEditor(model, { autoIndent: 'full' }, (editor, viewModel, instantiationService) => {
|
||||
registerLanguage(instantiationService, languageId, Language.TypeScript, disposables);
|
||||
const text = [
|
||||
'/*----------------',
|
||||
' * Copyright (c) ',
|
||||
' * Licensed under ...',
|
||||
' *-----------------*/',
|
||||
].join('\n');
|
||||
viewModel.paste(text, true, undefined, 'keyboard');
|
||||
const autoIndentOnPasteController = editor.registerAndInstantiateContribution(AutoIndentOnPaste.ID, AutoIndentOnPaste);
|
||||
autoIndentOnPasteController.trigger(new Range(1, 1, 4, 22));
|
||||
assert.strictEqual(model.getValue(), text);
|
||||
});
|
||||
});
|
||||
|
||||
// Failing tests found in issues...
|
||||
|
||||
test.skip('issue #181065: Incorrect paste of object within comment', () => {
|
||||
|
@ -523,7 +601,7 @@ suite('`Full` Auto Indent On Paste - TypeScript/JavaScript', () => {
|
|||
});
|
||||
});
|
||||
|
||||
suite('`Full` Auto Indent On Type - TypeScript/JavaScript', () => {
|
||||
suite('Auto Indent On Type - TypeScript/JavaScript', () => {
|
||||
|
||||
const languageId = "ts-test";
|
||||
let disposables: DisposableStore;
|
||||
|
@ -606,6 +684,98 @@ suite('`Full` Auto Indent On Type - TypeScript/JavaScript', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('issue #29755: do not add indentation on enter if indentation is already valid', () => {
|
||||
|
||||
//https://github.com/microsoft/vscode/issues/29755
|
||||
|
||||
const model = createTextModel([
|
||||
'function f() {',
|
||||
' const one = 1;',
|
||||
' const two = 2;',
|
||||
'}',
|
||||
].join('\n'), languageId, {});
|
||||
disposables.add(model);
|
||||
|
||||
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
|
||||
|
||||
registerLanguage(instantiationService, languageId, Language.TypeScript, disposables);
|
||||
editor.setSelection(new Selection(3, 1, 3, 1));
|
||||
viewModel.type('\n', 'keyboard');
|
||||
assert.strictEqual(model.getValue(), [
|
||||
'function f() {',
|
||||
' const one = 1;',
|
||||
'',
|
||||
' const two = 2;',
|
||||
'}',
|
||||
].join('\n'));
|
||||
});
|
||||
});
|
||||
|
||||
test('issue #36090', () => {
|
||||
|
||||
// https://github.com/microsoft/vscode/issues/36090
|
||||
|
||||
const model = createTextModel([
|
||||
'class ItemCtrl {',
|
||||
' getPropertiesByItemId(id) {',
|
||||
' return this.fetchItem(id)',
|
||||
' .then(item => {',
|
||||
' return this.getPropertiesOfItem(item);',
|
||||
' });',
|
||||
' }',
|
||||
'}',
|
||||
].join('\n'), languageId, {});
|
||||
disposables.add(model);
|
||||
|
||||
withTestCodeEditor(model, { autoIndent: 'advanced' }, (editor, viewModel, instantiationService) => {
|
||||
registerLanguage(instantiationService, languageId, Language.TypeScript, disposables);
|
||||
editor.setSelection(new Selection(7, 6, 7, 6));
|
||||
viewModel.type('\n', 'keyboard');
|
||||
assert.strictEqual(model.getValue(),
|
||||
[
|
||||
'class ItemCtrl {',
|
||||
' getPropertiesByItemId(id) {',
|
||||
' return this.fetchItem(id)',
|
||||
' .then(item => {',
|
||||
' return this.getPropertiesOfItem(item);',
|
||||
' });',
|
||||
' }',
|
||||
' ',
|
||||
'}',
|
||||
].join('\n')
|
||||
);
|
||||
assert.deepStrictEqual(editor.getSelection(), new Selection(8, 5, 8, 5));
|
||||
});
|
||||
});
|
||||
|
||||
test('issue #115304: indent block comment onEnter', () => {
|
||||
|
||||
// https://github.com/microsoft/vscode/issues/115304
|
||||
|
||||
const model = createTextModel([
|
||||
'/** */',
|
||||
'function f() {}',
|
||||
].join('\n'), languageId, {});
|
||||
disposables.add(model);
|
||||
|
||||
withTestCodeEditor(model, { autoIndent: 'advanced' }, (editor, viewModel, instantiationService) => {
|
||||
registerLanguage(instantiationService, languageId, Language.TypeScript, disposables);
|
||||
editor.setSelection(new Selection(1, 4, 1, 4));
|
||||
viewModel.type('\n', 'keyboard');
|
||||
assert.strictEqual(model.getValue(),
|
||||
[
|
||||
'/**',
|
||||
' * ',
|
||||
' */',
|
||||
'function f() {}',
|
||||
].join('\n')
|
||||
);
|
||||
assert.deepStrictEqual(editor.getSelection(), new Selection(2, 4, 2, 4));
|
||||
});
|
||||
});
|
||||
|
||||
// Failing tests...
|
||||
|
||||
test.skip('issue #40115: keep indentation when added', () => {
|
||||
|
||||
// https://github.com/microsoft/vscode/issues/40115
|
||||
|
@ -921,6 +1091,8 @@ suite('Auto Indent On Type - Ruby', () => {
|
|||
|
||||
test('issue #198350: in or when incorrectly match non keywords for Ruby', () => {
|
||||
|
||||
// https://github.com/microsoft/vscode/issues/198350
|
||||
|
||||
const model = createTextModel("", languageId, {});
|
||||
disposables.add(model);
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@ import { TextModel } from 'vs/editor/common/model/textModel';
|
|||
import { ViewModel } from 'vs/editor/common/viewModel/viewModelImpl';
|
||||
import { OutgoingViewModelEventKind } from 'vs/editor/common/viewModelEventDispatcher';
|
||||
import { ITestCodeEditor, TestCodeEditorInstantiationOptions, createCodeEditorServices, instantiateTestCodeEditor, withTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
|
||||
import { javascriptOnEnterRules } from 'vs/editor/test/common/modes/supports/javascriptOnEnterRules';
|
||||
import { IRelaxedTextModelCreationOptions, createTextModel, instantiateTextModel } from 'vs/editor/test/common/testTextModel';
|
||||
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
|
||||
|
||||
|
@ -4469,93 +4468,6 @@ suite('Editor Controller', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('issue #36090: JS: editor.autoIndent seems to be broken', () => {
|
||||
const languageId = 'jsMode';
|
||||
|
||||
disposables.add(languageService.registerLanguage({ id: languageId }));
|
||||
disposables.add(languageConfigurationService.register(languageId, {
|
||||
brackets: [
|
||||
['{', '}'],
|
||||
['[', ']'],
|
||||
['(', ')']
|
||||
],
|
||||
indentationRules: {
|
||||
// ^(.*\*/)?\s*\}.*$
|
||||
decreaseIndentPattern: /^((?!.*?\/\*).*\*\/)?\s*[\}\]\)].*$/,
|
||||
// ^.*\{[^}"']*$
|
||||
increaseIndentPattern: /^((?!\/\/).)*(\{[^}"'`]*|\([^)"'`]*|\[[^\]"'`]*)$/
|
||||
},
|
||||
onEnterRules: javascriptOnEnterRules
|
||||
}));
|
||||
|
||||
const model = createTextModel(
|
||||
[
|
||||
'class ItemCtrl {',
|
||||
' getPropertiesByItemId(id) {',
|
||||
' return this.fetchItem(id)',
|
||||
' .then(item => {',
|
||||
' return this.getPropertiesOfItem(item);',
|
||||
' });',
|
||||
' }',
|
||||
'}',
|
||||
].join('\n'),
|
||||
languageId
|
||||
);
|
||||
|
||||
withTestCodeEditor(model, { autoIndent: 'advanced' }, (editor, viewModel) => {
|
||||
moveTo(editor, viewModel, 7, 6, false);
|
||||
assertCursor(viewModel, new Selection(7, 6, 7, 6));
|
||||
|
||||
viewModel.type('\n', 'keyboard');
|
||||
assert.strictEqual(model.getValue(),
|
||||
[
|
||||
'class ItemCtrl {',
|
||||
' getPropertiesByItemId(id) {',
|
||||
' return this.fetchItem(id)',
|
||||
' .then(item => {',
|
||||
' return this.getPropertiesOfItem(item);',
|
||||
' });',
|
||||
' }',
|
||||
' ',
|
||||
'}',
|
||||
].join('\n')
|
||||
);
|
||||
assertCursor(viewModel, new Selection(8, 5, 8, 5));
|
||||
});
|
||||
});
|
||||
|
||||
test('issue #115304: OnEnter broken for TS', () => {
|
||||
const languageId = 'jsMode';
|
||||
|
||||
disposables.add(languageService.registerLanguage({ id: languageId }));
|
||||
disposables.add(languageConfigurationService.register(languageId, {
|
||||
onEnterRules: javascriptOnEnterRules
|
||||
}));
|
||||
|
||||
const model = createTextModel(
|
||||
[
|
||||
'/** */',
|
||||
'function f() {}',
|
||||
].join('\n'),
|
||||
languageId
|
||||
);
|
||||
|
||||
withTestCodeEditor(model, { autoIndent: 'advanced' }, (editor, viewModel) => {
|
||||
moveTo(editor, viewModel, 1, 4, false);
|
||||
assertCursor(viewModel, new Selection(1, 4, 1, 4));
|
||||
|
||||
viewModel.type('\n', 'keyboard');
|
||||
assert.strictEqual(model.getValue(),
|
||||
[
|
||||
'/**',
|
||||
' * ',
|
||||
' */',
|
||||
'function f() {}',
|
||||
].join('\n')
|
||||
);
|
||||
assertCursor(viewModel, new Selection(2, 4, 2, 4));
|
||||
});
|
||||
});
|
||||
|
||||
test('issue #38261: TAB key results in bizarre indentation in C++ mode ', () => {
|
||||
const languageId = 'indentRulesMode';
|
||||
|
|
Loading…
Reference in a new issue