Skip to content

Commit

Permalink
Add tests for some command line special keys
Browse files Browse the repository at this point in the history
Includes <C-u>, <C-p>, <C-n>, <C-b>, <C-e>, <Home>, and <End>.
Fixes #4040
  • Loading branch information
J-Fields committed Sep 22, 2019
1 parent 92ee6df commit 93c92b1
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions test/cmd_line/command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,64 @@ suite('cmd_line/search command', () => {
assert.equal(statusBar, '/|123', 'Failed to retain the text on the right of the cursor');
await modeHandler.handleKeyEvent('<Esc>');
});

test('<C-u> deletes from cursor to first character', async () => {
await modeHandler.handleMultipleKeyEvents(':s/abc/xyz'.split(''));
await modeHandler.handleMultipleKeyEvents(['<left>', '<left>', '<C-u>']);
const statusBar = StatusBar.Get().trim();
assert.equal(statusBar, ':|yz');
await modeHandler.handleKeyEvent('<Esc>');
});

test('<C-b> puts cursor at start of command line', async () => {
await modeHandler.handleMultipleKeyEvents(':s/abc/xyz'.split(''));
await modeHandler.handleKeyEvent('<C-b>');
const statusBar = StatusBar.Get().trim();
assert.equal(statusBar, ':|s/abc/xyz');
await modeHandler.handleKeyEvent('<Esc>');
});

test('<Home> puts cursor at start of command line', async () => {
await modeHandler.handleMultipleKeyEvents(':s/abc/xyz'.split(''));
await modeHandler.handleKeyEvent('<Home>');
const statusBar = StatusBar.Get().trim();
assert.equal(statusBar, ':|s/abc/xyz');
await modeHandler.handleKeyEvent('<Esc>');
});

test('<C-e> puts cursor at end of command line', async () => {
await modeHandler.handleMultipleKeyEvents(':s/abc/xyz'.split(''));
await modeHandler.handleMultipleKeyEvents(['<C-b>', '<C-e>']);
const statusBar = StatusBar.Get().trim();
assert.equal(statusBar, ':s/abc/xyz|');
await modeHandler.handleKeyEvent('<Esc>');
});

test('<End> puts cursor at end of command line', async () => {
await modeHandler.handleMultipleKeyEvents(':s/abc/xyz'.split(''));
await modeHandler.handleMultipleKeyEvents(['<Home>', '<End>']);
const statusBar = StatusBar.Get().trim();
assert.equal(statusBar, ':s/abc/xyz|');
await modeHandler.handleKeyEvent('<Esc>');
});

test('<C-p>/<C-n> go to the previous/next command', async () => {
// Establish a history - :s/a/b, then :s/x/y.
// :w is the current one, not yet confirmed
await modeHandler.handleMultipleKeyEvents(':s/a/b\n'.split(''));
await modeHandler.handleMultipleKeyEvents(':s/x/y\n'.split(''));
await modeHandler.handleMultipleKeyEvents([':', 'w', '<C-p>']);

// Going backward - :s/x/y, then :s/a/b
assert.equal(StatusBar.Get().trim(), ':s/x/y|');
await modeHandler.handleKeyEvent('<C-p>');
assert.equal(StatusBar.Get().trim(), ':s/a/b|');

// Going forward again - :s/x/y, then :w (the one we started typing)
await modeHandler.handleKeyEvent('<C-n>');
assert.equal(StatusBar.Get().trim(), ':s/x/y|');
await modeHandler.handleKeyEvent('<C-n>');
assert.equal(StatusBar.Get().trim(), ':w|');
await modeHandler.handleKeyEvent('<Esc>');
});
});

0 comments on commit 93c92b1

Please sign in to comment.