IfNullExpression.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. "#evaluateInternal()": {
  20. "should return the left hand side if the left hand side is not null or undefined": function testStuff() {
  21. assert.strictEqual(Expression.parseOperand({
  22. $ifNull: ["$a", "$b"]
  23. }).evaluateInternal({
  24. a: 1,
  25. b: 2
  26. }), 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({
  30. $ifNull: ["$a", "$b"]
  31. }).evaluateInternal({
  32. a: null,
  33. b: 2
  34. }), 2);
  35. assert.strictEqual(Expression.parseOperand({
  36. $ifNull: ["$a", "$b"]
  37. }).evaluateInternal({
  38. b: 2
  39. }), 2);
  40. }
  41. }
  42. }
  43. };
  44. if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);