Browse Source

Fixes #989 Added SingleValueAccumulator

http://source.rd.rcg.local/trac/eagle6/changeset/1302/Eagle6_SVN
Adam Bell 13 years ago
parent
commit
4f69297b68

+ 1 - 1
lib/pipeline/accumulator/Accumulator.js → lib/pipeline/accumulators/Accumulator.js

@@ -7,7 +7,7 @@ var Accumulator = module.exports = (function(){
 	var klass = function Accumulator(){
 		if(arguments.length !== 0) throw new Error("zero args expected");
 		base.call(this);
-	}, base = require("./NaryExpression"), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
+	}, base = require("../expressions/NaryExpression"), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 
 	// DEPENDENCIES
 	// var Value = require("../Value"),

+ 28 - 0
lib/pipeline/accumulators/SingleValueAccumulator.js

@@ -0,0 +1,28 @@
+var AccumulatorSingleValue = module.exports = (function(){
+
+	// Constructor
+	/*
+      This isn't a finished accumulator, but rather a convenient base class
+      for others such as $first, $last, $max, $min, and similar.  It just
+      provides a holder for a single Value, and the getter for that.  The
+      holder is protected so derived classes can manipulate it.
+     */
+
+	var klass = module.exports = function AccumulatorSingleValue(value){
+		if(arguments.length !== 1 ) throw new Error("expects a single value");
+		this.value = value;
+		base.call(this);
+	}, Accumulator = require("./Accumulator"), base = Accumulator, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
+
+	// DEPENDENCIES
+	var Value = require("../Value");
+
+	proto.getValue = function getValue(){
+		return this.value;
+	};
+
+	return klass;
+
+})();
+
+

+ 38 - 0
test/lib/pipeline/accumulators/SingleValueAccumulator.js

@@ -0,0 +1,38 @@
+var assert = require("assert"),
+	SingleValueAccumulator = require("../../../../lib/pipeline/accumulator/SingleValueAccumulator");
+
+//TODO: refactor these test cases using Expression.parseOperand() or something because these could be a whole lot cleaner...
+module.exports = {
+
+	"SingleValueAccumulator": {
+
+		"constructor()": {
+
+			"should not throw Error when constructing with 1 arg": function testConstructor(){
+				assert.doesNotThrow(function(){
+					new SingleValueAccumulator(null);
+				});
+			},
+			"should throw Error when constructing with > 1 arg": function testConstructor(){
+				assert.throws(function(){
+					new SingleValueAccumulator(null, null);
+				});
+			},
+			"should throw Error when constructing with < 1 arg": function testConstructor(){
+				assert.throws(function(){
+					new SingleValueAccumulator();
+				});
+			}
+		},
+
+		"#getValue()": {
+
+			"should return the correct value 'foo'": function testGetValue(){
+				assert.equal(new SingleValueAccumulator("foo").getValue(), "foo");
+			}
+
+		}
+	}
+};
+
+if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);