NotMatchExpression.js 1.2 KB

123456789101112131415161718192021222324252627282930
  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. module.exports = {
  7. "NotMatchExpression": {
  8. "Should match a scalar": function (){
  9. var lt = new LTMatchExpression();
  10. assert.strictEqual(lt.init('a', 5)['code'],'OK');
  11. var op = new NotMatchExpression();
  12. assert.strictEqual( op.init(lt)['code'], 'OK');
  13. assert.ok( op.matches({'a':6}), '{$not: {$lt: 5}}, {a:6}' );
  14. assert.ok( !op.matches({'a':4}), '{$not: {$lt: 5}}, {a:4}' );
  15. },
  16. "Should match an Array": function() {
  17. var lt = new LTMatchExpression();
  18. assert.strictEqual(lt.init('a',5)['code'],'OK');
  19. var op = new NotMatchExpression();
  20. assert.strictEqual(op.init(lt)['code'],'OK');
  21. assert.ok( op.matches({'a': [6]}) , '{$not: {$lt: 5}}, {a: [6]}');
  22. assert.ok( !op.matches({'a': [4]}) , '{$not: {$lt: 5}}, {a: [4]}');
  23. assert.ok( !op.matches({'a': [4,5,6]}) , '{$not: {$lt: 5}}, {a: [4,5,6]}');
  24. }
  25. }
  26. };
  27. if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);