Преглед изворни кода

EAGLESIX-2981: FalseMatchExpression and tests

Jason Walton пре 11 година
родитељ
комит
7bb174ee5f

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

@@ -3,7 +3,6 @@ var MatchExpression = require('./MatchExpression');
 
 /**
  * A match expression that always returns false
- * @see evaluate
  * @class FalseMatchExpression
  * @namespace mungedb-aggregate.pipeline.matcher
  * @module mungedb-aggregate
@@ -77,4 +76,5 @@ proto.shallowClone = function shallowClone(){
  */
 proto.toJson = function toJson(out){
 	out["$false"] = 1;
+	return out;
 };

+ 51 - 0
test/lib/pipeline/matcher/FalseMatchExpression.js

@@ -0,0 +1,51 @@
+"use strict";
+var assert = require("assert"),
+	FalseMatchExpression = require("../../../../lib/pipeline/matcher/FalseMatchExpression");
+
+
+module.exports = {
+	"FalseMatchExpression": {
+
+		"Constructor": function (){
+			var e = new FalseMatchExpression();
+			assert.equal(e._matchType, "ALWAYS_FALSE");
+		},
+
+		"DebugString": function () {
+			var e = new FalseMatchExpression();
+			assert.equal(e.debugString(0), "$false\n");
+		},
+
+		"Equivalent": function () {
+			var a = new FalseMatchExpression(),
+				b = new FalseMatchExpression();
+			assert.equal(a.equivalent(b), true);
+		},
+
+		"Matches": function () {
+			var e = new FalseMatchExpression();
+			assert.equal(e.matches({},{}), false);
+		},
+
+		"MatchesSingleElement": function () {
+			var e = new FalseMatchExpression();
+			assert.equal(e.matchesSingleElement({}), false);
+		},
+
+		"ShallowClone": function () {
+			var e = new FalseMatchExpression();
+			assert.deepEqual(e.shallowClone(), new FalseMatchExpression());
+		},
+
+		"toJson": function () {
+			var e = new FalseMatchExpression(),
+				obj = {};
+			assert.deepEqual(e.toJson(obj), {"$false":1});
+		}
+
+	}
+
+};
+
+if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);
+