Browse Source

REFS DEVOPS-234 to DEVOPS-273 Adjustments to parameter names

David Aebersold 11 years ago
parent
commit
0f95470298
34 changed files with 187 additions and 131 deletions
  1. 2 2
      lib/pipeline/expressions/AddExpression.js
  2. 4 4
      lib/pipeline/expressions/AllElementsTrueExpression.js
  3. 2 2
      lib/pipeline/expressions/AndExpression.js
  4. 5 5
      lib/pipeline/expressions/AnyElementTrueExpression.js
  5. 7 3
      lib/pipeline/expressions/CoerceToBoolExpression.js
  6. 69 18
      lib/pipeline/expressions/CondExpression.js
  7. 3 3
      lib/pipeline/expressions/DayOfMonthExpression.js
  8. 3 4
      lib/pipeline/expressions/DayOfWeekExpression.js
  9. 3 4
      lib/pipeline/expressions/DayOfYearExpression.js
  10. 4 5
      lib/pipeline/expressions/DivideExpression.js
  11. 1 1
      lib/pipeline/expressions/Expression.js
  12. 3 3
      lib/pipeline/expressions/HourExpression.js
  13. 3 3
      lib/pipeline/expressions/IfNullExpression.js
  14. 3 4
      lib/pipeline/expressions/MillisecondExpression.js
  15. 3 4
      lib/pipeline/expressions/MinuteExpression.js
  16. 3 3
      lib/pipeline/expressions/ModExpression.js
  17. 2 3
      lib/pipeline/expressions/MonthExpression.js
  18. 3 3
      lib/pipeline/expressions/MultiplyExpression.js
  19. 3 3
      lib/pipeline/expressions/NotExpression.js
  20. 2 2
      lib/pipeline/expressions/OrExpression.js
  21. 3 4
      lib/pipeline/expressions/SecondExpression.js
  22. 3 3
      lib/pipeline/expressions/SetDifferenceExpression.js
  23. 3 3
      lib/pipeline/expressions/SetEqualsExpression.js
  24. 3 3
      lib/pipeline/expressions/SetIsSubsetExpression.js
  25. 3 3
      lib/pipeline/expressions/SetUnionExpression.js
  26. 2 2
      lib/pipeline/expressions/SizeExpression.js
  27. 3 3
      lib/pipeline/expressions/StrcasecmpExpression.js
  28. 4 4
      lib/pipeline/expressions/SubstrExpression.js
  29. 3 3
      lib/pipeline/expressions/SubtractExpression.js
  30. 2 2
      lib/pipeline/expressions/ToLowerExpression.js
  31. 2 2
      lib/pipeline/expressions/ToUpperExpression.js
  32. 2 2
      lib/pipeline/expressions/WeekExpression.js
  33. 2 2
      lib/pipeline/expressions/YearExpression.js
  34. 24 16
      test/lib/pipeline/expressions/CondExpression.js

+ 2 - 2
lib/pipeline/expressions/AddExpression.js

@@ -25,10 +25,10 @@ proto.getOpName = function getOpName(){
  * Takes an array of one or more numbers and adds them together, returning the sum.
  * @method @evaluate
  **/
-proto.evaluateInternal = function evaluateInternal(doc) {
+proto.evaluateInternal = function evaluateInternal(vars) {
 	var total = 0;
 	for (var i = 0, n = this.operands.length; i < n; ++i) {
-		var value = this.operands[i].evaluateInternal(doc);
+		var value = this.operands[i].evaluateInternal(vars);
 		if (value instanceof Date) throw new Error("$add does not support dates; code 16415");
 		if (typeof value == "string") throw new Error("$add does not support strings; code 16416");
 		total += Value.coerceToDouble(value);

+ 4 - 4
lib/pipeline/expressions/AllElementsTrueExpression.js

@@ -34,12 +34,12 @@ proto.getOpName = function getOpName() {
  * Takes an array of one or more numbers and returns true if all.
  * @method @evaluateInternal
  **/
-proto.evaluateInternal = function evaluateInternal(doc) {
-		var value = evaluateInternal(doc);
-		if (!doc instanceof Array) throw new Error("$allElementsTrue requires an array");
+proto.evaluateInternal = function evaluateInternal(vars) {
+		var value = evaluateInternal(vars);
+		if (!vars instanceof Array) throw new Error("$allElementsTrue requires an array");
 
 		for (var i = 0, n = this.operands.length; i < n; ++i) {
-				var checkValue = this.operands[i].evaluateInternal(doc);
+				var checkValue = this.operands[i].evaluateInternal(vars);
 				if (!checkValue.coerceToBool()) return false;
 		}
 		return true;

+ 2 - 2
lib/pipeline/expressions/AndExpression.js

@@ -31,9 +31,9 @@ proto.getOpName = function getOpName(){
  * Takes an array one or more values and returns true if all of the values in the array are true. Otherwise $and returns false.
  * @method evaluate
  **/
-proto.evaluateInternal = function evaluateInternal(doc) {
+proto.evaluateInternal = function evaluateInternal(vars) {
 	for (var i = 0, n = this.operands.length; i < n; ++i) {
-		var value = this.operands[i].evaluateInternal(doc);
+		var value = this.operands[i].evaluateInternal(vars);
 		if (!Value.coerceToBool()) return false;
 	}
 	return true;

+ 5 - 5
lib/pipeline/expressions/AnyElementTrueExpression.js

@@ -26,13 +26,13 @@ proto.getOpName = function getOpName(){
  * Takes an array of one or more numbers and returns true if any.
  * @method @evaluateInternal
  **/
-proto.evaluateInternal = function evaluateInternal(doc) {
+proto.evaluateInternal = function evaluateInternal(vars) {
 
-	if (!doc instanceof Array) throw new Error("$anyElementTrue requires an array");
+	if (!vars instanceof Array) throw new Error("$anyElementTrue requires an array");
 
 	var total = 0;
-	for (var i = 0, n = doc.length; i < n; ++i) {
-		var value = doc[i].evaluateInternal([i]);
+	for (var i = 0, n = vars.length; i < n; ++i) {
+		var value = vars[i].evaluateInternal([i]);
 		if ( value.coerceToBool() )
 			return true;
 	}
@@ -40,4 +40,4 @@ proto.evaluateInternal = function evaluateInternal(doc) {
 };
 
 /** Register Expression */
-Expression.registerExpression("$anyElementTrue",AnyElementTrueExpression.parse);
+Expression.registerExpression("$anyElementTrue",AnyElementTrueExpression.evaluateInternal);

+ 7 - 3
lib/pipeline/expressions/CoerceToBoolExpression.js

@@ -17,7 +17,8 @@ var CoerceToBoolExpression = module.exports = function CoerceToBoolExpression(ex
 var Value = require("../Value"),
 	AndExpression = require("./AndExpression"),
 	OrExpression = require("./OrExpression"),
-	NotExpression = require("./NotExpression");
+	NotExpression = require("./NotExpression"),
+	Expression = require("./Expression");
 
 proto.optimize = function optimize() {
 	this.expression = this.expression.optimize();	// optimize the operand
@@ -38,8 +39,8 @@ proto.addDependencies = function addDependencies(deps, path) {
 };
 
 // PROTOTYPE MEMBERS
-proto.evaluateInternal = function evaluateInternal(doc){
-	var result = this.expression.evaluateInternal(doc);
+proto.evaluateInternal = function evaluateInternal(vars){
+	var result = this.expression.evaluateInternal(vars);
 	return Value.coerceToBool(result);
 };
 
@@ -57,5 +58,8 @@ proto.toJSON = function toJSON() {
 	return {$and:[this.expression.toJSON()]};
 };
 
+/** Register Expression */
+Expression.registerExpression("$coerceToBool",CoerceToBoolExpression.parse);
+
 //TODO:	proto.addToBsonObj   --- may be required for $project to work
 //TODO:	proto.addToBsonArray

+ 69 - 18
lib/pipeline/expressions/CondExpression.js

@@ -1,37 +1,88 @@
 "use strict";
 
 /**
- * $cond expression;  @see evaluate 
- * @class AndExpression
+ * $cond expression;  @see evaluate
+ * @class CondExpression
  * @namespace mungedb-aggregate.pipeline.expressions
  * @module mungedb-aggregate
  * @constructor
  **/
-var CondExpression = module.exports = function CondExpression(){
-	if (arguments.length !== 0) throw new Error("zero args expected");
-	base.call(this);
-}, klass = CondExpression, base = require("./NaryExpression"), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
+var CondExpression = module.exports = function CondExpression(vars) {
+		this.fixedArity(3);
+		this.pCond = this.evaluateInternal(vars);
+		this.idx = this.pCond.coerceToBool() ? 1 : 2;
+		//return vpOperand[this.idx].evaluateInternal(vars);
+
+		if (arguments.length !== 3) throw new Error("zero args expected");
+		base.call(this);
+}, klass = CondExpression,
+		base = require("./NaryExpression"),
+		proto = klass.prototype = Object.create(base.prototype, {
+				constructor: {
+						value: klass
+				}
+		});
 
 // DEPENDENCIES
-var Value = require("../Value");
+var Value = require("../Value"),
+		Expression = require("./Expression");
 
 // PROTOTYPE MEMBERS
-proto.getOpName = function getOpName(){
-	return "$cond";
+proto.getOpName = function getOpName() {
+		return "$cond";
 };
 
-proto.addOperand = function addOperand(expr) {
-	this.checkArgLimit(3);
-	base.prototype.addOperand.call(this, expr);
+proto.parse = function parse(expr, vps) {
+		this.checkArgLimit(3);
+
+		// if not an object, return;
+		if (typeof(expr) !== Object)
+				return Expression.parse(expr, vps);
+
+		// verify 
+		if (Expression.parseOperand(expr) !== "$cond")
+				throw new Error("Invalid expression");
+
+		var ret = new CondExpression();
+
+		var ex = Expression.parseObject(expr);
+		var args = Expression.parseOperand(expr, vps);
+		if (args[0] !== "if")
+				throw new Error("Missing 'if' parameter to $cond");
+		if (args[1] !== "then")
+				throw new Error("Missing 'then' parameter to $cond");
+		if (args[2] !== "else")
+				throw new Error("Missing 'else' parameter to $cond");
+
+
+		return ret;
 };
 
 /** 
- * Use the $cond operator with the following syntax:  { $cond: [ <boolean-expression>, <true-case>, <false-case> ] } 
+ * Use the $cond operator with the following syntax:  { $cond: [ <boolean-expression>, <true-case>, <false-case> ] }
  * @method evaluate
  **/
-proto.evaluate = function evaluate(doc){
-	this.checkArgCount(3);
-	var pCond = this.operands[0].evaluate(doc),
-		idx = Value.coerceToBool(pCond) ? 1 : 2;
-	return this.operands[idx].evaluate(doc);
+proto.evaluateInternal = function evaluateInternal(vars) {
+		var pCond1 = this.operands[0].evaluateInternal(vars);
+
+		this.idx = 0;
+		if (pCond1.coerceToBool()) {
+				this.idx = 1;
+		} else {
+				this.idx = 2;
+		}
+
+		return this.operands[this.idx].evaluateInternal(vars);
 };
+
+proto.evaluateInternal = function evaluateInternal(vars) {
+		this.checkArgCount(1);
+		var date = this.operands[0].evaluateInternal(vars);
+
+
+		return date.getUTCDate();
+};
+
+
+/** Register Expression */
+Expression.registerExpression("$cond", CondExpression.parse);

+ 3 - 3
lib/pipeline/expressions/DayOfMonthExpression.js

@@ -9,7 +9,7 @@
  **/
 var DayOfMonthExpression = module.exports = function DayOfMonthExpression() {
 		this.fixedArity(1);
-		if (arguments.length !== 1) throw new Error("one args expected");
+		if (arguments.length !== 1) throw new Error("one arg expected");
 		base.call(this);
 }, klass = DayOfMonthExpression,
 		base = require("./NaryExpression"),
@@ -31,8 +31,8 @@ proto.getOpName = function getOpName() {
  * Takes a date and returns the day of the month as a number between 1 and 31.
  * @method evaluate
  **/
-proto.evaluateInternal = function evaluateInternal(doc) {
-		var date = this.operands[0].evaluateInternal(doc);
+proto.evaluateInternal = function evaluateInternal(vars) {
+		var date = this.operands[0].evaluateInternal(vars);
 		return date.getUTCDate();
 };
 

+ 3 - 4
lib/pipeline/expressions/DayOfWeekExpression.js

@@ -9,7 +9,7 @@
  **/
 var DayOfWeekExpression = module.exports = function DayOfWeekExpression(){
 	this.fixedArity(1);
-	if (arguments.length !== 0) throw new Error("zero args expected");
+	if (arguments.length !== 1) throw new Error("one arg expected");
 	base.call(this);
 }, klass = DayOfWeekExpression, base = require("./NaryExpression"), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 
@@ -25,9 +25,8 @@ proto.getOpName = function getOpName(){
  * Takes a date and returns the day of the week as a number between 1 (Sunday) and 7 (Saturday.)
  * @method evaluate
  **/
-proto.evaluateInternal = function evaluateInternal(doc){
-	this.checkArgCount(1);
-	var date = this.operands[0].evaluateInternal(doc);
+proto.evaluateInternal = function evaluateInternal(vars){
+	var date = this.operands[0].evaluateInternal(vars);
 	return date.getUTCDay()+1;
 };
 

+ 3 - 4
lib/pipeline/expressions/DayOfYearExpression.js

@@ -9,7 +9,7 @@
  **/
 var DayOfYearExpression = module.exports = function DayOfYearExpression(){
 	this.fixedArity(1);
-	if(arguments.length !== 0) throw new Error("zero args expected");
+	if(arguments.length !== 1) throw new Error("one arg expected");
 	base.call(this);
 }, klass = DayOfYearExpression, base = require("./NaryExpression"), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 
@@ -25,10 +25,9 @@ proto.getOpName = function getOpName(){
  * Takes a date and returns the day of the year as a number between 1 and 366.
  * @method evaluate
  **/
-proto.evaluateInternal = function evaluateInternal(doc){
+proto.evaluateInternal = function evaluateInternal(vars){
 	//NOTE: the below silliness is to deal with the leap year scenario when we should be returning 366
-	this.checkArgCount(1);
-	var date = this.operands[0].evaluateInternal(doc);
+	var date = this.operands[0].evaluateInternal(vars);
 	return klass.getDateDayOfYear(date);
 };
 

+ 4 - 5
lib/pipeline/expressions/DivideExpression.js

@@ -10,7 +10,7 @@
  **/
 var DivideExpression = module.exports = function DivideExpression(){
 	this.fixedArity(2);
-	if (arguments.length !== 0) throw new Error("zero args expected");
+	if (arguments.length !== 2) throw new Error("two args expected");
 	base.call(this);
 }, klass = DivideExpression, base = require("./NaryExpression"), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 
@@ -27,10 +27,9 @@ proto.getOpName = function getOpName(){	//TODO: try to move this to a static and
  * Takes an array that contains a pair of numbers and returns the value of the first number divided by the second number.
  * @method evaluateInternal
  **/
-proto.evaluateInternal = function evaluateInternal(doc) {
-	this.checkArgCount(2);
-	var left = this.operands[0].evaluateInternal(doc),
-		right = this.operands[1].evaluateInternal(doc);
+proto.evaluateInternal = function evaluateInternal(vars) {
+	var left = this.operands[0].evaluateInternal(vars),
+		right = this.operands[1].evaluateInternal(vars);
 	if (!(left instanceof Date) && (!right instanceof Date)) throw new Error("$divide does not support dates; code 16373");
 	right = Value.coerceToDouble(right);
 	if (right === 0) return undefined;

+ 1 - 1
lib/pipeline/expressions/Expression.js

@@ -240,7 +240,7 @@ klass.removeFieldPrefix = function removeFieldPrefix(prefixedField) {
  * @method evaluate
  * @returns the computed value
  **/
-proto.evaluate = function evaluate(obj) {
+proto.evaluateInternal = function evaluateInternal(obj) {
 		throw new Error("WAS NOT IMPLEMENTED BY INHERITOR!");
 };
 

+ 3 - 3
lib/pipeline/expressions/HourExpression.js

@@ -10,7 +10,7 @@
  **/
 var HourExpression = module.exports = function HourExpression(){
 	this.fixedArity(1);
-	if (arguments.length !== 0) throw new Error("zero args expected");
+	if (arguments.length !== 1) throw new Error("one arg expected");
 	base.call(this);
 }, klass = HourExpression, base = require("./NaryExpression"), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 
@@ -26,9 +26,9 @@ var	Expression = require("./Expression");
  * Takes a date and returns the hour between 0 and 23. 
  * @method evaluateInternal
  **/
-proto.evaluateInternal = function evaluateInternal(doc){
+proto.evaluateInternal = function evaluateInternal(vars){
 	this.checkArgCount(1);
-	var date = this.operands[0].evaluateInternal(doc);
+	var date = this.operands[0].evaluateInternal(vars);
 	return date.getUTCHours();
 };
 

+ 3 - 3
lib/pipeline/expressions/IfNullExpression.js

@@ -34,11 +34,11 @@ proto.getOpName = function getOpName() {
  * Use the $ifNull operator with the following syntax: { $ifNull: [ <expression>, <replacement-if-null> ] }
  * @method evaluate
  **/
-proto.evaluateInternal = function evaluateInternal(doc) {
+proto.evaluateInternal = function evaluateInternal(vars) {
 		this.checkArgCount(2);
-		var left = this.operands[0].evaluateInternal(doc);
+		var left = this.operands[0].evaluateInternal(vars);
 		if (left !== undefined && left !== null) return left;
-		var right = this.operands[1].evaluateInternal(doc);
+		var right = this.operands[1].evaluateInternal(vars);
 		return right;
 };
 

+ 3 - 4
lib/pipeline/expressions/MillisecondExpression.js

@@ -10,7 +10,7 @@
  **/
 var MillisecondExpression = module.exports = function MillisecondExpression() {
 		this.fixedArity(1);
-		if (arguments.length !== 0) throw new Error("zero args expected");
+		if (arguments.length !== 1) throw new Error("one arg expected");
 		base.call(this);
 }, klass = MillisecondExpression,
 		base = require("./NaryExpression"),
@@ -32,9 +32,8 @@ proto.getOpName = function getOpName() {
  * Takes a date and returns the millisecond between 0 and 999, but can be 1000 to account for leap milliseconds.
  * @method evaluateInternal
  **/
-proto.evaluateInternal = function evaluateInternal(doc) {
-		this.checkArgCount(1);
-		var date = this.operands[0].evaluateInternal(doc);
+proto.evaluateInternal = function evaluateInternal(vars) {
+		var date = this.operands[0].evaluateInternal(vars);
 		return date.getUTCMilliseconds(); //TODO: incorrect for last millisecond of leap year, need to fix...
 		// currently leap milliseconds are unsupported in v8
 		// http://code.google.com/p/v8/issues/detail?id=1944

+ 3 - 4
lib/pipeline/expressions/MinuteExpression.js

@@ -10,7 +10,7 @@
  **/
 var MinuteExpression = module.exports = function MinuteExpression() {
 		this.fixedArity(1);
-		if (arguments.length !== 0) throw new Error("zero args expected");
+		if (arguments.length !== 1) throw new Error("one arg expected");
 		base.call(this);
 }, klass = MinuteExpression,
 		base = require("./NaryExpression"),
@@ -32,9 +32,8 @@ proto.getOpName = function getOpName() {
  * Takes a date and returns the minute between 0 and 59.
  * @method evaluateInternal
  **/
-proto.evaluateInternal = function evaluateInternal(doc) {
-		this.checkArgCount(1);
-		var date = this.operands[0].evaluateInternal(doc);
+proto.evaluateInternal = function evaluateInternal(vars) {
+		var date = this.operands[0].evaluateInternal(vars);
 		return date.getUTCMinutes();
 };
 

+ 3 - 3
lib/pipeline/expressions/ModExpression.js

@@ -33,10 +33,10 @@ proto.getOpName = function getOpName() {
  * Takes an array that contains a pair of numbers and returns the remainder of the first number divided by the second number.
  * @method evaluate
  **/
-proto.evaluateInternal = function evaluateInternal(doc) {
+proto.evaluateInternal = function evaluateInternal(vars) {
 		this.checkArgCount(2);
-		var left = this.operands[0].evaluateInternal(doc),
-				right = this.operands[1].evaluateInternal(doc);
+		var left = this.operands[0].evaluateInternal(vars),
+				right = this.operands[1].evaluateInternal(vars);
 		if (left instanceof Date || right instanceof Date) throw new Error("$mod does not support dates; code 16374");
 
 		// pass along jstNULLs and Undefineds

+ 2 - 3
lib/pipeline/expressions/MonthExpression.js

@@ -10,7 +10,7 @@
  **/
 var MonthExpression = module.exports = function MonthExpression() {
 		this.fixedArity(1);
-		if (arguments.length !== 0) throw new Error("zero args expected");
+		if (arguments.length !== 1) throw new Error("one arg expected");
 		base.call(this);
 }, klass = MonthExpression,
 		base = require("./NaryExpression"),
@@ -33,10 +33,9 @@ proto.getOpName = function getOpName() {
  * @method evaluate
  **/
 proto.evaluateInternal = function evaluateInternal(vars) {
-		this.checkArgCount(1);
 		var date = this.operands[0].evaluateInternal(vars);
 		return date.getUTCMonth();
 };
 
 /** Register Expression */
-Expression.registerExpression("$month", MonthExpression.getOpName);
+Expression.registerExpression("$month", MonthExpression.parse);

+ 3 - 3
lib/pipeline/expressions/MultiplyExpression.js

@@ -9,7 +9,7 @@
  * @constructor
  **/
 var MultiplyExpression = module.exports = function MultiplyExpression(){
-	if (arguments.length !== 0) throw new Error("zero args expected");
+	if (arguments.length !== 1) throw new Error("one arg expected");
 	base.call(this);
 }, klass = MultiplyExpression, base = require("./NaryExpression"), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 
@@ -26,10 +26,10 @@ proto.getOpName = function getOpName(){
  * Takes an array of one or more numbers and multiples them, returning the resulting product. 
  * @method evaluateInternal
  **/
-proto.evaluateInternal = function evaluateInternal(doc){
+proto.evaluateInternal = function evaluateInternal(vars){
 	var product = 1;
 	for(var i = 0, n = this.operands.length; i < n; ++i){
-		var value = this.operands[i].evaluateInternal(doc);
+		var value = this.operands[i].evaluateInternal(vars);
 		if(value instanceof Date) throw new Error("$multiply does not support dates; code 16375");
 		product *= Value.coerceToDouble(value);
 	}

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

@@ -10,7 +10,7 @@
  **/
 var NotExpression = module.exports = function NotExpression() {
 		this.fixedArity(1);
-		if (arguments.length !== 0) throw new Error("zero args expected");
+		if (arguments.length !== 1) throw new Error("one arg expected");
 		base.call(this);
 }, klass = NotExpression,
 		base = require("./NaryExpression"),
@@ -33,8 +33,8 @@ proto.getOpName = function getOpName() {
  * Returns the boolean opposite value passed to it. When passed a true value, $not returns false; when passed a false value, $not returns true.
  * @method evaluateInternal
  **/
-proto.evaluateInternal = function evaluateInternal(doc) {
-		var op = this.operands[0].evaluateInternal(doc);
+proto.evaluateInternal = function evaluateInternal(vars) {
+		var op = this.operands[0].evaluateInternal(vars);
 		return !Value.coerceToBool(op);
 };
 

+ 2 - 2
lib/pipeline/expressions/OrExpression.js

@@ -28,9 +28,9 @@ proto.getOpName = function getOpName(){
  * Takes an array of one or more values and returns true if any of the values in the array are true. Otherwise $or returns false. 
  * @method evaluateInternal
  **/
-proto.evaluateInternal = function evaluateInternal(doc){
+proto.evaluateInternal = function evaluateInternal(vars){
 	for(var i = 0, n = this.operands.length; i < n; ++i){
-		var value = this.operands[i].evaluateInternal(doc);
+		var value = this.operands[i].evaluateInternal(vars);
 		if (Value.coerceToBool(value)) return true;
 	}
 	return false;

+ 3 - 4
lib/pipeline/expressions/SecondExpression.js

@@ -10,7 +10,7 @@
  **/
 var SecondExpression = module.exports = function SecondExpression() {
 		this.fixedArity(1);
-		if (arguments.length !== 0) throw new Error("zero args expected");
+		if (arguments.length !== 1) throw new Error("one arg expected");
 		base.call(this);
 }, klass = SecondExpression,
 		base = require("./NaryExpression"),
@@ -32,9 +32,8 @@ proto.getOpName = function getOpName() {
  * Takes a date and returns the second between 0 and 59, but can be 60 to account for leap seconds.
  * @method evaluateInternal
  **/
-proto.evaluateInternal = function evaluateInternal(doc) {
-		this.checkArgCount(1);
-		var date = this.operands[0].evaluateInternal(doc);
+proto.evaluateInternal = function evaluateInternal(vars) {
+		var date = this.operands[0].evaluateInternal(vars);
 		return date.getUTCSeconds(); //TODO: incorrect for last second of leap year, need to fix...
 		// currently leap seconds are unsupported in v8
 		// http://code.google.com/p/v8/issues/detail?id=1944

+ 3 - 3
lib/pipeline/expressions/SetDifferenceExpression.js

@@ -33,9 +33,9 @@ proto.getOpName = function getOpName() {
  * Takes 2 arrays. Assigns the second array to the first array.
  * @method evaluateInternal
  **/
-proto.evaluateInternal = function evaluateInternal(doc) {
-		var array1 = this.operands[0].evaluateInternal(doc),
-				array2 = this.operands[1].evaluateInternal(doc);
+proto.evaluateInternal = function evaluateInternal(vars) {
+		var array1 = this.operands[0].evaluateInternal(vars),
+				array2 = this.operands[1].evaluateInternal(vars);
 		if (array1 instanceof Array) throw new Error(this.getOpName() + ": object 1 must be an array");
 		if (array2 instanceof Array) throw new Error(this.getOpName() + ": object 2 must be an array");
 

+ 3 - 3
lib/pipeline/expressions/SetEqualsExpression.js

@@ -33,9 +33,9 @@ proto.getOpName = function getOpName() {
  * Takes 2 arrays. Assigns the second array to the first array.
  * @method evaluateInternal
  **/
-proto.evaluateInternal = function evaluateInternal(doc) {
-		var array1 = this.operands[0].evaluateInternal(doc),
-				array2 = this.operands[1].evaluateInternal(doc);
+proto.evaluateInternal = function evaluateInternal(vars) {
+		var array1 = this.operands[0].evaluateInternal(vars),
+				array2 = this.operands[1].evaluateInternal(vars);
 		if (array1 instanceof Array) throw new Error(this.getOpName() + ": object 1 must be an array");
 		if (array2 instanceof Array) throw new Error(this.getOpName() + ": object 2 must be an array");
 		array1 = array2;

+ 3 - 3
lib/pipeline/expressions/SetIsSubsetExpression.js

@@ -57,9 +57,9 @@ proto.optimize = function optimize(cachedRhsSet, operands) {
  * Takes 2 arrays. Assigns the second array to the first array.
  * @method evaluateInternal
  **/
-proto.evaluateInternal = function evaluateInternal(doc) {
-		var array1 = this.operands[0].evaluateInternal(doc),
-				array2 = this.operands[1].evaluateInternal(doc);
+proto.evaluateInternal = function evaluateInternal(vars) {
+		var array1 = this.operands[0].evaluateInternal(vars),
+				array2 = this.operands[1].evaluateInternal(vars);
 		if (array1 instanceof Array) throw new Error(this.getOpName() + ": object 1 must be an array");
 		if (array2 instanceof Array) throw new Error(this.getOpName() + ": object 2 must be an array");
 

+ 3 - 3
lib/pipeline/expressions/SetUnionExpression.js

@@ -33,9 +33,9 @@ proto.getOpName = function getOpName() {
  * Takes 2 objects. Unions the objects
  * @method evaluateInternal
  **/
-proto.evaluateInternal = function evaluateInternal(doc) {
-		var object1 = this.operands[0].evaluateInternal(doc),
-				object2 = this.operands[1].evaluateInternal(doc);
+proto.evaluateInternal = function evaluateInternal(vars) {
+		var object1 = this.operands[0].evaluateInternal(vars),
+				object2 = this.operands[1].evaluateInternal(vars);
 		if (object1 instanceof Array) throw new Error(this.getOpName() + ": object 1 must be an object");
 		if (object2 instanceof Array) throw new Error(this.getOpName() + ": object 2 must be an object");
 

+ 2 - 2
lib/pipeline/expressions/SizeExpression.js

@@ -32,9 +32,9 @@ proto.getOpName = function getOpName() {
 /** 
  * Takes an array and return the size.
  **/
-proto.evaluateInternal = function evaluateInternal(doc) {
+proto.evaluateInternal = function evaluateInternal(vars) {
 		this.checkArgCount(1);
-		var array = this.operands[0].evaluateInternal(doc);
+		var array = this.operands[0].evaluateInternal(vars);
 		if (array instanceof Date) throw new Error("$size does not support dates; code 16376");
 		return array.length;
 };

+ 3 - 3
lib/pipeline/expressions/StrcasecmpExpression.js

@@ -34,10 +34,10 @@ proto.getOpName = function getOpName() {
  * Takes in two strings. Returns a number. $strcasecmp is positive if the first string is “greater than” the second and negative if the first string is “less than” the second. $strcasecmp returns 0 if the strings are identical.
  * @method evaluate
  **/
-proto.evaluateInternal = function evaluateInternal(doc) {
+proto.evaluateInternal = function evaluateInternal(vars) {
 		this.checkArgCount(2);
-		var val1 = this.operands[0].evaluateInternal(doc),
-				val2 = this.operands[1].evaluateInternal(doc),
+		var val1 = this.operands[0].evaluateInternal(vars),
+				val2 = this.operands[1].evaluateInternal(vars),
 				str1 = Value.coerceToString(val1).toUpperCase(),
 				str2 = Value.coerceToString(val2).toUpperCase(),
 				cmp = Value.compare(str1, str2);

+ 4 - 4
lib/pipeline/expressions/SubstrExpression.js

@@ -33,10 +33,10 @@ proto.getOpName = function getOpName() {
  * Takes a string and two numbers. The first number represents the number of bytes in the string to skip, and the second number specifies the number of bytes to return from the string.
  * @method evaluateInternal
  **/
-proto.evaluateInternal = function evaluateInternal(doc) {
-		var val = this.operands[0].evaluateInternal(doc),
-				idx = this.operands[1].evaluateInternal(doc),
-				len = this.operands[2].evaluateInternal(doc),
+proto.evaluateInternal = function evaluateInternal(vars) {
+		var val = this.operands[0].evaluateInternal(vars),
+				idx = this.operands[1].evaluateInternal(vars),
+				len = this.operands[2].evaluateInternal(vars),
 				str = Value.coerceToString(val);
 		if (typeof(idx) != "number") throw new Error(this.getOpName() + ": starting index must be a numeric type; code 16034");
 		if (typeof(len) != "number") throw new Error(this.getOpName() + ": length must be a numeric type; code 16035");

+ 3 - 3
lib/pipeline/expressions/SubtractExpression.js

@@ -32,10 +32,10 @@ proto.getOpName = function getOpName() {
 /** 
  * Takes an array that contains a pair of numbers and subtracts the second from the first, returning their difference.
  **/
-proto.evaluateInternal = function evaluateInternal(doc) {
+proto.evaluateInternal = function evaluateInternal(vars) {
 		this.checkArgCount(2);
-		var left = this.operands[0].evaluateInternal(doc),
-				right = this.operands[1].evaluateInternal(doc);
+		var left = this.operands[0].evaluateInternal(vars),
+				right = this.operands[1].evaluateInternal(vars);
 		if (left instanceof Date || right instanceof Date) throw new Error("$subtract does not support dates; code 16376");
 		return left - right;
 };

+ 2 - 2
lib/pipeline/expressions/ToLowerExpression.js

@@ -32,9 +32,9 @@ proto.getOpName = function getOpName() {
 /** 
  * Takes a single string and converts that string to lowercase, returning the result. All uppercase letters become lowercase.
  **/
-proto.evaluateInternal = function evaluateInternal(doc) {
+proto.evaluateInternal = function evaluateInternal(vars) {
 		this.checkArgCount(1);
-		var val = this.operands[0].evaluateInternal(doc),
+		var val = this.operands[0].evaluateInternal(vars),
 				str = Value.coerceToString(val);
 		return str.toLowerCase();
 };

+ 2 - 2
lib/pipeline/expressions/ToUpperExpression.js

@@ -32,9 +32,9 @@ proto.getOpName = function getOpName() {
 /** 
  * Takes a single string and converts that string to lowercase, returning the result. All uppercase letters become lowercase.
  **/
-proto.evaluateInternal = function evaluateInternal(doc) {
+proto.evaluateInternal = function evaluateInternal(vars) {
 		this.checkArgCount(1);
-		var val = this.operands[0].evaluateInternal(doc),
+		var val = this.operands[0].evaluateInternal(vars),
 				str = Value.coerceToString(val);
 		return str.toUpperCase();
 };

+ 2 - 2
lib/pipeline/expressions/WeekExpression.js

@@ -37,9 +37,9 @@ proto.getOpName = function getOpName() {
  * This behavior is the same as the “%U” operator to the strftime standard library function.
  * @method evaluateInternal
  **/
-proto.evaluateInternal = function evaluateInternal(doc) {
+proto.evaluateInternal = function evaluateInternal(vars) {
 		this.checkArgCount(1);
-		var date = this.operands[0].evaluateInternal(doc),
+		var date = this.operands[0].evaluateInternal(vars),
 				dayOfWeek = date.getUTCDay(),
 				dayOfYear = DayOfYearExpression.getDateDayOfYear(date),
 				prevSundayDayOfYear = dayOfYear - dayOfWeek, // may be negative

+ 2 - 2
lib/pipeline/expressions/YearExpression.js

@@ -35,9 +35,9 @@ proto.getOpName = function getOpName() {
  * Takes a date and returns the full year.
  * @method evaluateInternal
  **/
-proto.evaluateInternal = function evaluateInternal(doc) {
+proto.evaluateInternal = function evaluateInternal(vars) {
 		this.checkArgCount(1);
-		var date = this.operands[0].evaluateInternal(doc);
+		var date = this.operands[0].evaluateInternal(vars);
 		return date.getUTCFullYear();
 };
 

+ 24 - 16
test/lib/pipeline/expressions/CondExpression.js

@@ -10,12 +10,28 @@ module.exports = {
 
 		"constructor()": {
 
-			"should not throw Error when constructing without args": function testConstructor(){
-				assert.doesNotThrow(function(){
+			"should throw Error when constructing without args": function testConstructor(){
+				assert.throws(function(){
 					new CondExpression();
 				});
-			}
+			},
 
+			"should throw Error when constructing with 1 arg": function testConstructor1(){
+				assert.throws(function(){
+					new CondExpression({if:true === true});
+				});
+			},
+			"should throw Error when constructing with 2 args": function testConstructor2(){
+				assert.throws(function(){
+					new CondExpression(true === true,1);
+				});
+			},
+			"should now throw Error when constructing with 3 args": function testConstructor3(){
+				assert.doesNotThrow(function(){
+					//new CondExpression({$cond:[{"if":"true === true"},{"then":"1"},{"else":"0"}]});
+					new CondExpression({$cond:[ true === true, 1, 0 ]});
+				});
+			},
 		},
 
 		"#getOpName()": {
@@ -26,30 +42,22 @@ module.exports = {
 
 		},
 
-		"#getFactory()": {
-
-			"should return the constructor for this class": function factoryIsConstructor(){
-				assert.strictEqual(new CondExpression().getFactory(), undefined);
-			}
-
-		},
-
-		"#evaluate()": {
+		"#evaluateInternal()": {
 
 			"should evaluate boolean expression as true, then return 1; [ true === true, 1, 0 ]": function testStuff(){
-				assert.strictEqual(Expression.parseOperand({$cond:[ true === true, 1, 0 ]}).evaluate({}), 1);
+				assert.strictEqual(Expression.parseOperand({$cond:[ true === true, 1, 0 ]}).evaluateInternal({}), 1);
 			},
 
 			"should evaluate boolean expression as false, then return 0; [ false === true, 1, 0 ]": function testStuff(){
-				assert.strictEqual(Expression.parseOperand({$cond:[ false === true, 1, 0 ]}).evaluate({}), 0);
+				assert.strictEqual(Expression.parseOperand({$cond:[ false === true, 1, 0 ]}).evaluateInternal({}), 0);
 			}, 
 
 			"should evaluate boolean expression as true, then return 1; [ (true === true) && true, 1, 0 ]": function testStuff(){
-				assert.strictEqual(Expression.parseOperand({$cond:[ (true === true) && true , 1, 0 ]}).evaluate({}), 1);
+				assert.strictEqual(Expression.parseOperand({$cond:[ (true === true) && true , 1, 0 ]}).evaluateInternal({}), 1);
 			},
 
 			"should evaluate boolean expression as false, then return 0; [ (false === true) && true, 1, 0 ]": function testStuff(){
-				assert.strictEqual(Expression.parseOperand({$cond:[ (false === true) && true, 1, 0 ]}).evaluate({}), 0);
+				assert.strictEqual(Expression.parseOperand({$cond:[ (false === true) && true, 1, 0 ]}).evaluateInternal({}), 0);
 			},
 
 			"should evaluate complex boolean expression as true, then return 1; [ ( 1 > 0 ) && (( 'a' == 'b' ) || ( 3 <= 5 )), 1, 0 ]": function testStuff(){