浏览代码

EAGLESIX-2695 Added a new test file. Populated it with some tests and some test stubs.

Tony Ennis 11 年之前
父节点
当前提交
6b0e5d9df3
共有 2 个文件被更改,包括 104 次插入3 次删除
  1. 3 3
      lib/pipeline/expressions/LetExpression.js
  2. 101 0
      test/lib/pipeline/expressions/LetExpression_test.js

+ 3 - 3
lib/pipeline/expressions/LetExpression.js

@@ -1,7 +1,5 @@
 "use strict";
 "use strict";
 
 
-Expression.registerExpression("$let", LetExpression.parse);
-
 var LetExpression = module.exports = function LetExpression(vars, subExpression){
 var LetExpression = module.exports = function LetExpression(vars, subExpression){
 	//if (arguments.length !== 2) throw new Error("Two args expected");
 	//if (arguments.length !== 2) throw new Error("Two args expected");
 	this._variables = vars;
 	this._variables = vars;
@@ -14,7 +12,6 @@ var Variables = require("./Variables"),
 
 
 // PROTOTYPE MEMBERS
 // PROTOTYPE MEMBERS
 
 
-
 proto.parse = function parse(expr, vpsIn){
 proto.parse = function parse(expr, vpsIn){
 	if(!("$let" in expr)) {
 	if(!("$let" in expr)) {
 		throw new Error("Tried to create a $let with something other than let. Looks like your parse map went all funny.");
 		throw new Error("Tried to create a $let with something other than let. Looks like your parse map went all funny.");
@@ -67,6 +64,7 @@ proto.parse = function parse(expr, vpsIn){
 };
 };
 
 
 proto.optimize = function optimize() {
 proto.optimize = function optimize() {
+	// This statement doesn't look necessary. We do this work later on if there aren't (or are!) variables.
 	if(this._variables.empty()) {
 	if(this._variables.empty()) {
 		return this._subExpression.optimize();
 		return this._subExpression.optimize();
 	}
 	}
@@ -117,3 +115,5 @@ proto.addDependencies = function addDependencies(deps, path){
 					// addDependencies) in many places.
 					// addDependencies) in many places.
 
 
 };
 };
+
+Expression.registerExpression("$let", LetExpression.parse);

+ 101 - 0
test/lib/pipeline/expressions/LetExpression_test.js

@@ -0,0 +1,101 @@
+"use strict";
+var assert = require("assert"),
+	LetExpression = require("../../../../lib/pipeline/expressions/LetExpression"),
+	Expression = require("../../../../lib/pipeline/expressions/Expression");
+
+
+module.exports = {
+
+	"LetExpression": {
+
+		"constructor()": {
+
+			"should throw when there are not 2 args": function testConstructorNot2() {
+				assert.throws(function () {
+					new LetExpression({});
+				});
+				assert.throws(function () {
+					new LetExpression({}, {}, {});
+				});
+			},
+			"should not throw when there are 2 args": function testConstructor2() {
+				assert.doesNotThrow(function () {
+					new LetExpression({}, {});
+				});
+			}
+		},
+
+		"#parse()": {
+			"should throw if $let isn't in expr": function () {
+				assert.throws(function(){
+					new LetExpression.parse({$noLetIsHere:1}, {})
+				});
+			},
+			"should throw if the $let expression isn't an object": function () {
+				assert.throws(function(){
+					new LetExpression.parse({$expr:"this is not an object"}, {})
+				});
+			},
+			"should throw if the $let expression is an array": function () {
+				assert.throws(function(){
+					new LetExpression.parse({$expr:[1,2,3]}, {})
+				});
+			},
+			"should throw if there is no vars parameter to $let": function () {
+				assert.throws(function(){
+					new LetExpression.parse({$expr:{noVars:1}}, {})
+				});
+			},
+			"should throw if there is no input parameter to $let": function () {
+				assert.throws(function(){
+					new LetExpression.parse({$expr:{vars:1, noIn:2}}, {})
+				});
+			},
+			"should throw if any of the arguments to $let are not 'in' or 'var'": function () {
+				assert.throws(function(){
+					new LetExpression.parse({$expr:{vars:1, in:2, zoot:3}}, {})
+				});
+			},
+			"should throw if the var name is not writable": function () {
+				assert.throws(function(){
+					new LetExpression.parse({$expr:{vars:["$$bad$$"], in:2}}, {})
+				});
+			},
+			"should return a Let expression": function () {
+				var letExpression = new LetExpression.parse({$expr:{vars:["$valid"], in:2}}, {})
+				assert(letExpression);
+				assert(false);	// I don't know how to test this yet.
+			}
+		},
+
+		"#optimize()": {
+			"should optimize subexpressions if there are no variables": function () {
+				assert(fail);
+			},
+			"should optimize variables": function () {
+				assert(fail);
+			},
+			"should optimize subexpressions if there are variables": function () {
+				assert(fail);
+			}
+		},
+		"#serialize()": {
+			"should serialize variables and the subexpression": function () {
+				assert(fail);
+			}
+		},
+		"#evaluateInternal()": {
+			"should preform the evaluation for variables and the subexpression": function () {
+				assert(fail);
+			}
+		},
+		"#addDependencies()": {
+			"add dependencies to the variables and the subexpression": function () {
+				assert(fail);
+			}
+		}
+	}
+
+};
+
+if (!module.parent)(new (require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);