Browse Source

style

v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
08d8116f6b
  1. 103
      test/simple/test-repl.js

103
test/simple/test-repl.js

@ -41,54 +41,56 @@ function clean_up() {
} }
function error_test() { function error_test() {
// The other stuff is done so reuse unix socket // The other stuff is done so reuse unix socket
var read_buffer = ""; var read_buffer = "";
client_unix.removeAllListeners('data'); client_unix.removeAllListeners('data');
client_unix.addListener('data', function (data) {
read_buffer += data.toString('ascii', 0, data.length);
common.error("Unix data: " + JSON.stringify(read_buffer) + ", expecting " +
(client_unix.expect.exec ? client_unix.expect :
JSON.stringify(client_unix.expect)));
if (read_buffer.indexOf(prompt_unix) !== -1) {
assert.ok(read_buffer.match(client_unix.expect));
common.error("match");
read_buffer = "";
if (client_unix.list && client_unix.list.length > 0) {
send_expect(client_unix.list);
} else {
common.error("End of Error test, running TCP test.");
tcp_test();
}
client_unix.addListener('data', function (data) { } else if (read_buffer === prompt_multiline) {
read_buffer += data.toString('ascii', 0, data.length); // Check that you meant to send a multiline test
common.error("Unix data: " + JSON.stringify(read_buffer) + ", expecting " assert.strictEqual(prompt_multiline, client_unix.expect);
+ (client_unix.expect.exec ? client_unix.expect : JSON.stringify(client_unix.expect))); read_buffer = "";
if (read_buffer.indexOf(prompt_unix) !== -1) { if (client_unix.list && client_unix.list.length > 0) {
assert.ok(read_buffer.match(client_unix.expect)); send_expect(client_unix.list);
common.error("match"); } else {
read_buffer = ""; common.error("End of Error test, running TCP test.\n");
if (client_unix.list && client_unix.list.length > 0) { tcp_test();
send_expect(client_unix.list); }
} else {
common.error("End of Error test, running TCP test.");
tcp_test();
}
}
else if(read_buffer === prompt_multiline) {
// Check that you meant to send a multiline test
assert.strictEqual(prompt_multiline, client_unix.expect);
read_buffer = "";
if (client_unix.list && client_unix.list.length > 0) {
send_expect(client_unix.list);
} else {
common.error("End of Error test, running TCP test.\n");
tcp_test();
}
}
else {
common.error("didn't see prompt yet, buffering.");
}
});
send_expect([ } else {
// Uncaught error throws and prints out common.error("didn't see prompt yet, buffering.");
{ client: client_unix, send: "throw new Error('test error');", expect: /^Error: test error/ }, }
// Common syntax error is treated as multiline command });
{ client: client_unix, send: "function test_func() {", expect: prompt_multiline },
// You can recover with the .break command send_expect([
{ client: client_unix, send: ".break", expect: prompt_unix }, // Uncaught error throws and prints out
// Can parse valid JSON { client: client_unix, send: "throw new Error('test error');", expect: /^Error: test error/ },
{ client: client_unix, send: "JSON.parse('{\"valid\": \"json\"}');", expect: "{ valid: 'json' }"}, // Common syntax error is treated as multiline command
// invalid input to JSON.parse error is special case of syntax error, should throw { client: client_unix, send: "function test_func() {", expect: prompt_multiline },
{ client: client_unix, send: "JSON.parse('{invalid: \\'json\\'}');", // You can recover with the .break command
expect: /^SyntaxError: Unexpected token ILLEGAL/ } { client: client_unix, send: ".break", expect: prompt_unix },
]); // Can parse valid JSON
{ client: client_unix, send: "JSON.parse('{\"valid\": \"json\"}');", expect: "{ valid: 'json' }"},
// invalid input to JSON.parse error is special case of syntax error, should throw
{ client: client_unix, send: "JSON.parse('{invalid: \\'json\\'}');",
expect: /^SyntaxError: Unexpected token ILLEGAL/ }
]);
} }
function tcp_test() { function tcp_test() {
@ -131,13 +133,11 @@ function tcp_test() {
read_buffer = ""; read_buffer = "";
if (client_tcp.list && client_tcp.list.length > 0) { if (client_tcp.list && client_tcp.list.length > 0) {
send_expect(client_tcp.list); send_expect(client_tcp.list);
} } else {
else {
common.error("End of TCP test.\n"); common.error("End of TCP test.\n");
clean_up(); clean_up();
} }
} } else {
else {
common.error("didn't see prompt yet, buffering"); common.error("didn't see prompt yet, buffering");
} }
}); });
@ -195,8 +195,7 @@ function unix_test() {
common.error("End of Unix test, running Error test.\n"); common.error("End of Unix test, running Error test.\n");
process.nextTick(error_test); process.nextTick(error_test);
} }
} } else {
else {
common.error("didn't see prompt yet, buffering."); common.error("didn't see prompt yet, buffering.");
} }
}); });

Loading…
Cancel
Save