diff options
author | Anna Henningsen <anna@addaleax.net> | 2021-06-28 15:02:07 +0200 |
---|---|---|
committer | Node.js GitHub Bot <github-bot@iojs.org> | 2021-07-05 11:27:36 +0000 |
commit | 64e483701191c5920c48dd9fbcacb76a55ca3968 (patch) | |
tree | 90b4b94d3d465485ecb74fb53a51351c41eadc7b /test/parallel | |
parent | 392213a3873ca702e49a16911b3cb74348b6cbab (diff) | |
download | node-new-64e483701191c5920c48dd9fbcacb76a55ca3968.tar.gz |
readline: allow completer to rewrite existing input
Sometimes, it makes sense for a completer to change the existing
input, e.g. by adjusting the casing (imagine a completer that
corrects `Number.isNan` to `Number.IsNaN`, for example).
This commit allows that in the readline implemention.
PR-URL: https://github.com/nodejs/node/pull/39178
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Diffstat (limited to 'test/parallel')
-rw-r--r-- | test/parallel/test-readline-tab-complete.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test/parallel/test-readline-tab-complete.js b/test/parallel/test-readline-tab-complete.js index c283d446f9..be993911c6 100644 --- a/test/parallel/test-readline-tab-complete.js +++ b/test/parallel/test-readline-tab-complete.js @@ -100,3 +100,39 @@ common.skipIfDumbTerminal(); }); rli.close(); } + +{ + let output = ''; + class FakeInput extends EventEmitter { + columns = 80 + + write = common.mustCall((data) => { + output += data; + }, 9) + + resume() {} + pause() {} + end() {} + } + + const fi = new FakeInput(); + const rli = new readline.Interface({ + input: fi, + output: fi, + terminal: true, + completer: common.mustCall((input, cb) => { + cb(null, [[input[0].toUpperCase() + input.slice(1)], input]); + }), + }); + + rli.on('line', common.mustNotCall()); + fi.emit('data', 'input'); + queueMicrotask(() => { + fi.emit('data', '\t'); + queueMicrotask(() => { + assert.match(output, /> Input/); + output = ''; + rli.close(); + }); + }); +} |