浏览代码

Refs #2307. Making include 0, null, undefined (as null)

Chris Sexton 12 年之前
父节点
当前提交
6051a618c5
共有 2 个文件被更改,包括 20 次插入4 次删除
  1. 4 2
      lib/pipeline/accumulators/PushAccumulator.js
  2. 16 2
      test/lib/pipeline/accumulators/PushAccumulator.js

+ 4 - 2
lib/pipeline/accumulators/PushAccumulator.js

@@ -19,8 +19,10 @@ var PushAccumulator = module.exports = (function(){
 	proto.evaluate = function evaluate(doc){
 		if(this.operands.length != 1) throw new Error("this should never happen");
 		var v = this.operands[0].evaluate(doc);
-		if(v)
-			this.values.push(v);
+
+		if (v === undefined) v = null;
+
+		this.values.push(v);
 	
 		return null;
 	};

+ 16 - 2
test/lib/pipeline/accumulators/PushAccumulator.js

@@ -55,11 +55,25 @@ module.exports = {
 				assert.deepEqual(accumulator.getValue(), [1,2]);
 			},
 
-			"should evaluate one document with null and one document with a value and return an array of 1": function testStuff(){
+			"should evaluate one document with null and one document with a value and return an array of 1, null": function testStuff(){
 				var accumulator = createAccumulator();
 				accumulator.evaluate({b:1});
 				accumulator.evaluate({b:null});
-				assert.deepEqual(accumulator.getValue(), [1]);
+				assert.deepEqual(accumulator.getValue(), [1, null]);
+			},
+
+			"should evaluate one document with undefined and one document with a value and return an array of 1, null": function testStuff(){
+				var accumulator = createAccumulator();
+				accumulator.evaluate({b:1});
+				accumulator.evaluate({b:undefined});
+				assert.deepEqual(accumulator.getValue(), [1, null]);
+			},
+
+			"should evaluate one document with zero and one document with a value and return an array of 1, 0": function testStuff(){
+				var accumulator = createAccumulator();
+				accumulator.evaluate({b:1});
+				accumulator.evaluate({b:0});
+				assert.deepEqual(accumulator.getValue(), [1, 0]);
 			}
 
 		}