ToLowerExpression_test.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. "use strict";
  2. var assert = require("assert"),
  3. ToLowerExpression = require("../../../../lib/pipeline/expressions/ToLowerExpression"),
  4. VariablesParseState = require("../../../../lib/pipeline/expressions/VariablesParseState"),
  5. VariablesIdGenerator = require("../../../../lib/pipeline/expressions/VariablesIdGenerator"),
  6. Expression = require("../../../../lib/pipeline/expressions/Expression");
  7. module.exports = {
  8. "ToLowerExpression": {
  9. beforeEach: function () {
  10. this.vps = new VariablesParseState(new VariablesIdGenerator());
  11. },
  12. "constructor()": {
  13. "should not throw Error when constructing without args": function testConstructor() {
  14. assert.doesNotThrow(function () {
  15. new ToLowerExpression();
  16. });
  17. },
  18. "should throw Error when constructing with args": function testConstructor() {
  19. assert.throws(function () {
  20. new ToLowerExpression(1);
  21. });
  22. }
  23. },
  24. "#getOpName()": {
  25. "should return the correct op name; $toLower": function testOpName() {
  26. assert.equal(new ToLowerExpression().getOpName(), "$toLower");
  27. }
  28. },
  29. "#evaluate()": {
  30. "should lowercase a string": function(){
  31. assert.strictEqual(Expression.parseOperand({$toLower: "$a"}, this.vps).evaluate({a: "NOW IS THE TIME"}), "now is the time");
  32. },
  33. "should not change symbols": function(){
  34. var symbs = "!@#$%^&*()_+{}[]:\";'<>?/.,;";
  35. assert.strictEqual(Expression.parseOperand({$toLower: "$a"}, this.vps).evaluate({a: symbs}), symbs);
  36. },
  37. "should not change lowercase": function(){
  38. var symbs = "now is the time for all good men to come from the aid of their computers";
  39. assert.strictEqual(Expression.parseOperand({$toLower: "$a"}, this.vps).evaluate({a: symbs}), symbs);
  40. },
  41. "should return the lowercase version of the string if there is a null character in the middle of the string": function() {
  42. assert.strictEqual(Expression.parseOperand({$toLower: "$a"}, this.vps).evaluate({a: "a\0B"}), "a\0b");
  43. },
  44. "should return the lowercase version of the string if there is a null character at the beginning of the string": function() {
  45. assert.strictEqual(Expression.parseOperand({$toLower: "$a"}, this.vps).evaluate({a: "\0aB"}), "\0ab");
  46. },
  47. "should return the lowercase version of the string if there is a null character at the end of the string": function() {
  48. assert.strictEqual(Expression.parseOperand({$toLower: "$a" }, this.vps).evaluate({a: "aB\0"}), "ab\0");
  49. }
  50. }
  51. }
  52. };
  53. if (!module.parent)(new (require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);