11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_cirequire('../common'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst stream = require('stream'); 61cb0ef41Sopenharmony_ciconst assert = require('assert'); 71cb0ef41Sopenharmony_ciconst repl = require('repl'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_cilet output = ''; 101cb0ef41Sopenharmony_ciconst inputStream = new stream.PassThrough(); 111cb0ef41Sopenharmony_ciconst outputStream = new stream.PassThrough(); 121cb0ef41Sopenharmony_cioutputStream.on('data', function(d) { 131cb0ef41Sopenharmony_ci output += d; 141cb0ef41Sopenharmony_ci}); 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ciconst r = repl.start({ 171cb0ef41Sopenharmony_ci input: inputStream, 181cb0ef41Sopenharmony_ci output: outputStream, 191cb0ef41Sopenharmony_ci terminal: true 201cb0ef41Sopenharmony_ci}); 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_cir.defineCommand('say1', { 231cb0ef41Sopenharmony_ci help: 'help for say1', 241cb0ef41Sopenharmony_ci action: function(thing) { 251cb0ef41Sopenharmony_ci output = ''; 261cb0ef41Sopenharmony_ci this.output.write(`hello ${thing}\n`); 271cb0ef41Sopenharmony_ci this.displayPrompt(); 281cb0ef41Sopenharmony_ci } 291cb0ef41Sopenharmony_ci}); 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_cir.defineCommand('say2', function() { 321cb0ef41Sopenharmony_ci output = ''; 331cb0ef41Sopenharmony_ci this.output.write('hello from say2\n'); 341cb0ef41Sopenharmony_ci this.displayPrompt(); 351cb0ef41Sopenharmony_ci}); 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ciinputStream.write('.help\n'); 381cb0ef41Sopenharmony_ciassert.match(output, /\n\.say1 {5}help for say1\n/); 391cb0ef41Sopenharmony_ciassert.match(output, /\n\.say2\n/); 401cb0ef41Sopenharmony_ciinputStream.write('.say1 node developer\n'); 411cb0ef41Sopenharmony_ciassert.ok(output.startsWith('hello node developer\n'), 421cb0ef41Sopenharmony_ci `say1 output starts incorrectly: "${output}"`); 431cb0ef41Sopenharmony_ciassert.ok(output.includes('> '), 441cb0ef41Sopenharmony_ci `say1 output does not include prompt: "${output}"`); 451cb0ef41Sopenharmony_ciinputStream.write('.say2 node developer\n'); 461cb0ef41Sopenharmony_ciassert.ok(output.startsWith('hello from say2\n'), 471cb0ef41Sopenharmony_ci `say2 output starts incorrectly: "${output}"`); 481cb0ef41Sopenharmony_ciassert.ok(output.includes('> '), 491cb0ef41Sopenharmony_ci `say2 output does not include prompt: "${output}"`); 50