Skip to content

Commit

Permalink
Rewrite many more tests to new simplified style.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfn committed Jun 18, 2016
1 parent 3e66fe9 commit 1aa616c
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 78 deletions.
4 changes: 4 additions & 0 deletions src/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,10 @@ export class DeleteOperator extends BaseOperator {
vimState.cursorPosition = start;
}

if (vimState.effectiveRegisterMode() === RegisterMode.LineWise) {
vimState.cursorPosition = vimState.cursorPosition.getLineBegin();
}

vimState.currentMode = ModeName.Normal;

return vimState;
Expand Down
130 changes: 53 additions & 77 deletions test/mode/modeNormal.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

import { setupWorkspace, cleanUpWorkspace, assertEqualLines, assertEqual } from './../testUtils';
import { setupWorkspace, cleanUpWorkspace, assertEqual } from './../testUtils';
import { ModeName } from '../../src/mode/mode';
import { ModeHandler } from '../../src/mode/modeHandler';
import { getTestingFunctions } from '../testSimplifier';
Expand Down Expand Up @@ -34,98 +34,74 @@ suite("Mode Normal", () => {
assertEqual(modeHandler.currentMode.name, ModeName.Normal);
});

test("Can handle 'x'", async () => {
await modeHandler.handleMultipleKeyEvents([
'i',
't', 'e', 'x', 't',
'<esc>',
'^', 'l', 'l',
'x',
]);

assertEqualLines(["tet"]);
newTest({
title: "Can handle x",
start: ['te|xt'],
keysPressed: 'x',
end: ["tet"],
});

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

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

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

await assertEqualLines(["text "]);

await modeHandler.handleMultipleKeyEvents(['d', 'w']);
await assertEqualLines(["text"]);
newTest({
title: "Can handle dw",
start: ['one |two three'],
keysPressed: 'dw',
end: ["one |three"],
});

test("Can handle dd last line", async () => {
await modeHandler.handleMultipleKeyEvents("ione\ntwo".split(""));
await modeHandler.handleMultipleKeyEvents([
'<esc>', '^',
'd', 'd'
]);

assertEqualLines(["one"]);
newTest({
title: "Can handle dw",
start: ['one | '],
keysPressed: 'dw',
end: ["one| "],
});

test("Can handle dd single line", async () => {
await modeHandler.handleMultipleKeyEvents("ione".split(""));
await modeHandler.handleMultipleKeyEvents([
'<esc>',
'd', 'd'
]);

assertEqualLines([""]);
newTest({
title: "Can handle dw",
start: ['one |two'],
keysPressed: 'dw',
end: ["one| "],
});

test("Can handle dd", async () => {
await modeHandler.handleMultipleKeyEvents("ione\ntwo".split(""));
await modeHandler.handleMultipleKeyEvents([
'<esc>', 'g', 'g',
'd', 'd'
]);

assertEqualLines(["two"]);
newTest({
title: "Can handle dd last line",
start: ['one', '|two'],
keysPressed: 'dd',
end: ["|one"],
});


test("Can handle dd empty line", async () => {
await modeHandler.handleMultipleKeyEvents("ione\n\ntwo".split(""));
await modeHandler.handleMultipleKeyEvents([
'<esc>', 'g', 'g', 'j',
'd', 'd'
]);

assertEqualLines(["one", "two"]);
newTest({
title: "Can handle dd single line",
start: ['|one'],
keysPressed: 'dd',
end: ["|"],
});

test("Can handle cc", async () => {
await modeHandler.handleMultipleKeyEvents("ione\none two".split(""));
await modeHandler.handleMultipleKeyEvents([
'<esc>', '^',
'c', 'c', 'a', '<esc>'
]);

assertEqualLines(["one", "a"]);
newTest({
title: "Can handle dd",
start: ['|one', 'two'],
keysPressed: 'dd',
end: ["|two"],
});

newTest({
title: "Can handle dd empty line",
start: ['one', '|', 'two'],
keysPressed: 'dd',
end: ["one", "|two"],
});

test("Can handle yy", async () => {
await modeHandler.handleMultipleKeyEvents("ione".split(""));
await modeHandler.handleMultipleKeyEvents([
'<esc>', '^',
'y', 'y', 'O', '<esc>', 'p'
]);
newTest({
title: "Can handle 'cc'",
start: ['one', '|one two'],
keysPressed: 'cca<esc>',
end: ["one", "|a"],
});

assertEqualLines(["", "one", "one"]);
newTest({
title: "Can handle 'yy'",
start: ['|one'],
keysPressed: 'yyO<esc>p',
end: ["", "|one", "one"],
});

newTest({
Expand Down
32 changes: 31 additions & 1 deletion test/testSimplifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,36 @@ class TestObjectHelper {
}
}

/**
* Tokenize a string like "abc<esc>d<c-c>" into ["a", "b", "c", "<esc>", "d", "<c-c>"]
*/
function tokenizeKeySequence(sequence: string): string[] {
let isBracketedKey = false;
let key = "";
let result = [];

for (const char of sequence) {
key += char;

if (char === '<') {
isBracketedKey = true;
}

if (char === '>') {
isBracketedKey = false;
}

if (isBracketedKey) {
continue;
}

result.push(key);
key = "";
}

return result;
}

async function testIt(modeHandler: ModeHandler, testObj: ITestObject): Promise<void> {
let helper = new TestObjectHelper(testObj);

Expand All @@ -158,7 +188,7 @@ async function testIt(modeHandler: ModeHandler, testObj: ITestObject): Promise<v
await modeHandler.handleMultipleKeyEvents(helper.getKeyPressesToMoveToStartPosition());

// assumes key presses are single characters for now
await modeHandler.handleMultipleKeyEvents(testObj.keysPressed.split(''));
await modeHandler.handleMultipleKeyEvents(tokenizeKeySequence(testObj.keysPressed));

// Check valid test object input
assert(helper.isValid, "Missing '|' in test object.");
Expand Down

0 comments on commit 1aa616c

Please sign in to comment.