Skip to content

Commit

Permalink
test: add test cases to test-readline-keys.js
Browse files Browse the repository at this point in the history
PR-URL: nodejs#10772
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
  • Loading branch information
hiroppy authored and jasnell committed Feb 8, 2017
1 parent a8734af commit 2db3b94
Showing 1 changed file with 99 additions and 8 deletions.
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

0 comments on commit 2db3b94

Please sign in to comment.