ソースを参照

Fixed munge day of week expression and added test cases. fixes #964

http://source.rd.rcg.local/trac/eagle6/changeset/1270/Eagle6_SVN
Philip Murray 12 年 前
コミット
a4d2b31906

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

@@ -12,7 +12,7 @@ var DayOfWeekExpression = 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 day of the week as a number between 1 (Sunday) and 7 (Saturday.) **/

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

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