Browse Source

ref #3359: Ported a few initial test cases

Brennan Chesley 12 years ago
parent
commit
34380a6157

+ 30 - 0
test/lib/pipeline/matcher/NotMatchExpression.js

@@ -0,0 +1,30 @@
+"use strict";
+var assert = require("assert"),
+	NotMatchExpression = require("../../../../lib/pipeline/matcher/NotMatchExpression"),
+	LTMatchExpression = require("../../../../lib/pipeline/matcher/LTMatchExpression"), 
+	GTMatchExpression = require("../../../../lib/pipeline/matcher/GTMatchExpression");	
+
+module.exports = {
+	"NotMatchExpression": {
+		"Should match a scalar": function (){
+			var lt = new LTMatchExpression();
+			assert.strictEqual(lt.init('a', 5)['code'],'OK');
+			var op = new NotMatchExpression();
+			assert.strictEqual( op.init(lt)['code'], 'OK');
+			assert.ok( op.matches({'a':6}), '{$not: {$lt: 5}}, {a:6}' );
+			assert.ok( !op.matches({'a':4}), '{$not: {$lt: 5}}, {a:4}' );
+		},
+		"Should match an Array": function() {
+			var lt = new LTMatchExpression();
+			assert.strictEqual(lt.init('a',5)['code'],'OK');
+			var op = new NotMatchExpression();
+			assert.strictEqual(op.init(lt)['code'],'OK');
+			assert.ok( op.matches({'a': [6]}) , '{$not: {$lt: 5}}, {a: [6]}');	
+			assert.ok( !op.matches({'a': [4]}) , '{$not: {$lt: 5}}, {a: [4]}');	
+			assert.ok( !op.matches({'a': [4,5,6]}) , '{$not: {$lt: 5}}, {a: [4,5,6]}');
+			}
+		}
+};
+
+if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);
+

+ 24 - 0
test/lib/pipeline/matcher/OrMatchExpression.js

@@ -0,0 +1,24 @@
+"use strict";
+var assert = require("assert"),
+	OrMatchExpression = require("../../../../lib/pipeline/matcher/OrMatchExpression"),
+	GTEMatchExpression = require("../../../../lib/pipeline/matcher/GTEMatchExpression");
+
+
+module.exports = {
+	"OrMatchExpression": {
+		"Should not match with 0 clauses": function (){
+			var op = new OrMatchExpression();
+			assert.ok( ! op.matches(5, '{$or: []}, 5'));
+		},
+		"Should match with a single matching clause": function() {
+			var op = new OrMatchExpression();
+			var gt = new GTEMatchExpression();
+			gt.init('', 5);
+			op.add(gt);
+			assert.ok( op.matches(6) , '{$or: [{$gte: 5}]}, 6');
+			}
+		}
+}
+
+if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);
+