LetExpression_test.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. "use strict";
  2. var assert = require("assert"),
  3. LetExpression = require("../../../../lib/pipeline/expressions/LetExpression"),
  4. Expression = require("../../../../lib/pipeline/expressions/Expression");
  5. module.exports = {
  6. "LetExpression": {
  7. "constructor()": {
  8. "should throw when there are not 2 args": function testConstructorNot2() {
  9. assert.throws(function () {
  10. new LetExpression({});
  11. });
  12. assert.throws(function () {
  13. new LetExpression({}, {}, {});
  14. });
  15. },
  16. "should not throw when there are 2 args": function testConstructor2() {
  17. assert.doesNotThrow(function () {
  18. new LetExpression({}, {});
  19. });
  20. }
  21. },
  22. "#parse()": {
  23. "should throw if $let isn't in expr": function () {
  24. assert.throws(function(){
  25. new LetExpression.parse({$noLetIsHere:1}, {})
  26. });
  27. },
  28. "should throw if the $let expression isn't an object": function () {
  29. assert.throws(function(){
  30. new LetExpression.parse({$expr:"this is not an object"}, {})
  31. });
  32. },
  33. "should throw if the $let expression is an array": function () {
  34. assert.throws(function(){
  35. new LetExpression.parse({$expr:[1,2,3]}, {})
  36. });
  37. },
  38. "should throw if there is no vars parameter to $let": function () {
  39. assert.throws(function(){
  40. new LetExpression.parse({$expr:{noVars:1}}, {})
  41. });
  42. },
  43. "should throw if there is no input parameter to $let": function () {
  44. assert.throws(function(){
  45. new LetExpression.parse({$expr:{vars:1, noIn:2}}, {})
  46. });
  47. },
  48. "should throw if any of the arguments to $let are not 'in' or 'var'": function () {
  49. assert.throws(function(){
  50. new LetExpression.parse({$expr:{vars:1, in:2, zoot:3}}, {})
  51. });
  52. },
  53. "should throw if the var name is not writable": function () {
  54. assert.throws(function(){
  55. new LetExpression.parse({$expr:{vars:["$$bad$$"], in:2}}, {})
  56. });
  57. },
  58. "should return a Let expression": function () {
  59. var letExpression = new LetExpression.parse({$expr:{vars:["$valid"], in:2}}, {})
  60. assert(letExpression);
  61. assert(false); // I don't know how to test this yet.
  62. }
  63. },
  64. "#optimize()": {
  65. "should optimize subexpressions if there are no variables": function () {
  66. assert(fail);
  67. },
  68. "should optimize variables": function () {
  69. assert(fail);
  70. },
  71. "should optimize subexpressions if there are variables": function () {
  72. assert(fail);
  73. }
  74. },
  75. "#serialize()": {
  76. "should serialize variables and the subexpression": function () {
  77. assert(fail);
  78. }
  79. },
  80. "#evaluateInternal()": {
  81. "should preform the evaluation for variables and the subexpression": function () {
  82. assert(fail);
  83. }
  84. },
  85. "#addDependencies()": {
  86. "add dependencies to the variables and the subexpression": function () {
  87. assert(fail);
  88. }
  89. }
  90. }
  91. };
  92. if (!module.parent)(new (require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);