Skip to content

Commit 73e8d29

Browse files
committed
Refactor setupWorkspace to simplify tests a bit
1 parent 72e67f5 commit 73e8d29

24 files changed

+225
-224
lines changed

test/actions/insertLine.test.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
import * as assert from 'assert';
2-
import { Position, window } from 'vscode';
3-
import {
4-
getCurrentParagraphBeginning,
5-
getCurrentParagraphEnd,
6-
} from '../../src/textobject/paragraph';
7-
import { WordType } from '../../src/textobject/word';
8-
import { TextEditor } from '../../src/textEditor';
9-
import { assertEqualLines, cleanUpWorkspace, setupWorkspace } from '../testUtils';
2+
import { cleanUpWorkspace, setupWorkspace } from '../testUtils';
103
import { ModeHandler } from '../../src/mode/modeHandler';
114
import { getAndUpdateModeHandler } from '../../extension';
125
import * as vscode from 'vscode';
13-
import { Configuration } from '../testConfiguration';
146

157
suite('insertLineBefore', () => {
168
let modeHandler: ModeHandler;
179

1810
suiteSetup(async () => {
19-
const configuration = new Configuration();
20-
configuration.tabstop = 4;
21-
configuration.expandtab = true;
22-
23-
await setupWorkspace(configuration);
11+
await setupWorkspace({
12+
config: {
13+
tabstop: 4,
14+
expandtab: true,
15+
},
16+
});
2417
await setupWorkspace();
2518
modeHandler = (await getAndUpdateModeHandler())!;
2619
});

test/cmd_line/bang.test.ts

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Configuration } from '../../test/testConfiguration';
21
import { newTest } from '../../test/testSimplifier';
32
import { getAndUpdateModeHandler } from '../../extension';
43
import { ModeHandler } from '../../src/mode/modeHandler';
@@ -114,37 +113,21 @@ suite('custom bang shell', () => {
114113
return;
115114
}
116115

117-
suite('sh', () => {
118-
setup(async () => {
119-
const configuration = new Configuration();
120-
configuration.shell = '/bin/sh';
121-
await setupWorkspace(configuration);
116+
for (const shell of ['sh', 'bash']) {
117+
suite(shell, () => {
118+
setup(async () => {
119+
await setupWorkspace({
120+
config: { shell: `/bin/${shell}` },
121+
});
122+
});
123+
teardown(cleanUpWorkspace);
124+
125+
newTest({
126+
title: `! supports /bin/${shell}`,
127+
start: ['|'],
128+
keysPressed: '<Esc>:.!echo $0\n',
129+
end: [`|/bin/${shell}`],
130+
});
122131
});
123-
124-
teardown(cleanUpWorkspace);
125-
126-
newTest({
127-
title: '! supports /bin/sh',
128-
start: ['|'],
129-
keysPressed: '<Esc>:.!echo $0\n',
130-
end: ['|/bin/sh'],
131-
});
132-
});
133-
134-
suite('bash', () => {
135-
setup(async () => {
136-
const configuration = new Configuration();
137-
configuration.shell = '/bin/bash';
138-
await setupWorkspace(configuration);
139-
});
140-
141-
teardown(cleanUpWorkspace);
142-
143-
newTest({
144-
title: '! supports /bin/bash',
145-
start: ['|'],
146-
keysPressed: '<Esc>:.!echo $0\n',
147-
end: ['|/bin/bash'],
148-
});
149-
});
132+
}
150133
});

test/configuration/configuration.test.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import * as assert from 'assert';
22
import * as srcConfiguration from '../../src/configuration/configuration';
3-
import * as testConfiguration from '../testConfiguration';
43
import * as vscode from 'vscode';
54
import { cleanUpWorkspace, setupWorkspace } from './../testUtils';
65
import { Mode } from '../../src/mode/mode';
76
import { newTest } from '../testSimplifier';
7+
import { IConfiguration } from '../../src/configuration/iconfiguration';
88

9-
suite('Configuration', () => {
10-
const configuration = new testConfiguration.Configuration();
11-
configuration.leader = '<space>';
12-
configuration.normalModeKeyBindingsNonRecursive = [
9+
const testConfig: Partial<IConfiguration> = {
10+
leader: '<space>',
11+
normalModeKeyBindingsNonRecursive: [
1312
{
1413
before: ['leader', 'o'],
1514
after: ['o', 'eSc', 'k'],
@@ -18,21 +17,23 @@ suite('Configuration', () => {
1817
before: ['<leader>', 'f', 'e', 's'],
1918
after: ['v'],
2019
},
21-
];
22-
configuration.whichwrap = 'h,l';
20+
],
21+
whichwrap: 'h,l',
22+
};
2323

24+
suite('Configuration', () => {
2425
setup(async () => {
25-
await setupWorkspace(configuration);
26+
await setupWorkspace({ config: testConfig });
2627
});
2728

2829
teardown(cleanUpWorkspace);
2930

3031
test('remappings are normalized', async () => {
3132
const normalizedKeybinds = srcConfiguration.configuration.normalModeKeyBindingsNonRecursive;
3233
const normalizedKeybindsMap = srcConfiguration.configuration.normalModeKeyBindingsMap;
33-
const testingKeybinds = configuration.normalModeKeyBindingsNonRecursive;
34+
const testingKeybinds = testConfig.normalModeKeyBindingsNonRecursive;
3435

35-
assert.strictEqual(normalizedKeybinds.length, testingKeybinds.length);
36+
assert.strictEqual(normalizedKeybinds.length, testingKeybinds!.length);
3637
assert.strictEqual(normalizedKeybinds.length, normalizedKeybindsMap.size);
3738
assert.deepStrictEqual(normalizedKeybinds[0].before, [' ', 'o']);
3839
assert.deepStrictEqual(normalizedKeybinds[0].after, ['o', '<Esc>', 'k']);

test/configuration/remapper.test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,15 @@ suite('Remapper', () => {
102102
normalModeKeyBindingsNonRecursive?: IKeyRemapping[];
103103
visualModeKeyBindings?: IKeyRemapping[];
104104
}) => {
105-
const configuration = new Configuration();
106-
configuration.leader = leaderKey;
107-
configuration.insertModeKeyBindings = insertModeKeyBindings || [];
108-
configuration.normalModeKeyBindings = normalModeKeyBindings || [];
109-
configuration.normalModeKeyBindingsNonRecursive = normalModeKeyBindingsNonRecursive || [];
110-
configuration.visualModeKeyBindings = visualModeKeyBindings || [];
111-
112-
await setupWorkspace(configuration);
105+
await setupWorkspace({
106+
config: {
107+
leader: leaderKey,
108+
insertModeKeyBindings: insertModeKeyBindings || [],
109+
normalModeKeyBindings: normalModeKeyBindings || [],
110+
normalModeKeyBindingsNonRecursive: normalModeKeyBindingsNonRecursive || [],
111+
visualModeKeyBindings: visualModeKeyBindings || [],
112+
},
113+
});
113114
modeHandler = (await getAndUpdateModeHandler())!;
114115
vimState = modeHandler.vimState;
115116
};

test/configuration/remaps.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import { getAndUpdateModeHandler } from '../../extension';
22
import { Mode } from '../../src/mode/mode';
33
import { ModeHandler } from '../../src/mode/modeHandler';
4-
import { Configuration } from '../testConfiguration';
54
import { newTestWithRemaps, newTestWithRemapsSkip } from '../testSimplifier';
65
import { cleanUpWorkspace, setupWorkspace } from '../testUtils';
76

87
suite('Remaps', () => {
98
let modeHandler: ModeHandler;
109

1110
setup(async () => {
12-
const configuration = new Configuration();
1311
// The timeout shouldn't be lower then 200ms when testing because it might result in some tests
1412
// failing when they shouldn't. I ran this test successfully with this timeout as low as 50ms, but
1513
// lower than that I start getting some issues. I still set this a little bit higher because it
1614
// might change from machine to machine.
17-
configuration.timeout = 200;
18-
configuration.leader = ' ';
19-
20-
await setupWorkspace(configuration);
15+
await setupWorkspace({
16+
config: {
17+
timeout: 200,
18+
leader: ' ',
19+
},
20+
});
2121
modeHandler = (await getAndUpdateModeHandler())!;
2222
});
2323

test/macro.test.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import { Mode } from '../src/mode/mode';
22
import { newTest, newTestWithRemaps } from './testSimplifier';
33
import { cleanUpWorkspace, setupWorkspace } from './testUtils';
4-
import * as testConfiguration from './testConfiguration';
54

65
suite('Record and execute a macro', () => {
76
setup(async () => {
8-
const configuration = new testConfiguration.Configuration();
9-
10-
// for testing with <leader>
11-
configuration.camelCaseMotion.enable = true;
12-
13-
await setupWorkspace(configuration);
7+
await setupWorkspace({
8+
config: {
9+
// for testing with <leader>
10+
camelCaseMotion: { enable: true },
11+
},
12+
});
1413
});
15-
1614
teardown(cleanUpWorkspace);
1715

1816
newTest({

test/marks.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as vscode from 'vscode';
22
import { strict as assert } from 'assert';
33
import { getAndUpdateModeHandler } from '../extensionBase';
44
import { Mode } from '../src/mode/mode';
5-
import { Configuration } from './testConfiguration';
65
import { newTest, newTestSkip } from './testSimplifier';
76
import { cleanUpWorkspace, setupWorkspace } from './testUtils';
87
import { ModeHandler } from '../src/mode/modeHandler';
@@ -17,10 +16,12 @@ suite('Marks', async () => {
1716
suiteTeardown(cleanUpWorkspace);
1817

1918
const jumpToNewFile = async () => {
20-
const configuration = new Configuration();
21-
configuration.tabstop = 4;
22-
configuration.expandtab = false;
23-
await setupWorkspace(configuration);
19+
await setupWorkspace({
20+
config: {
21+
tabstop: 4,
22+
expandtab: false,
23+
},
24+
});
2425
return (await getAndUpdateModeHandler())!;
2526
};
2627

test/mode/modeNormal.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ import * as assert from 'assert';
22
import { getAndUpdateModeHandler } from '../../extension';
33
import { Mode } from '../../src/mode/mode';
44
import { ModeHandler } from '../../src/mode/modeHandler';
5-
import { Configuration } from '../testConfiguration';
65
import { newTest, newTestSkip } from '../testSimplifier';
76
import { cleanUpWorkspace, setupWorkspace } from './../testUtils';
87

98
suite('Mode Normal', () => {
109
let modeHandler: ModeHandler;
1110

1211
suiteSetup(async () => {
13-
const configuration = new Configuration();
14-
configuration.tabstop = 4;
15-
configuration.expandtab = false;
16-
17-
await setupWorkspace(configuration);
12+
await setupWorkspace({
13+
config: {
14+
tabstop: 4,
15+
expandtab: false,
16+
},
17+
});
1818
modeHandler = (await getAndUpdateModeHandler())!;
1919
});
2020
suiteTeardown(cleanUpWorkspace);

test/mode/normalModeTests/dot.test.ts

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import { cleanUpWorkspace, setupWorkspace } from './../../testUtils';
55

66
suite('Dot Operator', () => {
77
suiteSetup(async () => {
8-
const configuration = new Configuration();
9-
configuration.tabstop = 4;
10-
configuration.expandtab = false;
11-
12-
await setupWorkspace(configuration);
8+
await setupWorkspace({
9+
config: {
10+
tabstop: 4,
11+
expandtab: false,
12+
},
13+
});
1314
});
1415
suiteTeardown(cleanUpWorkspace);
1516

@@ -65,11 +66,12 @@ suite('Dot Operator', () => {
6566

6667
suite('Repeat content change', () => {
6768
suiteSetup(async () => {
68-
const configuration = new Configuration();
69-
configuration.tabstop = 4;
70-
configuration.expandtab = false;
71-
72-
await setupWorkspace(configuration);
69+
await setupWorkspace({
70+
config: {
71+
tabstop: 4,
72+
expandtab: false,
73+
},
74+
});
7375
});
7476
suiteTeardown(cleanUpWorkspace);
7577

@@ -255,22 +257,23 @@ suite('Repeat content change', () => {
255257

256258
suite('Dot Operator repeat with remap', () => {
257259
setup(async () => {
258-
const configuration = new Configuration();
259-
configuration.insertModeKeyBindings = [
260-
{
261-
before: ['j', 'j', 'k'],
262-
after: ['<esc>'],
263-
},
264-
];
265-
configuration.normalModeKeyBindings = [
266-
{
267-
before: ['<leader>', 'w'],
268-
after: ['d', 'w'],
260+
await setupWorkspace({
261+
config: {
262+
insertModeKeyBindings: [
263+
{
264+
before: ['j', 'j', 'k'],
265+
after: ['<esc>'],
266+
},
267+
],
268+
normalModeKeyBindings: [
269+
{
270+
before: ['<leader>', 'w'],
271+
after: ['d', 'w'],
272+
},
273+
],
274+
leader: ' ',
269275
},
270-
];
271-
configuration.leader = ' ';
272-
273-
await setupWorkspace(configuration);
276+
});
274277
});
275278

276279
teardown(cleanUpWorkspace);

test/mode/normalModeTests/motionMatchpairs.test.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import { newTest } from '../../testSimplifier';
22
import { cleanUpWorkspace, setupWorkspace } from './../../testUtils';
3-
import { Configuration } from '../../testConfiguration';
43

54
suite('matchpair empty', () => {
65
setup(async () => {
7-
const configuration = new Configuration();
8-
configuration.matchpairs = '';
9-
await setupWorkspace(configuration);
6+
await setupWorkspace({ config: { matchpairs: '' } });
107
});
118

129
teardown(cleanUpWorkspace);
@@ -21,9 +18,7 @@ suite('matchpair empty', () => {
2118

2219
suite('matchpairs enabled', () => {
2320
suiteSetup(async () => {
24-
const configuration = new Configuration();
25-
configuration.matchpairs = '<:>';
26-
await setupWorkspace(configuration);
21+
await setupWorkspace({ config: { matchpairs: '<:>' } });
2722
});
2823
suiteTeardown(cleanUpWorkspace);
2924

0 commit comments

Comments
 (0)