You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test.js 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. 'use strict';
  2. var encoding = require('../lib/encoding');
  3. exports['General tests'] = {
  4. 'From UTF-8 to Latin_1': function (test) {
  5. var input = 'ÕÄÖÜ',
  6. expected = Buffer.from([0xd5, 0xc4, 0xd6, 0xdc]);
  7. test.deepEqual(encoding.convert(input, 'latin1'), expected);
  8. test.done();
  9. },
  10. 'From Latin_1 to UTF-8': function (test) {
  11. var input = Buffer.from([0xd5, 0xc4, 0xd6, 0xdc]),
  12. expected = 'ÕÄÖÜ';
  13. test.deepEqual(encoding.convert(input, 'utf-8', 'latin1').toString(), expected);
  14. test.done();
  15. },
  16. 'From UTF-8 to UTF-8': function (test) {
  17. var input = 'ÕÄÖÜ',
  18. expected = Buffer.from('ÕÄÖÜ');
  19. test.deepEqual(encoding.convert(input, 'utf-8', 'utf-8'), expected);
  20. test.done();
  21. },
  22. 'From Latin_13 to Latin_15': function (test) {
  23. var input = Buffer.from([0xd5, 0xc4, 0xd6, 0xdc, 0xd0]),
  24. expected = Buffer.from([0xd5, 0xc4, 0xd6, 0xdc, 0xa6]);
  25. test.deepEqual(encoding.convert(input, 'latin_15', 'latin13'), expected);
  26. test.done();
  27. }
  28. /*
  29. // ISO-2022-JP is not supported by iconv-lite
  30. "From ISO-2022-JP to UTF-8 with Iconv": function (test) {
  31. var input = Buffer.from(
  32. "GyRCM1g5OzU7PVEwdzgmPSQ4IUYkMnFKczlwGyhC",
  33. "base64"
  34. ),
  35. expected = Buffer.from(
  36. "5a2m5qCh5oqA6KGT5ZOh56CU5L+u5qSc6KiO5Lya5aCx5ZGK",
  37. "base64"
  38. );
  39. test.deepEqual(encoding.convert(input, "utf-8", "ISO-2022-JP"), expected);
  40. test.done();
  41. },
  42. */
  43. };