Browse Source

EAGLESIX-2995 updated GTE, GT, LTE, LT to mongo 2.6.5

Jared Hall 11 years ago
parent
commit
57be52299c

+ 15 - 13
lib/pipeline/matcher/GTEMatchExpression.js

@@ -1,24 +1,26 @@
 "use strict";
 
-var ComparisonMatchExpression = require('./ComparisonMatchExpression');
+var ComparisonMatchExpression = require("./ComparisonMatchExpression");
 
-// Autogenerated by cport.py on 2013-09-17 14:37
+/**
+ * File: matcher/expression_leaf.h
+ * @class GTEMatchExpression
+ * @namespace mungedb-aggregate.pipeline.matcher
+ * @module mungedb-aggregate
+ * @constructor
+ */
 var GTEMatchExpression = module.exports = function GTEMatchExpression(){
-	base.call(this);
-	this._matchType = 'GTE';
-}, klass = GTEMatchExpression, base =  ComparisonMatchExpression, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
+	base.call(this, "GTE");
+}, klass = GTEMatchExpression, base = ComparisonMatchExpression, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 
 /**
- *
- * Return a new instance of this class, with fields set the same as ourself
  * @method shallowClone
- * @param
- *
  */
-proto.shallowClone = function shallowClone( /*  */ ){
-// File: expression_leaf.h lines: 141-144
+proto.shallowClone = function shallowClone(){
 	var e = new GTEMatchExpression();
-	e.init( this.path(), this._rhs );
+	e.init(this.path(), this._rhs);
+	if(this.getTag()) {
+		e.setTag(this.getTag().clone());
+	}
 	return e;
 };
-

+ 14 - 13
lib/pipeline/matcher/GTMatchExpression.js

@@ -1,25 +1,26 @@
 "use strict";
 
-var ComparisonMatchExpression = require('./ComparisonMatchExpression.js');
+var ComparisonMatchExpression = require("./ComparisonMatchExpression.js");
 
-// Autogenerated by cport.py on 2013-09-17 14:37
+/**
+ * File: matcher/expression_leaf.h
+ * @class GTMatchExpression
+ * @namespace mungedb-aggregate.pipeline.matcher
+ * @module mungedb-aggregate
+ * @constructor
+ */
 var GTMatchExpression = module.exports = function GTMatchExpression(){
-	base.call(this);
-	this._matchType = 'GT';
+	base.call(this, "GT");
 }, klass = GTMatchExpression, base = ComparisonMatchExpression, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 
-
 /**
- *
- * Return a new instance of this class, with fields set the same as ourself
  * @method shallowClone
- * @param
- *
  */
-proto.shallowClone = function shallowClone( /* */ ){
-	// File: expression_leaf.h lines: 130-133
+proto.shallowClone = function shallowClone(){
 	var e = new GTMatchExpression();
-	e.init( this.path(), this._rhs );
+	e.init(this.path(), this._rhs);
+	if(this.getTag()) {
+		e.setTag(this.getTag().clone());
+	}
 	return e;
 };
-

+ 14 - 12
lib/pipeline/matcher/LTEMatchExpression.js

@@ -1,24 +1,26 @@
 "use strict";
 
-var ComparisonMatchExpression = require('./ComparisonMatchExpression');
+var ComparisonMatchExpression = require("./ComparisonMatchExpression");
 
-// Autogenerated by cport.py on 2013-09-17 14:37
+/**
+ * File: matcher/expression_leaf.h
+ * @class LTEMatchExpression
+ * @namespace mungedb-aggregate.pipeline.matcher
+ * @module mungedb-aggregate
+ * @constructor
+ */
 var LTEMatchExpression = module.exports = function LTEMatchExpression(){
-	base.call(this);
-	this._matchType = 'LTE';
+	base.call(this, "LTE");
 }, klass = LTEMatchExpression, base = ComparisonMatchExpression, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 
 /**
- *
- * Return a new instance of this class, with fields set the same as ourself
  * @method shallowClone
- * @param
- *
  */
-proto.shallowClone = function shallowClone( /* */ ){
-	// File: expression_leaf.h lines: 108-111
+proto.shallowClone = function shallowClone(){
 	var e = new LTEMatchExpression();
-	e.init( this.path(), this._rhs );
+	e.init(this.path(), this._rhs);
+	if(this.getTag()) {
+		e.setTag(this.getTag().clone());
+	}
 	return e;
 };
-

+ 14 - 12
lib/pipeline/matcher/LTMatchExpression.js

@@ -1,24 +1,26 @@
 "use strict";
 
-var ComparisonMatchExpression = require('./ComparisonMatchExpression');
+var ComparisonMatchExpression = require("./ComparisonMatchExpression");
 
-// Autogenerated by cport.py on 2013-09-17 14:37
+/**
+ * File: matcher/expression_leaf.h
+ * @class LTMatchExpression
+ * @namespace mungedb-aggregate.pipeline.matcher
+ * @module mungedb-aggregate
+ * @constructor
+ */
 var LTMatchExpression = module.exports = function LTMatchExpression(){
-	base.call(this);
-	this._matchType = 'LT';
+	base.call(this, "LT");
 }, klass = LTMatchExpression, base = ComparisonMatchExpression, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 
 /**
- *
- * Return a new instance of this class, with fields set the same as ourself
  * @method shallowClone
- * @param
- *
  */
-proto.shallowClone = function shallowClone( /* */ ){
-	// File: expression_leaf.h lines: 119-122
+proto.shallowClone = function shallowClone(){
 	var e = new LTMatchExpression();
-	e.init( this.path(), this._rhs );
+	e.init(this.path(), this._rhs);
+	if(this.getTag()) {
+		e.setTag(this.getTag().clone());
+	}
 	return e;
 };
-

+ 2 - 1
package.json

@@ -33,7 +33,8 @@
     "mocha": "*",
     "jshint": "*",
     "jscoverage": "*",
-    "jscheckstyle": "*"
+    "jscheckstyle": "*",
+    "bson": "0.2.15"
   },
   "license": "AGPL",
   "private": true,

+ 84 - 59
test/lib/pipeline/matcher/GTMatchExpression.js

@@ -1,75 +1,100 @@
 "use strict";
 var assert = require("assert"),
-	MatchDetails = require('../../../../lib/pipeline/matcher/MatchDetails'),
+	BSON = require("bson"),
+	MatchDetails = require("../../../../lib/pipeline/matcher/MatchDetails"),
 	GTMatchExpression = require("../../../../lib/pipeline/matcher/GTMatchExpression");
 
 
 module.exports = {
 	"GTMatchExpression": {
-		"should match scalars and strings properly": function (){
-			var e = new GTMatchExpression();
-			var s = e.init('x',5);
-
-			assert.strictEqual(s.code, 'OK');
-			assert.ok( ! e.matches({'x':5}) );
-			assert.ok( ! e.matches({'x':4}) );
-			assert.ok( e.matches({'x':6}) );
-			assert.ok( ! e.matches({'x': 'eliot'}) );
+		"should match scalars properly": function (){
+			var operand = {$gt:5},
+				gt = new GTMatchExpression();
+			var s = gt.init("a",operand.$gt);
+			assert.strictEqual(s.code, "OK");
+			assert.ok(gt.matchesJSON({"a":5.5}, null));
+			assert.ok(!gt.matchesJSON({"a":4}), null);
 		},
-		"should handle invalid End of Object Operand": function testInvalidEooOperand(){
-			var e = new GTMatchExpression();
-			var s = e.init('',{});
-
-			assert.strictEqual(s.code, 'BAD_VALUE');
+		"should match array values": function (){
+			var operand = {$gt:5},
+				gt = new GTMatchExpression();
+			var s = gt.init("a",operand.$gt);
+			assert.strictEqual(s.code, "OK");
+			assert.ok(gt.matchesJSON({"a":[3,5.5]}, null));
+			assert.ok(!gt.matchesJSON({"a":[2,4]}), null);
 		},
-		"should match a pathed number":function() {
-			var e = new GTMatchExpression();
-			var s = e.init('a',5);
-
-			assert.strictEqual(s.code, 'OK');
-			assert.ok( e.matches({'a':5.5}) );
-			assert.ok( ! e.matches({'a':4}) );
+		"should match whole arrays": function (){
+			var operand = {$gt:5},
+				gt = new GTMatchExpression();
+			var s = gt.init("a",operand.$gt);
+			assert.strictEqual(s.code, "OK");
+			assert.ok(!gt.matchesJSON({"a":[4]}, null));
+			assert.ok(!gt.matchesJSON({"a":[5]}, null));
+			assert.ok(gt.matchesJSON({"a":[6]}, null));
+			// Nested array.
+			// XXX: The following assertion documents current behavior.
+			assert.ok(gt.matchesJSON({"a":[[4]]}, null));
+			// XXX: The following assertion documents current behavior.
+			assert.ok(gt.matchesJSON({"a":[[5]]}, null));
+			assert.ok(gt.matchesJSON({"a":[[6]]}, null));
 		},
-		"should match stuff in an array": function() {
-			var e = new GTMatchExpression();
-			var s = e.init('a',5);
-
-			assert.strictEqual(s.code, 'OK');
-			assert.ok( e.matches({'a':[3,5.5]}) );
-			assert.ok( ! e.matches({'a':[2,4]}) );
+		"should match null values": function (){
+			var operand = {$gt:null},
+				gt = new GTMatchExpression();
+			var s = gt.init("a",operand.$gt);
+			assert.strictEqual(s.code, "OK");
+			assert.ok(!gt.matchesJSON({}, null));
+			assert.ok(!gt.matchesJSON({"a":null}, null));
+			assert.ok(!gt.matchesJSON({"a":4}), null);
+			// A non-existent field is treated same way as an empty bson object
+			assert.ok(!gt.matchesJSON({"b":4}), null);
 		},
-		"should not match full array" : function() {
-			var e = new GTMatchExpression();
-			var s = e.init('a',[5]);
-
-			assert.strictEqual(s.code, 'OK');
-			assert.ok( ! e.matches({'a':[6]}) );
+		"should match dot notation when null": function (){
+			var operand = {$gt:null},
+				gt = new GTMatchExpression();
+			var s = gt.init("a.b",operand.$gt);
+			assert.strictEqual(s.code, "OK");
+			assert.ok(!gt.matchesJSON({}, null));
+			assert.ok(!gt.matchesJSON({"a":null}, null));
+			assert.ok(!gt.matchesJSON({"a":4}), null);
+			assert.ok(!gt.matchesJSON({"a":{}}), null);
+			assert.ok(!gt.matchesJSON({"a":[{b:null}]}), null);
+			assert.ok(!gt.matchesJSON({"a":[{a:4},{b:4}]}), null);
+			assert.ok(!gt.matchesJSON({"a":[4]}), null);
+			assert.ok(!gt.matchesJSON({"a":[{b:4}]}), null);
 		},
-		"should not match null" : function() {
-			var e = new GTMatchExpression();
-			var s = e.init('a',null);
-		
-			assert.strictEqual(s.code, 'OK');
-			assert.ok( !e.matches({}) );
-			assert.ok( !e.matches({'a':null}) );
-			assert.ok( ! e.matches({'a':4}) );
+		"should match MinKey": function (){
+			var operand = {a:new BSON.MinKey()},
+				gt = new GTMatchExpression();
+			var s = gt.init("a",operand.a);
+			assert.strictEqual(s.code, "OK");
+			assert.ok(!gt.matchesJSON({"a":new BSON.MinKey()}, null));
+			assert.ok(gt.matchesJSON({"a":new BSON.MaxKey()}, null));
+			assert.ok(gt.matchesJSON({"a":4}), null);
 		},
-		"should handle elemMatchKey":function() {
-			var e = new GTMatchExpression();
-			var s = e.init('a',5);
-			var m = new MatchDetails();
-			m.requestElemMatchKey();
-			assert.strictEqual( s.code, 'OK' );
-
-			assert.ok( ! e.matches({'a':4}, m) );
-			assert.ok( ! m.hasElemMatchKey() );
-
-			assert.ok( e.matches({'a':6}, m) );
-			assert.ok( ! m.hasElemMatchKey() );
-
-			assert.ok( e.matches({'a':[2,6,5]}, m));
-			assert.ok( m.hasElemMatchKey());
-			assert.strictEqual('1', m.elemMatchKey());
+		"should match MaxKey": function (){
+			var operand = {a:new BSON.MaxKey()},
+				gt = new GTMatchExpression();
+			var s = gt.init("a",operand.a);
+			assert.strictEqual(s.code, "OK");
+			assert.ok(!gt.matchesJSON({"a":new BSON.MaxKey()}, null));
+			assert.ok(!gt.matchesJSON({"a":new BSON.MinKey()}, null));
+			assert.ok(!gt.matchesJSON({"a":4}), null);
+		},
+		"should use ElemMatchKey": function(){
+			var operand = {$gt:5},
+				gt = new GTMatchExpression(),
+				s = gt.init("a",operand.$gt);
+			assert.strictEqual(s.code, "OK");
+			var details = new MatchDetails();
+			details.requestElemMatchKey();
+			assert(!gt.matchesJSON({a:4}, details));
+			assert(!details.hasElemMatchKey());
+			assert(gt.matchesJSON({a:6}, details));
+			assert(!details.hasElemMatchKey());
+			assert(gt.matchesJSON({a:[2,6,5]}, details));
+			assert(details.hasElemMatchKey());
+			assert.strictEqual(details.elemMatchKey(), "1");
 		}
 	}
 };

+ 101 - 60
test/lib/pipeline/matcher/LTEMatchExpression.js

@@ -1,75 +1,116 @@
 "use strict";
 var assert = require("assert"),
-	MatchDetails = require('../../../../lib/pipeline/matcher/MatchDetails'),
+	BSON = require("bson"),
+	MatchDetails = require("../../../../lib/pipeline/matcher/MatchDetails"),
 	LTEMatchExpression = require("../../../../lib/pipeline/matcher/LTEMatchExpression");
 
-
 module.exports = {
 	"LTEMatchExpression": {
-		"should match scalars and strings properly": function (){
-			var e = new LTEMatchExpression();
-			var s = e.init('x',5);
-			
-			assert.strictEqual(s.code, 'OK');
-			assert.ok( e.matches({'x':5}) );
-			assert.ok( e.matches({'x':4}) );
-			assert.ok( ! e.matches({'x':6}) );
-			assert.ok( ! e.matches({'x': 'eliot'}) );
+		"should match element": function (){
+			var operand = {$lte:5},
+				match = {a:4.5},
+				equalMatch = {a:4.5},
+				notMatch = {a:6},
+				notMatchWrongType = {a:"foo"},
+				lte = new LTEMatchExpression();
+			var s = lte.init("",operand.$lte);
+			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));
 		},
-		"should handle invalid End of Object Operand": function testInvalidEooOperand(){
-			var e = new LTEMatchExpression();
-			var s = e.init('',{});
-
-			assert.strictEqual(s.code, 'BAD_VALUE');
+		"should not work for invalid eoo operand": function(){
+			var operand = {},
+				lte = new LTEMatchExpression();
+			assert.ok(lte.init("", operand).code !== "OK");
 		},
-		"should match a pathed number":function() {
-			var e = new LTEMatchExpression();
-			var s = e.init('a',5);
-
-			assert.strictEqual(s.code, 'OK');
-			assert.ok( e.matches({'a':4.5}) );
-			assert.ok( ! e.matches({'a':6}) );
+		"should match scalars properly": function (){
+			var operand = {$lte:5},
+				lte = new LTEMatchExpression();
+			var s = lte.init("a",operand.$lte);
+			assert.strictEqual(s.code, "OK");
+			assert.ok(lte.matchesJSON({"a":4.5}, null));
+			assert.ok(!lte.matchesJSON({"a":6}), null);
 		},
-		"should match stuff in an array": function() {
-			var e = new LTEMatchExpression();
-			var s = e.init('a',5);
-
-			assert.strictEqual(s.code, 'OK');
-			assert.ok( e.matches({'a':[6,4.5]}) );
-			assert.ok( ! e.matches({'a':[6,7]}) );
+		"should match array values": function (){
+			var operand = {$lte:5},
+				lte = new LTEMatchExpression();
+			var s = lte.init("a",operand.$lte);
+			assert.strictEqual(s.code, "OK");
+			assert.ok(lte.matchesJSON({"a":[6,4.5]}, null));
+			assert.ok(!lte.matchesJSON({"a":[6,7]}), null);
 		},
-		"should not match full array" : function() {
-			var e = new LTEMatchExpression();
-			var s = e.init('a',[5]);
-
-			assert.strictEqual(s.code, 'OK');
-			assert.ok( ! e.matches({'a':[4]}) );
+		"should match whole arrays": function (){
+			var operand = {$lte:5},
+				lte = new LTEMatchExpression();
+			var s = lte.init("a",operand.$lte);
+			assert.strictEqual(s.code, "OK");
+			assert.ok(lte.matchesJSON({"a":[4]}, null));
+			assert.ok(lte.matchesJSON({"a":[5]}, null));
+			assert.ok(!lte.matchesJSON({"a":[6]}, null));
+			// Nested array.
+			assert.ok(lte.matchesJSON({"a":[[4]]}, null));
+			assert.ok(lte.matchesJSON({"a":[[5]]}, null));
+			assert.ok(!lte.matchesJSON({"a":[[6]]}, null));
 		},
-		"should not match null" : function() {
-			var e = new LTEMatchExpression();
-			var s = e.init('a',null);
-		
-			assert.strictEqual(s.code, 'OK');
-			assert.ok( e.matches({}) );
-			assert.ok( e.matches({'a':null}) );
-			assert.ok( ! e.matches({'a':4}) );
+		"should match null values": function (){
+			var operand = {$lte:null},
+				lte = new LTEMatchExpression();
+			var s = lte.init("a",operand.$lte);
+			assert.strictEqual(s.code, "OK");
+			assert.ok(lte.matchesJSON({}, null));
+			assert.ok(lte.matchesJSON({"a":null}, null));
+			assert.ok(!lte.matchesJSON({"a":4}), null);
+			// A non-existent field is treated same way as an empty bson object
+			assert.ok(lte.matchesJSON({"b":4}), null);
 		},
-		"should handle elemMatchKey":function() {
-			var e = new LTEMatchExpression();
-			var s = e.init('a',5);
-			var m = new MatchDetails();
-			m.requestElemMatchKey();
-			assert.strictEqual( s.code, 'OK' );
-
-			assert.ok( ! e.matches({'a':6}, m) );
-			assert.ok( ! m.hasElemMatchKey() );
-
-			assert.ok( e.matches({'a':4}, m) );
-			assert.ok( ! m.hasElemMatchKey() );
-
-			assert.ok( e.matches({'a':[6,2,5]}, m));
-			assert.ok( m.hasElemMatchKey());
-			assert.strictEqual('1', m.elemMatchKey());
+		"should match dot notation when null": function (){
+			var operand = {$lte:null},
+				lte = new LTEMatchExpression();
+			var s = lte.init("a.b",operand.$lte);
+			assert.strictEqual(s.code, "OK");
+			assert.ok(lte.matchesJSON({}, null));
+			assert.ok(lte.matchesJSON({"a":null}, null));
+			assert.ok(lte.matchesJSON({"a":4}), null);
+			assert.ok(lte.matchesJSON({"a":{}}), null);
+			assert.ok(lte.matchesJSON({"a":[{b:null}]}), null);
+			assert.ok(lte.matchesJSON({"a":[{a:4},{b:4}]}), null);
+			assert.ok(!lte.matchesJSON({"a":[4]}), null);
+			assert.ok(!lte.matchesJSON({"a":[{b:4}]}), null);
+		},
+		"should match MinKey": function (){
+			var operand = {a:new BSON.MinKey()},
+				lte = new LTEMatchExpression();
+			var s = lte.init("a",operand.a);
+			assert.strictEqual(s.code, "OK");
+			assert.ok(lte.matchesJSON({"a":new BSON.MinKey()}, null));
+			assert.ok(!lte.matchesJSON({"a":new BSON.MaxKey()}, null));
+			assert.ok(!lte.matchesJSON({"a":4}), null);
+		},
+		"should match MaxKey": function (){
+			var operand = {a:new BSON.MaxKey()},
+				lte = new LTEMatchExpression();
+			var s = lte.init("a",operand.a);
+			assert.strictEqual(s.code, "OK");
+			assert.ok(lte.matchesJSON({"a":new BSON.MaxKey()}, null));
+			assert.ok(lte.matchesJSON({"a":new BSON.MinKey()}, null));
+			assert.ok(lte.matchesJSON({"a":4}), null);
+		},
+		"should use ElemMatchKey": function(){
+			var operand = {$lte:5},
+				lte = new LTEMatchExpression(),
+				s = lte.init("a",operand.$lte);
+			assert.strictEqual(s.code, "OK");
+			var details = new MatchDetails();
+			details.requestElemMatchKey();
+			assert(!lte.matchesJSON({a:6}, details));
+			assert(!details.hasElemMatchKey());
+			assert(lte.matchesJSON({a:4}, details));
+			assert(!details.hasElemMatchKey());
+			assert(lte.matchesJSON({a:[6,2,5]}, details));
+			assert(details.hasElemMatchKey());
+			assert.strictEqual(details.elemMatchKey(), "1");
 		}
 
 	}