Browse Source

Fixed munge year expression and added test cases. fixes #980

http://source.rd.rcg.local/trac/eagle6/changeset/1271/Eagle6_SVN
Philip Murray 12 years ago
parent
commit
0f85697c87

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

@@ -17,7 +17,7 @@ var YearExpression = module.exports = (function(){
 
 	proto.addOperand = function addOperand(expr) {
 		this.checkArgLimit(1);
-		base.addOperand(expr);
+		base.prototype.addOperand.call(this, expr);
 	};
 
 	/** Takes a date and returns the full year. **/

+ 47 - 0
test/lib/pipeline/expressions/YearExpression.js

@@ -0,0 +1,47 @@
+var assert = require("assert"),
+	YearExpression = require("../../../../lib/pipeline/expressions/YearExpression"),
+	Expression = require("../../../../lib/pipeline/expressions/Expression");
+
+module.exports = {
+
+	"YearExpression": {
+
+		"constructor()": {
+
+			"should not throw Error when constructing without args": function testConstructor(){
+				assert.doesNotThrow(function(){
+					new YearExpression();
+				});
+			}
+
+		},
+
+		"#getOpName()": {
+
+			"should return the correct op name; $year": function testOpName(){
+				assert.equal(new YearExpression().getOpName(), "$year");
+			}
+
+		},
+
+		"#getFactory()": {
+
+			"should return the constructor for this class": function factoryIsConstructor(){
+				assert.strictEqual(new YearExpression().getFactory(), undefined);
+			}
+
+		},
+
+		"#evaluate()": {
+
+			"should return day of week; 2013 for 2013-02-18": function testStuff(){
+				assert.strictEqual(Expression.parseOperand({$year:"$someDate"}).evaluate({someDate:new Date("Mon Feb 18 2013 00:00:00 GMT-0500 (EST)")}), 2013);
+			}
+
+		}
+
+	}
+
+};
+
+if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);