Browse Source

Fixes #982. Fixed minor bugs in NotExpression, and added test case.

http://source.rd.rcg.local/trac/eagle6/changeset/1285/Eagle6_SVN
Spencer Rathbun 12 years ago
parent
commit
fdf1c93259

+ 9 - 3
lib/pipeline/expressions/NotExpression.js

@@ -1,6 +1,10 @@
 var NotExpression = module.exports = (function(){
 	// CONSTRUCTOR
-	/** An $not pipeline expression. @see evaluate **/
+	/** 
+	* An $not pipeline expression. 
+	*
+	* @see evaluate 
+	**/
 	var klass = function NotExpression(){
 		if(arguments.length !== 0) throw new Error("zero args expected");
 		base.call(this);
@@ -16,10 +20,12 @@ var NotExpression = module.exports = (function(){
 
 	proto.addOperand = function addOperand(expr) {
 		this.checkArgLimit(1);
-		base.addOperand(expr);
+		base.prototype.addOperand.call(this, expr);
 	};
 
-	/** Returns the boolean opposite value passed to it. When passed a true value, $not returns false; when passed a false value, $not returns true. **/
+	/** 
+	* Returns the boolean opposite value passed to it. When passed a true value, $not returns false; when passed a false value, $not returns true. 
+	**/
 	proto.evaluate = function evaluate(doc){
 		this.checkArgCount(1);
 		var op = this.operands[0].evaluate(doc);

+ 51 - 0
test/lib/pipeline/expressions/NotExpression.js

@@ -0,0 +1,51 @@
+var assert = require("assert"),
+	NotExpression = require("../../../../lib/pipeline/expressions/NotExpression"),
+	Expression = require("../../../../lib/pipeline/expressions/Expression");
+
+module.exports = {
+
+	"NotExpression": {
+
+		"constructor()": {
+
+			"should not throw Error when constructing without args": function testConstructor(){
+				assert.doesNotThrow(function(){
+					new NotExpression();
+				});
+			}
+
+		},
+
+		"#getOpName()": {
+
+			"should return the correct op name; $dayOfYear": function testOpName(){
+				assert.equal(new NotExpression().getOpName(), "$not");
+			}
+
+		},
+
+		"#getFactory()": {
+
+			"should return the constructor for this class": function factoryIsConstructor(){
+				assert.strictEqual(new NotExpression().getFactory(), undefined);
+			}
+
+		},
+
+		"#evaluate()": {
+
+			"should return false for a true input; false for true": function testStuff(){
+				assert.strictEqual(Expression.parseOperand({$not:true}).evaluate({}), false);
+			},
+
+			"should return true for a false input; true for false": function testStuff(){
+				assert.strictEqual(Expression.parseOperand({$not:false}).evaluate({}), true);
+			}
+
+		}
+
+	}
+
+};
+
+if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);