1'use strict'; 2 3// Flags: --expose-internals 4 5const common = require('../common'); 6const readline = require('readline'); 7const assert = require('assert'); 8const EventEmitter = require('events').EventEmitter; 9const { getStringWidth } = require('internal/util/inspect'); 10 11common.skipIfDumbTerminal(); 12 13// This test verifies that the tab completion supports unicode and the writes 14// are limited to the minimum. 15[ 16 'あ', 17 '', 18 '' 19].forEach((char) => { 20 [true, false].forEach((lineBreak) => { 21 const completer = (line) => [ 22 [ 23 'First group', 24 '', 25 `${char}${'a'.repeat(10)}`, `${char}${'b'.repeat(10)}`, char.repeat(11), 26 ], 27 line 28 ]; 29 30 let output = ''; 31 const width = getStringWidth(char) - 1; 32 33 class FakeInput extends EventEmitter { 34 columns = ((width + 1) * 10 + (lineBreak ? 0 : 10)) * 3 35 36 write = common.mustCall((data) => { 37 output += data; 38 }, 6) 39 40 resume() {} 41 pause() {} 42 end() {} 43 } 44 45 const fi = new FakeInput(); 46 const rli = new readline.Interface({ 47 input: fi, 48 output: fi, 49 terminal: true, 50 completer: completer 51 }); 52 53 const last = '\r\nFirst group\r\n\r\n' + 54 `${char}${'a'.repeat(10)}${' '.repeat(2 + width * 10)}` + 55 `${char}${'b'.repeat(10)}` + 56 (lineBreak ? '\r\n' : ' '.repeat(2 + width * 10)) + 57 `${char.repeat(11)}\r\n` + 58 `\r\n\u001b[1G\u001b[0J> ${char}\u001b[${4 + width}G`; 59 60 const expectations = [char, '', last]; 61 62 rli.on('line', common.mustNotCall()); 63 for (const character of `${char}\t\t`) { 64 fi.emit('data', character); 65 assert.strictEqual(output, expectations.shift()); 66 output = ''; 67 } 68 rli.close(); 69 }); 70}); 71