unesc.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. "use strict";
  2. var _helpers = require("../util/helpers");
  3. (0, _helpers.test)('id selector', '#foo', function (t, tree) {
  4. t.deepEqual(tree.nodes[0].nodes[0].value, 'foo');
  5. });
  6. (0, _helpers.test)('escaped special char', '#w\\+', function (t, tree) {
  7. t.deepEqual(tree.nodes[0].nodes[0].value, 'w+');
  8. });
  9. (0, _helpers.test)('tailing escape', '#foo\\', function (t, tree) {
  10. t.deepEqual(tree.nodes[0].nodes[0].value, 'foo\\');
  11. });
  12. (0, _helpers.test)('double escape', '#wow\\\\k', function (t, tree) {
  13. t.deepEqual(tree.nodes[0].nodes[0].value, 'wow\\k');
  14. });
  15. (0, _helpers.test)('leading numeric', '.\\31 23', function (t, tree) {
  16. t.deepEqual(tree.nodes[0].nodes[0].value, '123');
  17. });
  18. (0, _helpers.test)('emoji', '.\\🐐', function (t, tree) {
  19. t.deepEqual(tree.nodes[0].nodes[0].value, '🐐');
  20. }); // https://www.w3.org/International/questions/qa-escapes#cssescapes
  21. (0, _helpers.test)('hex escape', '.\\E9motion', function (t, tree) {
  22. t.deepEqual(tree.nodes[0].nodes[0].value, 'émotion');
  23. });
  24. (0, _helpers.test)('hex escape with space', '.\\E9 dition', function (t, tree) {
  25. t.deepEqual(tree.nodes[0].nodes[0].value, 'édition');
  26. });
  27. (0, _helpers.test)('hex escape with hex number', '.\\0000E9dition', function (t, tree) {
  28. t.deepEqual(tree.nodes[0].nodes[0].value, 'édition');
  29. });
  30. (0, _helpers.test)('class selector with escaping', '.\\1D306', function (t, tree) {
  31. t.deepEqual(tree.nodes[0].nodes[0].value, '𝌆');
  32. });
  33. (0, _helpers.test)('class selector with escaping with more chars', '.\\1D306k', function (t, tree) {
  34. t.deepEqual(tree.nodes[0].nodes[0].value, '𝌆k');
  35. });
  36. (0, _helpers.test)('class selector with escaping with more chars with whitespace', '.wow\\1D306 k', function (t, tree) {
  37. t.deepEqual(tree.nodes[0].nodes[0].value, 'wow𝌆k');
  38. });
  39. (0, _helpers.test)('handles 0 value hex', '\\0', function (t, tree) {
  40. t.deepEqual(tree.nodes[0].nodes[0].value, String.fromCodePoint(0xFFFD));
  41. });
  42. (0, _helpers.test)('handles lone surrogate value hex', '\\DBFF', function (t, tree) {
  43. t.deepEqual(tree.nodes[0].nodes[0].value, String.fromCodePoint(0xFFFD));
  44. });
  45. (0, _helpers.test)('handles out of bound values', '\\110000', function (t, tree) {
  46. t.deepEqual(tree.nodes[0].nodes[0].value, String.fromCodePoint(0xFFFD));
  47. });