4 * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
8 (function (module, io, should) {
10 var parser = io.parser;
14 'decoding error packet': function () {
15 parser.decodePacket('7:::').should().eql({
23 'decoding error packet with reason': function () {
24 parser.decodePacket('7:::0').should().eql({
26 , reason: 'transport not supported'
32 'decoding error packet with reason and advice': function () {
33 parser.decodePacket('7:::2+0').should().eql({
35 , reason: 'unauthorized'
41 'decoding error packet with endpoint': function () {
42 parser.decodePacket('7::/woot').should().eql({
50 'decoding ack packet': function () {
51 parser.decodePacket('6:::140').should().eql({
59 'decoding ack packet with args': function () {
60 parser.decodePacket('6:::12+["woot","wa"]').should().eql({
64 , args: ['woot', 'wa']
68 'decoding ack packet with bad json': function () {
72 parser.decodePacket('6:::1+{"++]').should().eql({
82 thrown.should().be_false;
85 'decoding json packet': function () {
86 parser.decodePacket('4:::"2"').should().eql({
93 'decoding json packet with message id and ack data': function () {
94 parser.decodePacket('4:1+::{"a":"b"}').should().eql({
103 'decoding an event packet': function () {
104 parser.decodePacket('5:::{"name":"woot"}').should().eql({
112 'decoding an event packet with message id and ack': function () {
113 parser.decodePacket('5:1+::{"name":"tobi"}').should().eql({
123 'decoding an event packet with data': function () {
124 parser.decodePacket('5:::{"name":"edwald","args":[{"a": "b"},2,"3"]}')
129 , args: [{a: 'b'}, 2, '3']
133 'decoding a message packet': function () {
134 parser.decodePacket('3:::woot').should().eql({
141 'decoding a message packet with id and endpoint': function () {
142 parser.decodePacket('3:5:/tobi').should().eql({
151 'decoding a heartbeat packet': function () {
152 parser.decodePacket('2:::').should().eql({
158 'decoding a connection packet': function () {
159 parser.decodePacket('1::/tobi').should().eql({
166 'decoding a connection packet with query string': function () {
167 parser.decodePacket('1::/test:?test=1').should().eql({
174 'decoding a disconnection packet': function () {
175 parser.decodePacket('0::/woot').should().eql({
181 'encoding error packet': function () {
182 parser.encodePacket({
187 }).should().eql('7::');
190 'encoding error packet with reason': function () {
191 parser.encodePacket({
193 , reason: 'transport not supported'
196 }).should().eql('7:::0');
199 'encoding error packet with reason and advice': function () {
200 parser.encodePacket({
202 , reason: 'unauthorized'
203 , advice: 'reconnect'
205 }).should().eql('7:::2+0');
208 'encoding error packet with endpoint': function () {
209 parser.encodePacket({
214 }).should().eql('7::/woot');
217 'encoding ack packet': function () {
218 parser.encodePacket({
223 }).should().eql('6:::140');
226 'encoding ack packet with args': function () {
227 parser.encodePacket({
231 , args: ['woot', 'wa']
232 }).should().eql('6:::12+["woot","wa"]');
235 'encoding json packet': function () {
236 parser.encodePacket({
240 }).should().eql('4:::"2"');
243 'encoding json packet with message id and ack data': function () {
244 parser.encodePacket({
250 }).should().eql('4:1+::{"a":"b"}');
253 'encoding an event packet': function () {
254 parser.encodePacket({
259 }).should().eql('5:::{"name":"woot"}');
262 'encoding an event packet with message id and ack': function () {
263 parser.encodePacket({
270 }).should().eql('5:1+::{"name":"tobi"}');
273 'encoding an event packet with data': function () {
274 parser.encodePacket({
278 , args: [{a: 'b'}, 2, '3']
279 }).should().eql('5:::{"name":"edwald","args":[{"a":"b"},2,"3"]}');
282 'encoding a message packet': function () {
283 parser.encodePacket({
287 }).should().eql('3:::woot');
290 'encoding a message packet with id and endpoint': function () {
291 parser.encodePacket({
297 }).should().eql('3:5:/tobi');
300 'encoding a heartbeat packet': function () {
301 parser.encodePacket({
304 }).should().eql('2::');
307 'encoding a connection packet': function () {
308 parser.encodePacket({
312 }).should().eql('1::/tobi');
315 'encoding a connection packet with query string': function () {
316 parser.encodePacket({
320 }).should().eql('1::/test:?test=1');
323 'encoding a disconnection packet': function () {
324 parser.encodePacket({
327 }).should().eql('0::/woot');
330 'test decoding a payload': function () {
331 parser.decodePayload('\ufffd5\ufffd3:::5\ufffd7\ufffd3:::53d'
332 + '\ufffd3\ufffd0::').should().eql([
333 { type: 'message', data: '5', endpoint: '' }
334 , { type: 'message', data: '53d', endpoint: '' }
335 , { type: 'disconnect', endpoint: '' }
339 'test encoding a payload': function () {
340 parser.encodePayload([
341 parser.encodePacket({ type: 'message', data: '5', endpoint: '' })
342 , parser.encodePacket({ type: 'message', data: '53d', endpoint: '' })
343 ]).should().eql('\ufffd5\ufffd3:::5\ufffd7\ufffd3:::53d')
346 'test decoding newline': function () {
347 parser.decodePacket('3:::\n').should().eql({
357 'undefined' == typeof module ? module = {} : module
358 , 'undefined' == typeof io ? require('socket.io-client') : io
359 , 'undefined' == typeof should ? require('should') : should