GTEMatchExpression.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. "use strict";
  2. var assert = require("assert"),
  3. MatchDetails = require('../../../../lib/pipeline/matcher/MatchDetails'),
  4. GTEMatchExpression = require("../../../../lib/pipeline/matcher/GTEMatchExpression");
  5. module.exports = {
  6. "GTEMatchExpression": {
  7. "should match scalars and strings properly": function (){
  8. var e = new GTEMatchExpression();
  9. var s = e.init('a',5);
  10. assert.strictEqual(s.code, 'OK');
  11. assert.ok( e.matches({'a':5.5}) );
  12. assert.ok( e.matches({'a':5}) );
  13. assert.ok( ! e.matches({'a':4}) );
  14. assert.ok( ! e.matches({'a': 'foo'}) );
  15. },
  16. "should handle invalid End of Object Operand": function testInvalidEooOperand(){
  17. var e = new GTEMatchExpression();
  18. var s = e.init('',{});
  19. assert.strictEqual(s.code, 'BAD_VALUE');
  20. },
  21. "should match a pathed number":function() {
  22. var e = new GTEMatchExpression();
  23. var s = e.init('a',5);
  24. assert.strictEqual(s.code, 'OK');
  25. assert.ok( e.matches({'a':5.5}) );
  26. assert.ok( ! e.matches({'a':4}) );
  27. },
  28. "should match stuff in an array": function() {
  29. var e = new GTEMatchExpression();
  30. var s = e.init('a',5);
  31. assert.strictEqual(s.code, 'OK');
  32. assert.ok( e.matches({'a':[4,5.5]}) );
  33. assert.ok( ! e.matches({'a':[1,2]}) );
  34. },
  35. "should not match full array" : function() {
  36. var e = new GTEMatchExpression();
  37. var s = e.init('a',[5]);
  38. assert.strictEqual(s.code, 'OK');
  39. assert.ok( ! e.matches({'a':[4]}) );
  40. assert.ok( e.matches({'a':[5]}) );
  41. assert.ok( e.matches({'a':[6]}) );
  42. },
  43. "should not match null" : function() {
  44. var e = new GTEMatchExpression();
  45. var s = e.init('a',null);
  46. assert.strictEqual(s.code, 'OK');
  47. assert.ok( e.matches({}) );
  48. assert.ok( e.matches({'a':null}) );
  49. assert.ok( ! e.matches({'a':4}) );
  50. assert.ok( e.matches({'b':4}) );
  51. },
  52. "should match dot notation nulls": function() {
  53. var e = new GTEMatchExpression();
  54. var s = e.init('a.b',null);
  55. assert.strictEqual(s.code, 'OK');
  56. assert.ok(e.matchesJSON({}));
  57. assert.ok(e.matchesJSON({a:null}));
  58. assert.ok(e.matchesJSON({a:{}}));
  59. assert.ok(e.matchesJSON({a:[{b: null}]}));
  60. assert.ok(e.matchesJSON({a:[{a:4}, {b:4}]}));
  61. assert.ok(!e.matchesJSON({a:[4]}));
  62. assert.ok(!e.matchesJSON({a:[{b:4}]}));
  63. },
  64. "should match MinKey": function() {
  65. },
  66. "should match MaxKey": function() {
  67. },
  68. "should handle elemMatchKey":function() {
  69. var e = new GTEMatchExpression();
  70. var s = e.init('a',5);
  71. var m = new MatchDetails();
  72. m.requestElemMatchKey();
  73. assert.strictEqual( s.code, 'OK' );
  74. assert.ok( ! e.matches({'a':4}, m) );
  75. assert.ok( ! m.hasElemMatchKey() );
  76. assert.ok( e.matches({'a':6}, m) );
  77. assert.ok( ! m.hasElemMatchKey() );
  78. assert.ok( e.matches({'a':[2,6,5]}, m));
  79. assert.ok( m.hasElemMatchKey());
  80. assert.strictEqual('1', m.elemMatchKey());
  81. }
  82. }
  83. };
  84. if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);