Browse Source

Fixed munge hour expression and added test cases. fixes #966

http://source.rd.rcg.local/trac/eagle6/changeset/1279/Eagle6_SVN
Philip Murray 12 years ago
parent
commit
a33c95f8cb

+ 4 - 2
lib/pipeline/expressions/HourExpression.js

@@ -13,10 +13,12 @@ var HourExpression = 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 hour between 0 and 23. **/
+	/** 
+	* Takes a date and returns the hour between 0 and 23. 
+	**/
 	proto.evaluate = function evaluate(doc){
 		this.checkArgCount(1);
 		var date = this.operands[0].evaluate(doc);

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

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