lossy.js 7.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.testLossy = exports.parse = void 0;
  4. var _ava = _interopRequireDefault(require("ava"));
  5. var _index = _interopRequireDefault(require("../index"));
  6. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  7. var parse = function parse(input, options, transform) {
  8. return (0, _index["default"])(transform).processSync(input, options);
  9. };
  10. exports.parse = parse;
  11. var testLossy = function testLossy(t, input, expected) {
  12. var result = parse(input, {
  13. lossless: false
  14. });
  15. t.deepEqual(result, expected);
  16. };
  17. exports.testLossy = testLossy;
  18. (0, _ava["default"])('combinator, descendant - single', testLossy, '.one .two', '.one .two');
  19. (0, _ava["default"])('combinator, descendant - multiple', testLossy, '.one .two', '.one .two');
  20. (0, _ava["default"])('combinator, child - space before', testLossy, '.one >.two', '.one>.two');
  21. (0, _ava["default"])('combinator, child - space after', testLossy, '.one> .two', '.one>.two');
  22. (0, _ava["default"])('combinator, sibling - space before', testLossy, '.one ~.two', '.one~.two');
  23. (0, _ava["default"])('combinator, sibling - space after', testLossy, '.one~ .two', '.one~.two');
  24. (0, _ava["default"])('combinator, adj sibling - space before', testLossy, '.one +.two', '.one+.two');
  25. (0, _ava["default"])('combinator, adj sibling - space after', testLossy, '.one+ .two', '.one+.two');
  26. (0, _ava["default"])('classes, extraneous spaces', testLossy, ' .h1 , .h2 ', '.h1,.h2');
  27. (0, _ava["default"])('ids, extraneous spaces', testLossy, ' #h1 , #h2 ', '#h1,#h2');
  28. (0, _ava["default"])('attribute, spaces in selector', testLossy, 'h1[ href *= "test" ]', 'h1[href*="test"]');
  29. (0, _ava["default"])('attribute, insensitive flag 1', testLossy, '[href="test" i ]', '[href="test"i]');
  30. (0, _ava["default"])('attribute, insensitive flag 2', testLossy, '[href=TEsT i ]', '[href=TEsT i]');
  31. (0, _ava["default"])('attribute, insensitive flag 3', testLossy, '[href=test i ]', '[href=test i]');
  32. (0, _ava["default"])('attribute, extreneous whitespace', testLossy, ' [href] , [class] ', '[href],[class]');
  33. (0, _ava["default"])('namespace, space before', testLossy, ' postcss|button', 'postcss|button');
  34. (0, _ava["default"])('namespace, space after', testLossy, 'postcss|button ', 'postcss|button');
  35. (0, _ava["default"])('namespace - all elements, space before', testLossy, ' postcss|*', 'postcss|*');
  36. (0, _ava["default"])('namespace - all elements, space after', testLossy, 'postcss|* ', 'postcss|*');
  37. (0, _ava["default"])('namespace - all namespaces, space before', testLossy, ' *|button', '*|button');
  38. (0, _ava["default"])('namespace - all namespaces, space after', testLossy, '*|button ', '*|button');
  39. (0, _ava["default"])('namespace - all elements in all namespaces, space before', testLossy, ' *|*', '*|*');
  40. (0, _ava["default"])('namespace - all elements in all namespaces, space after', testLossy, '*|* ', '*|*');
  41. (0, _ava["default"])('namespace - all elements without namespace, space before', testLossy, ' |*', '|*');
  42. (0, _ava["default"])('namespace - all elements without namespace, space after', testLossy, '|* ', '|*');
  43. (0, _ava["default"])('namespace - tag with no namespace, space before', testLossy, ' |button', '|button');
  44. (0, _ava["default"])('namespace - tag with no namespace, space after', testLossy, '|button ', '|button');
  45. (0, _ava["default"])('namespace - inside attribute, space before', testLossy, ' [ postcss|href=test]', '[postcss|href=test]');
  46. (0, _ava["default"])('namespace - inside attribute, space after', testLossy, '[postcss|href= test ] ', '[postcss|href=test]');
  47. (0, _ava["default"])('namespace - inside attribute (2), space before', testLossy, ' [ postcss|href]', '[postcss|href]');
  48. (0, _ava["default"])('namespace - inside attribute (2), space after', testLossy, '[postcss|href ] ', '[postcss|href]');
  49. (0, _ava["default"])('namespace - inside attribute (3), space before', testLossy, ' [ *|href=test]', '[*|href=test]');
  50. (0, _ava["default"])('namespace - inside attribute (3), space after', testLossy, '[*|href= test ] ', '[*|href=test]');
  51. (0, _ava["default"])('namespace - inside attribute (4), space after', testLossy, '[|href= test ] ', '[|href=test]');
  52. (0, _ava["default"])('tag - extraneous whitespace', testLossy, ' h1 , h2 ', 'h1,h2');
  53. (0, _ava["default"])('tag - trailing comma', testLossy, 'h1, ', 'h1,');
  54. (0, _ava["default"])('tag - trailing comma (1)', testLossy, 'h1,', 'h1,');
  55. (0, _ava["default"])('tag - trailing comma (2)', testLossy, 'h1', 'h1');
  56. (0, _ava["default"])('tag - trailing slash (1)', testLossy, 'h1\\ ', 'h1\\ ');
  57. (0, _ava["default"])('tag - trailing slash (2)', testLossy, 'h1\\ h2\\', 'h1\\ h2\\');
  58. (0, _ava["default"])('universal - combinator', testLossy, ' * + * ', '*+*');
  59. (0, _ava["default"])('universal - extraneous whitespace', testLossy, ' * , * ', '*,*');
  60. (0, _ava["default"])('universal - qualified universal selector', testLossy, '*[href] *:not(*.green)', '*[href] *:not(*.green)');
  61. (0, _ava["default"])('nesting - spacing before', testLossy, ' &.class', '&.class');
  62. (0, _ava["default"])('nesting - spacing after', testLossy, '&.class ', '&.class');
  63. (0, _ava["default"])('nesting - spacing between', testLossy, '& .class ', '& .class');
  64. (0, _ava["default"])('pseudo (single) - spacing before', testLossy, ' :after', ':after');
  65. (0, _ava["default"])('pseudo (single) - spacing after', testLossy, ':after ', ':after');
  66. (0, _ava["default"])('pseudo (double) - spacing before', testLossy, ' ::after', '::after');
  67. (0, _ava["default"])('pseudo (double) - spacing after', testLossy, '::after ', '::after');
  68. (0, _ava["default"])('pseudo - multiple', testLossy, ' *:target::before , a:after ', '*:target::before,a:after');
  69. (0, _ava["default"])('pseudo - negated', testLossy, 'h1:not( .heading )', 'h1:not(.heading)');
  70. (0, _ava["default"])('pseudo - negated with combinators (1)', testLossy, 'h1:not(.heading > .title) > h1', 'h1:not(.heading>.title)>h1');
  71. (0, _ava["default"])('pseudo - negated with combinators (2)', testLossy, '.foo:nth-child(2n + 1)', '.foo:nth-child(2n+1)');
  72. (0, _ava["default"])('pseudo - extra whitespace', testLossy, 'a:not( h2 )', 'a:not(h2)');
  73. (0, _ava["default"])('comments - comment inside descendant selector', testLossy, "div /* wtf */.foo", "div /* wtf */.foo");
  74. (0, _ava["default"])('comments - comment inside complex selector', testLossy, "div /* wtf */ > .foo", "div/* wtf */>.foo");
  75. (0, _ava["default"])('comments - comment inside compound selector with space', testLossy, "div /* wtf */ .foo", "div /* wtf */.foo");
  76. (0, _ava["default"])('@words - space before', testLossy, ' @media', '@media');
  77. (0, _ava["default"])('@words - space after', testLossy, '@media ', '@media');
  78. (0, _ava["default"])('@words - maintains space between', testLossy, '@media (min-width: 700px) and (orientation: landscape)', '@media (min-width: 700px) and (orientation: landscape)');
  79. (0, _ava["default"])('@words - extraneous space between', testLossy, '@media (min-width: 700px) and (orientation: landscape)', '@media (min-width: 700px) and (orientation: landscape)');
  80. (0, _ava["default"])('@words - multiple', testLossy, '@media (min-width: 700px), (min-height: 400px)', '@media (min-width: 700px),(min-height: 400px)');