Skip to content

Commit f6e74f9

Browse files
authored
Refactoring the moveLinesCommant.test.ts file (microsoft#209034)
refactoring slightly the moveLinesCommant.test.ts file
1 parent 7bee156 commit f6e74f9

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

src/vs/editor/contrib/linesOperations/test/browser/moveLinesCommand.test.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,42 @@ import { MoveLinesCommand } from 'vs/editor/contrib/linesOperations/browser/move
1414
import { testCommand } from 'vs/editor/test/browser/testCommand';
1515
import { TestLanguageConfigurationService } from 'vs/editor/test/common/modes/testLanguageConfigurationService';
1616

17+
const enum MoveLinesDirection {
18+
Up,
19+
Down
20+
}
21+
1722
function testMoveLinesDownCommand(lines: string[], selection: Selection, expectedLines: string[], expectedSelection: Selection, languageConfigurationService?: ILanguageConfigurationService): void {
18-
const disposables = new DisposableStore();
19-
if (!languageConfigurationService) {
20-
languageConfigurationService = disposables.add(new TestLanguageConfigurationService());
21-
}
22-
testCommand(lines, null, selection, (accessor, sel) => new MoveLinesCommand(sel, true, EditorAutoIndentStrategy.Advanced, languageConfigurationService), expectedLines, expectedSelection);
23-
disposables.dispose();
23+
testMoveLinesUpOrDownCommand(MoveLinesDirection.Down, lines, selection, expectedLines, expectedSelection, languageConfigurationService);
2424
}
2525

2626
function testMoveLinesUpCommand(lines: string[], selection: Selection, expectedLines: string[], expectedSelection: Selection, languageConfigurationService?: ILanguageConfigurationService): void {
27-
const disposables = new DisposableStore();
28-
if (!languageConfigurationService) {
29-
languageConfigurationService = disposables.add(new TestLanguageConfigurationService());
30-
}
31-
testCommand(lines, null, selection, (accessor, sel) => new MoveLinesCommand(sel, false, EditorAutoIndentStrategy.Advanced, languageConfigurationService), expectedLines, expectedSelection);
32-
disposables.dispose();
27+
testMoveLinesUpOrDownCommand(MoveLinesDirection.Up, lines, selection, expectedLines, expectedSelection, languageConfigurationService);
3328
}
3429

3530
function testMoveLinesDownWithIndentCommand(languageId: string, lines: string[], selection: Selection, expectedLines: string[], expectedSelection: Selection, languageConfigurationService?: ILanguageConfigurationService): void {
31+
testMoveLinesUpOrDownWithIndentCommand(MoveLinesDirection.Down, languageId, lines, selection, expectedLines, expectedSelection, languageConfigurationService);
32+
}
33+
34+
function testMoveLinesUpWithIndentCommand(languageId: string, lines: string[], selection: Selection, expectedLines: string[], expectedSelection: Selection, languageConfigurationService?: ILanguageConfigurationService): void {
35+
testMoveLinesUpOrDownWithIndentCommand(MoveLinesDirection.Up, languageId, lines, selection, expectedLines, expectedSelection, languageConfigurationService);
36+
}
37+
38+
function testMoveLinesUpOrDownCommand(direction: MoveLinesDirection, lines: string[], selection: Selection, expectedLines: string[], expectedSelection: Selection, languageConfigurationService?: ILanguageConfigurationService) {
3639
const disposables = new DisposableStore();
3740
if (!languageConfigurationService) {
3841
languageConfigurationService = disposables.add(new TestLanguageConfigurationService());
3942
}
40-
testCommand(lines, languageId, selection, (accessor, sel) => new MoveLinesCommand(sel, true, EditorAutoIndentStrategy.Full, languageConfigurationService), expectedLines, expectedSelection);
43+
testCommand(lines, null, selection, (accessor, sel) => new MoveLinesCommand(sel, direction === MoveLinesDirection.Up ? false : true, EditorAutoIndentStrategy.Advanced, languageConfigurationService), expectedLines, expectedSelection);
4144
disposables.dispose();
4245
}
4346

44-
function testMoveLinesUpWithIndentCommand(languageId: string, lines: string[], selection: Selection, expectedLines: string[], expectedSelection: Selection, languageConfigurationService?: ILanguageConfigurationService): void {
47+
function testMoveLinesUpOrDownWithIndentCommand(direction: MoveLinesDirection, languageId: string, lines: string[], selection: Selection, expectedLines: string[], expectedSelection: Selection, languageConfigurationService?: ILanguageConfigurationService) {
4548
const disposables = new DisposableStore();
4649
if (!languageConfigurationService) {
4750
languageConfigurationService = disposables.add(new TestLanguageConfigurationService());
4851
}
49-
testCommand(lines, languageId, selection, (accessor, sel) => new MoveLinesCommand(sel, false, EditorAutoIndentStrategy.Full, languageConfigurationService), expectedLines, expectedSelection);
52+
testCommand(lines, languageId, selection, (accessor, sel) => new MoveLinesCommand(sel, direction === MoveLinesDirection.Up ? false : true, EditorAutoIndentStrategy.Full, languageConfigurationService), expectedLines, expectedSelection);
5053
disposables.dispose();
5154
}
5255

0 commit comments

Comments
 (0)