NotMatchExpression.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. var assert = require("assert"),
  3. NotMatchExpression = require("../../../../lib/pipeline/matcher/NotMatchExpression"),
  4. LTMatchExpression = require("../../../../lib/pipeline/matcher/LTMatchExpression"),
  5. GTMatchExpression = require("../../../../lib/pipeline/matcher/GTMatchExpression"),
  6. MatchDetails = require("../../../../lib/pipeline/matcher/MatchDetails");
  7. module.exports = {
  8. "NotMatchExpression": {
  9. "Should match a scalar": function (){
  10. var lt = new LTMatchExpression();
  11. assert.strictEqual(lt.init('a', 5).code,'OK');
  12. var op = new NotMatchExpression();
  13. assert.strictEqual( op.init(lt).code, 'OK');
  14. assert.ok( op.matches({'a':6}), '{$not: {$lt: 5}}, {a:6}' );
  15. assert.ok( !op.matches({'a':4}), '{$not: {$lt: 5}}, {a:4}' );
  16. },
  17. "Should match an Array": function() {
  18. var lt = new LTMatchExpression();
  19. assert.strictEqual(lt.init('a',5).code,'OK');
  20. var op = new NotMatchExpression();
  21. assert.strictEqual(op.init(lt).code,'OK');
  22. assert.ok( op.matches({'a': [6]}) , '{$not: {$lt: 5}}, {a: [6]}');
  23. assert.ok( !op.matches({'a': [4]}) , '{$not: {$lt: 5}}, {a: [4]}');
  24. assert.ok( !op.matches({'a': [4,5,6]}) , '{$not: {$lt: 5}}, {a: [4,5,6]}');
  25. },
  26. "Should not have an ElemMatchKey": function() {
  27. var lt = new LTMatchExpression();
  28. assert.strictEqual(lt.init('a',5).code,'OK');
  29. var op = new NotMatchExpression();
  30. assert.strictEqual( op.init( lt ).code,'OK');
  31. var details = new MatchDetails();
  32. details.requestElemMatchKey();
  33. assert.ok( ! op.matches({'a':[1]}, details), '{$not: {a: {$lt : 5}}}, {a: [1]}' );
  34. assert.ok( ! details.hasElemMatchKey() , 'ElemMatchKey Check');
  35. assert.ok( op.matches({'a': 6 }, details), '{$not: {a: {$lt : 5}}},{a: 6}');
  36. assert.ok( ! details.hasElemMatchKey(), 'ElemMatchKey Check');
  37. assert.ok( op.matches({'a':[6]}, details), '{$not: {a: {$lt : 5}}}, {a:[6]}');
  38. assert.ok( ! details.hasElemMatchKey() );
  39. }
  40. }
  41. };
  42. if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);