guards.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. "use strict";
  2. var _ = _interopRequireDefault(require("../"));
  3. var _helpers = require("./util/helpers");
  4. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  5. var node = function node(tree, n) {
  6. if (n === void 0) {
  7. n = 0;
  8. }
  9. return tree.nodes[0].nodes[n];
  10. };
  11. (0, _helpers.test)('attribute guard', '[foo]', function (t, tree) {
  12. var n = node(tree);
  13. t["true"](_["default"].isNode(n));
  14. t["false"](_["default"].isAttribute(undefined));
  15. t["true"](_["default"].isAttribute(n));
  16. t["false"](_["default"].isContainer(n));
  17. t["true"](_["default"].isNamespace(n));
  18. });
  19. (0, _helpers.test)('className guard', '.foo', function (t, tree) {
  20. var n = node(tree);
  21. t["true"](_["default"].isNode(n));
  22. t["false"](_["default"].isClassName(undefined));
  23. t["true"](_["default"].isClassName(n));
  24. t["false"](_["default"].isContainer(n));
  25. t["false"](_["default"].isNamespace(n));
  26. });
  27. (0, _helpers.test)('combinator guard', '.foo > .bar', function (t, tree) {
  28. var n = node(tree, 1);
  29. t["true"](_["default"].isNode(n));
  30. t["false"](_["default"].isCombinator(undefined));
  31. t["true"](_["default"].isCombinator(n));
  32. t["false"](_["default"].isContainer(n));
  33. t["false"](_["default"].isNamespace(n));
  34. });
  35. (0, _helpers.test)('comment guard', '/* foo */.foo > .bar', function (t, tree) {
  36. var n = node(tree);
  37. t["true"](_["default"].isNode(n));
  38. t["false"](_["default"].isComment(undefined));
  39. t["true"](_["default"].isComment(n));
  40. t["false"](_["default"].isContainer(n));
  41. t["false"](_["default"].isNamespace(n));
  42. });
  43. (0, _helpers.test)('id guard', '#ident', function (t, tree) {
  44. var n = node(tree);
  45. t["true"](_["default"].isNode(n));
  46. t["false"](_["default"].isIdentifier(undefined));
  47. t["true"](_["default"].isIdentifier(n));
  48. t["false"](_["default"].isContainer(n));
  49. t["false"](_["default"].isNamespace(n));
  50. });
  51. (0, _helpers.test)('nesting guard', '&.foo', function (t, tree) {
  52. var n = node(tree);
  53. t["true"](_["default"].isNode(n));
  54. t["false"](_["default"].isNesting(undefined));
  55. t["true"](_["default"].isNesting(n));
  56. t["false"](_["default"].isContainer(n));
  57. t["false"](_["default"].isNamespace(n));
  58. });
  59. (0, _helpers.test)('pseudo class guard', ':hover', function (t, tree) {
  60. var n = node(tree);
  61. t["true"](_["default"].isNode(n));
  62. t["false"](_["default"].isPseudo(undefined));
  63. t["true"](_["default"].isPseudo(n));
  64. t["true"](_["default"].isPseudoClass(n));
  65. t["false"](_["default"].isPseudoElement(n));
  66. t["true"](_["default"].isContainer(n));
  67. t["false"](_["default"].isNamespace(n));
  68. });
  69. (0, _helpers.test)('pseudo element guard', '::first-line', function (t, tree) {
  70. var n = node(tree);
  71. t["true"](_["default"].isNode(n));
  72. t["false"](_["default"].isPseudo(undefined));
  73. t["true"](_["default"].isPseudo(n));
  74. t["false"](_["default"].isPseudoClass(n));
  75. t["true"](_["default"].isPseudoElement(n));
  76. t["true"](_["default"].isContainer(n));
  77. t["false"](_["default"].isNamespace(n));
  78. });
  79. (0, _helpers.test)('special pseudo element guard', ':before:after', function (t, tree) {
  80. [node(tree), node(tree, 1)].forEach(function (n) {
  81. t["true"](_["default"].isPseudo(n));
  82. t["false"](_["default"].isPseudoClass(n));
  83. t["true"](_["default"].isPseudoElement(n));
  84. t["true"](_["default"].isContainer(n));
  85. t["false"](_["default"].isNamespace(n));
  86. });
  87. });
  88. (0, _helpers.test)('special pseudo element guard (uppercase)', ':BEFORE:AFTER', function (t, tree) {
  89. [node(tree), node(tree, 1)].forEach(function (n) {
  90. t["true"](_["default"].isPseudo(n));
  91. t["false"](_["default"].isPseudoClass(n));
  92. t["true"](_["default"].isPseudoElement(n));
  93. t["true"](_["default"].isContainer(n));
  94. t["false"](_["default"].isNamespace(n));
  95. });
  96. });
  97. (0, _helpers.test)('string guard', '"string"', function (t, tree) {
  98. var n = node(tree);
  99. t["true"](_["default"].isNode(n));
  100. t["false"](_["default"].isString(undefined));
  101. t["true"](_["default"].isString(n));
  102. t["false"](_["default"].isContainer(n));
  103. t["false"](_["default"].isNamespace(n));
  104. });
  105. (0, _helpers.test)('tag guard', 'h1', function (t, tree) {
  106. var n = node(tree);
  107. t["false"](_["default"].isNode(undefined));
  108. t["true"](_["default"].isNode(n));
  109. t["false"](_["default"].isTag(undefined));
  110. t["true"](_["default"].isTag(n));
  111. t["false"](_["default"].isContainer(n));
  112. t["true"](_["default"].isNamespace(n));
  113. });
  114. (0, _helpers.test)('universal guard', '*', function (t, tree) {
  115. var n = node(tree);
  116. t["true"](_["default"].isNode(n));
  117. t["false"](_["default"].isUniversal(undefined));
  118. t["true"](_["default"].isUniversal(n));
  119. t["false"](_["default"].isContainer(n));
  120. t["false"](_["default"].isNamespace(n));
  121. });