mirror of
https://github.com/VSCodeVim/Vim.git
synced 2024-11-10 00:59:44 +03:00
Basic test for substitute.
This commit is contained in:
parent
9c941a1080
commit
c3c720397f
@ -23,7 +23,7 @@ export async function showCmdLine(initialText: string, modeHandler : ModeHandler
|
||||
}
|
||||
}
|
||||
|
||||
function runCmdLine(command : string, modeHandler : ModeHandler) : Promise<{}> {
|
||||
export async function runCmdLine(command : string, modeHandler : ModeHandler) : Promise<{}> {
|
||||
if (!command || command.length === 0) {
|
||||
return;
|
||||
}
|
||||
@ -34,7 +34,7 @@ function runCmdLine(command : string, modeHandler : ModeHandler) : Promise<{}> {
|
||||
return;
|
||||
}
|
||||
|
||||
cmd.execute(vscode.window.activeTextEditor, modeHandler);
|
||||
await cmd.execute(vscode.window.activeTextEditor, modeHandler);
|
||||
} catch (e) {
|
||||
modeHandler.setupStatusBarItem(e.toString());
|
||||
}
|
||||
|
@ -87,16 +87,16 @@ export class CommandLine {
|
||||
return ":" + this.range.toString() + " " + this.command.toString();
|
||||
}
|
||||
|
||||
execute(document : vscode.TextEditor, modeHandler : ModeHandler) : void {
|
||||
async execute(document : vscode.TextEditor, modeHandler : ModeHandler) : Promise<void> {
|
||||
if (!this.command) {
|
||||
this.range.execute(document);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.range.isEmpty) {
|
||||
this.command.execute(modeHandler);
|
||||
await this.command.execute(modeHandler);
|
||||
} else {
|
||||
this.command.executeWithRange(modeHandler, this.range);
|
||||
await this.command.executeWithRange(modeHandler, this.range);
|
||||
}
|
||||
|
||||
}
|
||||
|
59
test/cmd_line/substitute.test.ts
Normal file
59
test/cmd_line/substitute.test.ts
Normal file
@ -0,0 +1,59 @@
|
||||
"use strict";
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { ModeHandler } from '../../src/mode/modeHandler';
|
||||
import { setupWorkspace, cleanUpWorkspace, assertEqualLines, assertEqual } from './../testUtils';
|
||||
import { ModeName } from '../../src/mode/mode';
|
||||
import { TextEditor } from '../../src/textEditor';
|
||||
import { runCmdLine } from '../../src/cmd_line/main';
|
||||
|
||||
suite("Basic substitute", () => {
|
||||
let modeHandler: ModeHandler;
|
||||
|
||||
setup(async () => {
|
||||
await setupWorkspace();
|
||||
modeHandler = new ModeHandler();
|
||||
});
|
||||
|
||||
teardown(cleanUpWorkspace);
|
||||
|
||||
test("Replace single word once", async () => {
|
||||
await modeHandler.handleMultipleKeyEvents(['i', 'a', 'b', 'a', '<esc>']);
|
||||
await runCmdLine("%s/a/d", modeHandler);
|
||||
|
||||
assertEqualLines([
|
||||
"dba"
|
||||
]);
|
||||
});
|
||||
|
||||
test("Replace with `g` flag", async () => {
|
||||
await modeHandler.handleMultipleKeyEvents(['i', 'a', 'b', 'a', '<esc>']);
|
||||
await runCmdLine("%s/a/d/g", modeHandler);
|
||||
|
||||
assertEqualLines([
|
||||
"dbd"
|
||||
]);
|
||||
});
|
||||
|
||||
test("Replace multiple lines", async () => {
|
||||
await modeHandler.handleMultipleKeyEvents(['i', 'a', 'b', 'a', '<esc>', 'o', 'a', 'b']);
|
||||
await runCmdLine("%s/a/d/g", modeHandler);
|
||||
|
||||
assertEqualLines([
|
||||
"dbd",
|
||||
"db"
|
||||
]);
|
||||
});
|
||||
|
||||
test("Replace across specific lines", async () => {
|
||||
await modeHandler.handleMultipleKeyEvents(['i', 'a', 'b', 'a', '<esc>', 'o', 'a', 'b']);
|
||||
await runCmdLine("1,1s/a/d/g", modeHandler);
|
||||
|
||||
assertEqualLines([
|
||||
"dbd",
|
||||
"ab"
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
});
|
Loading…
Reference in New Issue
Block a user