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.

45 lines
958 B

  1. var utf8 = require('./utf8.js');
  2. var stringEscape = require('string-escape');
  3. utf8.encode('\xA9');
  4. // console.log(
  5. // utf8.encode('\uD800\uDC01'),
  6. // '\xF0\x90\x80\x81',
  7. // utf8.encode('\uD800\uDC01') == '\xF0\x90\x80\x81'
  8. // );
  9. var obj = {
  10. 'description': 'Low surrogate followed by another low surrogate',
  11. // 'decoded': '\uDC00\uDC00',
  12. // 'encoded': '\xED\xB0\x80\xED\xB0\x80'
  13. 'decoded': '\xA9',
  14. 'encoded': '\xED\xB0\x80'
  15. };
  16. // Encoding
  17. actual = utf8.encode(obj.decoded);
  18. expected = obj.encoded;
  19. if (actual != expected) {
  20. console.log(
  21. 'fail\n',
  22. 'actual ', stringEscape(actual), '\n',
  23. 'expected', stringEscape(expected)
  24. );
  25. } else {
  26. console.log('encoding successsssss')
  27. }
  28. // // Decoding
  29. // actual = utf8.decode(obj.encoded);
  30. // expected = obj.decoded;
  31. // if (actual != expected) {
  32. // console.log(
  33. // 'fail\n',
  34. // 'actual ', actual, '\n',
  35. // 'expected', expected
  36. // );
  37. // } else {
  38. // console.log('decoding successsssss')
  39. // }