add tests for Parser

This commit is contained in:
Naoyuki Kanezawa
2013-05-01 02:45:48 +09:00
parent 8b7b2125fc
commit 1200b464a1
4 changed files with 226 additions and 7 deletions

View File

@@ -249,7 +249,7 @@ public abstract class Socket extends Emitter {
transport[0].off(Transport.EVENT_ERROR, onerror);
self.emit(EVENT_UPGRADE, transport);
self.setTransport(transport[0]);
Packet packet = new Packet(Packet.UPGRADE, null);
Packet packet = new Packet(Packet.UPGRADE);
transport[0].send(new Packet[]{packet});
transport[0] = null;
self.upgrading = false;

View File

@@ -15,14 +15,12 @@ public class Packet {
public String type;
public String data;
public Packet(String type) {
this(type, null);
}
public Packet(String type, String data) {
this.type = type;
this.data = data;
}
@Override
public String toString() {
return String.format("{\"type\": \"%s\", \"data\": \"%s\"}", this.type, this.data);
}
}

View File

@@ -114,6 +114,7 @@ public class Parser {
}
public static interface DecodePayloadCallback {
public boolean call(Packet packet, int index, int total);
}
}