浏览代码

EAGLESIX3005: ListOfMatchExpression tests

Jason Walton 11 年之前
父节点
当前提交
d9d5db0c5e
共有 2 个文件被更改,包括 74 次插入1 次删除
  1. 2 1
      lib/pipeline/matcher/ListOfMatchExpression.js
  2. 72 0
      test/lib/pipeline/matcher/ListOfMatchExpression.js

+ 2 - 1
lib/pipeline/matcher/ListOfMatchExpression.js

@@ -9,7 +9,7 @@ var MatchExpression = require('./MatchExpression');
  * @module mungedb-aggregate
  * @constructor
  */
-vvar ListOfMatchExpression = module.exports = function ListOfMatchExpression(matchType){
+var ListOfMatchExpression = module.exports = function ListOfMatchExpression(matchType){
 	base.call(this);
 	this._expressions = [];
 	this._matchType = matchType;
@@ -102,6 +102,7 @@ proto.equivalent = function equivalent(other){
 	if (this._matchType != other._matchType)
 		return false;
 
+	debugger
 	var realOther = new ListOfMatchExpression(other);
 
 	if (this._expressions.length != realOther._expressions.length)

+ 72 - 0
test/lib/pipeline/matcher/ListOfMatchExpression.js

@@ -0,0 +1,72 @@
+"use strict";
+var assert = require("assert"),
+	MatchExpression = require("../../../../lib/pipeline/matcher/MatchExpression"),
+	ListOfMatchExpression = require("../../../../lib/pipeline/matcher/ListOfMatchExpression");
+
+
+module.exports = {
+	"ListOfMatchExpression": {
+
+		"Constructor": function (){
+			var e = new ListOfMatchExpression('AND');
+			assert.equal(e._matchType, "AND");
+		},
+
+		"Add": function () {
+			var e = new ListOfMatchExpression();
+			e.add(new MatchExpression("OR"));
+			assert.equal(e._expressions[0]._matchType, "OR");
+		},
+
+		"Add2": function () {
+			var e = new ListOfMatchExpression();
+			e.add(new MatchExpression("OR"));
+			e.add(new MatchExpression("NOT"));
+			assert.equal(e._expressions[0]._matchType, "OR");
+			assert.equal(e._expressions[1]._matchType, "NOT");
+		},
+
+		"ClearAndRelease": function () {
+			var e = new ListOfMatchExpression();
+			e.add(new MatchExpression("OR"));
+			e.add(new MatchExpression("NOT"));
+			e.clearAndRelease();
+			assert.equal(e._expressions.length, 0);
+		},
+
+		"NumChildren": function () {
+			var e = new ListOfMatchExpression();
+			e.add(new MatchExpression("OR"));
+			e.add(new MatchExpression("NOT"));
+			assert.equal(e.numChildren(), 2);
+		},
+
+		"GetChild": function () {
+			var e = new ListOfMatchExpression(),
+				match1 = new MatchExpression("NOT");
+			e.add(new MatchExpression("OR"));
+			e.add(match1);
+			assert.deepEqual(e.getChild(1), match1);
+		},
+
+		"GetChildVector": function () {
+			var e = new ListOfMatchExpression(),
+				match0 = new MatchExpression("NOT"),
+				match1 = new MatchExpression("OR");
+			e.add(match0);
+			e.add(match1);
+			assert.equal(e.getChildVector().length, 2);
+		},
+
+		"Equivalent": function () {
+			var e = new ListOfMatchExpression('TEXT'),
+				f = new ListOfMatchExpression("TEXT");
+			assert.equal(e.equivalent(f), true);
+		}
+
+	}
+
+};
+
+if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);
+