PageRenderTime 223ms CodeModel.GetById 121ms app.highlight 4ms RepoModel.GetById 97ms app.codeStats 0ms

/js/lib/Socket.IO-node/tests/utils.js

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
JavaScript | 38 lines | 33 code | 5 blank | 0 comment | 0 complexity | 88f75719a1bade575b3266e7a896ed14 MD5 | raw file
 1var assert = require('assert')
 2    encode = require('socket.io/utils').encode,
 3    decode = require('socket.io/utils').decode;
 4
 5module.exports = {
 6  'test decoding': function(){
 7    var decoded = decode('~m~5~m~abcde' + '~m~9~m~123456789');
 8    assert.equal(decoded.length, 2);
 9    assert.equal(decoded[0], 'abcde');
10    assert.equal(decoded[1], '123456789');
11  },
12  
13  'test decoding of invalid data length recovery': function(){
14    var decoded = decode('~m~2~m~hello there' + '~m~5~m~again');
15    assert.equal(decoded.length, 2);
16    assert.equal(decoded[0], 'he');
17    assert.equal(decoded[1], 'again');
18
19    var decoded = decode('~m~5~m~hello there' + '~m~5~m~again');
20    assert.equal(decoded.length, 2);
21    assert.equal(decoded[0], 'hello');
22    assert.equal(decoded[1], 'again');
23  },
24  
25  'test decoding of bad framed messages': function(){
26    var decoded = decode('~m~5~m~abcde' + '~m\uffsdaasdfd9~m~1aaa23456789');
27    assert.equal(decoded.length, 1);
28    assert.equal(decoded[0], 'abcde');
29    assert.equal(decoded[1], undefined);
30  },
31  
32  'test encoding': function(){
33    assert.equal(encode(['abcde', '123456789']), '~m~5~m~abcde' + '~m~9~m~123456789');
34    assert.equal(encode('asdasdsad'), '~m~9~m~asdasdsad');
35    assert.equal(encode(''), '~m~0~m~');
36    assert.equal(encode(null), '~m~0~m~');
37  }
38};