Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: improve lib/internal/readline/promises.js coverage #42420

Merged
Merged
Changes from all 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
63 changes: 63 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,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);
}
}