diff options
author | MURAKAMI Masahiko <m-murakami@esm.co.jp> | 2022-04-03 18:40:30 +0900 |
---|---|---|
committer | Juan José Arboleda <soyjuanarbol@gmail.com> | 2022-04-06 12:25:53 -0500 |
commit | fb25ba435c53b8b01a6d7548bf59437b52772f8f (patch) | |
tree | f85b2616858eb1d18ec1b05f474b7473ccc8daa6 | |
parent | 4cbb1ea9100a4b2311c52c6442736f67384469f2 (diff) | |
download | node-new-fb25ba435c53b8b01a6d7548bf59437b52772f8f.tar.gz |
test: improve lib/internal/readline/promises.js coverage
PR-URL: https://github.com/nodejs/node/pull/42420
Refs: https://coverage.nodejs.org/coverage-419f02ba1f00cac3/lib/internal/readline/promises.js.html
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
-rw-r--r-- | test/parallel/test-readline-promises-csi.mjs | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/test/parallel/test-readline-promises-csi.mjs b/test/parallel/test-readline-promises-csi.mjs index 71a3ad7a81..9b0d0bb2b8 100644 --- a/test/parallel/test-readline-promises-csi.mjs +++ b/test/parallel/test-readline-promises-csi.mjs @@ -4,6 +4,7 @@ import '../common/index.mjs'; import assert from 'assert'; import { Readline } from 'readline/promises'; +import { setImmediate } from 'timers/promises'; import { Writable } from 'stream'; import utils from 'internal/readline/utils'; @@ -161,3 +162,65 @@ class TestWritable extends Writable { await assert.rejects(readline.cursorTo(1).commit(), error); } + +{ + const writable = new TestWritable(); + const readline = new Readline(writable, { autoCommit: true }); + + await readline.clearScreenDown(); + await setImmediate(); // Wait for next tick as auto commit is asynchronous. + assert.deepStrictEqual(writable.data, CSI.kClearScreenDown); +} + +{ + const writable = new TestWritable(); + const readline = new Readline(writable, { autoCommit: true }); + for (const [dir, data] of + [ + [-1, CSI.kClearToLineBeginning], + [1, CSI.kClearToLineEnd], + [0, CSI.kClearLine], + ]) { + writable.data = ''; + readline.clearLine(dir); + await setImmediate(); // Wait for next tick as auto commit is asynchronous. + assert.deepStrictEqual(writable.data, data); + } +} + +{ + const writable = new TestWritable(); + const readline = new Readline(writable, { autoCommit: true }); + for (const [x, y, data] of + [ + [0, 0, ''], + [1, 0, '\x1b[1C'], + [-1, 0, '\x1b[1D'], + [0, 1, '\x1b[1B'], + [0, -1, '\x1b[1A'], + [1, 1, '\x1b[1C\x1b[1B'], + [-1, 1, '\x1b[1D\x1b[1B'], + [-1, -1, '\x1b[1D\x1b[1A'], + [1, -1, '\x1b[1C\x1b[1A'], + ]) { + writable.data = ''; + readline.moveCursor(x, y); + await setImmediate(); // Wait for next tick as auto commit is asynchronous. + assert.deepStrictEqual(writable.data, data); + } +} + +{ + const writable = new TestWritable(); + const readline = new Readline(writable, { autoCommit: true }); + for (const [x, y, data] of + [ + [1, undefined, '\x1b[2G'], + [1, 2, '\x1b[3;2H'], + ]) { + writable.data = ''; + readline.cursorTo(x, y); + await setImmediate(); // Wait for next tick as auto commit is asynchronous. + assert.deepStrictEqual(writable.data, data); + } +} |