@@ -63,14 +63,26 @@ function isWarned(emitter) {
6363}
6464
6565{
66- // Maximum crlfDelay is 2000ms
66+ // set crlfDelay to float 100.5ms
6767 const fi = new FakeInput ( ) ;
6868 const rli = new readline . Interface ( {
6969 input : fi ,
7070 output : fi ,
71- crlfDelay : 1 << 30
71+ crlfDelay : 100.5
7272 } ) ;
73- assert . strictEqual ( rli . crlfDelay , 2000 ) ;
73+ assert . strictEqual ( rli . crlfDelay , 100.5 ) ;
74+ rli . close ( ) ;
75+ }
76+
77+ {
78+ // set crlfDelay to 5000ms
79+ const fi = new FakeInput ( ) ;
80+ const rli = new readline . Interface ( {
81+ input : fi ,
82+ output : fi ,
83+ crlfDelay : 5000
84+ } ) ;
85+ assert . strictEqual ( rli . crlfDelay , 5000 ) ;
7486 rli . close ( ) ;
7587}
7688
@@ -248,7 +260,7 @@ function isWarned(emitter) {
248260 rli . close ( ) ;
249261
250262 // Emit two line events when the delay
251- // between \r and \n exceeds crlfDelay
263+ // between \r and \n exceeds crlfDelay
252264 {
253265 const fi = new FakeInput ( ) ;
254266 const delay = 200 ;
@@ -270,8 +282,55 @@ function isWarned(emitter) {
270282 } ) , delay * 2 ) ;
271283 }
272284
285+ // Emit one line events when the delay between \r and \n is
286+ // over the default crlfDelay but within the setting value
287+ {
288+ const fi = new FakeInput ( ) ;
289+ const delay = 200 ;
290+ const crlfDelay = 500 ;
291+ const rli = new readline . Interface ( {
292+ input : fi ,
293+ output : fi ,
294+ terminal : terminal ,
295+ crlfDelay
296+ } ) ;
297+ let callCount = 0 ;
298+ rli . on ( 'line' , function ( line ) {
299+ callCount ++ ;
300+ } ) ;
301+ fi . emit ( 'data' , '\r' ) ;
302+ setTimeout ( common . mustCall ( ( ) => {
303+ fi . emit ( 'data' , '\n' ) ;
304+ assert . strictEqual ( callCount , 1 ) ;
305+ rli . close ( ) ;
306+ } ) , delay ) ;
307+ }
308+
309+ // set crlfDelay to `Infinity` is allowed
310+ {
311+ const fi = new FakeInput ( ) ;
312+ const delay = 200 ;
313+ const crlfDelay = Infinity ;
314+ const rli = new readline . Interface ( {
315+ input : fi ,
316+ output : fi ,
317+ terminal : terminal ,
318+ crlfDelay
319+ } ) ;
320+ let callCount = 0 ;
321+ rli . on ( 'line' , function ( line ) {
322+ callCount ++ ;
323+ } ) ;
324+ fi . emit ( 'data' , '\r' ) ;
325+ setTimeout ( common . mustCall ( ( ) => {
326+ fi . emit ( 'data' , '\n' ) ;
327+ assert . strictEqual ( callCount , 1 ) ;
328+ rli . close ( ) ;
329+ } ) , delay ) ;
330+ }
331+
273332 // \t when there is no completer function should behave like an ordinary
274- // character
333+ // character
275334 fi = new FakeInput ( ) ;
276335 rli = new readline . Interface ( { input : fi , output : fi , terminal : true } ) ;
277336 called = false ;
@@ -517,7 +576,7 @@ function isWarned(emitter) {
517576 assert . strictEqual ( isWarned ( process . stdout . _events ) , false ) ;
518577 }
519578
520- //can create a new readline Interface with a null output arugument
579+ // can create a new readline Interface with a null output arugument
521580 fi = new FakeInput ( ) ;
522581 rli = new readline . Interface ( { input : fi , output : null , terminal : terminal } ) ;
523582
0 commit comments