11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci// emitKeypressEvents is thoroughly tested in test-readline-keys.js. 31cb0ef41Sopenharmony_ci// However, that test calls it implicitly. This is just a quick sanity check 41cb0ef41Sopenharmony_ci// to verify that it works when called explicitly. 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_cirequire('../common'); 71cb0ef41Sopenharmony_ciconst assert = require('assert'); 81cb0ef41Sopenharmony_ciconst readline = require('readline'); 91cb0ef41Sopenharmony_ciconst PassThrough = require('stream').PassThrough; 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciconst expectedSequence = ['f', 'o', 'o']; 121cb0ef41Sopenharmony_ciconst expectedKeys = [ 131cb0ef41Sopenharmony_ci { sequence: 'f', name: 'f', ctrl: false, meta: false, shift: false }, 141cb0ef41Sopenharmony_ci { sequence: 'o', name: 'o', ctrl: false, meta: false, shift: false }, 151cb0ef41Sopenharmony_ci { sequence: 'o', name: 'o', ctrl: false, meta: false, shift: false }, 161cb0ef41Sopenharmony_ci]; 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci{ 191cb0ef41Sopenharmony_ci const stream = new PassThrough(); 201cb0ef41Sopenharmony_ci const sequence = []; 211cb0ef41Sopenharmony_ci const keys = []; 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci readline.emitKeypressEvents(stream); 241cb0ef41Sopenharmony_ci stream.on('keypress', (s, k) => { 251cb0ef41Sopenharmony_ci sequence.push(s); 261cb0ef41Sopenharmony_ci keys.push(k); 271cb0ef41Sopenharmony_ci }); 281cb0ef41Sopenharmony_ci stream.write('foo'); 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci assert.deepStrictEqual(sequence, expectedSequence); 311cb0ef41Sopenharmony_ci assert.deepStrictEqual(keys, expectedKeys); 321cb0ef41Sopenharmony_ci} 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci{ 351cb0ef41Sopenharmony_ci const stream = new PassThrough(); 361cb0ef41Sopenharmony_ci const sequence = []; 371cb0ef41Sopenharmony_ci const keys = []; 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci stream.on('keypress', (s, k) => { 401cb0ef41Sopenharmony_ci sequence.push(s); 411cb0ef41Sopenharmony_ci keys.push(k); 421cb0ef41Sopenharmony_ci }); 431cb0ef41Sopenharmony_ci readline.emitKeypressEvents(stream); 441cb0ef41Sopenharmony_ci stream.write('foo'); 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci assert.deepStrictEqual(sequence, expectedSequence); 471cb0ef41Sopenharmony_ci assert.deepStrictEqual(keys, expectedKeys); 481cb0ef41Sopenharmony_ci} 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ci{ 511cb0ef41Sopenharmony_ci const stream = new PassThrough(); 521cb0ef41Sopenharmony_ci const sequence = []; 531cb0ef41Sopenharmony_ci const keys = []; 541cb0ef41Sopenharmony_ci const keypressListener = (s, k) => { 551cb0ef41Sopenharmony_ci sequence.push(s); 561cb0ef41Sopenharmony_ci keys.push(k); 571cb0ef41Sopenharmony_ci }; 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ci stream.on('keypress', keypressListener); 601cb0ef41Sopenharmony_ci readline.emitKeypressEvents(stream); 611cb0ef41Sopenharmony_ci stream.removeListener('keypress', keypressListener); 621cb0ef41Sopenharmony_ci stream.write('foo'); 631cb0ef41Sopenharmony_ci 641cb0ef41Sopenharmony_ci assert.deepStrictEqual(sequence, []); 651cb0ef41Sopenharmony_ci assert.deepStrictEqual(keys, []); 661cb0ef41Sopenharmony_ci 671cb0ef41Sopenharmony_ci stream.on('keypress', keypressListener); 681cb0ef41Sopenharmony_ci stream.write('foo'); 691cb0ef41Sopenharmony_ci 701cb0ef41Sopenharmony_ci assert.deepStrictEqual(sequence, expectedSequence); 711cb0ef41Sopenharmony_ci assert.deepStrictEqual(keys, expectedKeys); 721cb0ef41Sopenharmony_ci} 73