11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst ArrayStream = require('../common/arraystream'); 41cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 51cb0ef41Sopenharmony_ciconst assert = require('assert'); 61cb0ef41Sopenharmony_ciconst repl = require('repl'); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_cicommon.skipIfDumbTerminal(); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst command = `.load ${fixtures.path('repl-load-multiline.js')}`; 111cb0ef41Sopenharmony_ciconst terminalCode = '\u001b[1G\u001b[0J \u001b[1G'; 121cb0ef41Sopenharmony_ciconst terminalCodeRegex = new RegExp(terminalCode.replace(/\[/g, '\\['), 'g'); 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ciconst expected = `${command} 151cb0ef41Sopenharmony_ciconst getLunch = () => 161cb0ef41Sopenharmony_ci placeOrder('tacos') 171cb0ef41Sopenharmony_ci .then(eat); 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ciconst placeOrder = (order) => Promise.resolve(order); 201cb0ef41Sopenharmony_ciconst eat = (food) => '<nom nom nom>'; 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ciundefined 231cb0ef41Sopenharmony_ci`; 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_cilet accum = ''; 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ciconst inputStream = new ArrayStream(); 281cb0ef41Sopenharmony_ciconst outputStream = new ArrayStream(); 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_cioutputStream.write = (data) => accum += data.replace('\r', ''); 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ciconst r = repl.start({ 331cb0ef41Sopenharmony_ci prompt: '', 341cb0ef41Sopenharmony_ci input: inputStream, 351cb0ef41Sopenharmony_ci output: outputStream, 361cb0ef41Sopenharmony_ci terminal: true, 371cb0ef41Sopenharmony_ci useColors: false 381cb0ef41Sopenharmony_ci}); 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_cir.write(`${command}\n`); 411cb0ef41Sopenharmony_ciassert.strictEqual(accum.replace(terminalCodeRegex, ''), expected); 421cb0ef41Sopenharmony_cir.close(); 43