File tree 1 file changed +44
-0
lines changed
1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change
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
+ const common = require ( '../common' ) ;
7
+ const assert = require ( 'assert' ) ;
8
+ const readline = require ( 'readline' ) ;
9
+ const { PassThrough } = require ( 'stream' ) ;
10
+
11
+ const input = new PassThrough ( ) ;
12
+ const output = new PassThrough ( ) ;
13
+
14
+ const rl1 = 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
+ function rl1OnLine ( line ) {
30
+ assert . strictEqual ( line , 'foo' ) ;
31
+ rl1 . close ( ) ;
32
+ const rl2 = 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
+ }
You can’t perform that action at this time.
0 commit comments