diff options
author | Claudio Rodriguez <cjrodr@yahoo.com> | 2017-03-27 12:45:08 +0100 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2017-09-22 21:48:44 -0300 |
commit | 7a953929fef5a7892d4697ed73e6fd314055beee (patch) | |
tree | dba85c41cbf3f4e22b51eb6a666e2800584d059c /test/parallel/test-readline-interface.js | |
parent | 9d7574eef54de1a3675eb58328aeac17d6327de4 (diff) | |
download | android-node-v8-7a953929fef5a7892d4697ed73e6fd314055beee.tar.gz android-node-v8-7a953929fef5a7892d4697ed73e6fd314055beee.tar.bz2 android-node-v8-7a953929fef5a7892d4697ed73e6fd314055beee.zip |
test: improve readline test coverage for tty
Adds the following tests for tty readline:
- go to beginning and end of line
- wordLeft
- wordRight
- deleteWordLeft
- deleteWordRight
PR-URL: https://github.com/nodejs/node/pull/12064
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-readline-interface.js')
-rw-r--r-- | test/parallel/test-readline-interface.js | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/test/parallel/test-readline-interface.js b/test/parallel/test-readline-interface.js index 6abde57494..a7c33ba842 100644 --- a/test/parallel/test-readline-interface.js +++ b/test/parallel/test-readline-interface.js @@ -527,6 +527,142 @@ function isWarned(emitter) { assert.strictEqual(cursorPos.cols, expectedLines.slice(-1)[0].length); rli.close(); } + + { + // Beginning and end of line + const fi = new FakeInput(); + const rli = new readline.Interface({ + input: fi, + output: fi, + prompt: '', + terminal: terminal + }); + fi.emit('data', 'the quick brown fox'); + fi.emit('keypress', '.', { ctrl: true, name: 'a' }); + let cursorPos = rli._getCursorPos(); + assert.strictEqual(cursorPos.rows, 0); + assert.strictEqual(cursorPos.cols, 0); + fi.emit('keypress', '.', { ctrl: true, name: 'e' }); + cursorPos = rli._getCursorPos(); + assert.strictEqual(cursorPos.rows, 0); + assert.strictEqual(cursorPos.cols, 19); + rli.close(); + } + + { + // `wordLeft` and `wordRight` + const fi = new FakeInput(); + const rli = new readline.Interface({ + input: fi, + output: fi, + prompt: '', + terminal: terminal + }); + fi.emit('data', 'the quick brown fox'); + fi.emit('keypress', '.', { ctrl: true, name: 'left' }); + let cursorPos = rli._getCursorPos(); + assert.strictEqual(cursorPos.rows, 0); + assert.strictEqual(cursorPos.cols, 16); + fi.emit('keypress', '.', { meta: true, name: 'b' }); + cursorPos = rli._getCursorPos(); + assert.strictEqual(cursorPos.rows, 0); + assert.strictEqual(cursorPos.cols, 10); + fi.emit('keypress', '.', { ctrl: true, name: 'right' }); + cursorPos = rli._getCursorPos(); + assert.strictEqual(cursorPos.rows, 0); + assert.strictEqual(cursorPos.cols, 16); + fi.emit('keypress', '.', { meta: true, name: 'f' }); + cursorPos = rli._getCursorPos(); + assert.strictEqual(cursorPos.rows, 0); + assert.strictEqual(cursorPos.cols, 19); + rli.close(); + } + + { + // `deleteWordLeft` + [ + { ctrl: true, name: 'w' }, + { ctrl: true, name: 'backspace' }, + { meta: true, name: 'backspace' } + ] + .forEach((deleteWordLeftKey) => { + let fi = new FakeInput(); + let rli = new readline.Interface({ + input: fi, + output: fi, + prompt: '', + terminal: terminal + }); + fi.emit('data', 'the quick brown fox'); + fi.emit('keypress', '.', { ctrl: true, name: 'left' }); + rli.on('line', common.mustCall((line) => { + assert.strictEqual(line, 'the quick fox'); + })); + fi.emit('keypress', '.', deleteWordLeftKey); + fi.emit('data', '\n'); + rli.close(); + + // No effect if pressed at beginning of line + fi = new FakeInput(); + rli = new readline.Interface({ + input: fi, + output: fi, + prompt: '', + terminal: terminal + }); + fi.emit('data', 'the quick brown fox'); + fi.emit('keypress', '.', { ctrl: true, name: 'a' }); + rli.on('line', common.mustCall((line) => { + assert.strictEqual(line, 'the quick brown fox'); + })); + fi.emit('keypress', '.', deleteWordLeftKey); + fi.emit('data', '\n'); + rli.close(); + }); + } + + { + // `deleteWordRight` + [ + { ctrl: true, name: 'delete' }, + { meta: true, name: 'delete' }, + { meta: true, name: 'd' } + ] + .forEach((deleteWordRightKey) => { + let fi = new FakeInput(); + let rli = new readline.Interface({ + input: fi, + output: fi, + prompt: '', + terminal: terminal + }); + fi.emit('data', 'the quick brown fox'); + fi.emit('keypress', '.', { ctrl: true, name: 'left' }); + fi.emit('keypress', '.', { ctrl: true, name: 'left' }); + rli.on('line', common.mustCall((line) => { + assert.strictEqual(line, 'the quick fox'); + })); + fi.emit('keypress', '.', deleteWordRightKey); + fi.emit('data', '\n'); + rli.close(); + + // No effect if pressed at end of line + fi = new FakeInput(); + rli = new readline.Interface({ + input: fi, + output: fi, + prompt: '', + terminal: terminal + }); + fi.emit('data', 'the quick brown fox'); + rli.on('line', common.mustCall((line) => { + assert.strictEqual(line, 'the quick brown fox'); + })); + fi.emit('keypress', '.', deleteWordRightKey); + fi.emit('data', '\n'); + rli.close(); + }); + } } // isFullWidthCodePoint() should return false for non-numeric values |