IfNullExpression.js 1.4 KB

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