From 1aa616cfca15004445f06362e66c1a9fdb550036 Mon Sep 17 00:00:00 2001 From: johnfn Date: Sat, 18 Jun 2016 11:59:22 -0700 Subject: [PATCH] Rewrite many more tests to new simplified style. --- src/actions/actions.ts | 4 ++ test/mode/modeNormal.test.ts | 130 ++++++++++++++--------------------- test/testSimplifier.ts | 32 ++++++++- 3 files changed, 88 insertions(+), 78 deletions(-) diff --git a/src/actions/actions.ts b/src/actions/actions.ts index 75bfb08e03a..7cb39713ad4 100644 --- a/src/actions/actions.ts +++ b/src/actions/actions.ts @@ -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; diff --git a/test/mode/modeNormal.test.ts b/test/mode/modeNormal.test.ts index e80d0b5b5c0..08853d9388c 100644 --- a/test/mode/modeNormal.test.ts +++ b/test/mode/modeNormal.test.ts @@ -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'; @@ -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', - '', - '^', '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([ - '', - '^', '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([ - '', '^', - '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([ - '', - '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([ - '', '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([ - '', '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([ - '', '^', - 'c', 'c', 'a', '' - ]); - - 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([ - '', '^', - 'y', 'y', 'O', '', 'p' - ]); + newTest({ + title: "Can handle 'cc'", + start: ['one', '|one two'], + keysPressed: 'cca', + end: ["one", "|a"], + }); - assertEqualLines(["", "one", "one"]); + newTest({ + title: "Can handle 'yy'", + start: ['|one'], + keysPressed: 'yyOp', + end: ["", "|one", "one"], }); newTest({ diff --git a/test/testSimplifier.ts b/test/testSimplifier.ts index 0e673d33c03..11563b714e9 100644 --- a/test/testSimplifier.ts +++ b/test/testSimplifier.ts @@ -142,6 +142,36 @@ class TestObjectHelper { } } +/** + * Tokenize a string like "abcd" into ["a", "b", "c", "", "d", ""] + */ +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 { let helper = new TestObjectHelper(testObj); @@ -158,7 +188,7 @@ async function testIt(modeHandler: ModeHandler, testObj: ITestObject): Promise