Skip to content

Commit 7a95392

Browse files
claudiorodriguezBridgeAR
authored andcommitted
test: improve readline test coverage for tty
Adds the following tests for tty readline: - go to beginning and end of line - wordLeft - wordRight - deleteWordLeft - deleteWordRight PR-URL: #12064 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 9d7574e commit 7a95392

File tree

1 file changed

+136
-0
lines changed

1 file changed

+136
-0
lines changed

Diff for: test/parallel/test-readline-interface.js

+136
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,142 @@ function isWarned(emitter) {
527527
assert.strictEqual(cursorPos.cols, expectedLines.slice(-1)[0].length);
528528
rli.close();
529529
}
530+
531+
{
532+
// Beginning and end of line
533+
const fi = new FakeInput();
534+
const rli = new readline.Interface({
535+
input: fi,
536+
output: fi,
537+
prompt: '',
538+
terminal: terminal
539+
});
540+
fi.emit('data', 'the quick brown fox');
541+
fi.emit('keypress', '.', { ctrl: true, name: 'a' });
542+
let cursorPos = rli._getCursorPos();
543+
assert.strictEqual(cursorPos.rows, 0);
544+
assert.strictEqual(cursorPos.cols, 0);
545+
fi.emit('keypress', '.', { ctrl: true, name: 'e' });
546+
cursorPos = rli._getCursorPos();
547+
assert.strictEqual(cursorPos.rows, 0);
548+
assert.strictEqual(cursorPos.cols, 19);
549+
rli.close();
550+
}
551+
552+
{
553+
// `wordLeft` and `wordRight`
554+
const fi = new FakeInput();
555+
const rli = new readline.Interface({
556+
input: fi,
557+
output: fi,
558+
prompt: '',
559+
terminal: terminal
560+
});
561+
fi.emit('data', 'the quick brown fox');
562+
fi.emit('keypress', '.', { ctrl: true, name: 'left' });
563+
let cursorPos = rli._getCursorPos();
564+
assert.strictEqual(cursorPos.rows, 0);
565+
assert.strictEqual(cursorPos.cols, 16);
566+
fi.emit('keypress', '.', { meta: true, name: 'b' });
567+
cursorPos = rli._getCursorPos();
568+
assert.strictEqual(cursorPos.rows, 0);
569+
assert.strictEqual(cursorPos.cols, 10);
570+
fi.emit('keypress', '.', { ctrl: true, name: 'right' });
571+
cursorPos = rli._getCursorPos();
572+
assert.strictEqual(cursorPos.rows, 0);
573+
assert.strictEqual(cursorPos.cols, 16);
574+
fi.emit('keypress', '.', { meta: true, name: 'f' });
575+
cursorPos = rli._getCursorPos();
576+
assert.strictEqual(cursorPos.rows, 0);
577+
assert.strictEqual(cursorPos.cols, 19);
578+
rli.close();
579+
}
580+
581+
{
582+
// `deleteWordLeft`
583+
[
584+
{ ctrl: true, name: 'w' },
585+
{ ctrl: true, name: 'backspace' },
586+
{ meta: true, name: 'backspace' }
587+
]
588+
.forEach((deleteWordLeftKey) => {
589+
let fi = new FakeInput();
590+
let rli = new readline.Interface({
591+
input: fi,
592+
output: fi,
593+
prompt: '',
594+
terminal: terminal
595+
});
596+
fi.emit('data', 'the quick brown fox');
597+
fi.emit('keypress', '.', { ctrl: true, name: 'left' });
598+
rli.on('line', common.mustCall((line) => {
599+
assert.strictEqual(line, 'the quick fox');
600+
}));
601+
fi.emit('keypress', '.', deleteWordLeftKey);
602+
fi.emit('data', '\n');
603+
rli.close();
604+
605+
// No effect if pressed at beginning of line
606+
fi = new FakeInput();
607+
rli = new readline.Interface({
608+
input: fi,
609+
output: fi,
610+
prompt: '',
611+
terminal: terminal
612+
});
613+
fi.emit('data', 'the quick brown fox');
614+
fi.emit('keypress', '.', { ctrl: true, name: 'a' });
615+
rli.on('line', common.mustCall((line) => {
616+
assert.strictEqual(line, 'the quick brown fox');
617+
}));
618+
fi.emit('keypress', '.', deleteWordLeftKey);
619+
fi.emit('data', '\n');
620+
rli.close();
621+
});
622+
}
623+
624+
{
625+
// `deleteWordRight`
626+
[
627+
{ ctrl: true, name: 'delete' },
628+
{ meta: true, name: 'delete' },
629+
{ meta: true, name: 'd' }
630+
]
631+
.forEach((deleteWordRightKey) => {
632+
let fi = new FakeInput();
633+
let rli = new readline.Interface({
634+
input: fi,
635+
output: fi,
636+
prompt: '',
637+
terminal: terminal
638+
});
639+
fi.emit('data', 'the quick brown fox');
640+
fi.emit('keypress', '.', { ctrl: true, name: 'left' });
641+
fi.emit('keypress', '.', { ctrl: true, name: 'left' });
642+
rli.on('line', common.mustCall((line) => {
643+
assert.strictEqual(line, 'the quick fox');
644+
}));
645+
fi.emit('keypress', '.', deleteWordRightKey);
646+
fi.emit('data', '\n');
647+
rli.close();
648+
649+
// No effect if pressed at end of line
650+
fi = new FakeInput();
651+
rli = new readline.Interface({
652+
input: fi,
653+
output: fi,
654+
prompt: '',
655+
terminal: terminal
656+
});
657+
fi.emit('data', 'the quick brown fox');
658+
rli.on('line', common.mustCall((line) => {
659+
assert.strictEqual(line, 'the quick brown fox');
660+
}));
661+
fi.emit('keypress', '.', deleteWordRightKey);
662+
fi.emit('data', '\n');
663+
rli.close();
664+
});
665+
}
530666
}
531667

532668
// isFullWidthCodePoint() should return false for non-numeric values

0 commit comments

Comments
 (0)