IfNullExpression.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. "use strict";
  2. var assert = require("assert"),
  3. IfNullExpression = require("../../../../lib/pipeline/expressions/IfNullExpression"),
  4. Expression = require("../../../../lib/pipeline/expressions/Expression");
  5. module.exports = {
  6. "IfNullExpression": {
  7. "constructor()": {
  8. "should not throw Error when constructing without args": function testConstructor(){
  9. assert.doesNotThrow(function(){
  10. new IfNullExpression();
  11. });
  12. }
  13. },
  14. "#getOpName()": {
  15. "should return the correct op name; $ifNull": function testOpName(){
  16. assert.equal(new IfNullExpression().getOpName(), "$ifNull");
  17. }
  18. },
  19. "#getFactory()": {
  20. "should return the constructor for this class": function factoryIsConstructor(){
  21. assert.strictEqual(new IfNullExpression().getFactory(), undefined);
  22. }
  23. },
  24. "#evaluate()": {
  25. "should return the left hand side if the left hand side is not null or undefined": function testStuff(){
  26. assert.strictEqual(Expression.parseOperand({$ifNull:["$a", "$b"]}).evaluate({a:1, b:2}), 1);
  27. },
  28. "should return the right hand side if the left hand side is null or undefined": function testStuff(){
  29. assert.strictEqual(Expression.parseOperand({$ifNull:["$a", "$b"]}).evaluate({a:null, b:2}), 2);
  30. assert.strictEqual(Expression.parseOperand({$ifNull:["$a", "$b"]}).evaluate({b:2}), 2);
  31. }
  32. }
  33. }
  34. };
  35. if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);