queryDescendant.js 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. define([
  2. "esquery",
  3. "jstestr/assert",
  4. "jstestr/test",
  5. "./fixtures/conditional",
  6. ], function (esquery, assert, test, conditional) {
  7. test.defineSuite("Pseudo matches query", {
  8. "conditional matches": function () {
  9. var matches = esquery(conditional, "Program IfStatement");
  10. assert.contains([
  11. conditional.body[0],
  12. conditional.body[1],
  13. conditional.body[1].alternate
  14. ], matches);
  15. },
  16. "#8: descendant selector includes ancestor in search": function() {
  17. var matches = esquery(conditional, "Identifier[name=x]");
  18. assert.isSame(4, matches.length);
  19. matches = esquery(conditional, "Identifier [name=x]");
  20. assert.isSame(0, matches.length);
  21. matches = esquery(conditional, "BinaryExpression [name=x]");
  22. assert.isSame(2, matches.length);
  23. matches = esquery(conditional, "AssignmentExpression [name=x]");
  24. assert.isSame(1, matches.length);
  25. }
  26. });
  27. });