@ -1,3 +1,4 @@
'use strict' ;
// Can't test this when 'make test' doesn't assign a tty to the stdout.
// Can't test this when 'make test' doesn't assign a tty to the stdout.
// Yet another use-case for require('tty').spawn ?
// Yet another use-case for require('tty').spawn ?
var common = require ( '../common' ) ;
var common = require ( '../common' ) ;
@ -36,10 +37,10 @@ var readlineFakeStream = function() {
}
}
} ) ;
} ) ;
var _ stdoutWrite = process . stdout . write ;
var _ stdoutWrite = process . stdout . write ;
process . stdout . write = function ( data ) {
process . stdout . write = function ( data ) {
data . split ( '' ) . forEach ( rl . written_bytes . push . bind ( rl . written_bytes ) ) ;
data . split ( '' ) . forEach ( rl . written_bytes . push . bind ( rl . written_bytes ) ) ;
_ stdoutWrite . apply ( this , arguments ) ;
_ stdoutWrite . apply ( this , arguments ) ;
}
} ;
rl . written_bytes = written_bytes ;
rl . written_bytes = written_bytes ;
return rl ;
return rl ;
} ;
} ;
@ -49,7 +50,7 @@ var written_bytes_length, refreshed;
rl . write ( 'foo' ) ;
rl . write ( 'foo' ) ;
assert . equal ( 3 , rl . cursor ) ;
assert . equal ( 3 , rl . cursor ) ;
[ key . xterm , key . rxvt , key . gnome , key . putty ] . forEach ( function ( key ) {
[ key . xterm , key . rxvt , key . gnome , key . putty ] . forEach ( function ( key ) {
rl . write . apply ( rl , key . home ) ;
rl . write . apply ( rl , key . home ) ;
assert . equal ( 0 , rl . cursor ) ;
assert . equal ( 0 , rl . cursor ) ;
rl . write . apply ( rl , key . end ) ;
rl . write . apply ( rl , key . end ) ;
@ -72,7 +73,7 @@ rl.write.apply(rl, key.xterm.home);
{ cursor : 7 , key : key . xterm . metab } ,
{ cursor : 7 , key : key . xterm . metab } ,
{ cursor : 4 , key : key . xterm . metab } ,
{ cursor : 4 , key : key . xterm . metab } ,
{ cursor : 0 , key : key . xterm . metab } ,
{ cursor : 0 , key : key . xterm . metab } ,
] . forEach ( function ( action ) {
] . forEach ( function ( action ) {
written_bytes_length = rl . written_bytes . length ;
written_bytes_length = rl . written_bytes . length ;
rl . write . apply ( rl , action . key ) ;
rl . write . apply ( rl , action . key ) ;
assert . equal ( action . cursor , rl . cursor ) ;
assert . equal ( action . cursor , rl . cursor ) ;
@ -83,7 +84,14 @@ rl.write.apply(rl, key.xterm.home);
rl = readlineFakeStream ( ) ;
rl = readlineFakeStream ( ) ;
rl . write ( 'foo bar.hop/zoo' ) ;
rl . write ( 'foo bar.hop/zoo' ) ;
rl . write . apply ( rl , key . xterm . home ) ;
rl . write . apply ( rl , key . xterm . home ) ;
[ 'bar.hop/zoo' , '.hop/zoo' , 'hop/zoo' , '/zoo' , 'zoo' , '' ] . forEach ( function ( expectedLine ) {
[
'bar.hop/zoo' ,
'.hop/zoo' ,
'hop/zoo' ,
'/zoo' ,
'zoo' ,
''
] . forEach ( function ( expectedLine ) {
rl . write . apply ( rl , key . xterm . metad ) ;
rl . write . apply ( rl , key . xterm . metad ) ;
assert . equal ( 0 , rl . cursor ) ;
assert . equal ( 0 , rl . cursor ) ;
assert . equal ( expectedLine , rl . line ) ;
assert . equal ( expectedLine , rl . line ) ;