hex.js 916 B

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict';
  2. var test = require('tape');
  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. } else {
  10. var b = '&#x' + i.toString(16) + ';';
  11. t.equal(ent.decode(b), a);
  12. t.equal(ent.encode(a), '&#' + i + ';');
  13. }
  14. }
  15. for (var i = 127; i < 2000; i++) {
  16. var a = String.fromCharCode(i);
  17. var b = '&#x' + i.toString(16) + ';';
  18. var c = '&#X' + i.toString(16) + ';';
  19. t.equal(ent.decode(b), a);
  20. t.equal(ent.decode(c), a);
  21. var encoded = ent.encode(a);
  22. var encoded2 = ent.encode(a + a);
  23. if (!encoded.match(/^&\w+;/)) {
  24. t.equal(encoded, '&#' + i + ';');
  25. t.equal(encoded2, '&#' + i + ';&#' + i + ';');
  26. }
  27. }
  28. t.end();
  29. });