소스 검색

Fixed munge tolower expression and added test cases. fixes #977

http://source.rd.rcg.local/trac/eagle6/changeset/1290/Eagle6_SVN
Philip Murray 12 년 전
부모
커밋
de9c21f134
2개의 변경된 파일59개의 추가작업 그리고 3개의 파일을 삭제
  1. 7 3
      lib/pipeline/expressions/ToLowerExpression.js
  2. 52 0
      test/lib/pipeline/expressions/ToLowerExpression.js

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

@@ -1,6 +1,8 @@
 var ToLowerExpression = module.exports = (function(){
 	// CONSTRUCTOR
-	/** A $toLower pipeline expression. @see evaluate **/
+	/** 
+	* A $toLower pipeline expression. @see evaluate 
+	**/
 	var klass = function ToLowerExpression(){
 		if(arguments.length !== 0) throw new Error("zero args expected");
 		base.call(this);
@@ -16,10 +18,12 @@ var ToLowerExpression = module.exports = (function(){
 
 	proto.addOperand = function addOperand(expr) {
 		this.checkArgLimit(1);
-		base.addOperand(expr);
+		base.prototype.addOperand.call(this, expr);
 	};
 
-	/** 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.evaluate = function evaluate(doc) {
 		this.checkArgCount(1);
 		var val = this.operands[0].evaluate(doc),

+ 52 - 0
test/lib/pipeline/expressions/ToLowerExpression.js

@@ -0,0 +1,52 @@
+var assert = require("assert"),
+	ToLowerExpression = require("../../../../lib/pipeline/expressions/ToLowerExpression"),
+	Expression = require("../../../../lib/pipeline/expressions/Expression");
+
+module.exports = {
+
+	"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");
+			}
+
+		},
+
+		"#getFactory()": {
+
+			"should return the constructor for this class": function factoryIsConstructor(){
+				assert.strictEqual(new ToLowerExpression().getFactory(), undefined);
+			}
+
+		},
+
+		"#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);