queryClass.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. define([
  2. "esquery",
  3. "jstestr/assert",
  4. "jstestr/test",
  5. "./fixtures/allClasses"
  6. ], function (esquery, assert, test, ast) {
  7. test.defineSuite("Class query", {
  8. ":statement": function () {
  9. var matches = esquery(ast, ":statement");
  10. assert.contains([
  11. ast.body[0],
  12. ast.body[0].body,
  13. ast.body[0].body.body[0],
  14. ast.body[0].body.body[1],
  15. ast.body[0].body.body[2],
  16. ast.body[0].body.body[3]
  17. ], matches);
  18. assert.isSame(6, matches.length);
  19. },
  20. ":expression": function () {
  21. var matches = esquery(ast, ":Expression");
  22. assert.contains([
  23. ast.body[0].id,
  24. ast.body[0].body.body[0].expression,
  25. ast.body[0].body.body[0].expression.left.elements[0],
  26. ast.body[0].body.body[0].expression.right,
  27. ast.body[0].body.body[0].expression.right.body,
  28. ast.body[0].body.body[1].expression,
  29. ast.body[0].body.body[2].expression,
  30. ast.body[0].body.body[3].expression,
  31. ast.body[0].body.body[3].expression.expressions[0]
  32. ], matches);
  33. assert.isSame(9, matches.length);
  34. },
  35. ":function": function () {
  36. var matches = esquery(ast, ":FUNCTION");
  37. assert.contains([
  38. ast.body[0],
  39. ast.body[0].body.body[0].expression.right
  40. ], matches);
  41. assert.isSame(2, matches.length);
  42. },
  43. ":declaration": function () {
  44. var matches = esquery(ast, ":declaratioN");
  45. assert.contains([
  46. ast.body[0]
  47. ], matches);
  48. assert.isSame(1, matches.length);
  49. },
  50. ":pattern": function () {
  51. var matches = esquery(ast, ":paTTern");
  52. assert.contains([
  53. ast.body[0].id,
  54. ast.body[0].body.body[0].expression,
  55. ast.body[0].body.body[0].expression.left,
  56. ast.body[0].body.body[0].expression.left.elements[0],
  57. ast.body[0].body.body[0].expression.right,
  58. ast.body[0].body.body[0].expression.right.body,
  59. ast.body[0].body.body[1].expression,
  60. ast.body[0].body.body[2].expression,
  61. ast.body[0].body.body[3].expression,
  62. ast.body[0].body.body[3].expression.expressions[0]
  63. ], matches);
  64. assert.isSame(10, matches.length);
  65. }
  66. });
  67. });