Skip to content

Commit 2ea529b

Browse files
committed
test: add regression test for 13557
Fixes: #13557 PR-URL: #13560 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 0df6c0b commit 2ea529b

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use strict';
2+
3+
// Regression test for https://github.com/nodejs/node/issues/13557
4+
// Tests that multiple subsequent readline instances can re-use an input stream.
5+
6+
constcommon=require('../common');
7+
constassert=require('assert');
8+
constreadline=require('readline');
9+
const{ PassThrough }=require('stream');
10+
11+
constinput=newPassThrough();
12+
constoutput=newPassThrough();
13+
14+
constrl1=readline.createInterface({
15+
input,
16+
output,
17+
terminal: true
18+
});
19+
20+
rl1.on('line',common.mustCall(rl1OnLine));
21+
22+
// Write a line plus the first byte of a UTF-8 multibyte character to make sure
23+
// that it doesn’t get lost when closing the readline instance.
24+
input.write(Buffer.concat([
25+
Buffer.from('foo\n'),
26+
Buffer.from([0xe2])// Exactly one third of a ☃ snowman.
27+
]));
28+
29+
functionrl1OnLine(line){
30+
assert.strictEqual(line,'foo');
31+
rl1.close();
32+
constrl2=readline.createInterface({
33+
input,
34+
output,
35+
terminal: true
36+
});
37+
38+
rl2.on('line',common.mustCall((line)=>{
39+
assert.strictEqual(line,'☃bar');
40+
rl2.close();
41+
}));
42+
input.write(Buffer.from([0x98,0x83]));// The rest of the ☃ snowman.
43+
input.write('bar\n');
44+
}

0 commit comments

Comments
 (0)