ConstantExpression.js 1.2 KB

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