ConcatExpression_test.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. "should throw Error when constructing with args": function testConstructor(){
  14. assert.throws(function(){
  15. new ConcatExpression("should die");
  16. });
  17. }
  18. },
  19. "#getOpName()": {
  20. "should return the correct op name; $concat": function testOpName(){
  21. assert.equal(new ConcatExpression().getOpName(), "$concat");
  22. }
  23. },
  24. "#getFactory()": {
  25. "should return the constructor for this class": function factoryIsConstructor(){
  26. assert.equal(new ConcatExpression().getFactory(), ConcatExpression);
  27. }
  28. },
  29. "#evaluate()": {
  30. "should return empty string if no operands were given; {$concat:[]}": function testEmpty(){
  31. assert.equal(Expression.parseOperand({$concat:[]}).evaluate(), "");
  32. },
  33. "should return mystring if operands are my string; {$concat:[my, string]}": function testConcat(){
  34. assert.equal(Expression.parseOperand({$concat:["my", "string"]}).evaluate(), "mystring");
  35. },
  36. "should return mystring if operands are my and $a; {$concat:[my,$a]}": function testFieldPath(){
  37. assert.equal(Expression.parseOperand({$concat:["my","$a"]}).evaluate({a:"string"}), "mystring");
  38. },
  39. "should return null if an operand evaluates to null; {$concat:[my,$a]}": function testNull(){
  40. assert.equal(Expression.parseOperand({$concat:["my","$a"]}).evaluate({a:null}), null);
  41. },
  42. "should throw if a non-string is passed in: {$concat:[my,$a]}": function testNull(){
  43. assert.throws(function(){
  44. Expression.parseOperand({$concat:["my","$a"]}).evaluate({a:100});
  45. });
  46. }
  47. }
  48. }
  49. };
  50. if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);