@ -12,8 +12,8 @@ const prompt_unix = 'node via Unix socket> ';
const prompt_tcp = 'node via TCP socket> ' ;
const prompt_multiline = '... ' ;
const prompt_npm = 'npm should be run outside of the ' +
'node repl, in your normal shell.\r\ n' +
'(Press Control-D to exit.)\r\ n' ;
'node repl, in your normal shell.\n' +
'(Press Control-D to exit.)\n' ;
const expect_npm = prompt_npm + prompt_unix ;
var server_tcp , server_unix , client_tcp , client_unix , replServer ;
@ -37,7 +37,7 @@ function send_expect(list) {
cur . client . expect = cur . expect ;
cur . client . list = list ;
if ( cur . send . length > 0 ) {
cur . client . write ( cur . send + '\r\ n' ) ;
cur . client . write ( cur . send + '\n' ) ;
}
}
}
@ -99,7 +99,7 @@ function error_test() {
run_strict_test = false ;
strict_mode_error_test ( ) ;
} else {
console . error ( 'End of Error test, running TCP test.\r\ n' ) ;
console . error ( 'End of Error test, running TCP test.\n' ) ;
tcp_test ( ) ;
}
@ -109,11 +109,6 @@ function error_test() {
} ) ;
send_expect ( [
// Can handle carriage returns
{ client : client_unix , send : '(function(){return "JungMinu";})()' ,
expect : "'JungMinu'\r\n" + prompt_unix } ,
{ client : client_unix , send : 'const JungMinu="\\r\\nMinwooJung";JungMinu' ,
expect : 'MinwooJung' } ,
// Uncaught error throws and prints out
{ client : client_unix , send : 'throw new Error(\'test error\');' ,
expect : /^Error: test error/ } ,
@ -136,12 +131,12 @@ function error_test() {
{ client : client_unix , send : '`io.js ${"1.0"' ,
expect : prompt_multiline } ,
{ client : client_unix , send : '+ ".2"}`' ,
expect : ` 'io.js 1.0.2' \r \ n ${ prompt_unix } ` } ,
expect : ` 'io.js 1.0.2' \n ${ prompt_unix } ` } ,
// Dot prefix in multiline commands aren't treated as commands
{ client : client_unix , send : '("a"' ,
expect : prompt_multiline } ,
{ client : client_unix , send : '.charAt(0))' ,
expect : ` 'a' \r \ n ${ prompt_unix } ` } ,
expect : ` 'a' \n ${ prompt_unix } ` } ,
// Floating point numbers are not interpreted as REPL commands.
{ client : client_unix , send : '.1234' ,
expect : '0.1234' } ,
@ -187,7 +182,7 @@ function error_test() {
{ client : client_unix , send : 'function blah() { return 1; }' ,
expect : prompt_unix } ,
{ client : client_unix , send : 'blah()' ,
expect : '1\r\ n' + prompt_unix } ,
expect : '1\n' + prompt_unix } ,
// Functions should not evaluate twice (#2773)
{ client : client_unix , send : 'var I = [1,2,3,function() {}]; I.pop()' ,
expect : '[Function]' } ,
@ -211,13 +206,13 @@ function error_test() {
{ client : client_unix , send : '2)' ,
expect : prompt_multiline } ,
{ client : client_unix , send : ')' ,
expect : 'undefined\r\ n' + prompt_unix } ,
expect : 'undefined\n' + prompt_unix } ,
// npm prompt error message
{ client : client_unix , send : 'npm install foobar' ,
expect : expect_npm } ,
{ client : client_unix , send : '(function() {\r\ n\r \nreturn 1;\r \n})()' ,
{ client : client_unix , send : '(function() {\n\nreturn 1;\n})()' ,
expect : '1' } ,
{ client : client_unix , send : '{\r\ n\r\ na: 1\r \n}' ,
{ client : client_unix , send : '{\n\na: 1\n}' ,
expect : '{ a: 1 }' } ,
{ client : client_unix , send : 'url.format("http://google.com")' ,
expect : 'http://google.com/' } ,
@ -226,18 +221,18 @@ function error_test() {
// this makes sure that we don't print `undefined` when we actually print
// the error message
{ client : client_unix , send : '.invalid_repl_command' ,
expect : 'Invalid REPL keyword\r\ n' + prompt_unix } ,
expect : 'Invalid REPL keyword\n' + prompt_unix } ,
// this makes sure that we don't crash when we use an inherited property as
// a REPL command
{ client : client_unix , send : '.toString' ,
expect : 'Invalid REPL keyword\r\ n' + prompt_unix } ,
expect : 'Invalid REPL keyword\n' + prompt_unix } ,
// fail when we are not inside a String and a line continuation is used
{ client : client_unix , send : '[] \\' ,
expect : /\bSyntaxError: Unexpected token ILLEGAL/ } ,
// do not fail when a String is created with line continuation
{ client : client_unix , send : '\'the\\\r\ nfourth\\\r \neye\'' ,
{ client : client_unix , send : '\'the\\\nfourth\\\neye\'' ,
expect : prompt_multiline + prompt_multiline +
'\'thefourtheye\'\r\ n' + prompt_unix } ,
'\'thefourtheye\'\n' + prompt_unix } ,
// Don't fail when a partial String is created and line continuation is used
// with whitespace characters at the end of the string. We are to ignore it.
// This test is to make sure that we properly remove the whitespace
@ -245,99 +240,99 @@ function error_test() {
{ client : client_unix , send : ' \t .break \t ' ,
expect : prompt_unix } ,
// multiline strings preserve whitespace characters in them
{ client : client_unix , send : '\'the \\\r\ n fourth\t\t\\\r \n eye \'' ,
{ client : client_unix , send : '\'the \\\n fourth\t\t\\\n eye \'' ,
expect : prompt_multiline + prompt_multiline +
'\'the fourth\\t\\t eye \'\r\ n' + prompt_unix } ,
'\'the fourth\\t\\t eye \'\n' + prompt_unix } ,
// more than one multiline strings also should preserve whitespace chars
{ client : client_unix , send : '\'the \\\r\ n fourth\' + \'\t\t\\\r \n eye \'' ,
{ client : client_unix , send : '\'the \\\n fourth\' + \'\t\t\\\n eye \'' ,
expect : prompt_multiline + prompt_multiline +
'\'the fourth\\t\\t eye \'\r\ n' + prompt_unix } ,
'\'the fourth\\t\\t eye \'\n' + prompt_unix } ,
// using REPL commands within a string literal should still work
{ client : client_unix , send : '\'\\\r\ n.break' ,
{ client : client_unix , send : '\'\\\n.break' ,
expect : prompt_unix } ,
// using REPL command "help" within a string literal should still work
{ client : client_unix , send : '\'thefourth\\\r\ n.help\r \neye\'' ,
{ client : client_unix , send : '\'thefourth\\\n.help\neye\'' ,
expect : /'thefourtheye'/ } ,
// empty lines in the REPL should be allowed
{ client : client_unix , send : '\r\ n\r\r\ n\r \r\n' ,
{ client : client_unix , send : '\n\r\n\r\n' ,
expect : prompt_unix + prompt_unix + prompt_unix } ,
// empty lines in the string literals should not affect the string
{ client : client_unix , send : '\'the\\\r\ n\\\r \nfourtheye\'\r \n' ,
{ client : client_unix , send : '\'the\\\n\\\nfourtheye\'\n' ,
expect : prompt_multiline + prompt_multiline +
'\'thefourtheye\'\r\ n' + prompt_unix } ,
'\'thefourtheye\'\n' + prompt_unix } ,
// Regression test for https://github.com/nodejs/node/issues/597
{ client : client_unix ,
send : '/(.)(.)(.)(.)(.)(.)(.)(.)(.)/.test(\'123456789\')\r\ n' ,
expect : ` true \r \ n ${ prompt_unix } ` } ,
send : '/(.)(.)(.)(.)(.)(.)(.)(.)(.)/.test(\'123456789\')\n' ,
expect : ` true \n ${ prompt_unix } ` } ,
// the following test's result depends on the RegEx's match from the above
{ client : client_unix ,
send : 'RegExp.$1\r\ nRegExp.$2\r\ nRegExp.$3\r\ nRegExp.$4\r \nRegExp.$5\r \n' +
'RegExp.$6\r\ nRegExp.$7\r \nRegExp.$8\r\ nRegExp.$9\r \n' ,
expect : [ '\'1\'\r\ n' , '\'2\'\r\ n' , '\'3\'\r \n' , '\'4\'\r\ n' , '\'5\'\r\ n' , '\'6\'\r \n' ,
'\'7\'\r\ n' , '\'8\'\r\ n' , '\'9\'\r \n' ] . join ( ` ${ prompt_unix } ` ) } ,
send : 'RegExp.$1\nRegExp.$2\nRegExp.$3\nRegExp.$4\nRegExp.$5\n' +
'RegExp.$6\nRegExp.$7\nRegExp.$8\nRegExp.$9\n' ,
expect : [ '\'1\'\n' , '\'2\'\n' , '\'3\'\n' , '\'4\'\n' , '\'5\'\n' , '\'6\'\n' ,
'\'7\'\n' , '\'8\'\n' , '\'9\'\n' ] . join ( ` ${ prompt_unix } ` ) } ,
// regression tests for https://github.com/nodejs/node/issues/2749
{ client : client_unix , send : 'function x() {\r\ nreturn \'\\r\\ n\';\r \n }' ,
{ client : client_unix , send : 'function x() {\nreturn \'\\n\';\n }' ,
expect : prompt_multiline + prompt_multiline +
'undefined\r\ n' + prompt_unix } ,
{ client : client_unix , send : 'function x() {\r\ nreturn \'\\\\\';\r \n }' ,
'undefined\n' + prompt_unix } ,
{ client : client_unix , send : 'function x() {\nreturn \'\\\\\';\n }' ,
expect : prompt_multiline + prompt_multiline +
'undefined\r\ n' + prompt_unix } ,
'undefined\n' + prompt_unix } ,
// regression tests for https://github.com/nodejs/node/issues/3421
{ client : client_unix , send : 'function x() {\r\ n//\'\r \n }' ,
{ client : client_unix , send : 'function x() {\n//\'\n }' ,
expect : prompt_multiline + prompt_multiline +
'undefined\r\ n' + prompt_unix } ,
{ client : client_unix , send : 'function x() {\r\ n//"\r \n }' ,
'undefined\n' + prompt_unix } ,
{ client : client_unix , send : 'function x() {\n//"\n }' ,
expect : prompt_multiline + prompt_multiline +
'undefined\r\ n' + prompt_unix } ,
{ client : client_unix , send : 'function x() {//\'\r\ n }' ,
expect : prompt_multiline + 'undefined\r\ n' + prompt_unix } ,
{ client : client_unix , send : 'function x() {//"\r\ n }' ,
expect : prompt_multiline + 'undefined\r\ n' + prompt_unix } ,
{ client : client_unix , send : 'function x() {\r\ nvar i = "\'";\r \n }' ,
'undefined\n' + prompt_unix } ,
{ client : client_unix , send : 'function x() {//\'\n }' ,
expect : prompt_multiline + 'undefined\n' + prompt_unix } ,
{ client : client_unix , send : 'function x() {//"\n }' ,
expect : prompt_multiline + 'undefined\n' + prompt_unix } ,
{ client : client_unix , send : 'function x() {\nvar i = "\'";\n }' ,
expect : prompt_multiline + prompt_multiline +
'undefined\r\ n' + prompt_unix } ,
'undefined\n' + prompt_unix } ,
{ client : client_unix , send : 'function x(/*optional*/) {}' ,
expect : 'undefined\r\ n' + prompt_unix } ,
expect : 'undefined\n' + prompt_unix } ,
{ client : client_unix , send : 'function x(/* // 5 */) {}' ,
expect : 'undefined\r\ n' + prompt_unix } ,
expect : 'undefined\n' + prompt_unix } ,
{ client : client_unix , send : '// /* 5 */' ,
expect : 'undefined\r\ n' + prompt_unix } ,
expect : 'undefined\n' + prompt_unix } ,
{ client : client_unix , send : '"//"' ,
expect : '\'//\'\r\ n' + prompt_unix } ,
expect : '\'//\'\n' + prompt_unix } ,
{ client : client_unix , send : '"data /*with*/ comment"' ,
expect : '\'data /*with*/ comment\'\r\ n' + prompt_unix } ,
expect : '\'data /*with*/ comment\'\n' + prompt_unix } ,
{ client : client_unix , send : 'function x(/*fn\'s optional params*/) {}' ,
expect : 'undefined\r\ n' + prompt_unix } ,
{ client : client_unix , send : '/* \'\r\ n"\r \n\'"\'\r \n*/' ,
expect : 'undefined\r\ n' + prompt_unix } ,
expect : 'undefined\n' + prompt_unix } ,
{ client : client_unix , send : '/* \'\n"\n\'"\'\n*/' ,
expect : 'undefined\n' + prompt_unix } ,
// REPL should get a normal require() function, not one that allows
// access to internal modules without the --expose_internals flag.
{ client : client_unix , send : 'require("internal/repl")' ,
expect : /^Error: Cannot find module 'internal\/repl'/ } ,
// REPL should handle quotes within regexp literal in multiline mode
{ client : client_unix , send : "function x(s) {\r\ nreturn s.replace(/'/,'');\r \n}" ,
{ client : client_unix , send : "function x(s) {\nreturn s.replace(/'/,'');\n}" ,
expect : prompt_multiline + prompt_multiline +
'undefined\r\ n' + prompt_unix } ,
{ client : client_unix , send : "function x(s) {\r\ nreturn s.replace(/\'/,'');\r \n}" ,
'undefined\n' + prompt_unix } ,
{ client : client_unix , send : "function x(s) {\nreturn s.replace(/\'/,'');\n}" ,
expect : prompt_multiline + prompt_multiline +
'undefined\r\ n' + prompt_unix } ,
{ client : client_unix , send : 'function x(s) {\r\ nreturn s.replace(/"/,"");\r \n}' ,
'undefined\n' + prompt_unix } ,
{ client : client_unix , send : 'function x(s) {\nreturn s.replace(/"/,"");\n}' ,
expect : prompt_multiline + prompt_multiline +
'undefined\r\ n' + prompt_unix } ,
{ client : client_unix , send : 'function x(s) {\r\ nreturn s.replace(/.*/,"");\r \n}' ,
'undefined\n' + prompt_unix } ,
{ client : client_unix , send : 'function x(s) {\nreturn s.replace(/.*/,"");\n}' ,
expect : prompt_multiline + prompt_multiline +
'undefined\r\ n' + prompt_unix } ,
'undefined\n' + prompt_unix } ,
{ client : client_unix , send : '{ var x = 4; }' ,
expect : 'undefined\r\ n' + prompt_unix } ,
expect : 'undefined\n' + prompt_unix } ,
// Illegal token is not recoverable outside string literal, RegExp literal,
// or block comment. https://github.com/nodejs/node/issues/3611
{ client : client_unix , send : 'a = 3.5e' ,
expect : /\bSyntaxError: Unexpected token ILLEGAL/ } ,
// Mitigate https://github.com/nodejs/node/issues/548
{ client : client_unix , send : 'function name(){ return "node"; };name()' ,
expect : "'node'\r\ n" + prompt_unix } ,
expect : "'node'\n" + prompt_unix } ,
{ client : client_unix , send : 'function name(){ return "nodejs"; };name()' ,
expect : "'nodejs'\r\ n" + prompt_unix } ,
expect : "'nodejs'\n" + prompt_unix } ,
// Avoid emitting repl:line-number for SyntaxError
{ client : client_unix , send : 'a = 3.5e' ,
expect : /^(?!repl)/ } ,
@ -371,12 +366,12 @@ function tcp_test() {
{ client : client_tcp , send : '' ,
expect : prompt_tcp } ,
{ client : client_tcp , send : 'invoke_me(333)' ,
expect : ( '\'' + 'invoked 333' + '\'\r\ n' + prompt_tcp ) } ,
expect : ( '\'' + 'invoked 333' + '\'\n' + prompt_tcp ) } ,
{ client : client_tcp , send : 'a += 1' ,
expect : ( '12346' + '\r\ n' + prompt_tcp ) } ,
expect : ( '12346' + '\n' + prompt_tcp ) } ,
{ client : client_tcp ,
send : 'require(' + JSON . stringify ( moduleFilename ) + ').number' ,
expect : ( '42' + '\r\ n' + prompt_tcp ) }
expect : ( '42' + '\n' + prompt_tcp ) }
] ) ;
} ) ;
@ -391,7 +386,7 @@ function tcp_test() {
if ( client_tcp . list && client_tcp . list . length > 0 ) {
send_expect ( client_tcp . list ) ;
} else {
console . error ( 'End of TCP test.\r\ n' ) ;
console . error ( 'End of TCP test.\n' ) ;
clean_up ( ) ;
}
} else {
@ -440,13 +435,13 @@ function unix_test() {
{ client : client_unix , send : '' ,
expect : prompt_unix } ,
{ client : client_unix , send : 'message' ,
expect : ( '\'' + message + '\'\r\ n' + prompt_unix ) } ,
expect : ( '\'' + message + '\'\n' + prompt_unix ) } ,
{ client : client_unix , send : 'invoke_me(987)' ,
expect : ( '\'' + 'invoked 987' + '\'\r\ n' + prompt_unix ) } ,
expect : ( '\'' + 'invoked 987' + '\'\n' + prompt_unix ) } ,
{ client : client_unix , send : 'a = 12345' ,
expect : ( '12345' + '\r\ n' + prompt_unix ) } ,
expect : ( '12345' + '\n' + prompt_unix ) } ,
{ client : client_unix , send : '{a:1}' ,
expect : ( '{ a: 1 }' + '\r\ n' + prompt_unix ) }
expect : ( '{ a: 1 }' + '\n' + prompt_unix ) }
] ) ;
} ) ;
@ -461,7 +456,7 @@ function unix_test() {
if ( client_unix . list && client_unix . list . length > 0 ) {
send_expect ( client_unix . list ) ;
} else {
console . error ( 'End of Unix test, running Error test.\r\ n' ) ;
console . error ( 'End of Unix test, running Error test.\n' ) ;
process . nextTick ( error_test ) ;
}
} else {