11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ciconst PassThrough = require('stream').PassThrough;
61cb0ef41Sopenharmony_ciconst readline = require('readline');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_cicommon.skipIfDumbTerminal();
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci// Checks that tab completion still works
111cb0ef41Sopenharmony_ci// when output column size is undefined
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciconst iStream = new PassThrough();
141cb0ef41Sopenharmony_ciconst oStream = new PassThrough();
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_cireadline.createInterface({
171cb0ef41Sopenharmony_ci  terminal: true,
181cb0ef41Sopenharmony_ci  input: iStream,
191cb0ef41Sopenharmony_ci  output: oStream,
201cb0ef41Sopenharmony_ci  completer: function(line, cb) {
211cb0ef41Sopenharmony_ci    cb(null, [['process.stdout', 'process.stdin', 'process.stderr'], line]);
221cb0ef41Sopenharmony_ci  }
231cb0ef41Sopenharmony_ci});
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_cilet output = '';
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_cioStream.on('data', function(data) {
281cb0ef41Sopenharmony_ci  output += data;
291cb0ef41Sopenharmony_ci});
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_cioStream.on('end', common.mustCall(() => {
321cb0ef41Sopenharmony_ci  const expect = 'process.stdout\r\n' +
331cb0ef41Sopenharmony_ci                 'process.stdin\r\n' +
341cb0ef41Sopenharmony_ci                 'process.stderr';
351cb0ef41Sopenharmony_ci  assert.match(output, new RegExp(expect));
361cb0ef41Sopenharmony_ci}));
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ciiStream.write('process.s\t');
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ci// Completion works.
411cb0ef41Sopenharmony_ciassert.match(output, /process\.std\b/);
421cb0ef41Sopenharmony_ci// Completion doesn’t show all results yet.
431cb0ef41Sopenharmony_ciassert.doesNotMatch(output, /stdout/);
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ciiStream.write('\t');
461cb0ef41Sopenharmony_cioStream.end();
47