ConstantExpression.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. "use strict";
  2. var assert = require("assert"),
  3. ConstantExpression = require("../../../../lib/pipeline/expressions/ConstantExpression");
  4. module.exports = {
  5. "ConstantExpression": {
  6. "constructor() / #evaluate": {
  7. "should be able to construct from a value type": function testCreate(){
  8. assert.strictEqual(new ConstantExpression(5).evaluate({}), 5);
  9. }
  10. //TODO: CreateFromBsonElement ? ?? ???
  11. },
  12. // TODO: the constructor() tests this so not really needed here
  13. // "#evaluate()": {
  14. // },
  15. "#optimize()": {
  16. "should not optimize anything": function testOptimize(){
  17. var expr = new ConstantExpression(5);
  18. assert.strictEqual(expr, expr.optimize());
  19. }
  20. },
  21. "#addDependencies()": {
  22. "should return nothing": function testDependencies(){
  23. assert.strictEqual(new ConstantExpression(5).addDependencies(), undefined);
  24. }
  25. },
  26. "#toJson()": {
  27. "should output proper JSON": function testJson(){
  28. var expr = new ConstantExpression(5);
  29. assert.strictEqual(expr.toJson(), 5);
  30. assert.deepEqual(expr.toJson(true), {$const:5});
  31. }
  32. }
  33. }
  34. };
  35. if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);