PageRenderTime 25ms CodeModel.GetById 22ms RepoModel.GetById 1ms 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
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. var assert = require('assert')
  2. encode = require('socket.io/utils').encode,
  3. decode = require('socket.io/utils').decode;
  4. module.exports = {
  5. 'test decoding': function(){
  6. var decoded = decode('~m~5~m~abcde' + '~m~9~m~123456789');
  7. assert.equal(decoded.length, 2);
  8. assert.equal(decoded[0], 'abcde');
  9. assert.equal(decoded[1], '123456789');
  10. },
  11. 'test decoding of invalid data length recovery': function(){
  12. var decoded = decode('~m~2~m~hello there' + '~m~5~m~again');
  13. assert.equal(decoded.length, 2);
  14. assert.equal(decoded[0], 'he');
  15. assert.equal(decoded[1], 'again');
  16. var decoded = decode('~m~5~m~hello there' + '~m~5~m~again');
  17. assert.equal(decoded.length, 2);
  18. assert.equal(decoded[0], 'hello');
  19. assert.equal(decoded[1], 'again');
  20. },
  21. 'test decoding of bad framed messages': function(){
  22. var decoded = decode('~m~5~m~abcde' + '~m\uffsdaasdfd9~m~1aaa23456789');
  23. assert.equal(decoded.length, 1);
  24. assert.equal(decoded[0], 'abcde');
  25. assert.equal(decoded[1], undefined);
  26. },
  27. 'test encoding': function(){
  28. assert.equal(encode(['abcde', '123456789']), '~m~5~m~abcde' + '~m~9~m~123456789');
  29. assert.equal(encode('asdasdsad'), '~m~9~m~asdasdsad');
  30. assert.equal(encode(''), '~m~0~m~');
  31. assert.equal(encode(null), '~m~0~m~');
  32. }
  33. };