StrcasecmpExpression.js 2.2 KB

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