Sfoglia il codice sorgente

REFS DEVOPS-270 Added v2.5 compatibility + fixedAirty

David Aebersold 11 anni fa
parent
commit
5356a3f564

+ 22 - 15
lib/pipeline/expressions/ToLowerExpression.js

@@ -1,35 +1,42 @@
 "use strict";
-	
+
 /** 
  * A $toLower pipeline expression.
- * @see evaluateInternal 
+ * @see evaluateInternal
  * @class ToLowerExpression
  * @namespace mungedb-aggregate.pipeline.expressions
  * @module mungedb-aggregate
  * @constructor
  **/
-var ToLowerExpression = module.exports = function ToLowerExpression(){
-	if (arguments.length !== 0) throw new Error("zero args expected");
-	base.call(this);
-}, klass = ToLowerExpression, base = require("./NaryExpression"), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
+var ToLowerExpression = module.exports = function ToLowerExpression() {
+		this.fixedAirty(1);
+		if (arguments.length !== 0) throw new Error("zero args expected");
+		base.call(this);
+}, klass = ToLowerExpression,
+		base = require("./NaryExpression"),
+		proto = klass.prototype = Object.create(base.prototype, {
+				constructor: {
+						value: klass
+				}
+		});
 
 // DEPENDENCIES
 var Value = require("../Value"),
- Expression = require("./Expression");
+		Expression = require("./Expression");
 
 // PROTOTYPE MEMBERS
-proto.getOpName = function getOpName(){
-	return "$toLower";
+proto.getOpName = function getOpName() {
+		return "$toLower";
 };
 
 /** 
-* Takes a single string and converts that string to lowercase, returning the result. All uppercase letters become lowercase. 
-**/
+ * Takes a single string and converts that string to lowercase, returning the result. All uppercase letters become lowercase.
+ **/
 proto.evaluateInternal = function evaluateInternal(doc) {
-	this.checkArgCount(1);
-	var val = this.operands[0].evaluateInternal(doc),
-		str = Value.coerceToString(val);
-	return str.toLowerCase();
+		this.checkArgCount(1);
+		var val = this.operands[0].evaluateInternal(doc),
+				str = Value.coerceToString(val);
+		return str.toLowerCase();
 };
 
 /** Register Expression */

+ 26 - 20
lib/pipeline/expressions/ToUpperExpression.js

@@ -2,36 +2,42 @@
 
 /** 
  * A $toUpper pipeline expression.
- * @see evaluate 
+ * @see evaluateInternal
  * @class ToUpperExpression
  * @namespace mungedb-aggregate.pipeline.expressions
  * @module mungedb-aggregate
  * @constructor
  **/
-var ToUpperExpression = module.exports = function ToUpperExpression(){
-	if (arguments.length !== 0) throw new Error("zero args expected");
-	base.call(this);
-}, klass = ToUpperExpression, base = require("./NaryExpression"), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
+var ToUpperExpression = module.exports = function ToUpperExpression() {
+		this.fixedAirty(1);
+		if (arguments.length !== 0) throw new Error("zero args expected");
+		base.call(this);
+}, klass = ToUpperExpression,
+		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 "$toUpper";
-};
-
-proto.addOperand = function addOperand(expr) {
-	this.checkArgLimit(1);
-	base.prototype.addOperand.call(this, expr);
+proto.getOpName = function getOpName() {
+		return "$toUpper";
 };
 
 /** 
-* Takes a single string and converts that string to lowercase, returning the result. All uppercase letters become lowercase. 
-**/
-proto.evaluate = function evaluate(doc) {
-	this.checkArgCount(1);
-	var val = this.operands[0].evaluate(doc),
-		str = Value.coerceToString(val);
-	return str.toUpperCase();
+ * Takes a single string and converts that string to lowercase, returning the result. All uppercase letters become lowercase.
+ **/
+proto.evaluateInternal = function evaluateInternal(doc) {
+		this.checkArgCount(1);
+		var val = this.operands[0].evaluateInternal(doc),
+				str = Value.coerceToString(val);
+		return str.toUpperCase();
 };
+
+/** Register Expression */
+Expression.registerExpression("$toUpper", ToUpperExpression.parse);

+ 47 - 35
test/lib/pipeline/expressions/ToLowerExpression.js

@@ -1,46 +1,58 @@
 "use strict";
 var assert = require("assert"),
-	ToLowerExpression = require("../../../../lib/pipeline/expressions/ToLowerExpression"),
-	Expression = require("../../../../lib/pipeline/expressions/Expression");
+		ToLowerExpression = require("../../../../lib/pipeline/expressions/ToLowerExpression"),
+		Expression = require("../../../../lib/pipeline/expressions/Expression");
 
 
 module.exports = {
 
-	"ToLowerExpression": {
+		"ToLowerExpression": {
+
+				"constructor()": {
+
+						"should not throw Error when constructing without args": function testConstructor() {
+								assert.doesNotThrow(function() {
+										new ToLowerExpression();
+								});
+						}
+
+				},
+
+				"#getOpName()": {
+
+						"should return the correct op name; $toLower": function testOpName() {
+								assert.equal(new ToLowerExpression().getOpName(), "$toLower");
+						}
+
+				},
+
+				"#evaluate()": {
+
+						"should return the lowercase version of the string if there is a null character in the middle of the string": function testStuff() {
+								assert.strictEqual(Expression.parseOperand({
+										$toLower: "$a"
+								}).evaluate({
+										a: "a\0B"
+								}), "a\0b");
+						},
+						"should return the lowercase version of the string if there is a null character at the beginning of the string": function testStuff() {
+								assert.strictEqual(Expression.parseOperand({
+										$toLower: "$a"
+								}).evaluate({
+										a: "\0aB"
+								}), "\0ab");
+						},
+						"should return the lowercase version of the string if there is a null character at the end of the string": function testStuff() {
+								assert.strictEqual(Expression.parseOperand({
+										$toLower: "$a"
+								}).evaluate({
+										a: "aB\0"
+								}), "ab\0");
+						}
+				}
 
-		"constructor()": {
-
-			"should not throw Error when constructing without args": function testConstructor(){
-				assert.doesNotThrow(function(){
-					new ToLowerExpression();
-				});
-			}
-
-		},
-
-		"#getOpName()": {
-
-			"should return the correct op name; $toLower": function testOpName(){
-				assert.equal(new ToLowerExpression().getOpName(), "$toLower");
-			}
-
-		},
-
-		"#evaluate()": {
-
-			"should return the lowercase version of the string if there is a null character in the middle of the string": function testStuff(){
-				assert.strictEqual(Expression.parseOperand({$toLower:"$a"}).evaluate({a:"a\0B"}), "a\0b");
-			},
-			"should return the lowercase version of the string if there is a null character at the beginning of the string": function testStuff(){
-				assert.strictEqual(Expression.parseOperand({$toLower:"$a"}).evaluate({a:"\0aB"}), "\0ab");
-			},
-			"should return the lowercase version of the string if there is a null character at the end of the string": function testStuff(){
-				assert.strictEqual(Expression.parseOperand({$toLower:"$a"}).evaluate({a:"aB\0"}), "ab\0");
-			}
 		}
 
-	}
-
 };
 
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);
+if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);

+ 47 - 43
test/lib/pipeline/expressions/ToUpperExpression.js

@@ -1,54 +1,58 @@
 "use strict";
 var assert = require("assert"),
-	ToUpperExpression = require("../../../../lib/pipeline/expressions/ToUpperExpression"),
-	Expression = require("../../../../lib/pipeline/expressions/Expression");
+		ToUpperExpression = require("../../../../lib/pipeline/expressions/ToUpperExpression"),
+		Expression = require("../../../../lib/pipeline/expressions/Expression");
 
 
 module.exports = {
 
-	"ToUpperExpression": {
+		"ToUpperExpression": {
+
+				"constructor()": {
+
+						"should not throw Error when constructing without args": function testConstructor() {
+								assert.doesNotThrow(function() {
+										new ToUpperExpression();
+								});
+						}
+
+				},
+
+				"#getOpName()": {
+
+						"should return the correct op name; $toUpper": function testOpName() {
+								assert.equal(new ToUpperExpression().getOpName(), "$toUpper");
+						}
+
+				},
+
+				"#evaluateInternal()": {
+
+						"should return the uppercase version of the string if there is a null character in the middle of the string": function testStuff() {
+								assert.strictEqual(Expression.parseOperand({
+										$toUpper: "$a"
+								}).evaluateInternal({
+										a: "a\0B"
+								}), "A\0B");
+						},
+						"should return the uppercase version of the string if there is a null character at the beginning of the string": function testStuff() {
+								assert.strictEqual(Expression.parseOperand({
+										$toUpper: "$a"
+								}).evaluateInternal({
+										a: "\0aB"
+								}), "\0AB");
+						},
+						"should return the uppercase version of the string if there is a null character at the end of the string": function testStuff() {
+								assert.strictEqual(Expression.parseOperand({
+										$toUpper: "$a"
+								}).evaluateInternal({
+										a: "aB\0"
+								}), "AB\0");
+						}
+				}
 
-		"constructor()": {
-
-			"should not throw Error when constructing without args": function testConstructor(){
-				assert.doesNotThrow(function(){
-					new ToUpperExpression();
-				});
-			}
-
-		},
-
-		"#getOpName()": {
-
-			"should return the correct op name; $toUpper": function testOpName(){
-				assert.equal(new ToUpperExpression().getOpName(), "$toUpper");
-			}
-
-		},
-
-		"#getFactory()": {
-
-			"should return the constructor for this class": function factoryIsConstructor(){
-				assert.strictEqual(new ToUpperExpression().getFactory(), undefined);
-			}
-
-		},
-
-		"#evaluate()": {
-
-			"should return the uppercase version of the string if there is a null character in the middle of the string": function testStuff(){
-				assert.strictEqual(Expression.parseOperand({$toUpper:"$a"}).evaluate({a:"a\0B"}), "A\0B");
-			},
-			"should return the uppercase version of the string if there is a null character at the beginning of the string": function testStuff(){
-				assert.strictEqual(Expression.parseOperand({$toUpper:"$a"}).evaluate({a:"\0aB"}), "\0AB");
-			},
-			"should return the uppercase version of the string if there is a null character at the end of the string": function testStuff(){
-				assert.strictEqual(Expression.parseOperand({$toUpper:"$a"}).evaluate({a:"aB\0"}), "AB\0");
-			}
 		}
 
-	}
-
 };
 
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);
+if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);