瀏覽代碼

Fixes #973. Test cases and bug fixes for SecondExpression. The test case for leap seconds is commented out, because v8 does not support it. We can come back and fix it later.

http://source.rd.rcg.local/trac/eagle6/changeset/1282/Eagle6_SVN
Spencer Rathbun 12 年之前
父節點
當前提交
66c08fd85d
共有 2 個文件被更改,包括 56 次插入1 次删除
  1. 3 1
      lib/pipeline/expressions/SecondExpression.js
  2. 53 0
      test/lib/pipeline/expressions/SecondExpression.js

+ 3 - 1
lib/pipeline/expressions/SecondExpression.js

@@ -13,7 +13,7 @@ var SecondExpression = 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 second between 0 and 59, but can be 60 to account for leap seconds. **/
@@ -21,6 +21,8 @@ var SecondExpression = module.exports = (function(){
 		this.checkArgCount(1);
 		var date = this.operands[0].evaluate(doc);
 		return date.getSeconds();	//TODO: incorrect for last second of leap year, need to fix...
+		// currently leap seconds are unsupported in v8
+		// http://code.google.com/p/v8/issues/detail?id=1944
 	};
 
 	return klass;

+ 53 - 0
test/lib/pipeline/expressions/SecondExpression.js

@@ -0,0 +1,53 @@
+var assert = require("assert"),
+	SecondExpression = require("../../../../lib/pipeline/expressions/SecondExpression"),
+	Expression = require("../../../../lib/pipeline/expressions/Expression");
+
+module.exports = {
+
+	"SecondExpression": {
+
+		"constructor()": {
+
+			"should not throw Error when constructing without args": function testConstructor(){
+				assert.doesNotThrow(function(){
+					new SecondExpression();
+				});
+			}
+
+		},
+
+		"#getOpName()": {
+
+			"should return the correct op name; $second": function testOpName(){
+				assert.equal(new SecondExpression().getOpName(), "$second");
+			}
+
+		},
+
+		"#getFactory()": {
+
+			"should return the constructor for this class": function factoryIsConstructor(){
+				assert.strictEqual(new SecondExpression().getFactory(), undefined);
+			}
+
+		},
+
+		"#evaluate()": {
+
+			"should return the current second in the date; 19 for 2013-02-18 11:24:19 EST": function testStuff(){
+				assert.strictEqual(Expression.parseOperand({$second:"$someDate"}).evaluate({someDate:new Date("2013-02-18 11:24:19 EST")}), 19);
+			}
+
+				/*
+			"should return the leap second in the date; 60 for June 30, 2012 at 23:59:60 UTC": function testStuff(){
+				assert.strictEqual(Expression.parseOperand({$second:"$someDate"}).evaluate({someDate:new Date("June 30, 2012 at 23:59:60 UTC")}), 60);
+			}
+
+				*/
+		}
+
+	}
+
+};
+
+if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);