CondExpression.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. var assert = require("assert"),
  2. CondExpression = require("../../../../lib/pipeline/expressions/CondExpression"),
  3. Expression = require("../../../../lib/pipeline/expressions/Expression");
  4. module.exports = {
  5. "CondExpression": {
  6. "constructor()": {
  7. "should not throw Error when constructing without args": function testConstructor(){
  8. assert.doesNotThrow(function(){
  9. new CondExpression();
  10. });
  11. }
  12. },
  13. "#getOpName()": {
  14. "should return the correct op name; $cond": function testOpName(){
  15. assert.equal(new CondExpression().getOpName(), "$cond");
  16. }
  17. },
  18. "#getFactory()": {
  19. "should return the constructor for this class": function factoryIsConstructor(){
  20. assert.strictEqual(new CondExpression().getFactory(), undefined);
  21. }
  22. },
  23. "#evaluate()": {
  24. "should evaluate boolean expression as true, then return 1; [ true === true, 1, 0 ]": function testStuff(){
  25. assert.strictEqual(Expression.parseOperand({$cond:[ true === true, 1, 0 ]}).evaluate({}), 1);
  26. },
  27. "should evaluate boolean expression as false, then return 0; [ false === true, 1, 0 ]": function testStuff(){
  28. assert.strictEqual(Expression.parseOperand({$cond:[ false === true, 1, 0 ]}).evaluate({}), 0);
  29. },
  30. "should evaluate boolean expression as true, then return 1; [ (true === true) && true, 1, 0 ]": function testStuff(){
  31. assert.strictEqual(Expression.parseOperand({$cond:[ (true === true) && true , 1, 0 ]}).evaluate({}), 1);
  32. },
  33. "should evaluate boolean expression as false, then return 0; [ (false === true) && true, 1, 0 ]": function testStuff(){
  34. assert.strictEqual(Expression.parseOperand({$cond:[ (false === true) && true, 1, 0 ]}).evaluate({}), 0);
  35. },
  36. "should evaluate complex boolean expression as true, then return 1; [ ( 1 > 0 ) && (( 'a' == 'b' ) || ( 3 <= 5 )), 1, 0 ]": function testStuff(){
  37. assert.strictEqual(Expression.parseOperand({$cond:[ ( 1 > 0 ) && (( 'a' == 'b' ) || ( 3 <= 5 )), 1, 0 ]}).evaluate({}), 1);
  38. },
  39. }
  40. }
  41. };
  42. if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);