diff --git a/test/cmd_line/command.test.ts b/test/cmd_line/command.test.ts index a3e3a202dac3..f9d8a94b389e 100644 --- a/test/cmd_line/command.test.ts +++ b/test/cmd_line/command.test.ts @@ -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(''); }); + + test(' deletes from cursor to first character', async () => { + await modeHandler.handleMultipleKeyEvents(':s/abc/xyz'.split('')); + await modeHandler.handleMultipleKeyEvents(['', '', '']); + const statusBar = StatusBar.Get().trim(); + assert.equal(statusBar, ':|yz'); + await modeHandler.handleKeyEvent(''); + }); + + test(' puts cursor at start of command line', async () => { + await modeHandler.handleMultipleKeyEvents(':s/abc/xyz'.split('')); + await modeHandler.handleKeyEvent(''); + const statusBar = StatusBar.Get().trim(); + assert.equal(statusBar, ':|s/abc/xyz'); + await modeHandler.handleKeyEvent(''); + }); + + test(' puts cursor at start of command line', async () => { + await modeHandler.handleMultipleKeyEvents(':s/abc/xyz'.split('')); + await modeHandler.handleKeyEvent(''); + const statusBar = StatusBar.Get().trim(); + assert.equal(statusBar, ':|s/abc/xyz'); + await modeHandler.handleKeyEvent(''); + }); + + test(' puts cursor at end of command line', async () => { + await modeHandler.handleMultipleKeyEvents(':s/abc/xyz'.split('')); + await modeHandler.handleMultipleKeyEvents(['', '']); + const statusBar = StatusBar.Get().trim(); + assert.equal(statusBar, ':s/abc/xyz|'); + await modeHandler.handleKeyEvent(''); + }); + + test(' puts cursor at end of command line', async () => { + await modeHandler.handleMultipleKeyEvents(':s/abc/xyz'.split('')); + await modeHandler.handleMultipleKeyEvents(['', '']); + const statusBar = StatusBar.Get().trim(); + assert.equal(statusBar, ':s/abc/xyz|'); + await modeHandler.handleKeyEvent(''); + }); + + test('/ 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', '']); + + // Going backward - :s/x/y, then :s/a/b + assert.equal(StatusBar.Get().trim(), ':s/x/y|'); + await modeHandler.handleKeyEvent(''); + assert.equal(StatusBar.Get().trim(), ':s/a/b|'); + + // Going forward again - :s/x/y, then :w (the one we started typing) + await modeHandler.handleKeyEvent(''); + assert.equal(StatusBar.Get().trim(), ':s/x/y|'); + await modeHandler.handleKeyEvent(''); + assert.equal(StatusBar.Get().trim(), ':w|'); + await modeHandler.handleKeyEvent(''); + }); });