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: add test cases to test-readline-keys.js #10772

Closed
Closed
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
107 changes: 99 additions & 8 deletions test/parallel/test-readline-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const fo = new FakeInput();
new Interface({ input: fi, output: fo, terminal: true });

let keys = [];
fi.on('keypress', function(s, k) {
fi.on('keypress', (s, k) => {
keys.push(k);
});

Expand All @@ -32,13 +32,13 @@ function addTest(sequences, expectedKeys) {
expectedKeys = [ expectedKeys ];
}

expectedKeys = expectedKeys.map(function(k) {
expectedKeys = expectedKeys.map((k) => {
return k ? extend({ ctrl: false, meta: false, shift: false }, k) : k;
});

keys = [];

sequences.forEach(function(sequence) {
sequences.forEach((sequence) => {
fi.write(sequence);
});
assert.deepStrictEqual(keys, expectedKeys);
Expand All @@ -65,7 +65,7 @@ const addKeyIntervalTest = (sequences, expectedKeys, interval = 550,
expectedKeys = [ expectedKeys ];
}

expectedKeys = expectedKeys.map(function(k) {
expectedKeys = expectedKeys.map((k) => {
return k ? extend({ ctrl: false, meta: false, shift: false }, k) : k;
});

Expand Down Expand Up @@ -129,10 +129,63 @@ addTest('a\x1baA\x1bA', [
{ name: 'a', sequence: '\x1bA', meta: true, shift: true },
]);

// xterm/gnome
addTest('\x1bOA\x1bOB', [
// xterm/gnome ESC O letter
addTest('\x1bOP\x1bOQ\x1bOR\x1bOS', [
{ name: 'f1', sequence: '\x1bOP', code: 'OP' },
{ name: 'f2', sequence: '\x1bOQ', code: 'OQ' },
{ name: 'f3', sequence: '\x1bOR', code: 'OR' },
{ name: 'f4', sequence: '\x1bOS', code: 'OS' },
]);

// xterm/rxvt ESC [ number ~ */
addTest('\x1b[11~\x1b[12~\x1b[13~\x1b[14~', [
{ name: 'f1', sequence: '\x1b[11~', code: '[11~' },
{ name: 'f2', sequence: '\x1b[12~', code: '[12~' },
{ name: 'f3', sequence: '\x1b[13~', code: '[13~' },
{ name: 'f4', sequence: '\x1b[14~', code: '[14~' },
]);

// from Cygwin and used in libuv
addTest('\x1b[[A\x1b[[B\x1b[[C\x1b[[D\x1b[[E', [
{ name: 'f1', sequence: '\x1b[[A', code: '[[A' },
{ name: 'f2', sequence: '\x1b[[B', code: '[[B' },
{ name: 'f3', sequence: '\x1b[[C', code: '[[C' },
{ name: 'f4', sequence: '\x1b[[D', code: '[[D' },
{ name: 'f5', sequence: '\x1b[[E', code: '[[E' },
]);

// common
addTest('\x1b[15~\x1b[17~\x1b[18~\x1b[19~\x1b[20~\x1b[21~\x1b[23~\x1b[24~', [
{ name: 'f5', sequence: '\x1b[15~', code: '[15~' },
{ name: 'f6', sequence: '\x1b[17~', code: '[17~' },
{ name: 'f7', sequence: '\x1b[18~', code: '[18~' },
{ name: 'f8', sequence: '\x1b[19~', code: '[19~' },
{ name: 'f9', sequence: '\x1b[20~', code: '[20~' },
{ name: 'f10', sequence: '\x1b[21~', code: '[21~' },
{ name: 'f11', sequence: '\x1b[23~', code: '[23~' },
{ name: 'f12', sequence: '\x1b[24~', code: '[24~' },
]);

// xterm ESC [ letter
addTest('\x1b[A\x1b[B\x1b[C\x1b[D\x1b[E\x1b[F\x1b[H', [
{ name: 'up', sequence: '\x1b[A', code: '[A' },
{ name: 'down', sequence: '\x1b[B', code: '[B' },
{ name: 'right', sequence: '\x1b[C', code: '[C' },
{ name: 'left', sequence: '\x1b[D', code: '[D' },
{ name: 'clear', sequence: '\x1b[E', code: '[E' },
{ name: 'end', sequence: '\x1b[F', code: '[F' },
{ name: 'home', sequence: '\x1b[H', code: '[H' },
]);

// xterm/gnome ESC O letter
addTest('\x1bOA\x1bOB\x1bOC\x1bOD\x1bOE\x1bOF\x1bOH', [
{ name: 'up', sequence: '\x1bOA', code: 'OA' },
{ name: 'down', sequence: '\x1bOB', code: 'OB' },
{ name: 'right', sequence: '\x1bOC', code: 'OC' },
{ name: 'left', sequence: '\x1bOD', code: 'OD' },
{ name: 'clear', sequence: '\x1bOE', code: 'OE' },
{ name: 'end', sequence: '\x1bOF', code: 'OF' },
{ name: 'home', sequence: '\x1bOH', code: 'OH' },
]);

// old xterm shift-arrows
Expand All @@ -141,6 +194,28 @@ addTest('\x1bO2A\x1bO2B', [
{ name: 'down', sequence: '\x1bO2B', code: 'OB', shift: true },
]);

// xterm/rxvt ESC [ number ~
addTest('\x1b[1~\x1b[2~\x1b[3~\x1b[4~\x1b[5~\x1b[6~', [
{ name: 'home', sequence: '\x1b[1~', code: '[1~' },
{ name: 'insert', sequence: '\x1b[2~', code: '[2~' },
{ name: 'delete', sequence: '\x1b[3~', code: '[3~' },
{ name: 'end', sequence: '\x1b[4~', code: '[4~' },
{ name: 'pageup', sequence: '\x1b[5~', code: '[5~' },
{ name: 'pagedown', sequence: '\x1b[6~', code: '[6~' },
]);

// putty
addTest('\x1b[[5~\x1b[[6~', [
{ name: 'pageup', sequence: '\x1b[[5~', code: '[[5~' },
{ name: 'pagedown', sequence: '\x1b[[6~', code: '[[6~' },
]);

// rxvt
addTest('\x1b[7~\x1b[8~', [
{ name: 'home', sequence: '\x1b[7~', code: '[7~' },
{ name: 'end', sequence: '\x1b[8~', code: '[8~' },
]);

// gnome terminal
addTest('\x1b[A\x1b[B\x1b[2A\x1b[2B', [
{ name: 'up', sequence: '\x1b[A', code: '[A' },
Expand All @@ -149,11 +224,27 @@ addTest('\x1b[A\x1b[B\x1b[2A\x1b[2B', [
{ name: 'down', sequence: '\x1b[2B', code: '[B', shift: true },
]);

// rxvt
addTest('\x1b[20~\x1b[2$\x1b[2^', [
// rxvt keys with modifiers
// eslint-disable-next-line max-len
addTest('\x1b[20~\x1b[2$\x1b[2^\x1b[3$\x1b[3^\x1b[5$\x1b[5^\x1b[6$\x1b[6^\x1b[7$\x1b[7^\x1b[8$\x1b[8^', [
{ name: 'f9', sequence: '\x1b[20~', code: '[20~' },
{ name: 'insert', sequence: '\x1b[2$', code: '[2$', shift: true },
{ name: 'insert', sequence: '\x1b[2^', code: '[2^', ctrl: true },
{ name: 'delete', sequence: '\x1b[3$', code: '[3$', shift: true },
{ name: 'delete', sequence: '\x1b[3^', code: '[3^', ctrl: true },
{ name: 'pageup', sequence: '\x1b[5$', code: '[5$', shift: true },
{ name: 'pageup', sequence: '\x1b[5^', code: '[5^', ctrl: true },
{ name: 'pagedown', sequence: '\x1b[6$', code: '[6$', shift: true },
{ name: 'pagedown', sequence: '\x1b[6^', code: '[6^', ctrl: true },
{ name: 'home', sequence: '\x1b[7$', code: '[7$', shift: true },
{ name: 'home', sequence: '\x1b[7^', code: '[7^', ctrl: true },
{ name: 'end', sequence: '\x1b[8$', code: '[8$', shift: true },
{ name: 'end', sequence: '\x1b[8^', code: '[8^', ctrl: true },
]);

// misc
addTest('\x1b[Z', [
{ name: 'tab', sequence: '\x1b[Z', code: '[Z', shift: true },
]);

// xterm + modifiers
Expand Down