ComparisonMatchExpression.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. "use strict";
  2. var assert = require("assert"),
  3. ComparisonMatchExpression = require("../../../../lib/pipeline/matcher/ComparisonMatchExpression");
  4. module.exports = {
  5. "ComparisonMatchExpression": {
  6. "Should properly initialize with an empty path and a number": function (){
  7. var e = new ComparisonMatchExpression();
  8. e._matchType = 'LT';
  9. assert.strictEqual(e.init('', 5 ).code,'OK');
  10. },
  11. "Should not initialize when given an undefined rhs": function() {
  12. var e = new ComparisonMatchExpression();
  13. assert.strictEqual(e.init('',5).code,'BAD_VALUE');
  14. e._matchType = 'LT';
  15. assert.strictEqual(e.init('',{}).code,'BAD_VALUE');
  16. assert.strictEqual(e.init('',undefined).code,'BAD_VALUE');
  17. assert.strictEqual(e.init('',{}).code,'BAD_VALUE');
  18. },
  19. "Should match numbers with GTE": function (){
  20. var e = new ComparisonMatchExpression();
  21. e._matchType = 'GTE';
  22. assert.strictEqual(e.init('',5).code,'OK');
  23. assert.ok(e.matchesSingleElement(6), "6 ≥ 5");
  24. assert.ok(e.matchesSingleElement(5), "5 ≥ 5");
  25. assert.ok(!e.matchesSingleElement(4), "4 ≥ 5");
  26. assert.ok(!e.matchesSingleElement('foo'), "5 ≥ 'foo'");
  27. },
  28. "Should match with simple paths and GTE": function(){
  29. var e = new ComparisonMatchExpression();
  30. e._matchType = 'GTE';
  31. assert.strictEqual(e.init('a', 5).code,'OK');
  32. assert.ok(e.matches({'a':6}));
  33. },
  34. "Should match arrays with GTE": function (){
  35. var e = new ComparisonMatchExpression();
  36. e._matchType = 'GTE';
  37. assert.strictEqual(e.init('a',5).code,'OK');
  38. assert.ok(e.matches({'a':[6,10]}),'[6,10] ≥ 5');
  39. assert.ok(e.matches({'a':[4,5.5]}), '[4,5.5] ≥ 5');
  40. assert.ok(!e.matches({'a':[1,2]}),'[1,2] ≥ 5');
  41. assert.ok(e.matches({'a':[1,10]}),'[1,10] ≥ 5');
  42. }
  43. }
  44. };
  45. if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);