Browse Source

EAGLESIX-2722 Minor change to ToLowerExpression, filled out the tests a little.

Tony Ennis 11 years ago
parent
commit
e56b8b1edc

+ 1 - 0
lib/pipeline/expressions/ToLowerExpression.js

@@ -9,6 +9,7 @@
  * @constructor
  **/
 var ToLowerExpression = module.exports = function ToLowerExpression(){
+	if (arguments.length !== 0) throw new Error(klass.name + ": args expected: value");
 	base.call(this);
 }, klass = ToLowerExpression, base = require("./FixedArityExpressionT")(ToLowerExpression, 1), proto = klass.prototype = Object.create(base.prototype, {constructor: {value: klass}});
 

+ 48 - 45
test/lib/pipeline/expressions/ToLowerExpression_test.js

@@ -1,64 +1,67 @@
 "use strict";
 var assert = require("assert"),
-		ToLowerExpression = require("../../../../lib/pipeline/expressions/ToLowerExpression"),
-		Expression = require("../../../../lib/pipeline/expressions/Expression");
+	ToLowerExpression = require("../../../../lib/pipeline/expressions/ToLowerExpression"),
+	VariablesParseState = require("../../../../lib/pipeline/expressions/VariablesParseState"),
+	VariablesIdGenerator = require("../../../../lib/pipeline/expressions/VariablesIdGenerator"),
+	Expression = require("../../../../lib/pipeline/expressions/Expression");
 
 
 module.exports = {
 
-		"ToLowerExpression": {
+	"ToLowerExpression": {
 
-				"constructor()": {
+		beforeEach: function () {
+			this.vps = new VariablesParseState(new VariablesIdGenerator());
+		},
 
-						"should not throw Error when constructing without args": function testConstructor() {
-								assert.doesNotThrow(function() {
-										new ToLowerExpression();
-								});
-						},
+		"constructor()": {
 
-					"should throw Error when constructing with args": function testConstructor(){
-						assert.throws(function(){
-							new ToLowerExpression(1);
-						});
-					}
+			"should not throw Error when constructing without args": function testConstructor() {
+				assert.doesNotThrow(function () {
+					new ToLowerExpression();
+				});
+			},
 
-				},
+			"should throw Error when constructing with args": function testConstructor() {
+				assert.throws(function () {
+					new ToLowerExpression(1);
+				});
+			}
 
-				"#getOpName()": {
+		},
 
-						"should return the correct op name; $toLower": function testOpName() {
-								assert.equal(new ToLowerExpression().getOpName(), "$toLower");
-						}
+		"#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");
-						}
-				}
+		"#evaluate()": {
 
+			"should lowercase a string": function(){
+				assert.strictEqual(Expression.parseOperand({$toLower: "$a"}, this.vps).evaluate({a: "NOW IS THE TIME"}), "now is the time");
+			},
+			"should not change symbols": function(){
+				var symbs = "!@#$%^&*()_+{}[]:\";'<>?/.,;";
+				assert.strictEqual(Expression.parseOperand({$toLower: "$a"}, this.vps).evaluate({a: symbs}), symbs);
+			},
+			"should not change lowercase": function(){
+				var symbs = "now is the time for all good men to come from the aid of their computers";
+				assert.strictEqual(Expression.parseOperand({$toLower: "$a"}, this.vps).evaluate({a: symbs}), symbs);
+			},
+			"should return the lowercase version of the string if there is a null character in the middle of the string": function() {
+				assert.strictEqual(Expression.parseOperand({$toLower: "$a"}, this.vps).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() {
+				assert.strictEqual(Expression.parseOperand({$toLower: "$a"}, this.vps).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() {
+				assert.strictEqual(Expression.parseOperand({$toLower: "$a" }, this.vps).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);