StrcasecmpExpression.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. var assert = require("assert"),
  2. StrcasecmpExpression = require("../../../../lib/pipeline/expressions/StrcasecmpExpression"),
  3. Expression = require("../../../../lib/pipeline/expressions/Expression");
  4. module.exports = {
  5. "StrcasecmpExpression": {
  6. "constructor()": {
  7. "should not throw Error when constructing without args": function testConstructor(){
  8. assert.doesNotThrow(function(){
  9. new StrcasecmpExpression();
  10. });
  11. }
  12. },
  13. "#getOpName()": {
  14. "should return the correct op name; $strcasecmp": function testOpName(){
  15. assert.equal(new StrcasecmpExpression().getOpName(), "$strcasecmp");
  16. }
  17. },
  18. "#getFactory()": {
  19. "should return the constructor for this class": function factoryIsConstructor(){
  20. assert.strictEqual(new StrcasecmpExpression().getFactory(), undefined);
  21. }
  22. },
  23. "#evaluate()": {
  24. "should return 0 if the strings are equivalent and begin with a null character": function testStuff(){
  25. assert.strictEqual(Expression.parseOperand({$strcasecmp:["$a", "$b"]}).evaluate({a:"\0ab", b:"\0AB"}), 0);
  26. },
  27. "should return 0 if the strings are equivalent and end with a null character": function testStuff(){
  28. assert.strictEqual(Expression.parseOperand({$strcasecmp:["$a", "$b"]}).evaluate({a:"ab\0", b:"AB\0"}), 0);
  29. },
  30. "should return -1 if the left hand side is less than the right hand side and both contain a null character": function testStuff(){
  31. assert.strictEqual(Expression.parseOperand({$strcasecmp:["$a", "$b"]}).evaluate({a:"a\0a", b:"A\0B"}), -1);
  32. },
  33. "should return 0 if the strings are equivalent and both contain a null character": function testStuff(){
  34. assert.strictEqual(Expression.parseOperand({$strcasecmp:["$a", "$b"]}).evaluate({a:"a\0b", b:"A\0B"}), 0);
  35. },
  36. "should return 1 if the left hand side is greater than the right hand side and both contain a null character": function testStuff(){
  37. assert.strictEqual(Expression.parseOperand({$strcasecmp:["$a", "$b"]}).evaluate({a:"a\0c", b:"A\0B"}), 1);
  38. }
  39. }
  40. }
  41. };
  42. if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);