ConcatExpression.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. "use strict";
  2. var assert = require("assert"),
  3. ConcatExpression = require("../../../../lib/pipeline/expressions/ConcatExpression"),
  4. Expression = require("../../../../lib/pipeline/expressions/Expression");
  5. module.exports = {
  6. "ConcatExpression": {
  7. "constructor()": {
  8. "should not throw Error when constructing without args": function testConstructor(){
  9. assert.doesNotThrow(function(){
  10. new ConcatExpression();
  11. });
  12. }
  13. },
  14. "#getOpName()": {
  15. "should return the correct op name; $concat": function testOpName(){
  16. assert.equal(new ConcatExpression().getOpName(), "$concat");
  17. }
  18. },
  19. "#getFactory()": {
  20. "should return the constructor for this class": function factoryIsConstructor(){
  21. assert.equal(new ConcatExpression().getFactory(), ConcatExpression);
  22. }
  23. },
  24. "#evaluate()": {
  25. "should return empty string if no operands were given; {$concat:[]}": function testEmpty(){
  26. assert.equal(Expression.parseOperand({$concat:[]}).evaluate(), "");
  27. },
  28. "should return mystring if operands are my string; {$concat:[my, string]}": function testConcat(){
  29. assert.equal(Expression.parseOperand({$concat:["my", "string"]}).evaluate(), "mystring");
  30. },
  31. "should return mystring if operands are my and $a; {$concat:[my,$a]}": function testFieldPath(){
  32. assert.equal(Expression.parseOperand({$concat:["my","$a"]}).evaluate({a:"string"}), "mystring");
  33. },
  34. "should return null if an operand evaluates to null; {$concat:[my,$a]}": function testNull(){
  35. assert.equal(Expression.parseOperand({$concat:["my","$a"]}).evaluate({a:null}), null);
  36. }
  37. }
  38. }
  39. };
  40. if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);