Browse Source

ref #3359: Pass AndMatchExpression tests

Brennan Chesley 12 years ago
parent
commit
69da503c91

+ 5 - 1
lib/pipeline/matcher/AndMatchExpression.js

@@ -32,12 +32,16 @@ proto.debugString = function debugString( level ) { //  StringBuilder& debug, in
  */
 proto.matches = function matches( doc, details ) { //  const MatchableDocument* doc, MatchDetails* details
 // File: expression_tree.cpp lines: 64-72	
+	var tChild;
 	for (var i = 0; i < this.numChildren(); i++) {
-		if (!this.getChild(i).matches(doc,details)) {
+		tChild = this.getChild(i);
+		if ( ! tChild.matches(doc,details)) {
 			if (details) {
 				details.resetOutput();
 			}
 			return false;
+		} else {
+			debugger;
 		}
 	}
 	return true;

+ 5 - 0
lib/pipeline/matcher/CLUDGES

@@ -14,4 +14,9 @@ debugString takes one argument 'level', as does debugAddSpace. Debug statements
 
 verify is a macro function that throws an exception if the input is falsey, with the current file and lineno, so there is no need for the function itself
 
+.get() returns a copy of whatever called it. Since we don't manually manage memory, we don't need this.
+
+.release() is manual memory management, it gets dropped.
+
+obj.reset( arg ) is replaced with obj = arg; Everything else that happens in reset is manual memory management.
 

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

@@ -167,7 +167,7 @@ proto.matchesSingleElement = function matchesSingleElement( e ){ //  const BSONE
 			return x === 0;
 			break;
 		case "GT":
-			return x == 1;
+			return x === 1;
 			break;
 		case "GTE":
 			return x >= 0;

+ 0 - 5
lib/pipeline/matcher/ElementPath.js

@@ -130,20 +130,15 @@ proto.shouldTraverseLeafArray = function shouldTraverseLeafArray( /*  */ ){
 
 
 klass.objAtPath = function objAtPath( doc,path) {
-	debugger;
 	if(path.length == 0) {
-		debugger;
 		return doc;
 	}
 	if (path.length > 0 && Object.keys(doc).length == 0){
-		debugger;
 		return {};
 	}
 	if (doc === null || doc === undefined) {
-		debugger;
 		return doc;
 	}
 	var tpath = path.split('.');
-	debugger;
 	return klass.objAtPath(doc[tpath[0]],tpath.slice(1).join('.'));
 };

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

@@ -4,8 +4,8 @@ var ComparisonMatchExpression = require('./ComparisonMatchExpression');
 
 // Autogenerated by cport.py on 2013-09-17 14:37
 var GTMatchExpression = module.exports = function GTMatchExpression(){
-	this._matchType = 'GTE'
-}, klass = GTMatchExpression, base =  Object  , proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
+	this._matchType = 'GT'
+}, klass = GTMatchExpression, base =  ComparisonMatchExpression  , proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 
 
 /**

+ 42 - 0
test/lib/pipeline/matcher/AndMatchExpression.js

@@ -0,0 +1,42 @@
+"use strict";
+var assert = require("assert"),
+	AndMatchExpression = require("../../../../lib/pipeline/matcher/AndMatchExpression"),
+	LTMatchExpression = require("../../../../lib/pipeline/matcher/LTMatchExpression"),
+	GTMatchExpression = require("../../../../lib/pipeline/matcher/GTMatchExpression"),
+	RegexMatchExpression = require("../../../../lib/pipeline/matcher/RegexMatchExpression"),
+	EqualityMatchExpression = require("../../../../lib/pipeline/matcher/EqualityMatchExpression");
+
+
+
+module.exports = {
+	"AndMatchExpression": {
+		"Should match nothing with no clauses": function (){
+			var op = new AndMatchExpression();
+			assert.ok( op.matches({}));
+		},
+		"Should match with a three element clause": function() {
+			var lt = new LTMatchExpression();
+			var gt = new GTMatchExpression();
+			var rgx = new RegexMatchExpression();
+			var op = new AndMatchExpression();
+
+			assert.strictEqual( lt.init('a','z1')['code'],'OK');
+			assert.strictEqual( gt.init('a','a1')['code'],'OK');
+			assert.strictEqual( rgx.init('a','1','')['code'],'OK');
+			
+			op.add(lt);
+			op.add(gt);
+			op.add(rgx);
+
+			assert.ok( op.matches({'a':'r1'}) );
+			assert.ok( ! op.matches({'a': 'z1'}) );
+			debugger;
+			assert.ok( ! op.matches({'a': 'a1'}) );
+			assert.ok( ! op.matches({'a':'r'}) );
+			}
+
+		}
+}
+
+if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);
+