@ -32,14 +32,17 @@ function FakeInput() {
inherits ( FakeInput , EventEmitter ) ;
FakeInput . prototype . resume = function ( ) { } ;
FakeInput . prototype . pause = function ( ) { } ;
FakeInput . prototype . write = function ( ) { } ;
FakeInput . prototype . end = function ( ) { } ;
[ true , false ] . forEach ( function ( terminal ) {
var fi ;
var rli ;
var called ;
// sending a full line
fi = new FakeInput ( ) ;
rli = new readline . Interface ( fi , { } ) ;
rli = new readline . Interface ( { input : fi , output : fi , terminal : terminal } ) ;
called = false ;
rli . on ( 'line' , function ( line ) {
called = true ;
@ -50,7 +53,7 @@ assert.ok(called);
// sending a blank line
fi = new FakeInput ( ) ;
rli = new readline . Interface ( fi , { } ) ;
rli = new readline . Interface ( { input : fi , output : fi , terminal : terminal } ) ;
called = false ;
rli . on ( 'line' , function ( line ) {
called = true ;
@ -72,7 +75,7 @@ rli.close();
// sending a single character with no newline and then a newline
fi = new FakeInput ( ) ;
rli = new readline . Interface ( fi , { } ) ;
rli = new readline . Interface ( { input : fi , output : fi , terminal : terminal } ) ;
called = false ;
rli . on ( 'line' , function ( line ) {
called = true ;
@ -86,8 +89,8 @@ rli.close();
// sending multiple newlines at once
fi = new FakeInput ( ) ;
rli = new readline . Interface ( fi , { } ) ;
var expectedLines = [ 'foo\n ' , 'bar\n ' , 'baz\n ' ] ;
rli = new readline . Interface ( { input : fi , output : fi , terminal : terminal } ) ;
var expectedLines = [ 'foo' , 'bar' , 'baz' ] ;
var callCount = 0 ;
rli . on ( 'line' , function ( line ) {
assert . equal ( line , expectedLines [ callCount ] ) ;
@ -99,9 +102,9 @@ rli.close();
// sending multiple newlines at once that does not end with a new line
fi = new FakeInput ( ) ;
rli = new readline . Interface ( fi , { } ) ;
var expectedLines = [ 'foo\n ' , 'bar\n ' , 'baz\n ' , 'bat' ] ;
var callCount = 0 ;
rli = new readline . Interface ( { input : fi , output : fi , terminal : terminal } ) ;
expectedLines = [ 'foo' , 'bar' , 'baz' , 'bat' ] ;
callCount = 0 ;
rli . on ( 'line' , function ( line ) {
assert . equal ( line , expectedLines [ callCount ] ) ;
callCount ++ ;
@ -113,7 +116,7 @@ rli.close();
// sending a multi-byte utf8 char over multiple writes
var buf = Buffer ( '☮' , 'utf8' ) ;
fi = new FakeInput ( ) ;
rli = new readline . Interface ( fi , { } ) ;
rli = new readline . Interface ( { input : fi , output : fi , terminal : terminal } ) ;
callCount = 0 ;
rli . on ( 'line' , function ( line ) {
callCount ++ ;
@ -128,4 +131,5 @@ assert.equal(callCount, 1);
rli . close ( ) ;
assert . deepEqual ( fi . listeners ( 'end' ) , [ ] ) ;
assert . deepEqual ( fi . listeners ( 'data' ) , [ ] ) ;
assert . deepEqual ( fi . listeners ( terminal ? 'keypress' : 'data' ) , [ ] ) ;
} ) ;