Merge pull request #208299 from microsoft/plastic-swift

Add tests for auto-indentation feature area
This commit is contained in:
Aiday Marlen Kyzy 2024-03-21 13:24:50 +01:00 committed by GitHub
commit d187a75687
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 64 additions and 3 deletions

View file

@ -738,7 +738,7 @@ suite('`Full` Auto Indent On Type - TypeScript/JavaScript', () => {
test.skip('issue #43244: indent after equal sign is detected', () => {
// https://github.com/microsoft/vscode/issues/43244
// issue: Indent after an equal sign is detected followed by whitespace.
// issue: Should indent after an equal sign is detected followed by whitespace characters.
// This should be outdented when a semi-colon is detected indicating the end of the assignment.
const model = createTextModel([
@ -783,7 +783,7 @@ suite('`Full` Auto Indent On Type - TypeScript/JavaScript', () => {
test.skip('issue #43244: indent after dot detected on a subsequent line after object/array signifying a method call', () => {
// https://github.com/microsoft/vscode/issues/43244
// issue: when a dot is written, we should detect that this is a method call and indent accordingly
// issue: When a dot is written, we should detect that this is a method call and indent accordingly
const model = createTextModel([
'const array = [1, 2, 3]',
@ -825,6 +825,51 @@ suite('`Full` Auto Indent On Type - TypeScript/JavaScript', () => {
});
});
test.skip('issue #43244: outdent when a semi-color is detected indicating the end of the assignment', () => {
// https://github.com/microsoft/vscode/issues/43244
const model = createTextModel([
'const array = [1, 2, 3]',
' .filter(() => true);'
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
registerLanguage(instantiationService, languageId, Language.TypeScript, disposables);
editor.setSelection(new Selection(2, 25, 2, 25));
viewModel.type("\n", 'keyboard');
assert.strictEqual(model.getValue(), [
'const array = [1, 2, 3]',
' .filter(() => true);',
''
].join('\n'));
});
});
test.skip('issue #43244: indent when lambda arrow function is detected, outdent when end is reached', () => {
// https://github.com/microsoft/vscode/issues/43244
const model = createTextModel([
'const array = [1, 2, 3, 4, 5];',
'array.map(v =>)'
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
registerLanguage(instantiationService, languageId, Language.TypeScript, disposables);
editor.setSelection(new Selection(2, 15, 2, 15));
viewModel.type("\n", 'keyboard');
assert.strictEqual(model.getValue(), [
'const array = [1, 2, 3, 4, 5];',
'array.map(v =>',
' ',
')'
].join('\n'));
});
});
// Add tests for:
// https://github.com/microsoft/vscode/issues/88638
// https://github.com/microsoft/vscode/issues/63388

View file

@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
export const javascriptIndentationRules = {
decreaseIndentPattern: /^((?!.*?\/\*).*\*\/)?\s*[\}\]].*$/,
decreaseIndentPattern: /^((?!.*?\/\*).*\*\/)?\s*[\}\]\)].*$/,
increaseIndentPattern: /^((?!\/\/).)*(\{([^}"'`]*|(\t|[ ])*\/\/.*)|\([^)"'`]*|\[[^\]"'`]*)$/,
// e.g. * ...| or */| or *-----*/|
unIndentedLinePattern: /^(\t|[ ])*[ ]\*[^/]*\*\/\s*$|^(\t|[ ])*[ ]\*\/\s*$|^(\t|[ ])*[ ]\*([ ]([^\*]|\*(?!\/))*)?$/

View file

@ -309,4 +309,20 @@ suite('Auto-Reindentation - TypeScript/JavaScript', () => {
const editOperations = getReindentEditOperations(model, languageConfigurationService, 1, model.getLineCount());
assert.deepStrictEqual(editOperations.length, 0);
});
test.skip('Issue 43244: incorrect indentation when signature of function call spans several lines', () => {
// issue: https://github.com/microsoft/vscode/issues/43244
const fileContents = [
'function callSomeOtherFunction(one: number, two: number) { }',
'function someFunction() {',
' callSomeOtherFunction(4,',
' 5)',
'}',
].join('\n');
const model = disposables.add(instantiateTextModel(instantiationService, fileContents, languageId, options));
const editOperations = getReindentEditOperations(model, languageConfigurationService, 1, model.getLineCount());
assert.deepStrictEqual(editOperations.length, 0);
});
});