소스 검색

Fixed munge toupper expression and added test cases. fixes #978

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

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

@@ -1,6 +1,8 @@
 var ToUpperExpression = module.exports = (function(){
 	// CONSTRUCTOR
-	/** A $toUpper pipeline expression. @see evaluate **/
+	/** 
+	* A $toUpper pipeline expression. @see evaluate 
+	**/
 	var klass = function ToUpperExpression(){
 		if(arguments.length !== 0) throw new Error("zero args expected");
 		base.call(this);
@@ -16,10 +18,12 @@ var ToUpperExpression = 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/ToUpperExpression.js

@@ -0,0 +1,52 @@
+var assert = require("assert"),
+	ToUpperExpression = require("../../../../lib/pipeline/expressions/ToUpperExpression"),
+	Expression = require("../../../../lib/pipeline/expressions/Expression");
+
+module.exports = {
+
+	"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");
+			}
+
+		},
+
+		"#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);