Skip to content

Commit abd49b2

Browse files
committed
Trivial cleanup in test utils
1 parent 4e3eba8 commit abd49b2

3 files changed

Lines changed: 29 additions & 26 deletions

File tree

test/cmd_line/tabCompletion.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as vscode from 'vscode';
22
import * as assert from 'assert';
3+
import * as os from 'os';
34
import { join, sep, basename } from 'path';
45
import { getAndUpdateModeHandler } from '../../extension';
56
import { ModeHandler } from '../../src/mode/modeHandler';
@@ -238,12 +239,15 @@ suite('cmd_line tabComplete', () => {
238239
});
239240

240241
test('command line file tab completion with space in file path', async () => {
241-
// Create an random file in temp folder with a space in the file name
242-
const spacedFilePath = await t.createFile({ fileExtension: 'vscode-vim completion-test' });
242+
// Create a random file in temp folder with a space in the file name
243+
const prefix = t.rndName();
244+
const spacedFilePath = await t.createFile({
245+
fsPath: join(os.tmpdir(), prefix + 'vscode-vim completion-test'),
246+
});
243247
try {
244-
// Get the base name of the path which is <random name>vscode-vim completion-test
248+
// Get the base name of the path which is '<prefix>vscode-vim completion-test'
245249
const baseName = basename(spacedFilePath);
246-
// Get the base name exclude the space which is <random name>vscode-vim
250+
// Get the base name exclude the space which is '<prefix>vscode-vim'
247251
const baseNameExcludeSpace = baseName.substring(0, baseName.lastIndexOf(' '));
248252
const fullPathExcludeSpace = spacedFilePath.substring(0, spacedFilePath.lastIndexOf(' '));
249253
const failMsg = 'Cannot complete to a path with space';

test/testSimplifier.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -250,22 +250,22 @@ async function testIt(testObj: ITestObject): Promise<ModeHandler> {
250250
// Check final cursor position
251251
const actualPosition = modeHandler.vimState.editor.selection.start;
252252
const expectedPosition = end.cursor;
253-
assert.deepStrictEqual(
253+
assert.deepEqual(
254254
{ line: actualPosition.line, character: actualPosition.character },
255255
{ line: expectedPosition.line, character: expectedPosition.character },
256256
'Cursor position is wrong.',
257257
);
258258

259259
if (testObj.endMode !== undefined) {
260-
assert.strictEqual(
260+
assert.equal(
261261
Mode[modeHandler.vimState.currentMode],
262262
Mode[testObj.endMode],
263263
"Didn't enter correct mode.",
264264
);
265265
}
266266

267267
if (testObj.endFsPath !== undefined) {
268-
assert.strictEqual(
268+
assert.equal(
269269
vscode.window.activeTextEditor?.document.uri.fsPath,
270270
typeof testObj.endFsPath === 'string' ? testObj.endFsPath : testObj.endFsPath(),
271271
'Active document is wrong.',
@@ -275,15 +275,15 @@ async function testIt(testObj: ITestObject): Promise<ModeHandler> {
275275
if (testObj.registers !== undefined) {
276276
for (const reg in testObj.registers) {
277277
if (testObj.registers[reg] !== undefined) {
278-
assert.strictEqual((await Register.get(reg))?.text, testObj.registers[reg]);
278+
assert.equal((await Register.get(reg))?.text, testObj.registers[reg]);
279279
} else {
280-
assert.strictEqual(await Register.get(reg), undefined);
280+
assert.equal(await Register.get(reg), undefined);
281281
}
282282
}
283283
}
284284

285285
if (testObj.statusBar !== undefined) {
286-
assert.strictEqual(
286+
assert.equal(
287287
StatusBar.getText(),
288288
testObj.statusBar.replace('{FILENAME}', modeHandler.vimState.document.fileName),
289289
'Status bar text is wrong.',
@@ -293,7 +293,7 @@ async function testIt(testObj: ITestObject): Promise<ModeHandler> {
293293
// jumps: check jumps are correct if given
294294
if (testObj.jumps !== undefined) {
295295
// TODO: Jumps should be specified by Positions, not line contents
296-
assert.deepStrictEqual(
296+
assert.deepEqual(
297297
globalState.jumpTracker.jumps.map((j) => end.lines[j.position.line] || '<MISSING>'),
298298
testObj.jumps.map((t) => t.replace('|', '')),
299299
'Incorrect jumps found',
@@ -306,11 +306,7 @@ async function testIt(testObj: ITestObject): Promise<ModeHandler> {
306306
'<FRONT>';
307307
const expectedJumpPosition = stripBar(testObj.jumps.find((t) => t.includes('|'))) || '<FRONT>';
308308

309-
assert.deepStrictEqual(
310-
actualJumpPosition,
311-
expectedJumpPosition,
312-
'Incorrect jump position found',
313-
);
309+
assert.deepEqual(actualJumpPosition, expectedJumpPosition, 'Incorrect jump position found');
314310
}
315311

316312
return modeHandler;
@@ -451,7 +447,7 @@ async function testItWithRemaps(testObj: ITestWithRemapsObject): Promise<ModeHan
451447
// Lines after keys pressed but before any timeout
452448

453449
// Check given end output is correct
454-
assert.strictEqual(
450+
assert.equal(
455451
result1.lines,
456452
resolvedStep.end.lines.join(os.EOL),
457453
`Document content does not match on step ${stepTitleOrIndex}.`,
@@ -460,7 +456,7 @@ async function testItWithRemaps(testObj: ITestWithRemapsObject): Promise<ModeHan
460456
// Check end cursor position
461457
const actualEndPosition = result1.position;
462458
const expectedEndPosition = resolvedStep.end.cursor;
463-
assert.deepStrictEqual(
459+
assert.deepEqual(
464460
{ line: actualEndPosition.line, character: actualEndPosition.character },
465461
{ line: expectedEndPosition.line, character: expectedEndPosition.character },
466462
`Cursor position is wrong on step ${stepTitleOrIndex}.`,
@@ -469,7 +465,7 @@ async function testItWithRemaps(testObj: ITestWithRemapsObject): Promise<ModeHan
469465
// endMode: check end mode is correct if given
470466
const expectedEndMode = step.stepResult.endMode;
471467
if (expectedEndMode !== undefined) {
472-
assert.strictEqual(
468+
assert.equal(
473469
Mode[result1.endMode],
474470
Mode[expectedEndMode],
475471
`Didn't enter correct mode on step ${stepTitleOrIndex}.`,
@@ -478,10 +474,10 @@ async function testItWithRemaps(testObj: ITestWithRemapsObject): Promise<ModeHan
478474

479475
if (result2) {
480476
// After the timeout finishes (plus an offset to be sure it finished)
481-
assert.notStrictEqual(result2, undefined);
477+
assert.notEqual(result2, undefined);
482478

483479
// Check given endAfterTimeout output is correct
484-
assert.strictEqual(
480+
assert.equal(
485481
result2.lines,
486482
resolvedStep.endAfterTimeout?.lines.join(os.EOL),
487483
`Document content does not match on step ${stepTitleOrIndex} after timeout.`,
@@ -490,7 +486,7 @@ async function testItWithRemaps(testObj: ITestWithRemapsObject): Promise<ModeHan
490486
// Check endAfterTimeout cursor position
491487
const actualEndAfterTimeoutPosition = result2.position;
492488
const expectedEndAfterTimeoutPosition = resolvedStep.endAfterTimeout!.cursor;
493-
assert.deepStrictEqual(
489+
assert.deepEqual(
494490
{
495491
line: actualEndAfterTimeoutPosition.line,
496492
character: actualEndAfterTimeoutPosition.character,
@@ -505,7 +501,7 @@ async function testItWithRemaps(testObj: ITestWithRemapsObject): Promise<ModeHan
505501
// endMode: check end mode is correct if given
506502
const expectedEndAfterTimeoutMode = step.stepResult.endModeAfterTimeout;
507503
if (expectedEndAfterTimeoutMode !== undefined) {
508-
assert.strictEqual(
504+
assert.equal(
509505
Mode[result2.endMode],
510506
Mode[expectedEndAfterTimeoutMode],
511507
`Didn't enter correct mode on step ${stepTitleOrIndex} after Timeout.`,

test/testUtils.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ export async function createFile(
7575
contents?: string;
7676
} = {},
7777
): Promise<string> {
78+
if (args.fileExtension) {
79+
assert.ok(args.fileExtension.startsWith('.'));
80+
}
7881
args.fsPath ??= join(os.tmpdir(), rndName() + (args.fileExtension ?? ''));
7982
await promisify(fs.writeFile)(args.fsPath, args.contents ?? '');
8083
return args.fsPath;
@@ -115,7 +118,7 @@ export async function waitForEditorsToClose(numExpectedEditors: number = 0): Pro
115118
}
116119

117120
export function assertEqualLines(expectedLines: string[]) {
118-
assert.strictEqual(
121+
assert.equal(
119122
vscode.window.activeTextEditor?.document.getText(),
120123
expectedLines.join(os.EOL),
121124
'Document content does not match.',
@@ -126,7 +129,7 @@ export function assertStatusBarEqual(
126129
expectedText: string,
127130
message: string = 'Status bar text does not match',
128131
) {
129-
assert.strictEqual(StatusBar.getText(), expectedText, message);
132+
assert.equal(StatusBar.getText(), expectedText, message);
130133
}
131134

132135
export async function setupWorkspace(
@@ -179,7 +182,7 @@ export async function setupWorkspace(
179182

180183
export async function cleanUpWorkspace(): Promise<void> {
181184
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
182-
assert.strictEqual(vscode.window.visibleTextEditors.length, 0, 'Expected all editors closed.');
185+
assert.equal(vscode.window.visibleTextEditors.length, 0, 'Expected all editors closed.');
183186
assert(!vscode.window.activeTextEditor, 'Expected no active text editor.');
184187
}
185188

0 commit comments

Comments
 (0)