queryWildcard.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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("Wildcard query", {
  11. "empty": function () {
  12. var matches = esquery(conditional, "");
  13. assert.isEqual(0, matches.length);
  14. },
  15. "conditional": function () {
  16. var matches = esquery(conditional, "*");
  17. assert.isEqual(35, matches.length);
  18. },
  19. "for loop": function () {
  20. var matches = esquery(forLoop, "*");
  21. assert.isEqual(18, matches.length);
  22. },
  23. "simple function": function () {
  24. var matches = esquery(simpleFunction, "*");
  25. assert.isEqual(17, matches.length);
  26. },
  27. "simple program": function () {
  28. var matches = esquery(simpleProgram, "*");
  29. assert.isEqual(22, matches.length);
  30. },
  31. "small program": function () {
  32. var program = {
  33. type: "Program",
  34. body: [{
  35. type: "VariableDeclaration",
  36. declarations: [{
  37. type: "VariableDeclarator",
  38. id: {type: "Identifier", name: "x"},
  39. init: {type: "Literal", value: 1, raw: "1"}
  40. }],
  41. kind: "var"
  42. }]
  43. };
  44. matches = esquery(program, "*");
  45. assert.contains([
  46. program,
  47. program.body[0],
  48. program.body[0].declarations[0],
  49. program.body[0].declarations[0].id,
  50. program.body[0].declarations[0].init
  51. ], matches);
  52. }
  53. });
  54. });