@@ -375,6 +375,37 @@ function isWarned(emitter) {
375
375
} ) ;
376
376
}
377
377
378
+ // constructor throws if historySize is not a positive number
379
+ {
380
+ const fi = new FakeInput ( ) ;
381
+ assert . throws ( function ( ) {
382
+ readline . createInterface ( {
383
+ input : fi , historySize : 'not a number'
384
+ } ) ;
385
+ } , common . expectsError ( {
386
+ type : TypeError ,
387
+ message : 'Argument "historySize" must be a positive number'
388
+ } ) ) ;
389
+
390
+ assert . throws ( function ( ) {
391
+ readline . createInterface ( {
392
+ input : fi , historySize : - 1
393
+ } ) ;
394
+ } , common . expectsError ( {
395
+ type : TypeError ,
396
+ message : 'Argument "historySize" must be a positive number'
397
+ } ) ) ;
398
+
399
+ assert . throws ( function ( ) {
400
+ readline . createInterface ( {
401
+ input : fi , historySize : NaN
402
+ } ) ;
403
+ } , common . expectsError ( {
404
+ type : TypeError ,
405
+ message : 'Argument "historySize" must be a positive number'
406
+ } ) ) ;
407
+ }
408
+
378
409
// duplicate lines are removed from history when
379
410
// `options.removeHistoryDuplicates` is `true`
380
411
{
@@ -404,6 +435,14 @@ function isWarned(emitter) {
404
435
assert . notStrictEqual ( rli . line , expectedLines [ -- callCount ] ) ;
405
436
assert . strictEqual ( rli . line , expectedLines [ -- callCount ] ) ;
406
437
assert . strictEqual ( callCount , 0 ) ;
438
+ fi . emit ( 'keypress' , '.' , { name : 'down' } ) ; // 'baz'
439
+ assert . strictEqual ( rli . line , 'baz' ) ;
440
+ fi . emit ( 'keypress' , '.' , { name : 'n' , ctrl : true } ) ; // 'bar'
441
+ assert . strictEqual ( rli . line , 'bar' ) ;
442
+ fi . emit ( 'keypress' , '.' , { name : 'down' } ) ; // 'bat'
443
+ assert . strictEqual ( rli . line , 'bat' ) ;
444
+ fi . emit ( 'keypress' , '.' , { name : 'down' } ) ; // ''
445
+ assert . strictEqual ( rli . line , '' ) ;
407
446
rli . close ( ) ;
408
447
}
409
448
@@ -499,7 +538,35 @@ function isWarned(emitter) {
499
538
rli . close ( ) ;
500
539
}
501
540
541
+ // calling the question callback
542
+ {
543
+ let called = false ;
544
+ const fi = new FakeInput ( ) ;
545
+ const rli = new readline . Interface (
546
+ { input : fi , output : fi , terminal : terminal }
547
+ ) ;
548
+ rli . question ( 'foo?' , function ( answer ) {
549
+ called = true ;
550
+ assert . strictEqual ( answer , 'bar' ) ;
551
+ } ) ;
552
+ rli . write ( 'bar\n' ) ;
553
+ assert . ok ( called ) ;
554
+ rli . close ( ) ;
555
+ }
556
+
502
557
if ( terminal ) {
558
+ // history is bound
559
+ {
560
+ const fi = new FakeInput ( ) ;
561
+ const rli = new readline . Interface (
562
+ { input : fi , output : fi , terminal, historySize : 2 }
563
+ ) ;
564
+ const lines = [ 'line 1' , 'line 2' , 'line 3' ] ;
565
+ fi . emit ( 'data' , lines . join ( '\n' ) + '\n' ) ;
566
+ assert . strictEqual ( rli . history . length , 2 ) ;
567
+ assert . strictEqual ( rli . history [ 0 ] , 'line 3' ) ;
568
+ assert . strictEqual ( rli . history [ 1 ] , 'line 2' ) ;
569
+ }
503
570
// question
504
571
{
505
572
const fi = new FakeInput ( ) ;
@@ -667,6 +734,22 @@ function isWarned(emitter) {
667
734
rli . close ( ) ;
668
735
} ) ;
669
736
}
737
+
738
+ // multi-line cursor position
739
+ {
740
+ const fi = new FakeInput ( ) ;
741
+ const rli = new readline . Interface ( {
742
+ input : fi ,
743
+ output : fi ,
744
+ prompt : '' ,
745
+ terminal : terminal
746
+ } ) ;
747
+ fi . columns = 10 ;
748
+ fi . emit ( 'data' , 'multi-line text' ) ;
749
+ const cursorPos = rli . _getCursorPos ( ) ;
750
+ assert . strictEqual ( cursorPos . rows , 1 ) ;
751
+ assert . strictEqual ( cursorPos . cols , 5 ) ;
752
+ }
670
753
}
671
754
672
755
// isFullWidthCodePoint() should return false for non-numeric values
0 commit comments