Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions test/parallel/test-readline-promises-csi.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -161,3 +162,61 @@ 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();
process.nextTick(() => assert.deepStrictEqual(writable.data, CSI.kClearScreenDown));
Comment thread
fossamagna marked this conversation as resolved.
Outdated
}

{
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);
assert.deepStrictEqual((await setImmediate(writable)).data, data);
Comment thread
fossamagna marked this conversation as resolved.
Outdated
}
}

{
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);
assert.deepStrictEqual((await setImmediate(writable)).data, data);
Comment thread
fossamagna marked this conversation as resolved.
Outdated
}
}

{
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);
assert.deepStrictEqual((await setImmediate(writable)).data, data);
Comment thread
fossamagna marked this conversation as resolved.
Outdated
}
}