Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite normal mode tests. #231

Merged
merged 1 commit into from
May 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function activate(context: vscode.ExtensionContext) {
}
});

registerCommand(context, 'extension.vim_esc', () => handleKeyEvent("esc"));
registerCommand(context, 'extension.vim_esc', () => handleKeyEvent("<esc>"));
registerCommand(context, 'extension.showCmdLine', () => {
if (!modeHandler) {
modeHandler = new ModeHandler();
Expand Down
198 changes: 128 additions & 70 deletions test/mode/modeNormal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import * as assert from 'assert';
import {CommandKeyMap} from '../../src/configuration/commandKeyMap';
import {setupWorkspace, cleanUpWorkspace, assertEqualLines} from './../testUtils';
import {setupWorkspace, cleanUpWorkspace, assertEqualLines, assertEqual} from './../testUtils';
import {NormalMode} from '../../src/mode/modeNormal';
import {ModeName} from '../../src/mode/mode';
import {Motion, MotionMode} from '../../src/motion/motion';
Expand All @@ -11,154 +11,212 @@ import {ModeHandler} from '../../src/mode/modeHandler';

suite("Mode Normal", () => {

let motion : Motion;
let modeNormal : NormalMode;
let modeHandler: ModeHandler;

setup(async () => {
await setupWorkspace();

modeHandler = new ModeHandler();
motion = new Motion(MotionMode.Cursor);
modeNormal = new NormalMode(motion, modeHandler, CommandKeyMap.DefaultNormalKeyMap());
});

teardown(cleanUpWorkspace);

test("can be activated", () => {
let activationKeys = ['<esc>', '<c-[>'];
test("can be activated", async () => {
let activationKeys = ['<esc>', '<c-[>', '<c-c>'];

for (let i = 0; i < activationKeys.length; i++) {
let key = activationKeys[i];
assert.equal(modeNormal.shouldBeActivated(key, ModeName.Insert), true, key);
for (let key of activationKeys) {
await modeHandler.handleKeyEvent('i');
await modeHandler.handleKeyEvent(key);

assertEqual(modeHandler.currentMode.name, ModeName.Normal);
}

assert.equal(modeNormal.shouldBeActivated("v", ModeName.Visual), true, "couldn't deactivate from visual with v");
await modeHandler.handleKeyEvent('v');
await modeHandler.handleKeyEvent('v');

assertEqual(modeHandler.currentMode.name, ModeName.Normal);
});

test("Can handle 'x'", async () => {
await TextEditor.insert("text");

motion = motion.moveTo(0, 2);
await modeNormal.handleKeyEvent("x");
await assertEqualLines(["tet"]);
await modeNormal.handleKeyEvent("x");
assertEqualLines(["te"]);
await modeHandler.handleMultipleKeyEvents([
'i',
't', 'e', 'x', 't',
'<esc>',
'^', 'l', 'l',
'x',
]);

assertEqualLines(["tet"]);
});

test("Can handle 'dw'", async () => {
await TextEditor.insert("text text text");
await modeHandler.handleMultipleKeyEvents(
'itext text text'.split('')
);

await modeHandler.handleMultipleKeyEvents([
'<esc>',
'^', 'w',
'd', 'w'
]);

motion = motion.moveTo(0, 5);
await modeNormal.handleKeyEvent("dw");
await assertEqualLines(["text text"]);
await modeNormal.handleKeyEvent("dw");
await modeHandler.handleMultipleKeyEvents(['d', 'w']);

await assertEqualLines(["text "]);
await modeNormal.handleKeyEvent("dw");

await modeHandler.handleMultipleKeyEvents(['d', 'w']);
await assertEqualLines(["text"]);
});

test("Can handle 'de'", async () => {
await TextEditor.insert("text text");
await modeHandler.handleMultipleKeyEvents(
'itext text'.split('')
);

await modeHandler.handleMultipleKeyEvents([
'<esc>',
'^',
'd', 'e'
]);

motion = motion.moveTo(0, 0);
await modeNormal.handleKeyEvent("de");
await assertEqualLines([" text"]);
await modeNormal.handleKeyEvent("de");
await modeHandler.handleMultipleKeyEvents(['d', 'e']);
await assertEqualLines([""]);
});

test("Can handle 'db'", async () => {
await TextEditor.insert("text text");
await modeHandler.handleMultipleKeyEvents(
'itext text'.split('')
);

await modeHandler.handleMultipleKeyEvents([
'<esc>',
'$',
'd', 'b'
]);

motion = motion.moveTo(0, 8);
await modeNormal.handleKeyEvent("db");
await assertEqualLines(["text t"]);
await modeNormal.handleKeyEvent("db");
await modeHandler.handleMultipleKeyEvents(['d', 'b']);
await assertEqualLines(["t"]);
});

test("Can handle 'D'", async () => {
await TextEditor.insert("text");
await modeHandler.handleMultipleKeyEvents(
'itext'.split('')
);

await modeHandler.handleMultipleKeyEvents([
'<esc>',
'^',
'l', 'l',
'D'
]);

motion = motion.moveTo(0, 2);
await modeNormal.handleKeyEvent("D");
await assertEqualLines(["te"]);
await modeNormal.handleKeyEvent("D");
await modeHandler.handleKeyEvent('D')
await assertEqualLines(["t"]);
});

test("Can handle 'ge'", async () => {
await TextEditor.insert("text text");
await modeHandler.handleMultipleKeyEvents(
'itext text'.split('')
);

await modeHandler.handleMultipleKeyEvents(['<esc>', '$', 'g', 'e']);

motion = motion.moveTo(0, 6);
await modeNormal.handleKeyEvent("g");
await modeNormal.handleKeyEvent("e");
await assert.equal(motion.position.character, 4, "wrong position");
assertEqual(TextEditor.getSelection().start.character, 3, "ge failed");
});

test("Can handle 'C'", async () => {
await TextEditor.insert("text");
await modeHandler.handleMultipleKeyEvents(
'itext'.split('')
);

await modeHandler.handleMultipleKeyEvents(['<esc>', '^', 'l', 'l', 'C']);

motion = motion.moveTo(0, 2);
await modeNormal.handleKeyEvent("C");
await assertEqualLines(["te"]);
await assert.equal(modeHandler.currentMode.name === ModeName.Insert, true, "didn't enter insert mode");
});

test("Can handle 'cw'", async () => {
await TextEditor.insert("text text text");
await modeHandler.handleMultipleKeyEvents(
'itext text text'.split('')
);

await modeHandler.handleMultipleKeyEvents([
'<esc>',
'^', 'l', 'l', 'l', 'l', 'l', 'l', 'l',
'c', 'w'
]);

motion = motion.moveTo(0, 7);
await modeNormal.handleKeyEvent("c");
await modeNormal.handleKeyEvent("w");
await assertEqualLines(["text te text"]);
await assert.equal(modeHandler.currentMode.name === ModeName.Insert, true, "didn't enter insert mode");
});

/*

These tests don't pass because the functionality is broken!

test("Can handle 'ciw'", async () => {
await TextEditor.insert("text text text");
await modeHandler.handleMultipleKeyEvents(
'itext text text'.split('')
);

await modeHandler.handleMultipleKeyEvents([
'<esc>',
'^', 'l', 'l', 'l', 'l', 'l', 'l', 'l',
'c', 'i', 'w'
]);

motion = motion.moveTo(0, 7);
await modeNormal.handleKeyEvent("c");
await modeNormal.handleKeyEvent("i");
await modeNormal.handleKeyEvent("w");
await assertEqualLines(["text text"]);
await assert.equal(modeHandler.currentMode.name, ModeName.Insert, "didn't enter insert mode");
});

test("Can handle 'ciw' on blanks", async () => {
await TextEditor.insert("text text text");
await modeHandler.handleMultipleKeyEvents(
'itext text text'.split('')
);

await modeHandler.handleMultipleKeyEvents([
'<esc>',
'^', 'l', 'l', 'l', 'l', 'l',
'c', 'i', 'w'
]);

motion = motion.moveTo(0, 5);
await modeNormal.handleKeyEvent("c");
await modeNormal.handleKeyEvent("i");
await modeNormal.handleKeyEvent("w");
await assertEqualLines(["texttext text"]);
await assert.equal(modeHandler.currentMode.name, ModeName.Insert, "didn't enter insert mode");
});

test("Can handle 'caw'", async () => {
await TextEditor.insert("text text text");
await modeHandler.handleMultipleKeyEvents(
'itext text text'.split('')
);

motion = motion.moveTo(0, 7);
await modeNormal.handleKeyEvent("c");
await modeNormal.handleKeyEvent("a");
await modeNormal.handleKeyEvent("w");
await assertEqualLines(["text text"]);
await assert.equal(motion.position.character, 5, "wrong position");
await modeHandler.handleMultipleKeyEvents([
'<esc>',
'^', 'l', 'l', 'l', 'l', 'l',
'c', 'a', 'w'
]);

assertEqual(TextEditor.getSelection().start.character, 5, "caw is on wrong position");
await assert.equal(modeHandler.currentMode.name, ModeName.Insert, "didn't enter insert mode");
});

test("Can handle 'caw' on blanks", async () => {
await TextEditor.insert("text text");
await modeHandler.handleMultipleKeyEvents(
'itext text text'.split('')
);

await modeHandler.handleMultipleKeyEvents([
'<esc>',
'^', 'l', 'l', 'l', 'l', 'l',
'c', 'a', 'w'
]);

motion = motion.moveTo(0, 5);
await modeNormal.handleKeyEvent("c");
await modeNormal.handleKeyEvent("a");
await modeNormal.handleKeyEvent("w");
await assertEqualLines(["text"]);
await assert.equal(motion.position.character, 4, "wrong position");
assertEqual(TextEditor.getSelection().start.character, 4, "caw is on wrong position");
await assert.equal(modeHandler.currentMode.name, ModeName.Insert, "didn't enter insert mode");
});
*/
});