wechat wss demo

test.js 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. 'use strict';
  2. var Iconv = require('../lib/iconv-loader');
  3. var encoding = require('../lib/encoding');
  4. exports['General tests'] = {
  5. 'Iconv is available': function (test) {
  6. test.ok(Iconv);
  7. test.done();
  8. },
  9. 'From UTF-8 to Latin_1 with Iconv': function (test) {
  10. var input = 'ÕÄÖÜ',
  11. expected = new Buffer([0xd5, 0xc4, 0xd6, 0xdc]);
  12. test.deepEqual(encoding.convert(input, 'latin1'), expected);
  13. test.done();
  14. },
  15. 'From Latin_1 to UTF-8 with Iconv': function (test) {
  16. var input = new Buffer([0xd5, 0xc4, 0xd6, 0xdc]),
  17. expected = 'ÕÄÖÜ';
  18. test.deepEqual(encoding.convert(input, 'utf-8', 'latin1').toString(), expected);
  19. test.done();
  20. },
  21. 'From UTF-8 to UTF-8 with Iconv': function (test) {
  22. var input = 'ÕÄÖÜ',
  23. expected = new Buffer('ÕÄÖÜ');
  24. test.deepEqual(encoding.convert(input, 'utf-8', 'utf-8'), expected);
  25. test.done();
  26. },
  27. 'From Latin_13 to Latin_15 with Iconv': function (test) {
  28. var input = new Buffer([0xd5, 0xc4, 0xd6, 0xdc, 0xd0]),
  29. expected = new Buffer([0xd5, 0xc4, 0xd6, 0xdc, 0xA6]);
  30. test.deepEqual(encoding.convert(input, 'latin_15', 'latin13'), expected);
  31. test.done();
  32. },
  33. 'From ISO-2022-JP to UTF-8 with Iconv': function (test) {
  34. var input = new Buffer('GyRCM1g5OzU7PVEwdzgmPSQ4IUYkMnFKczlwGyhC', 'base64'),
  35. expected = new Buffer('5a2m5qCh5oqA6KGT5ZOh56CU5L+u5qSc6KiO5Lya5aCx5ZGK', 'base64');
  36. test.deepEqual(encoding.convert(input, 'utf-8', 'ISO-2022-JP'), expected);
  37. test.done();
  38. },
  39. 'From UTF-8 to Latin_1 with iconv-lite': function (test) {
  40. var input = 'ÕÄÖÜ',
  41. expected = new Buffer([0xd5, 0xc4, 0xd6, 0xdc]);
  42. test.deepEqual(encoding.convert(input, 'latin1', false, true), expected);
  43. test.done();
  44. },
  45. 'From Latin_1 to UTF-8 with iconv-lite': function (test) {
  46. var input = new Buffer([0xd5, 0xc4, 0xd6, 0xdc]),
  47. expected = 'ÕÄÖÜ';
  48. test.deepEqual(encoding.convert(input, 'utf-8', 'latin1', true).toString(), expected);
  49. test.done();
  50. },
  51. 'From UTF-8 to UTF-8 with iconv-lite': function (test) {
  52. var input = 'ÕÄÖÜ',
  53. expected = new Buffer('ÕÄÖÜ');
  54. test.deepEqual(encoding.convert(input, 'utf-8', 'utf-8', true), expected);
  55. test.done();
  56. },
  57. 'From Latin_13 to Latin_15 with iconv-lite': function (test) {
  58. var input = new Buffer([0xd5, 0xc4, 0xd6, 0xdc, 0xd0]),
  59. expected = new Buffer([0xd5, 0xc4, 0xd6, 0xdc, 0xA6]);
  60. test.deepEqual(encoding.convert(input, 'latin_15', 'latin13', true), expected);
  61. test.done();
  62. }
  63. };