Skip to content

Commit 44ac5e8

Browse files
fossamagnajuanarbol
authored andcommitted
test: improve lib/internal/readline/promises.js coverage
PR-URL: #42420 Refs: https://coverage.nodejs.org/coverage-419f02ba1f00cac3/lib/internal/readline/promises.js.html Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent dd1ea77 commit 44ac5e8

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

test/parallel/test-readline-promises-csi.mjs

+63
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import '../common/index.mjs';
55
import assert from 'assert';
66
import { Readline } from 'readline/promises';
7+
import { setImmediate } from 'timers/promises';
78
import { Writable } from 'stream';
89

910
import utils from 'internal/readline/utils';
@@ -161,3 +162,65 @@ class TestWritable extends Writable {
161162

162163
await assert.rejects(readline.cursorTo(1).commit(), error);
163164
}
165+
166+
{
167+
const writable = new TestWritable();
168+
const readline = new Readline(writable, { autoCommit: true });
169+
170+
await readline.clearScreenDown();
171+
await setImmediate(); // Wait for next tick as auto commit is asynchronous.
172+
assert.deepStrictEqual(writable.data, CSI.kClearScreenDown);
173+
}
174+
175+
{
176+
const writable = new TestWritable();
177+
const readline = new Readline(writable, { autoCommit: true });
178+
for (const [dir, data] of
179+
[
180+
[-1, CSI.kClearToLineBeginning],
181+
[1, CSI.kClearToLineEnd],
182+
[0, CSI.kClearLine],
183+
]) {
184+
writable.data = '';
185+
readline.clearLine(dir);
186+
await setImmediate(); // Wait for next tick as auto commit is asynchronous.
187+
assert.deepStrictEqual(writable.data, data);
188+
}
189+
}
190+
191+
{
192+
const writable = new TestWritable();
193+
const readline = new Readline(writable, { autoCommit: true });
194+
for (const [x, y, data] of
195+
[
196+
[0, 0, ''],
197+
[1, 0, '\x1b[1C'],
198+
[-1, 0, '\x1b[1D'],
199+
[0, 1, '\x1b[1B'],
200+
[0, -1, '\x1b[1A'],
201+
[1, 1, '\x1b[1C\x1b[1B'],
202+
[-1, 1, '\x1b[1D\x1b[1B'],
203+
[-1, -1, '\x1b[1D\x1b[1A'],
204+
[1, -1, '\x1b[1C\x1b[1A'],
205+
]) {
206+
writable.data = '';
207+
readline.moveCursor(x, y);
208+
await setImmediate(); // Wait for next tick as auto commit is asynchronous.
209+
assert.deepStrictEqual(writable.data, data);
210+
}
211+
}
212+
213+
{
214+
const writable = new TestWritable();
215+
const readline = new Readline(writable, { autoCommit: true });
216+
for (const [x, y, data] of
217+
[
218+
[1, undefined, '\x1b[2G'],
219+
[1, 2, '\x1b[3;2H'],
220+
]) {
221+
writable.data = '';
222+
readline.cursorTo(x, y);
223+
await setImmediate(); // Wait for next tick as auto commit is asynchronous.
224+
assert.deepStrictEqual(writable.data, data);
225+
}
226+
}

0 commit comments

Comments
 (0)