Browse Source

EAGLESIX-2995 Updated test cases for LTEMatchExpression

Jared Hall 11 years ago
parent
commit
49e8fb6618

+ 0 - 1
lib/pipeline/matcher/ComparisonMatchExpression.js

@@ -121,7 +121,6 @@ proto.matchesSingleElement = function matchesSingleElement(e) {
 		if (["MaxKey","MinKey"].indexOf(Value.getType(this._rhs)) != -1) {
 		if (["MaxKey","MinKey"].indexOf(Value.getType(this._rhs)) != -1) {
 			return this._matchType !== "EQ";
 			return this._matchType !== "EQ";
 		}
 		}
-
 		return false;
 		return false;
 	}
 	}
 
 

+ 1 - 2
test/lib/pipeline/matcher/GTMatchExpression.js

@@ -56,7 +56,7 @@ module.exports = {
 		},
 		},
 		"should match dot notation null" : function() {
 		"should match dot notation null" : function() {
 			var e = new GTMatchExpression();
 			var e = new GTMatchExpression();
-			var s = e.init("a",null);
+			var s = e.init("a.b",null);
 
 
 			assert.strictEqual(s.code, "OK");
 			assert.strictEqual(s.code, "OK");
 			assert.ok( !e.matchesJSON({}) );
 			assert.ok( !e.matchesJSON({}) );
@@ -65,7 +65,6 @@ module.exports = {
 			assert.ok( ! e.matchesJSON({"a":{}}) );
 			assert.ok( ! e.matchesJSON({"a":{}}) );
 			assert.ok( ! e.matchesJSON({"a":[{b:null}]}) );
 			assert.ok( ! e.matchesJSON({"a":[{b:null}]}) );
 			assert.ok( ! e.matchesJSON({"a":[{a:4},{b:4}]}) );
 			assert.ok( ! e.matchesJSON({"a":[{a:4},{b:4}]}) );
-			assert.ok( ! e.matchesJSON({"a":[{a:4},{b:4}]}) );
 			assert.ok( ! e.matchesJSON({"a":[4]}) );
 			assert.ok( ! e.matchesJSON({"a":[4]}) );
 			assert.ok( ! e.matchesJSON({"a":[{b:4}]}) );
 			assert.ok( ! e.matchesJSON({"a":[{b:4}]}) );
 		},
 		},

+ 55 - 29
test/lib/pipeline/matcher/LTEMatchExpression.js

@@ -1,5 +1,6 @@
 "use strict";
 "use strict";
 var assert = require("assert"),
 var assert = require("assert"),
+	BSON = require("bson"),
 	MatchDetails = require("../../../../lib/pipeline/matcher/MatchDetails"),
 	MatchDetails = require("../../../../lib/pipeline/matcher/MatchDetails"),
 	LTEMatchExpression = require("../../../../lib/pipeline/matcher/LTEMatchExpression");
 	LTEMatchExpression = require("../../../../lib/pipeline/matcher/LTEMatchExpression");
 
 
@@ -15,10 +16,10 @@ module.exports = {
 				lte = new LTEMatchExpression();
 				lte = new LTEMatchExpression();
 			var s = lte.init("",operand.$lte);
 			var s = lte.init("",operand.$lte);
 			assert.strictEqual(s.code, "OK");
 			assert.strictEqual(s.code, "OK");
-			assert.ok(lte.matchesSingleElement(match));
-			assert.ok(lte.matchesSingleElement(equalMatch));
-			assert.ok(!lte.matchesSingleElement(notMatch));
-			assert.ok(!lte.matchesSingleElement(notMatchWrongType));
+			assert.ok(lte.matchesSingleElement(match.a));
+			assert.ok(lte.matchesSingleElement(equalMatch.a));
+			assert.ok(!lte.matchesSingleElement(notMatch.a));
+			assert.ok(!lte.matchesSingleElement(notMatchWrongType.a));
 		},
 		},
 		"should not work for invalid eoo operand": function(){
 		"should not work for invalid eoo operand": function(){
 			var operand = {},
 			var operand = {},
@@ -33,43 +34,68 @@ module.exports = {
 			assert.ok(lte.matchesJSON({"a":4.5}, null));
 			assert.ok(lte.matchesJSON({"a":4.5}, null));
 			assert.ok(!lte.matchesJSON({"a":6}), null);
 			assert.ok(!lte.matchesJSON({"a":6}), null);
 		},
 		},
-		"should handle invalid End of Object Operand": function testInvalidEooOperand(){
-			var e = new LTEMatchExpression();
-			var s = e.init("",{});
-
-			assert.strictEqual(s.code, "BAD_VALUE");
-		},
-		"should match a pathed number":function() {
+		"should match array value": function() {
 			var e = new LTEMatchExpression();
 			var e = new LTEMatchExpression();
 			var s = e.init("a",5);
 			var s = e.init("a",5);
 
 
 			assert.strictEqual(s.code, "OK");
 			assert.strictEqual(s.code, "OK");
-			assert.ok( e.matches({"a":4.5}) );
-			assert.ok( ! e.matches({"a":6}) );
+			assert.ok( e.matchesJSON({"a":[6,4.5]}) );
+			assert.ok( ! e.matchesJSON({"a":[6,7]}) );
 		},
 		},
-		"should match stuff in an array": function() {
-			var e = new LTEMatchExpression();
-			var s = e.init("a",5);
+		"should match whole array" : function() {
+			var e = new LTEMatchExpression(),
+				s = e.init("a",[5]);
 
 
 			assert.strictEqual(s.code, "OK");
 			assert.strictEqual(s.code, "OK");
-			assert.ok( e.matches({"a":[6,4.5]}) );
-			assert.ok( ! e.matches({"a":[6,7]}) );
+			assert.ok(e.matchesJSON({"a":[4]}));
+			assert.ok(e.matchesJSON({"a":[5]}));
+			assert.ok(!e.matchesJSON({"a":[6]}));
+			assert.ok(e.matchesJSON({"a":[[4]]}));
+			assert.ok(e.matchesJSON({"a":[[5]]}));
+			assert.ok(!e.matchesJSON({"a":[[6]]}));
 		},
 		},
-		"should not match full array" : function() {
+		"should match null" : function() {
 			var e = new LTEMatchExpression();
 			var e = new LTEMatchExpression();
-			var s = e.init("a",[5]);
+			var s = e.init("a",null);
 
 
 			assert.strictEqual(s.code, "OK");
 			assert.strictEqual(s.code, "OK");
-			assert.ok(e.matches({"a":[4]}) );
+			assert.ok( e.matchesJSON({}) );
+			assert.ok( e.matchesJSON({"a":null}) );
+			assert.ok( ! e.matchesJSON({"a":4}) );
+			// A non-existent field is treated same way as an empty bson object
+			assert.ok( e.matchesJSON({"b":4}) );
 		},
 		},
-		"should not match null" : function() {
+		"should match dot notation null" : function() {
 			var e = new LTEMatchExpression();
 			var e = new LTEMatchExpression();
-			var s = e.init("a",null);
+			var s = e.init("a.b",null);
 
 
 			assert.strictEqual(s.code, "OK");
 			assert.strictEqual(s.code, "OK");
-			assert.ok( e.matches({}) );
-			assert.ok( e.matches({"a":null}) );
-			assert.ok( ! e.matches({"a":4}) );
+			assert.ok( e.matchesJSON({}) );
+			assert.ok( e.matchesJSON({"a":null}) );
+			assert.ok( e.matchesJSON({"a":4}) );
+			assert.ok( e.matchesJSON({"a":{}}) );
+			assert.ok( e.matchesJSON({"a":[{b:null}]}) );
+			assert.ok( e.matchesJSON({"a":[{a:4},{b:4}]}) );
+			assert.ok( ! e.matchesJSON({"a":[4]}) );
+			assert.ok( ! e.matchesJSON({"a":[{b:4}]}) );
+		},
+		"should match MinKey": function (){
+			var operand = {a:new BSON.MinKey()},
+				e = new LTEMatchExpression();
+			var s = e.init("a",operand.a);
+			assert.strictEqual(s.code, "OK");
+			assert.ok(e.matchesJSON({"a":new BSON.MinKey()}, null));
+			assert.ok(!e.matchesJSON({"a":new BSON.MaxKey()}, null));
+			assert.ok(!e.matchesJSON({"a":4}), null);
+		},
+		"should match MaxKey": function (){
+			var operand = {a:new BSON.MaxKey()},
+				e = new LTEMatchExpression();
+			var s = e.init("a",operand.a);
+			assert.strictEqual(s.code, "OK");
+			assert.ok(e.matchesJSON({"a":new BSON.MaxKey()}, null));
+			assert.ok(e.matchesJSON({"a":new BSON.MinKey()}, null));
+			assert.ok(e.matchesJSON({"a":4}), null);
 		},
 		},
 		"should handle elemMatchKey":function() {
 		"should handle elemMatchKey":function() {
 			var e = new LTEMatchExpression();
 			var e = new LTEMatchExpression();
@@ -78,13 +104,13 @@ module.exports = {
 			m.requestElemMatchKey();
 			m.requestElemMatchKey();
 			assert.strictEqual( s.code, "OK" );
 			assert.strictEqual( s.code, "OK" );
 
 
-			assert.ok( ! e.matches({"a":6}, m) );
+			assert.ok( ! e.matchesJSON({"a":6}, m) );
 			assert.ok( ! m.hasElemMatchKey() );
 			assert.ok( ! m.hasElemMatchKey() );
 
 
-			assert.ok( e.matches({"a":4}, m) );
+			assert.ok( e.matchesJSON({"a":4}, m) );
 			assert.ok( ! m.hasElemMatchKey() );
 			assert.ok( ! m.hasElemMatchKey() );
 
 
-			assert.ok( e.matches({"a":[6,2,5]}, m));
+			assert.ok( e.matchesJSON({"a":[6,2,5]}, m));
 			assert.ok( m.hasElemMatchKey());
 			assert.ok( m.hasElemMatchKey());
 			assert.strictEqual("1", m.elemMatchKey());
 			assert.strictEqual("1", m.elemMatchKey());
 		}
 		}