Skip to content

Commit d6786d2

Browse files
cjihrigMylesBorins
authored andcommitted
test: add multiline repl input regression test
This commit adds a regression test for de848ac, which broke multiline input in the REPL. PR-URL: #18718 Refs: #17828 Refs: #18715 Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 18c4933 commit d6786d2

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

test/parallel/test-repl-multiline.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const repl = require('repl');
5+
const inputStream = new common.ArrayStream();
6+
const outputStream = new common.ArrayStream();
7+
const input = ['var foo = {', '};', 'foo;'];
8+
let output = '';
9+
10+
outputStream.write = (data) => { output += data.replace('\r', ''); };
11+
12+
const r = repl.start({
13+
prompt: '',
14+
input: inputStream,
15+
output: outputStream,
16+
terminal: true,
17+
useColors: false
18+
});
19+
20+
r.on('exit', common.mustCall(() => {
21+
const actual = output.split('\n');
22+
23+
// Validate the output, which contains terminal escape codes.
24+
assert.strictEqual(actual.length, 6);
25+
assert.ok(actual[0].endsWith(input[0]));
26+
assert.ok(actual[1].includes('... '));
27+
assert.ok(actual[1].endsWith(input[1]));
28+
assert.strictEqual(actual[2], 'undefined');
29+
assert.ok(actual[3].endsWith(input[2]));
30+
assert.strictEqual(actual[4], '{}');
31+
// Ignore the last line, which is nothing but escape codes.
32+
}));
33+
34+
inputStream.run(input);
35+
r.close();

0 commit comments

Comments
 (0)