11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst ArrayStream = require('../common/arraystream');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ciconst repl = require('repl');
61cb0ef41Sopenharmony_ciconst input = ['const foo = {', '};', 'foo'];
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_cifunction run({ useColors }) {
91cb0ef41Sopenharmony_ci  const inputStream = new ArrayStream();
101cb0ef41Sopenharmony_ci  const outputStream = new ArrayStream();
111cb0ef41Sopenharmony_ci  let output = '';
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci  outputStream.write = (data) => { output += data.replace('\r', ''); };
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci  const r = repl.start({
161cb0ef41Sopenharmony_ci    prompt: '',
171cb0ef41Sopenharmony_ci    input: inputStream,
181cb0ef41Sopenharmony_ci    output: outputStream,
191cb0ef41Sopenharmony_ci    terminal: true,
201cb0ef41Sopenharmony_ci    useColors
211cb0ef41Sopenharmony_ci  });
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci  r.on('exit', common.mustCall(() => {
241cb0ef41Sopenharmony_ci    const actual = output.split('\n');
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci    // Validate the output, which contains terminal escape codes.
271cb0ef41Sopenharmony_ci    assert.strictEqual(actual.length, 6);
281cb0ef41Sopenharmony_ci    assert.ok(actual[0].endsWith(input[0]));
291cb0ef41Sopenharmony_ci    assert.ok(actual[1].includes('... '));
301cb0ef41Sopenharmony_ci    assert.ok(actual[1].endsWith(input[1]));
311cb0ef41Sopenharmony_ci    assert.ok(actual[2].includes('undefined'));
321cb0ef41Sopenharmony_ci    assert.ok(actual[3].endsWith(input[2]));
331cb0ef41Sopenharmony_ci    assert.strictEqual(actual[4], '{}');
341cb0ef41Sopenharmony_ci  }));
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci  inputStream.run(input);
371cb0ef41Sopenharmony_ci  r.close();
381cb0ef41Sopenharmony_ci}
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_cirun({ useColors: true });
411cb0ef41Sopenharmony_cirun({ useColors: false });
42