AnyElementTrueExpression.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. "use strict";
  2. var assert = require("assert"),
  3. AnyElementTrueExpression = require("../../../../lib/pipeline/expressions/AnyElementTrueExpression"),
  4. Expression = require("../../../../lib/pipeline/expressions/Expression");
  5. var anyElementTrueExpression = new AnyElementTrueExpression();
  6. module.exports = {
  7. "AnyElementTrueExpression": {
  8. "constructor()": {
  9. "should not throw Error when constructing without args": function testConstructor(){
  10. assert.doesNotThrow(function(){
  11. new AnyElementTrueExpression();
  12. });
  13. }
  14. },
  15. "#getOpName()": {
  16. "should return the correct op name; $anyElement": function testOpName(){
  17. assert.equal(new AnyElementTrueExpression().getOpName(), "$anyElementTrue");
  18. }
  19. },
  20. "#evaluateInternal()": {
  21. "should return error if parameter is not an array": function testEmpty(){
  22. assert.throws(function(){
  23. anyElementTrueExpression.evaluateInternal("TEST");});
  24. },
  25. "should return true if only true was given a; {true}": function testEmpty(){
  26. assert.equal(anyElementTrueExpression.evaluateInternal({$anyElementTrue:[1,2,3,4]}), false);
  27. },
  28. "should return false if no element is true": function testEmpty(){
  29. assert.equal(anyElementTrueExpression.evaluateInternal({$anyElementTrue:[1,2,3,4]}), false);
  30. },
  31. "should return true if any element is true": function testEmpty(){
  32. assert.equal(anyElementTrueExpression.evaluateInternal({$anyElementTrue:[1,true,2,3,4]}), true);
  33. },
  34. }
  35. }
  36. };
  37. if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);