queryHas.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. define([
  2. "esquery",
  3. "jstestr/assert",
  4. "jstestr/test",
  5. "./fixtures/conditional"
  6. ], function (esquery, assert, test, conditional) {
  7. test.defineSuite("Parent selector query", {
  8. "conditional": function () {
  9. var matches = esquery(conditional, 'ExpressionStatement:has([name="foo"][type="Identifier"])');
  10. assert.isEqual(1, matches.length);
  11. },
  12. "one of": function () {
  13. var matches = esquery(conditional, 'IfStatement:has(LogicalExpression [name="foo"], LogicalExpression [name="x"])');
  14. assert.isEqual(1, matches.length);
  15. },
  16. "chaining": function () {
  17. var matches = esquery(conditional, 'BinaryExpression:has(Identifier[name="x"]):has(Literal[value="test"])');
  18. assert.isEqual(1, matches.length);
  19. },
  20. "nesting": function () {
  21. var matches = esquery(conditional, 'Program:has(IfStatement:has(Literal[value=true], Literal[value=false]))');
  22. assert.isEqual(1, matches.length);
  23. },
  24. "non-matching": function () {
  25. var matches = esquery(conditional, ':has([value="impossible"])');
  26. assert.isEqual(0, matches.length);
  27. }
  28. });
  29. });