Skip to content

Commit

Permalink
Merge pull request #914 from xconverge/add-tests
Browse files Browse the repository at this point in the history
Add some tests and fix some exceptions during the tests
  • Loading branch information
rebornix authored Oct 26, 2016
2 parents 60e7ea1 + 278662c commit 09af878
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 13 deletions.
45 changes: 33 additions & 12 deletions src/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4724,6 +4724,17 @@ abstract class MoveInsideCharacter extends BaseMovement {
diff : new PositionDiff(0, startPos === position ? 1 : 0)
};
}

public async execActionForOperator(position: Position, vimState: VimState): Promise<Position | IMovement> {
const result = await this.execAction(position, vimState);
if (isIMovement(result)) {
if (result.failed) {
vimState.recordedState.hasRunOperator = false;
vimState.recordedState.actionsRun = [];
}
}
return result;
}
}

@RegisterAction
Expand Down Expand Up @@ -4893,12 +4904,17 @@ abstract class MoveQuoteMatch extends BaseMovement {
};
}

public async execActionForOperator(position: Position, vimState: VimState): Promise<IMovement> {
const res = await this.execAction(position, vimState);

res.stop = res.stop.getRight();

return res;
public async execActionForOperator(position: Position, vimState: VimState): Promise<Position | IMovement> {
const result = await this.execAction(position, vimState);
if (isIMovement(result)) {
if (result.failed) {
vimState.recordedState.hasRunOperator = false;
vimState.recordedState.actionsRun = [];
} else {
result.stop = result.stop.getRight();
}
}
return result;
}
}

Expand Down Expand Up @@ -5168,12 +5184,17 @@ abstract class MoveTagMatch extends BaseMovement {
};
}

public async execActionForOperator(position: Position, vimState: VimState): Promise<IMovement> {
const res = await this.execAction(position, vimState);

res.stop = res.stop.getRight();

return res;
public async execActionForOperator(position: Position, vimState: VimState): Promise<Position | IMovement> {
const result = await this.execAction(position, vimState);
if (isIMovement(result)) {
if (result.failed) {
vimState.recordedState.hasRunOperator = false;
vimState.recordedState.actionsRun = [];
} else {
result.stop = result.stop.getRight();
}
}
return result;
}
}

Expand Down
21 changes: 20 additions & 1 deletion test/mode/modeInsert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,18 @@ suite("Mode Insert", () => {
assertEqual(TextEditor.getSelection().start.character, 4, "<Esc> moved cursor position.");
});

test("", async () => {
test("<C-c> can exit insert", async () => {
await modeHandler.handleMultipleKeyEvents([
'i',
't', 'e', 'x', 't',
'<C-c>',
'o'
]);

return assertEqualLines(["text", ""]);
});

test("<Esc> can exit insert", async () => {
await modeHandler.handleMultipleKeyEvents([
'i',
't', 'e', 'x', 't',
Expand All @@ -54,6 +65,14 @@ suite("Mode Insert", () => {
return assertEqualLines(["text", ""]);
});

test("Stay in insert when entering characters", async () => {
await modeHandler.handleKeyEvent('i');
for (var i = 0; i < 10; i++) {
await modeHandler.handleKeyEvent('1');
assertEqual(modeHandler.currentMode.name === ModeName.Insert, true);
}
});

test("Can handle 'O'", async () => {
await modeHandler.handleMultipleKeyEvents([
'i',
Expand Down
7 changes: 7 additions & 0 deletions test/mode/modeNormal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1321,4 +1321,11 @@ suite("Mode Normal", () => {
end: ["\t|one", "two"],
endMode: ModeName.Normal
});

newTest({
title: "Can handle <Esc> and do nothing",
start: ['te|st'],
keysPressed: '<Esc>',
end: ['te|st'],
});
});

0 comments on commit 09af878

Please sign in to comment.