hex.js 965 B

1234567891011121314151617181920212223242526272829303132333435
  1. var test = require('tape');
  2. var punycode = require('punycode');
  3. var ent = require('../');
  4. test('hex', function (t) {
  5. for (var i = 0; i < 32; i++) {
  6. var a = String.fromCharCode(i);
  7. if (a.match(/\s/)) {
  8. t.equal(ent.decode(a), a);
  9. }
  10. else {
  11. var b = '&#x' + i.toString(16) + ';';
  12. t.equal(ent.decode(b), a);
  13. t.equal(ent.encode(a), '&#' + i + ';');
  14. }
  15. }
  16. for (var i = 127; i < 2000; i++) {
  17. var a = String.fromCharCode(i);
  18. var b = '&#x' + i.toString(16) + ';';
  19. var c = '&#X' + i.toString(16) + ';';
  20. t.equal(ent.decode(b), a);
  21. t.equal(ent.decode(c), a);
  22. var encoded = ent.encode(a);
  23. var encoded2 = ent.encode(a + a);
  24. if (!encoded.match(/^&\w+;/)) {
  25. t.equal(encoded, '&#' + i + ';');
  26. t.equal(encoded2, '&#' + i + ';&#' + i + ';');
  27. }
  28. }
  29. t.end();
  30. });