Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1483ebd

Browse filesBrowse files
claudiorodriguezMylesBorins
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 <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 377f7b9 commit 1483ebd
Copy full SHA for 1483ebd

File tree

Expand file treeCollapse file tree

1 file changed

+136
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+136
-0
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-readline-interface.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-readline-interface.js
+136Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,142 @@ function isWarned(emitter) {
567567
assert.strictEqual(cursorPos.cols, expectedLines.slice(-1)[0].length);
568568
rli.close();
569569
}
570+
571+
{
572+
// Beginning and end of line
573+
const fi = new FakeInput();
574+
const rli = new readline.Interface({
575+
input: fi,
576+
output: fi,
577+
prompt: '',
578+
terminal: terminal
579+
});
580+
fi.emit('data', 'the quick brown fox');
581+
fi.emit('keypress', '.', { ctrl: true, name: 'a' });
582+
let cursorPos = rli._getCursorPos();
583+
assert.strictEqual(cursorPos.rows, 0);
584+
assert.strictEqual(cursorPos.cols, 0);
585+
fi.emit('keypress', '.', { ctrl: true, name: 'e' });
586+
cursorPos = rli._getCursorPos();
587+
assert.strictEqual(cursorPos.rows, 0);
588+
assert.strictEqual(cursorPos.cols, 19);
589+
rli.close();
590+
}
591+
592+
{
593+
// `wordLeft` and `wordRight`
594+
const fi = new FakeInput();
595+
const rli = new readline.Interface({
596+
input: fi,
597+
output: fi,
598+
prompt: '',
599+
terminal: terminal
600+
});
601+
fi.emit('data', 'the quick brown fox');
602+
fi.emit('keypress', '.', { ctrl: true, name: 'left' });
603+
let cursorPos = rli._getCursorPos();
604+
assert.strictEqual(cursorPos.rows, 0);
605+
assert.strictEqual(cursorPos.cols, 16);
606+
fi.emit('keypress', '.', { meta: true, name: 'b' });
607+
cursorPos = rli._getCursorPos();
608+
assert.strictEqual(cursorPos.rows, 0);
609+
assert.strictEqual(cursorPos.cols, 10);
610+
fi.emit('keypress', '.', { ctrl: true, name: 'right' });
611+
cursorPos = rli._getCursorPos();
612+
assert.strictEqual(cursorPos.rows, 0);
613+
assert.strictEqual(cursorPos.cols, 16);
614+
fi.emit('keypress', '.', { meta: true, name: 'f' });
615+
cursorPos = rli._getCursorPos();
616+
assert.strictEqual(cursorPos.rows, 0);
617+
assert.strictEqual(cursorPos.cols, 19);
618+
rli.close();
619+
}
620+
621+
{
622+
// `deleteWordLeft`
623+
[
624+
{ ctrl: true, name: 'w' },
625+
{ ctrl: true, name: 'backspace' },
626+
{ meta: true, name: 'backspace' }
627+
]
628+
.forEach((deleteWordLeftKey) => {
629+
let fi = new FakeInput();
630+
let rli = new readline.Interface({
631+
input: fi,
632+
output: fi,
633+
prompt: '',
634+
terminal: terminal
635+
});
636+
fi.emit('data', 'the quick brown fox');
637+
fi.emit('keypress', '.', { ctrl: true, name: 'left' });
638+
rli.on('line', common.mustCall((line) => {
639+
assert.strictEqual(line, 'the quick fox');
640+
}));
641+
fi.emit('keypress', '.', deleteWordLeftKey);
642+
fi.emit('data', '\n');
643+
rli.close();
644+
645+
// No effect if pressed at beginning of line
646+
fi = new FakeInput();
647+
rli = new readline.Interface({
648+
input: fi,
649+
output: fi,
650+
prompt: '',
651+
terminal: terminal
652+
});
653+
fi.emit('data', 'the quick brown fox');
654+
fi.emit('keypress', '.', { ctrl: true, name: 'a' });
655+
rli.on('line', common.mustCall((line) => {
656+
assert.strictEqual(line, 'the quick brown fox');
657+
}));
658+
fi.emit('keypress', '.', deleteWordLeftKey);
659+
fi.emit('data', '\n');
660+
rli.close();
661+
});
662+
}
663+
664+
{
665+
// `deleteWordRight`
666+
[
667+
{ ctrl: true, name: 'delete' },
668+
{ meta: true, name: 'delete' },
669+
{ meta: true, name: 'd' }
670+
]
671+
.forEach((deleteWordRightKey) => {
672+
let fi = new FakeInput();
673+
let rli = new readline.Interface({
674+
input: fi,
675+
output: fi,
676+
prompt: '',
677+
terminal: terminal
678+
});
679+
fi.emit('data', 'the quick brown fox');
680+
fi.emit('keypress', '.', { ctrl: true, name: 'left' });
681+
fi.emit('keypress', '.', { ctrl: true, name: 'left' });
682+
rli.on('line', common.mustCall((line) => {
683+
assert.strictEqual(line, 'the quick fox');
684+
}));
685+
fi.emit('keypress', '.', deleteWordRightKey);
686+
fi.emit('data', '\n');
687+
rli.close();
688+
689+
// No effect if pressed at end of line
690+
fi = new FakeInput();
691+
rli = new readline.Interface({
692+
input: fi,
693+
output: fi,
694+
prompt: '',
695+
terminal: terminal
696+
});
697+
fi.emit('data', 'the quick brown fox');
698+
rli.on('line', common.mustCall((line) => {
699+
assert.strictEqual(line, 'the quick brown fox');
700+
}));
701+
fi.emit('keypress', '.', deleteWordRightKey);
702+
fi.emit('data', '\n');
703+
rli.close();
704+
});
705+
}
570706
}
571707

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.