queryNot.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. define([
  2. "esquery",
  3. "jstestr/assert",
  4. "jstestr/test",
  5. "./fixtures/conditional",
  6. "./fixtures/forLoop",
  7. "./fixtures/simpleFunction",
  8. "./fixtures/simpleProgram"
  9. ], function (esquery, assert, test, conditional, forLoop, simpleFunction, simpleProgram) {
  10. test.defineSuite("Pseudo matches query", {
  11. "conditional": function () {
  12. var matches = esquery(conditional, ":not(Literal)");
  13. assert.isEqual(28, matches.length);
  14. },
  15. "for loop": function () {
  16. var matches = esquery(forLoop, ':not([name="x"])');
  17. assert.isEqual(18, matches.length);
  18. },
  19. "simple function": function () {
  20. var matches = esquery(simpleFunction, ":not(*)");
  21. assert.isEqual(0, matches.length);
  22. },
  23. "simple program": function () {
  24. var matches = esquery(simpleProgram, ":not(Identifier, IfStatement)");
  25. assert.isEqual(15, matches.length);
  26. },
  27. "small program": function () {
  28. var program = {
  29. type: "Program",
  30. body: [{
  31. type: "VariableDeclaration",
  32. declarations: [{
  33. type: "VariableDeclarator",
  34. id: {type: "Identifier", name: "x"},
  35. init: {type: "Literal", value: 1, raw: "1"}
  36. }],
  37. kind: "var"
  38. }]
  39. };
  40. matches = esquery(program, ":not([value=1])");
  41. assert.contains([
  42. program,
  43. program.body[0],
  44. program.body[0].declarations[0],
  45. program.body[0].declarations[0].id
  46. ], matches);
  47. }
  48. });
  49. });