ToLowerExpression_test.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. "use strict";
  2. var assert = require("assert"),
  3. ToLowerExpression = require("../../../../lib/pipeline/expressions/ToLowerExpression"),
  4. Expression = require("../../../../lib/pipeline/expressions/Expression");
  5. module.exports = {
  6. "ToLowerExpression": {
  7. "constructor()": {
  8. "should not throw Error when constructing without args": function testConstructor() {
  9. assert.doesNotThrow(function() {
  10. new ToLowerExpression();
  11. });
  12. },
  13. "should throw Error when constructing with args": function testConstructor(){
  14. assert.throws(function(){
  15. new ToLowerExpression(1);
  16. });
  17. }
  18. },
  19. "#getOpName()": {
  20. "should return the correct op name; $toLower": function testOpName() {
  21. assert.equal(new ToLowerExpression().getOpName(), "$toLower");
  22. }
  23. },
  24. "#evaluate()": {
  25. "should return the lowercase version of the string if there is a null character in the middle of the string": function testStuff() {
  26. assert.strictEqual(Expression.parseOperand({
  27. $toLower: "$a"
  28. }).evaluate({
  29. a: "a\0B"
  30. }), "a\0b");
  31. },
  32. "should return the lowercase version of the string if there is a null character at the beginning of the string": function testStuff() {
  33. assert.strictEqual(Expression.parseOperand({
  34. $toLower: "$a"
  35. }).evaluate({
  36. a: "\0aB"
  37. }), "\0ab");
  38. },
  39. "should return the lowercase version of the string if there is a null character at the end of the string": function testStuff() {
  40. assert.strictEqual(Expression.parseOperand({
  41. $toLower: "$a"
  42. }).evaluate({
  43. a: "aB\0"
  44. }), "ab\0");
  45. }
  46. }
  47. }
  48. };
  49. if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);