Skip to content

Commit 9978dd8

Browse files
committed
adding one more test
1 parent cd88c93 commit 9978dd8

File tree

2 files changed

+66
-2
lines changed

2 files changed

+66
-2
lines changed

src/vs/editor/contrib/indentation/test/browser/indentation.test.ts

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ import { AutoIndentOnPaste, IndentationToSpacesCommand, IndentationToTabsCommand
1919
import { withTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
2020
import { testCommand } from 'vs/editor/test/browser/testCommand';
2121
import { goIndentationRules, javascriptIndentationRules, phpIndentationRules, rubyIndentationRules } from 'vs/editor/test/common/modes/supports/indentationRules';
22-
import { javascriptOnEnterRules, phpOnEnterRules } from 'vs/editor/test/common/modes/supports/onEnterRules';
22+
import { cppOnEnterRules, javascriptOnEnterRules, phpOnEnterRules } from 'vs/editor/test/common/modes/supports/onEnterRules';
2323

2424
enum Language {
2525
TypeScript,
2626
Ruby,
2727
PHP,
28-
Go
28+
Go,
29+
CPP
2930
}
3031

3132
function testIndentationToSpacesCommand(lines: string[], selection: Selection, tabSize: number, expectedLines: string[], expectedSelection: Selection): void {
@@ -92,6 +93,16 @@ function registerLanguageConfiguration(instantiationService: TestInstantiationSe
9293
indentationRules: goIndentationRules
9394
}));
9495
break;
96+
case Language.CPP:
97+
disposables.add(languageConfigurationService.register(languageId, {
98+
brackets: [
99+
['{', '}'],
100+
['[', ']'],
101+
['(', ')']
102+
],
103+
onEnterRules: cppOnEnterRules
104+
}));
105+
break;
95106
}
96107
}
97108

@@ -1074,3 +1085,46 @@ suite('Auto Indent On Paste - Go', () => {
10741085
});
10751086
});
10761087
});
1088+
1089+
suite('Auto Indent On Type - CPP', () => {
1090+
1091+
const languageId = "cpp-test";
1092+
let disposables: DisposableStore;
1093+
1094+
setup(() => {
1095+
disposables = new DisposableStore();
1096+
});
1097+
1098+
teardown(() => {
1099+
disposables.dispose();
1100+
});
1101+
1102+
ensureNoDisposablesAreLeakedInTestSuite();
1103+
1104+
test('temp issue because there should be at least one passing test in a suite', () => {
1105+
assert.ok(true);
1106+
});
1107+
1108+
test('issue #178334: incorrect outdent of } when signature spans multiple lines', () => {
1109+
1110+
// https://github.com/microsoft/vscode/issues/178334
1111+
1112+
const model = createTextModel([
1113+
'int WINAPI WinMain(bool instance,',
1114+
' int nshowcmd) {}',
1115+
].join('\n'), languageId, {});
1116+
disposables.add(model);
1117+
1118+
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
1119+
registerLanguage(instantiationService, languageId, Language.CPP, disposables);
1120+
editor.setSelection(new Selection(2, 20, 2, 20));
1121+
viewModel.type("\n", 'keyboard');
1122+
assert.strictEqual(model.getValue(), [
1123+
'int WINAPI WinMain(bool instance,',
1124+
' int nshowcmd) {',
1125+
' ',
1126+
'}'
1127+
].join('\n'));
1128+
});
1129+
});
1130+
});

src/vs/editor/test/common/modes/supports/onEnterRules.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@ export const phpOnEnterRules = [
106106
},
107107
];
108108

109+
export const cppOnEnterRules = [
110+
{
111+
previousLineText: /^\s*(((else ?)?if|for|while)\s*\(.*\)\s*|else\s*)$/,
112+
beforeText: /^\s+([^{i\s]|i(?!f\b))/,
113+
action: {
114+
indentAction: IndentAction.Outdent
115+
}
116+
}
117+
];
118+
109119
/*
110120
export enum IndentAction {
111121
None = 0,

0 commit comments

Comments
 (0)