postcss.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. var _ava = _interopRequireDefault(require("ava"));
  3. var _postcss = _interopRequireDefault(require("postcss"));
  4. var _helpers = require("./util/helpers");
  5. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  6. var cse = 'CssSyntaxError';
  7. function showCode(t, selector) {
  8. var rule = _postcss["default"].parse(selector).first;
  9. try {
  10. (0, _helpers.parse)(rule);
  11. } catch (e) {
  12. if (e.name !== cse) {
  13. return;
  14. } // Removes ANSI codes from snapshot tests as it makes them illegible.
  15. // The formatting of this error is otherwise identical to e.toString()
  16. t.snapshot(cse + ": " + e.message + "\n\n" + e.showSourceCode(false) + "\n");
  17. }
  18. }
  19. (0, _ava["default"])('missing open square bracket', showCode, 'a b c] {}');
  20. (0, _ava["default"])('missing open parenthesis', showCode, 'a b c) {}');
  21. (0, _ava["default"])('missing pseudo class or pseudo element', showCode, 'a b c: {}');
  22. (0, _ava["default"])('space in between colon and word (incorrect pseudo)', showCode, 'a b: c {}');
  23. (0, _ava["default"])('string after colon (incorrect pseudo)', showCode, 'a b:"wow" {}'); // attribute selectors
  24. (0, _ava["default"])('bad string attribute', showCode, '["hello"] {}');
  25. (0, _ava["default"])('bad string attribute with value', showCode, '["foo"=bar] {}');
  26. (0, _ava["default"])('bad parentheses', showCode, '[foo=(bar)] {}');
  27. (0, _ava["default"])('bad lonely asterisk', showCode, '[*] {}');
  28. (0, _ava["default"])('bad lonely pipe', showCode, '[|] {}');
  29. (0, _ava["default"])('bad lonely caret', showCode, '[^] {}');
  30. (0, _ava["default"])('bad lonely dollar', showCode, '[$] {}');
  31. (0, _ava["default"])('bad lonely tilde', showCode, '[~] {}');
  32. (0, _ava["default"])('bad lonely equals', showCode, '[=] {}');
  33. (0, _ava["default"])('bad lonely operator', showCode, '[*=] {}');
  34. (0, _ava["default"])('bad lonely operator (2)', showCode, '[|=] {}');
  35. (0, _ava["default"])('bad doubled operator', showCode, '[href=foo=bar] {}');