Browse Source

Buffer partial reads before doing expect match.

v0.7.4-release
Matt Ranney 15 years ago
committed by Ryan Dahl
parent
commit
afe3c1cdea
  1. 28
      test/simple/test-repl.js

28
test/simple/test-repl.js

@ -40,6 +40,8 @@ function tcp_test() {
});
server_tcp.addListener('listening', function () {
var read_buffer = "";
client_tcp = net.createConnection(PORT);
client_tcp.addListener('connect', function () {
@ -54,9 +56,11 @@ function tcp_test() {
});
client_tcp.addListener('data', function (data) {
var data_str = data.asciiSlice(0, data.length);
sys.puts("TCP data: " + data_str + ", compare to " + client_tcp.expect);
assert.strictEqual(client_tcp.expect, data_str);
read_buffer += data.asciiSlice(0, data.length);
sys.puts("TCP data: " + read_buffer + ", expecting " + client_tcp.expect);
if (read_buffer.indexOf(prompt_tcp) !== -1) {
assert.strictEqual(client_tcp.expect, read_buffer);
read_buffer = "";
if (client_tcp.list && client_tcp.list.length > 0) {
send_expect(client_tcp.list);
}
@ -66,6 +70,10 @@ function tcp_test() {
client_unix.end();
clearTimeout(timer);
}
}
else {
sys.puts("didn't see prompt yet, buffering");
}
});
client_tcp.addListener("error", function (e) {
@ -93,6 +101,8 @@ function unix_test() {
});
server_unix.addListener('listening', function () {
var read_buffer = "";
client_unix = net.createConnection(unix_socket_path);
client_unix.addListener('connect', function () {
@ -108,9 +118,11 @@ function unix_test() {
});
client_unix.addListener('data', function (data) {
var data_str = data.asciiSlice(0, data.length);
sys.puts("Unix data: " + data_str + ", compare to " + client_unix.expect);
assert.strictEqual(client_unix.expect, data_str);
read_buffer += data.asciiSlice(0, data.length);
sys.puts("Unix data: " + read_buffer + ", expecting " + client_unix.expect);
if (read_buffer.indexOf(prompt_unix) !== -1) {
assert.strictEqual(client_unix.expect, read_buffer);
read_buffer = "";
if (client_unix.list && client_unix.list.length > 0) {
send_expect(client_unix.list);
}
@ -118,6 +130,10 @@ function unix_test() {
sys.puts("End of Unix test, running TCP test.");
tcp_test();
}
}
else {
sys.puts("didn't see prompt yet, bufering.");
}
});
client_unix.addListener("error", function (e) {

Loading…
Cancel
Save