Ver Fonte

EAGLESIX-3157: test: fix jshints, add jshintrc, fix matcher exports, update self-hosted mocha line

Kyle P Davis há 11 anos atrás
pai
commit
476023b9dc
100 ficheiros alterados com 1279 adições e 1483 exclusões
  1. 2 1
      lib/pipeline/index.js
  2. 36 0
      lib/pipeline/matcher/index.js
  3. 4 0
      test/.jshintrc
  4. 12 13
      test/lib/aggregate_test.js
  5. 1 3
      test/lib/pipeline/DepsTracker_test.js
  6. 3 5
      test/lib/pipeline/Document_test.js
  7. 1 3
      test/lib/pipeline/FieldPath_test.js
  8. 1 1
      test/lib/pipeline/ParsedDeps_test.js
  9. 20 23
      test/lib/pipeline/PipelineD_test.js
  10. 19 30
      test/lib/pipeline/Pipeline_test.js
  11. 2 4
      test/lib/pipeline/Value_test.js
  12. 3 4
      test/lib/pipeline/accumulators/AddToSetAccumulator_test.js
  13. 1 3
      test/lib/pipeline/accumulators/AvgAccumulator_test.js
  14. 1 3
      test/lib/pipeline/accumulators/FirstAccumulator_test.js
  15. 1 5
      test/lib/pipeline/accumulators/LastAccumulator_test.js
  16. 1 3
      test/lib/pipeline/accumulators/MinMaxAccumulator_test.js
  17. 1 6
      test/lib/pipeline/accumulators/PushAccumulator_test.js
  18. 2 5
      test/lib/pipeline/accumulators/SumAccumulator_test.js
  19. 3 7
      test/lib/pipeline/documentSources/CursorDocumentSource_test.js
  20. 4 6
      test/lib/pipeline/documentSources/DocumentSource_test.js
  21. 8 9
      test/lib/pipeline/documentSources/GeoNearDocumentSource_test.js
  22. 19 24
      test/lib/pipeline/documentSources/GroupDocumentSource_test.js
  23. 3 4
      test/lib/pipeline/documentSources/LimitDocumentSource_test.js
  24. 31 33
      test/lib/pipeline/documentSources/MatchDocumentSource_test.js
  25. 7 8
      test/lib/pipeline/documentSources/OutDocumentSource_test.js
  26. 19 22
      test/lib/pipeline/documentSources/ProjectDocumentSource_test.js
  27. 17 20
      test/lib/pipeline/documentSources/RedactDocumentSource_test.js
  28. 17 19
      test/lib/pipeline/documentSources/SkipDocumentSource_test.js
  29. 12 15
      test/lib/pipeline/documentSources/SortDocumentSource_test.js
  30. 0 47
      test/lib/pipeline/documentSources/TestBase.js
  31. 18 25
      test/lib/pipeline/documentSources/UnwindDocumentSource_test.js
  32. 3 7
      test/lib/pipeline/expressions/AddExpression_test.js
  33. 3 5
      test/lib/pipeline/expressions/AllElementsTrueExpression_test.js
  34. 2 4
      test/lib/pipeline/expressions/AndExpression_test.js
  35. 3 5
      test/lib/pipeline/expressions/AnyElementTrueExpression_test.js
  36. 1 2
      test/lib/pipeline/expressions/CoerceToBoolExpression_test.js
  37. 3 5
      test/lib/pipeline/expressions/CompareExpression_test.js
  38. 1 3
      test/lib/pipeline/expressions/ConcatExpression_test.js
  39. 1 3
      test/lib/pipeline/expressions/CondExpression_test.js
  40. 1 3
      test/lib/pipeline/expressions/ConstantExpression_test.js
  41. 1 3
      test/lib/pipeline/expressions/DayOfMonthExpression_test.js
  42. 1 3
      test/lib/pipeline/expressions/DayOfWeekExpression_test.js
  43. 1 3
      test/lib/pipeline/expressions/DayOfYearExpression_test.js
  44. 1 3
      test/lib/pipeline/expressions/DivideExpression_test.js
  45. 2 4
      test/lib/pipeline/expressions/FieldPathExpression_test.js
  46. 1 3
      test/lib/pipeline/expressions/HourExpression_test.js
  47. 1 4
      test/lib/pipeline/expressions/IfNullExpression_test.js
  48. 19 20
      test/lib/pipeline/expressions/LetExpression_test.js
  49. 1 3
      test/lib/pipeline/expressions/MapExpression_test.js
  50. 1 3
      test/lib/pipeline/expressions/MillisecondExpression_test.js
  51. 1 3
      test/lib/pipeline/expressions/MinuteExpression_test.js
  52. 1 3
      test/lib/pipeline/expressions/ModExpression_test.js
  53. 1 3
      test/lib/pipeline/expressions/MonthExpression_test.js
  54. 6 5
      test/lib/pipeline/expressions/MultiplyExpression_test.js
  55. 1 5
      test/lib/pipeline/expressions/NaryExpression_test.js
  56. 1 3
      test/lib/pipeline/expressions/NotExpression_test.js
  57. 48 52
      test/lib/pipeline/expressions/ObjectExpression_test.js
  58. 2 4
      test/lib/pipeline/expressions/OrExpression_test.js
  59. 1 3
      test/lib/pipeline/expressions/SecondExpression_test.js
  60. 1 3
      test/lib/pipeline/expressions/SetDifferenceExpression_test.js
  61. 1 3
      test/lib/pipeline/expressions/SetEqualsExpression_test.js
  62. 3 5
      test/lib/pipeline/expressions/SetExpectedResultBase.js
  63. 1 3
      test/lib/pipeline/expressions/SetIntersectionExpression_test.js
  64. 1 3
      test/lib/pipeline/expressions/SetIsSubsetExpression_test.js
  65. 1 3
      test/lib/pipeline/expressions/SetUnionExpression_test.js
  66. 1 4
      test/lib/pipeline/expressions/SizeExpression_test.js
  67. 2 4
      test/lib/pipeline/expressions/StrcasecmpExpression_test.js
  68. 2 4
      test/lib/pipeline/expressions/SubstrExpression_test.js
  69. 1 5
      test/lib/pipeline/expressions/SubtractExpression_test.js
  70. 5 9
      test/lib/pipeline/expressions/ToLowerExpression_test.js
  71. 5 9
      test/lib/pipeline/expressions/ToUpperExpression_test.js
  72. 2 3
      test/lib/pipeline/expressions/VariablesIdGenerator_test.js
  73. 15 17
      test/lib/pipeline/expressions/VariablesParseState_test.js
  74. 25 27
      test/lib/pipeline/expressions/Variables_test.js
  75. 1 3
      test/lib/pipeline/expressions/WeekExpression_test.js
  76. 1 3
      test/lib/pipeline/expressions/YearExpression_test.js
  77. 3 3
      test/lib/pipeline/expressions/utils.js
  78. 1 4
      test/lib/pipeline/expressions/utils_test.js
  79. 10 11
      test/lib/pipeline/matcher/AllElemMatchOp_test.js
  80. 20 21
      test/lib/pipeline/matcher/AndMatchExpression_test.js
  81. 67 68
      test/lib/pipeline/matcher/ComparisonMatchExpression_test.js
  82. 19 21
      test/lib/pipeline/matcher/ElemMatchObjectMatchExpression_test.js
  83. 15 16
      test/lib/pipeline/matcher/ElemMatchValueMatchExpression_test.js
  84. 13 13
      test/lib/pipeline/matcher/ElementPath_test.js
  85. 63 63
      test/lib/pipeline/matcher/EqualityMatchExpression_test.js
  86. 28 29
      test/lib/pipeline/matcher/ExistsMatchExpression_test.js
  87. 54 54
      test/lib/pipeline/matcher/InMatchExpression_test.js
  88. 3 5
      test/lib/pipeline/matcher/ListOfMatchExpression_test.js
  89. 262 262
      test/lib/pipeline/matcher/MatchExpressionParser_test.js
  90. 3 5
      test/lib/pipeline/matcher/Matcher2_test.js
  91. 39 40
      test/lib/pipeline/matcher/ModMatchExpression_test.js
  92. 29 31
      test/lib/pipeline/matcher/NorMatchExpression_test.js
  93. 23 24
      test/lib/pipeline/matcher/NotMatchExpression_test.js
  94. 29 31
      test/lib/pipeline/matcher/OrMatchExpression_test.js
  95. 54 53
      test/lib/pipeline/matcher/RegexMatchExpression_test.js
  96. 7 8
      test/lib/pipeline/matcher/SizeMatchExpression_test.js
  97. 23 25
      test/lib/pipeline/matcher/TextMatchExpression_test.js
  98. 40 40
      test/lib/pipeline/matcher/TypeMatchExpression_test.js
  99. 8 9
      test/lib/query/ArrayRunner_test.js
  100. 20 21
      test/lib/query/DocumentSourceRunner_test.js

+ 2 - 1
lib/pipeline/index.js

@@ -8,5 +8,6 @@ module.exports = {
 	Value: require("./Value"),
 	accumulators: require("./accumulators/"),
 	documentSources: require("./documentSources/"),
-	expressions: require("./expressions/")
+	expressions: require("./expressions/"),
+	matcher: require("./matcher/"),
 };

+ 36 - 0
lib/pipeline/matcher/index.js

@@ -0,0 +1,36 @@
+"use strict";
+module.exports = {
+	AllElemMatchOp: require("./AllElemMatchOp"),
+	AndMatchExpression: require("./AndMatchExpression"),
+	ArrayFilterEntries: require("./ArrayFilterEntries"),
+	ArrayMatchingMatchExpression: require("./ArrayMatchingMatchExpression"),
+	AtomicMatchExpression: require("./AtomicMatchExpression"),
+	ComparisonMatchExpression: require("./ComparisonMatchExpression"),
+	ElemMatchObjectMatchExpression: require("./ElemMatchObjectMatchExpression"),
+	ElemMatchValueMatchExpression: require("./ElemMatchValueMatchExpression"),
+	ElementPath: require("./ElementPath"),
+	EqualityMatchExpression: require("./EqualityMatchExpression"),
+	ExistsMatchExpression: require("./ExistsMatchExpression"),
+	FalseMatchExpression: require("./FalseMatchExpression"),
+	FieldRef: require("./FieldRef"),
+	GTEMatchExpression: require("./GTEMatchExpression"),
+	GTMatchExpression: require("./GTMatchExpression"),
+	InMatchExpression: require("./InMatchExpression"),
+	LTEMatchExpression: require("./LTEMatchExpression"),
+	LTMatchExpression: require("./LTMatchExpression"),
+	LeafMatchExpression: require("./LeafMatchExpression"),
+	ListOfMatchExpression: require("./ListOfMatchExpression"),
+	MatchDetails: require("./MatchDetails"),
+	MatchExpression: require("./MatchExpression"),
+	MatchExpressionParser: require("./MatchExpressionParser"),
+	Matcher2: require("./Matcher2"),
+	ModMatchExpression: require("./ModMatchExpression"),
+	NorMatchExpression: require("./NorMatchExpression"),
+	NotMatchExpression: require("./NotMatchExpression"),
+	OrMatchExpression: require("./OrMatchExpression"),
+	RegexMatchExpression: require("./RegexMatchExpression"),
+	SizeMatchExpression: require("./SizeMatchExpression"),
+	TextMatchExpression: require("./TextMatchExpression"),
+	TextMatchExpressionParser: require("./TextMatchExpressionParser"),
+	TypeMatchExpression: require("./TypeMatchExpression"),
+};

+ 4 - 0
test/.jshintrc

@@ -0,0 +1,4 @@
+{
+	"extends": "../.jshintrc",
+	"nonew": false
+}

+ 12 - 13
test/lib/aggregate_test.js

@@ -1,4 +1,6 @@
 "use strict";
+/*jshint camelcase:false*/
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	aggregate = require("../../");
 
@@ -28,7 +30,7 @@ function testAggregate(opts){
 
 		// SYNC: test that it is actually reusable
 		results = aggregator(opts.inputs);
-		assert.equal(JSON.stringify(results), JSON.stringify(opts.expected), "Reuse of aggregator should yield the same results!");
+		assert.equal(JSON.stringify(results), JSON.stringify(opts.expected), "should allow sync aggregator reuse");
 	}
 	// ASYNC: test one-off usage
 	aggregate(opts.pipeline, opts.inputs, function(err, results){
@@ -55,7 +57,7 @@ function testAggregate(opts){
 					// ASYNC: test that it is actually reusable
 					aggregator(opts.inputs, function(err, results){
 						assert.ifError(err);
-						assert.equal(JSON.stringify(results), JSON.stringify(opts.expected), "Reuse of aggregator should yield the same results!");
+						assert.equal(JSON.stringify(results), JSON.stringify(opts.expected), "should allow async aggregator reuse");
 
 						// success!
 						return opts.next();
@@ -75,7 +77,7 @@ function testBatches(opts){
 		actual = [],
 		eachExpected = [],
 		expected = [];
-		
+
 	for(var i = 0; i < opts.documents; i++){
 		inputs.push({a:i});
 		eachExpected.push({foo:i});
@@ -91,8 +93,8 @@ function testBatches(opts){
 			{$project:{
 				foo: "$a"
 			}}
-		]}, 
-		inputs, 
+		]},
+		inputs,
 		function(err, results){
 			assert.ifError(err);
 			if (results) {
@@ -399,7 +401,7 @@ module.exports = {
 				next: next
 			});
 		},
-		
+
 		"should be able to handle a large array of inputs": function(next){
 			var inputs = [],
 				expected = [];
@@ -453,7 +455,7 @@ module.exports = {
 			var pipeline = [
 					{$match:{e:1}},
 					{$match:{d:1}},
-					{$skip:2}, 
+					{$skip:2},
 					{$limit:1},
 					{$project:{
 						foo: "$a"
@@ -465,7 +467,7 @@ module.exports = {
 				expected = [
 					{$match:{$and:[{e:1},{d:1}]}},
 					{$limit:3},
-					{$skip:2}, 
+					{$skip:2},
 					{$project:{
 						foo: "$a"
 					}},
@@ -483,7 +485,7 @@ module.exports = {
 			var pipeline = [
 					{$match:{e:1}},
 					{$match:{d:1}},
-					{$skip:2}, 
+					{$skip:2},
 					{$limit:1},
 					{$project:{
 						foo: "$a"
@@ -535,7 +537,7 @@ module.exports = {
 			assert.throws(function(){
 				aggregate([{"$project":{"sum":{"$add":["$foo", "$bar"]}}}], [{"foo":1, "bar":"baz"}]);
 			});
-			
+
 			var agg = aggregate([{"$project":{"sum":{"$add":["$foo", "$bar"]}}}]);
 			assert.throws(function(){
 				agg([{"foo":1, "bar":"baz"}]);
@@ -560,6 +562,3 @@ module.exports = {
 	}
 
 };
-
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).grep(process.env.MOCHA_GREP || '').run(process.exit);

+ 1 - 3
test/lib/pipeline/DepsTracker_test.js

@@ -1,10 +1,8 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	DepsTracker = require("../../../lib/pipeline/DepsTracker");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.DepsTracker = {
 
 	"#toProjection()": {

+ 3 - 5
test/lib/pipeline/Document_test.js

@@ -1,11 +1,9 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	Document = require("../../../lib/pipeline/Document"),
 	FieldPath = require("../../../lib/pipeline/FieldPath");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.Document = {
 
 	//SKIPPED: Create -- ours is a static class so we have no constructor
@@ -20,7 +18,7 @@ exports.Document = {
 
 	".compare()": {
 
-		"should work": function testCompare() {
+		"should work": function testCompare() { //jshint latedef:false
             assertComparison(0, {}, {});
             assertComparison(0, {a:1}, {a:1});
             assertComparison(-1, {}, {a:1});
@@ -125,7 +123,7 @@ exports.Document = {
 		},
 
 		"should shallow clone a multi field document": function testCloneMultipleFields() {
-			var doc = {a:1,b:['ra',4],c:{z:1},d:'lal'},
+			var doc = {a:1,b:["ra",4],c:{z:1},d:"lal"},
 				clone = Document.clone(doc);
 			assert.deepEqual(doc, clone);
 		},

+ 1 - 3
test/lib/pipeline/FieldPath_test.js

@@ -1,10 +1,8 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	FieldPath = require("../../../lib/pipeline/FieldPath");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.FieldPath = {
 
 	"constructor(path)": {

+ 1 - 1
test/lib/pipeline/ParsedDeps_test.js

@@ -1,5 +1,5 @@
 "use strict";
-if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))).addFile(__filename).ui("exports").run(process.exit); //jshint ignore:line
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	ParsedDeps = require("../../../lib/pipeline/ParsedDeps");
 

+ 20 - 23
test/lib/pipeline/PipelineD_test.js

@@ -1,9 +1,9 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	Pipeline = require("../../../lib/pipeline/Pipeline"),
 	PipelineD = require("../../../lib/pipeline/PipelineD"),
-	DocumentSource = require('../../../lib/pipeline/documentSources/DocumentSource'),
-	CursorDocumentSource = require('../../../lib/pipeline/documentSources/CursorDocumentSource');
+	CursorDocumentSource = require("../../../lib/pipeline/documentSources/CursorDocumentSource");
 
 
 module.exports = {
@@ -13,14 +13,14 @@ module.exports = {
 		"prepareCursorSource": {
 
 			"should place a CursorDocumentSource in pipeline": function () {
-				var p = Pipeline.parseCommand({pipeline:[{$match:{a:true}}], aggregate:[]}),
-					cs = PipelineD.prepareCursorSource(p, {ns:[1,2,3,4,5]});
+				var p = Pipeline.parseCommand({pipeline:[{$match:{a:true}}], aggregate:[]});
+				PipelineD.prepareCursorSource(p, {ns:[1,2,3,4,5]});
 				assert.equal(p.sources[0].constructor, CursorDocumentSource);
 			},
 
 			"should get projection from all sources": function () {
-				var p = Pipeline.parseCommand({pipeline:[{$project:{a:"$x"}}], aggregate:[]}),
-					cs = PipelineD.prepareCursorSource(p, {ns:[1,2,3,4,5]});
+				var p = Pipeline.parseCommand({pipeline:[{$project:{a:"$x"}}], aggregate:[]});
+				PipelineD.prepareCursorSource(p, {ns:[1,2,3,4,5]});
 				assert.deepEqual(p.sources[0]._projection, {x:1, _id:1});
 				assert.deepEqual(p.sources[0]._dependencies, {_fields:{_id:true, x:true}});
 			},
@@ -44,9 +44,9 @@ module.exports = {
 						}}
 					]
 				};
-				var p = Pipeline.parseCommand(cmdObj),
-					cs = PipelineD.prepareCursorSource(p, {ns:[1,2,3,4,5]});
-				assert.deepEqual(p.sources[0]._projection, {'a.b.c': 1, d: 1, 'e.f.g': 1, _id: 1});
+				var p = Pipeline.parseCommand(cmdObj);
+				PipelineD.prepareCursorSource(p, {ns:[1,2,3,4,5]});
+				assert.deepEqual(p.sources[0]._projection, {"a.b.c": 1, d: 1, "e.f.g": 1, _id: 1});
 				assert.deepEqual(p.sources[0]._dependencies, {"_fields":{"_id":true,"a":{"b":{"c":true}},"d":true,"e":{"f":{"g":true}}}});
 			},
 			"should get group's deps": function(){
@@ -70,9 +70,9 @@ module.exports = {
 						}}
 					]
 				};
-				var p = Pipeline.parseCommand(cmdObj),
-					cs = PipelineD.prepareCursorSource(p, {ns:[1,2,3,4,5]});
-				assert.equal(JSON.stringify(p.sources[0]._projection), JSON.stringify({ a: 1, b: 1, 'x.y.z': 1, _id: 0 }));
+				var p = Pipeline.parseCommand(cmdObj);
+				PipelineD.prepareCursorSource(p, {ns:[1,2,3,4,5]});
+				assert.equal(JSON.stringify(p.sources[0]._projection), JSON.stringify({ a: 1, b: 1, "x.y.z": 1, _id: 0 }));
 				assert.deepEqual(p.sources[0]._dependencies, {"_fields":{"a":true,"b":true,"x":{"y":{"z":true}}}});
 			},
 			"should set the queryObj on the Cursor": function(){
@@ -85,8 +85,8 @@ module.exports = {
 						}}
 					]
 				};
-				var p = Pipeline.parseCommand(cmdObj),
-					cs = PipelineD.prepareCursorSource(p, {ns:[1,2,3,4,5]});
+				var p = Pipeline.parseCommand(cmdObj);
+				PipelineD.prepareCursorSource(p, {ns:[1,2,3,4,5]});
 				assert.deepEqual(p.sources[0]._query, {x:{$exists: true}, y:{$exists:false}});
 			},
 			"should set the sort on the Cursor": function(){
@@ -99,8 +99,8 @@ module.exports = {
 						}}
 					]
 				};
-				var p = Pipeline.parseCommand(cmdObj),
-					cs = PipelineD.prepareCursorSource(p, {ns:[1,2,3,4,5]});
+				var p = Pipeline.parseCommand(cmdObj);
+				PipelineD.prepareCursorSource(p, {ns:[1,2,3,4,5]});
 				assert.deepEqual(p.sources[0]._sort, {x:1, y:-1});
 			},
 			"should set the sort on the Cursor if there is a match first": function(){
@@ -117,8 +117,8 @@ module.exports = {
 						}}
 					]
 				};
-				var p = Pipeline.parseCommand(cmdObj),
-					cs = PipelineD.prepareCursorSource(p, {ns:[1,2,3,4,5]});
+				var p = Pipeline.parseCommand(cmdObj);
+				PipelineD.prepareCursorSource(p, {ns:[1,2,3,4,5]});
 				assert.deepEqual(p.sources[0]._sort, {x:1, y:-1});
 			},
 			"should coalesce the Cursor with the rest of the pipeline": function(){
@@ -128,8 +128,8 @@ module.exports = {
 						{$limit:1}
 					]
 				};
-				var p = Pipeline.parseCommand(cmdObj),
-					cs = PipelineD.prepareCursorSource(p, {ns:[1,2,3,4,5]});
+				var p = Pipeline.parseCommand(cmdObj);
+				PipelineD.prepareCursorSource(p, {ns:[1,2,3,4,5]});
 				assert.equal(p.sources[0].getLimit(), 1);
 				assert.equal(p.sources.length, 1);
 			},
@@ -137,6 +137,3 @@ module.exports = {
 	}
 
 };
-
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).grep(process.env.MOCHA_GREP || '').run(process.exit);

+ 19 - 30
test/lib/pipeline/Pipeline_test.js

@@ -1,21 +1,13 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	Pipeline = require("../../../lib/pipeline/Pipeline"),
-	FieldPath = require("../../../lib/pipeline/FieldPath"),
-	DocumentSource = require('../../../lib/pipeline/documentSources/DocumentSource'),
-	CursorDocumentSource = require("../../../lib/pipeline/documentSources/CursorDocumentSource"),
-	ProjectDocumentSource = require("../../../lib/pipeline/documentSources/ProjectDocumentSource"),
-	ArrayRunner = require("../../../lib/query/ArrayRunner");
-
-var addSource = function addSource(match, data) {
-	var cds = new CursorDocumentSource(null, new ArrayRunner(data), null);
-	match.setSource(cds);
-};
+	DocumentSource = require("../../../lib/pipeline/documentSources/DocumentSource");
 
-var shardedTest = function(inputPipeString, expectedMergePipeString, expectedShardPipeString) {
-	inputPipeString = '{"pipeline": ' + inputPipeString + '}';
-	expectedMergePipeString = '{"pipeline": ' + expectedMergePipeString + '}';
-	expectedShardPipeString = '{"pipeline": ' + expectedShardPipeString + '}';
+function shardedTest(inputPipeString, expectedMergePipeString, expectedShardPipeString) {
+	inputPipeString = "{\"pipeline\": " + inputPipeString + "}";
+	expectedMergePipeString = "{\"pipeline\": " + expectedMergePipeString + "}";
+	expectedShardPipeString = "{\"pipeline\": " + expectedShardPipeString + "}";
 	var inputPipe = JSON.parse(inputPipeString),
 		expectedMergePipe = JSON.parse(expectedMergePipeString),
 		expectedShardPipe = JSON.parse(expectedShardPipeString);
@@ -28,7 +20,7 @@ var shardedTest = function(inputPipeString, expectedMergePipeString, expectedSha
 
 	assert.deepEqual(shardPipe.serialize().pipeline, expectedShardPipe.pipeline);
 	assert.deepEqual(mergePipe.serialize().pipeline, expectedMergePipe.pipeline);
-};
+}
 
 module.exports = {
 
@@ -47,7 +39,7 @@ module.exports = {
 
 					this.current = 5;
 
-				}, TestDocumentSource = klass, base = DocumentSource, proto = klass.prototype = Object.create(base.prototype, {constructor: {value: klass}});
+				}, TestDocumentSource = klass, base = DocumentSource, proto = klass.prototype = Object.create(base.prototype, {constructor: {value: klass}}); //jshint ignore:line
 
 
 				proto.coalesce = function () {
@@ -155,30 +147,30 @@ module.exports = {
 			},
 
 			"should handle one unwind": function () {
-				var inputPipe = '[{"$unwind":"$a"}]',
+				var inputPipe = JSON.stringify([{$unwind:"$a"}]),
 					expectedShardPipe = "[]",
-					expectedMergePipe = '[{"$unwind":"$a"}]';
+					expectedMergePipe = JSON.stringify([{$unwind:"$a"}]);
 				shardedTest(inputPipe, expectedMergePipe, expectedShardPipe);
 			},
 
 			"should handle two unwinds": function () {
-				var inputPipe = '[{"$unwind":"$a"}, {"$unwind":"$b"}]',
+				var inputPipe = JSON.stringify([{$unwind:"$a"},{$unwind:"$b"}]),
 					expectedShardPipe = "[]",
-					expectedMergePipe = '[{"$unwind": "$a"}, {"$unwind": "$b"}]';
+					expectedMergePipe = JSON.stringify([{$unwind:"$a"},{$unwind:"$b"}]);
 				shardedTest(inputPipe, expectedMergePipe, expectedShardPipe);
 			},
 
 			"should handle unwind not final": function () {
-				var inputPipe = '[{"$unwind": "$a"}, {"$match": {"a":1}}]',
-					expectedShardPipe = '[]',
-					expectedMergePipe = '[{"$unwind": "$a"}, {"$match": {"a":1}}]';
+				var inputPipe = JSON.stringify([{$unwind:"$a"},{$match:{"a":1}}]),
+					expectedShardPipe = "[]",
+					expectedMergePipe = JSON.stringify([{$unwind:"$a"},{$match:{"a":1}}]);
 				shardedTest(inputPipe, expectedShardPipe, expectedMergePipe);
 			},
 
 			"should handle unwind with other": function () {
-				var inputPipe = '[{"$match": {"a":1}}, {"$unwind": "$a"}]',
-					expectedShardPipe = '[{"$match":{"a":1}}]',
-					expectedMergePipe = '[{"$unwind":"$a"}]';
+				var inputPipe = JSON.stringify([{$match:{"a":1}},{$unwind:"$a"}]),
+					expectedShardPipe = JSON.stringify([{$match:{"a":1}}]),
+					expectedMergePipe = JSON.stringify([{$unwind:"$a"}]);
 				shardedTest(inputPipe,expectedMergePipe, expectedShardPipe);
 			}
 
@@ -208,8 +200,7 @@ module.exports = {
 				});
 			},
 			"should handle sources that return errors": function (done) {
-				var p = Pipeline.parseCommand({pipeline:[{$test:{works:false}}]}),
-					results = [];
+				var p = Pipeline.parseCommand({pipeline:[{$test:{works:false}}]});
 				p.run(function(err, doc) {
 					assert(err);
 					done();
@@ -249,5 +240,3 @@ module.exports = {
 	}
 
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).grep(process.env.MOCHA_GREP || '').run(process.exit);

+ 2 - 4
test/lib/pipeline/Value_test.js

@@ -1,10 +1,8 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	Value = require("../../../lib/pipeline/Value");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.Value = {
 
 	".constructor()": {
@@ -197,7 +195,7 @@ exports.Value = {
 
 	".compare()": {
 
-		"should test things": function testCompare() {
+		"should test things": function testCompare() { //jshint maxstatements:52
             // BSONObjBuilder undefinedBuilder;
             // undefinedBuilder.appendUndefined( "" );
             // BSONObj undefined = undefinedBuilder.obj();

+ 3 - 4
test/lib/pipeline/accumulators/AddToSetAccumulator_test.js

@@ -1,11 +1,10 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	AddToSetAccumulator = require("../../../../lib/pipeline/accumulators/AddToSetAccumulator");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
 
-var testData = {
+var testData = { //jshint nonbsp:false
 	nil: null,
 	bF: false, bT: true,
 	numI: 123, numF: 123.456,
@@ -14,7 +13,7 @@ var testData = {
 	arr: [1, 2, 3, [4, 5, 6]],
 	date: new Date(),
 	re: /foo/gi,
-};
+}; //jshint nonbsp:true
 
 //TODO: refactor these test cases using Expression.parseOperand() or something because these could be a whole lot cleaner...
 exports.AddToSetAccumulator = {

+ 1 - 3
test/lib/pipeline/accumulators/AvgAccumulator_test.js

@@ -1,10 +1,8 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	AvgAccumulator = require("../../../../lib/pipeline/accumulators/AvgAccumulator");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.AvgAccumulator = {
 
 	".constructor()": {

+ 1 - 3
test/lib/pipeline/accumulators/FirstAccumulator_test.js

@@ -1,10 +1,8 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	FirstAccumulator = require("../../../../lib/pipeline/accumulators/FirstAccumulator");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.FirstAccumulator = {
 
 	".constructor()": {

+ 1 - 5
test/lib/pipeline/accumulators/LastAccumulator_test.js

@@ -1,10 +1,8 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	LastAccumulator = require("../../../../lib/pipeline/accumulators/LastAccumulator");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.LastAccumulator = {
 
 	".constructor()": {
@@ -98,5 +96,3 @@ exports.LastAccumulator = {
 	},
 
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);

+ 1 - 3
test/lib/pipeline/accumulators/MinMaxAccumulator_test.js

@@ -1,10 +1,8 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	MinMaxAccumulator = require("../../../../lib/pipeline/accumulators/MinMaxAccumulator");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.MinMaxAccumulator = {
 
 	".constructor()": {

+ 1 - 6
test/lib/pipeline/accumulators/PushAccumulator_test.js

@@ -1,11 +1,8 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	PushAccumulator = require("../../../../lib/pipeline/accumulators/PushAccumulator");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
-
 exports.PushAccumulator = {
 
 	".constructor()": {
@@ -117,5 +114,3 @@ exports.PushAccumulator = {
 	},
 
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);

+ 2 - 5
test/lib/pipeline/accumulators/SumAccumulator_test.js

@@ -1,10 +1,8 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	SumAccumulator = require("../../../../lib/pipeline/accumulators/SumAccumulator");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.SumAccumulator = {
 
 	".constructor()": {
@@ -150,8 +148,7 @@ exports.SumAccumulator = {
 
 		"should return sum for int and NaN as NaN": function testIntNanDouble() {
 			var summand1 = 4,
-				summand2 = NaN,
-				expected = NaN;
+				summand2 = NaN;
 			assert(isNaN(this.getSumValueFor(summand1, summand2)));
 			assert(isNaN(this.getSumValueFor(summand2, summand1)));
 		},

+ 3 - 7
test/lib/pipeline/documentSources/CursorDocumentSource_test.js

@@ -1,7 +1,7 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	async = require("async"),
-	DocumentSource = require("../../../../lib/pipeline/documentSources/DocumentSource"),
 	CursorDocumentSource = require("../../../../lib/pipeline/documentSources/CursorDocumentSource"),
 	LimitDocumentSource = require("../../../../lib/pipeline/documentSources/LimitDocumentSource"),
 	SkipDocumentSource = require("../../../../lib/pipeline/documentSources/SkipDocumentSource"),
@@ -79,8 +79,6 @@ module.exports = {
 
 		"#getNext": {
 			"should return the current cursor value async": function(next){
-				var expected = JSON.stringify([1,2]);
-
 				var cds = getCursorDocumentSource([1,2,3,4]);
 				async.series([
 						cds.getNext.bind(cds),
@@ -102,7 +100,7 @@ module.exports = {
 				var cds = getCursorDocumentSource(arr);
 				var doc = null,
 					error = null;
-				
+
 				async.doWhilst(
 					function iterator(next){
 						return cds.getNext(function (err, obj){
@@ -148,7 +146,7 @@ module.exports = {
 					project = ProjectDocumentSource.createFromJson({"a":1});
 				project.getDependencies(deps);
 				cds.setProjection(deps.toProjection(), deps.toParsedDeps());
-				
+
 				async.series([
 						cds.getNext.bind(cds),
 						cds.getNext.bind(cds),
@@ -166,5 +164,3 @@ module.exports = {
 	}
 
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).grep(process.env.MOCHA_GREP || '').run(process.exit);

+ 4 - 6
test/lib/pipeline/documentSources/DocumentSource_test.js

@@ -1,16 +1,14 @@
 "use strict";
-var assert = require("assert"),
-	DocumentSource = require("../../../../lib/pipeline/documentSources/DocumentSource");
-
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 
 module.exports = {
 
 	"DocumentSource": {
 
-		"should be tested via subclasses": function() {}
+		"should be tested via subclasses": function() {
+			//NOTE: here just to let you know that it was not simply forgotten but instead was intentionally omitted
+		}
 
 	}
 
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run();

+ 8 - 9
test/lib/pipeline/documentSources/GeoNearDocumentSource_test.js

@@ -1,19 +1,20 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
-	DocumentSource = require("../../../../lib/pipeline/documentSources/DocumentSource"),
 	GeoNearDocumentSource = require("../../../../lib/pipeline/documentSources/GeoNearDocumentSource"),
 	CursorDocumentSource = require("../../../../lib/pipeline/documentSources/CursorDocumentSource"),
 	ArrayRunner = require("../../../../lib/query/ArrayRunner"),
 	FieldPath = require("../../../../lib/pipeline/FieldPath");
 
-var createGeoNear = function(ctx) {
+function createGeoNear(ctx) {
 	var ds = new GeoNearDocumentSource(ctx);
 	return ds;
-};
-var addSource = function addSource(ds, data) {
+}
+
+function addSource(ds, data) {
 	var cds = new CursorDocumentSource(null, new ArrayRunner(data), null);
 	ds.setSource(cds);
-};
+}
 
 module.exports = {
 
@@ -23,7 +24,7 @@ module.exports = {
 
 			"should not throw when constructing without args":function() {
 				assert.doesNotThrow(function(){
-					var gnds = createGeoNear();
+					createGeoNear();
 				});
 			},
 
@@ -76,7 +77,7 @@ module.exports = {
 						// example options
 						near:[40.724, -73.997],
 						limit:25,
-						query:{type:'public'},
+						query:{type:"public"},
 						distanceField: "dist.calculated",
 						maxDistance:0.8,
 						uniqueDocs:true,
@@ -95,5 +96,3 @@ module.exports = {
 		}
 	}
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).grep(process.env.MOCHA_GREP || '').run(process.exit);

+ 19 - 24
test/lib/pipeline/documentSources/GroupDocumentSource_test.js

@@ -1,12 +1,10 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
-	DocumentSource = require("../../../../lib/pipeline/documentSources/DocumentSource"),
 	CursorDocumentSource = require("../../../../lib/pipeline/documentSources/CursorDocumentSource"),
 	GroupDocumentSource = require("../../../../lib/pipeline/documentSources/GroupDocumentSource"),
 	ArrayRunner = require("../../../../lib/query/ArrayRunner"),
-	async = require('async'),
-	utils = require("../expressions/utils"),
-	expressions = require("../../../../lib/pipeline/expressions");
+	async = require("async");
 
 
 /// An assertion for `ObjectExpression` instances based on Mongo's `ExpectedResultBase` class
@@ -55,7 +53,7 @@ function assertExpectedResult(args) {
 			});
 		} else {
 			assert.doesNotThrow(function(){
-				var gds = GroupDocumentSource.createFromJson(args.spec);
+				GroupDocumentSource.createFromJson(args.spec);
 			});
 		}
 	}
@@ -177,7 +175,7 @@ module.exports = {
 			// Note: Can't duplicate fields in javascript objects -- skipped
 
 			// $group _id is computed from an object expression
-			"should compute _id from an object expression": function testAdvance_ObjectExpression(){
+			"should compute _id from an object expression": function ObjectExpression(){
 				assertExpectedResult({
 					docs: [{a:6}],
 					spec: {_id:{z:"$a"}},
@@ -186,7 +184,7 @@ module.exports = {
 			},
 
 			// $group _id is a field path expression
-			"should compute _id from a field path expression": function testAdvance_FieldPathExpression(){
+			"should compute _id from a field path expression": function FieldPathExpression(){
 				assertExpectedResult({
 					docs: [{a:5}],
 					spec: {_id:"$a"},
@@ -195,7 +193,7 @@ module.exports = {
 			},
 
 			// $group _id is a field path expression
-			"should compute _id from a Date": function testAdvance_Date(){
+			"should compute _id from a Date": function Date(){
 				var d = new Date();
 				assertExpectedResult({
 					docs: [{a:d}],
@@ -205,7 +203,7 @@ module.exports = {
 			},
 
 			// Aggregate the value of an object expression
-			"should aggregate the value of an object expression": function testAdvance_ObjectExpression(){
+			"should aggregate the value of an object expression": function AggregateObjectExpression(){
 				assertExpectedResult({
 					docs: [{a:6}],
 					spec: {_id:0, z:{$first:{x:"$a"}}},
@@ -214,7 +212,7 @@ module.exports = {
 			},
 
 			// Aggregate the value of an operator expression
-			"should aggregate the value of an operator expression": function testAdvance_OperatorExpression(){
+			"should aggregate the value of an operator expression": function AggregateOperatorExpression(){
 				assertExpectedResult({
 					docs: [{a:6}],
 					spec: {_id:0, z:{$first:"$a"}},
@@ -222,14 +220,15 @@ module.exports = {
 				});
 			},
 
-			// Aggregate the value of an operator expression
-			"should aggregate the value of an operator expression with a null id": function testAdvance_Null(){
-				assertExpectedResult({
-					docs: [{a:6}],
-					spec: {_id:null, z:{$first:"$a"}},
-					expected: [{_id:null, z:6}]
-				});
-			},
+			//TODO: verify which tests are mongos vs which are *useful* tests that we've added and delete the rest
+			// // Aggregate the value of an operator expression
+			// "should aggregate the value of an operator expression with a null id": function testAdvance_Null(){
+			// 	assertExpectedResult({
+			// 		docs: [{a:6}],
+			// 		spec: {_id:null, z:{$first:"$a"}},
+			// 		expected: [{_id:null, z:6}]
+			// 	});
+			// },
 
 			// A $group performed on a single document
 			"should make one group with one values": function SingleDocument() {
@@ -290,7 +289,7 @@ module.exports = {
 				assertExpectedResult({
 					docs: [{a:"de", b:"ad", c:"beef", d:""}, {a:"d", b:"eadbe", c:"", d:"ef"}],
 					spec: {_id:{$concat:["$a", "$b", "$c", "$d"]}},
-					expected: [{_id:'deadbeef'}]
+					expected: [{_id:"deadbeef"}]
 				});
 			},
 
@@ -302,11 +301,9 @@ module.exports = {
 					expected: [{_id:0, first:null}]
 				});
 			},
-			
+
 			"should return errors in the callback": function(done){
 				var gds = GroupDocumentSource.createFromJson({_id:null, sum: {$sum:"$a"}}),
-					next,
-					results = [],
 					cds = new CursorDocumentSource(null, new ArrayRunner([{"a":"foo"}]), null);
 				gds.setSource(cds);
 				gds.getNext(function(err, doc) {
@@ -319,5 +316,3 @@ module.exports = {
 	}
 
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).grep(process.env.MOCHA_GREP || '').run(process.exit);

+ 3 - 4
test/lib/pipeline/documentSources/LimitDocumentSource_test.js

@@ -1,14 +1,15 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	DocumentSource = require("../../../../lib/pipeline/documentSources/DocumentSource"),
 	LimitDocumentSource = require("../../../../lib/pipeline/documentSources/LimitDocumentSource"),
 	CursorDocumentSource = require("../../../../lib/pipeline/documentSources/CursorDocumentSource"),
 	ArrayRunner = require("../../../../lib/query/ArrayRunner");
 
-var addSource = function addSource(ds, data) {
+function addSource(ds, data) {
 	var cds = new CursorDocumentSource(null, new ArrayRunner(data), null);
 	ds.setSource(cds);
-};
+}
 
 module.exports = {
 
@@ -132,5 +133,3 @@ module.exports = {
 		}
 	}
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);

+ 31 - 33
test/lib/pipeline/documentSources/MatchDocumentSource_test.js

@@ -1,19 +1,20 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	async = require("async"),
-	DocumentSource = require("../../../../lib/pipeline/documentSources/DocumentSource"),
 	MatchDocumentSource = require("../../../../lib/pipeline/documentSources/MatchDocumentSource"),
 	CursorDocumentSource = require("../../../../lib/pipeline/documentSources/CursorDocumentSource"),
 	ArrayRunner = require("../../../../lib/query/ArrayRunner");
 
-var testRedactSafe = function testRedactSafe(input, safePortion) {
+function testRedactSafe(input, safePortion) {
 	var match = MatchDocumentSource.createFromJson(input);
 	assert.deepEqual(match.redactSafePortion(), safePortion);
-};
-var addSource = function addSource(match, data) {
+}
+
+function addSource(match, data) {
 	var cds = new CursorDocumentSource(null, new ArrayRunner(data), null);
 	match.setSource(cds);
-};
+}
 
 module.exports = {
 
@@ -47,9 +48,9 @@ module.exports = {
 		"#serialize()": {
 
 			"should append the match query to the input builder": function sourceToJsonTest(){
-				var mds = new MatchDocumentSource({ location : { $in : ['Kentucky'] } });
+				var mds = new MatchDocumentSource({ location : { $in : ["Kentucky"] } });
 				var t = mds.serialize(false);
-				assert.deepEqual(t, { "$match" : { location : { $in : ['Kentucky'] } }});
+				assert.deepEqual(t, { "$match" : { location : { $in : ["Kentucky"] } }});
 			}
 
 		},
@@ -210,17 +211,17 @@ module.exports = {
 				testRedactSafe({a:1},
 					{a:1});
 
-				testRedactSafe({a:'asdf'},
-					{a:'asdf'});
+				testRedactSafe({a:"asdf"},
+					{a:"asdf"});
 
 				testRedactSafe({a:/asdf/i},
 					{a:/asdf/i});
 
-				testRedactSafe({a: {$regex: 'adsf'}},
-					{a: {$regex: 'adsf'}});
+				testRedactSafe({a: {$regex: "adsf"}},
+					{a: {$regex: "adsf"}});
 
-				testRedactSafe({a: {$regex: 'adsf', $options: 'i'}},
-					{a: {$regex: 'adsf', $options: 'i'}});
+				testRedactSafe({a: {$regex: "adsf", $options: "i"}},
+					{a: {$regex: "adsf", $options: "i"}});
 
 				testRedactSafe({a: {$mod: [1, 0]}},
 					{a: {$mod: [1, 0]}});
@@ -241,10 +242,10 @@ module.exports = {
 				testRedactSafe({a: []},
 					{});
 
-				testRedactSafe({'a.0': 1},
+				testRedactSafe({"a.0": 1},
 					{});
 
-				testRedactSafe({'a.0.b': 1},
+				testRedactSafe({"a.0.b": 1},
 					{});
 
 				testRedactSafe({a: {$ne: 1}},
@@ -268,8 +269,8 @@ module.exports = {
 			},
 
 			"Combinations": function() {
-				testRedactSafe({a:1, b: 'asdf'},
-					{a:1, b: 'asdf'});
+				testRedactSafe({a:1, b: "asdf"},
+					{a:1, b: "asdf"});
 
 				testRedactSafe({a:1, b: null},
 					{a:1});
@@ -345,17 +346,17 @@ module.exports = {
 		"#isTextQuery()": {
 
 			"should return true when $text operator is first stage in pipeline": function () {
-				var query = {$text:'textQuery'};
+				var query = {$text:"textQuery"};
 				assert.ok(MatchDocumentSource.isTextQuery(query)); // true
 			},
 
 			"should return true when $text operator is nested in the pipeline": function () {
-				var query = {$stage:{$text:'textQuery'}};
+				var query = {$stage:{$text:"textQuery"}};
 				assert.ok(MatchDocumentSource.isTextQuery(query)); // true
 			},
 
 			"should return false when $text operator is not in pipeline": function () {
-				var query = {$notText:'textQuery'};
+				var query = {$notText:"textQuery"};
 				assert.ok(!MatchDocumentSource.isTextQuery(query)); // false
 			}
 
@@ -364,58 +365,58 @@ module.exports = {
 		"#uassertNoDisallowedClauses()": {
 
 			"should throw if invalid stage is in match expression": function () {
-				var whereQuery = {$where:'where'};
+				var whereQuery = {$where:"where"};
 				assert.throws(function(){
 					MatchDocumentSource.uassertNoDisallowedClauses(whereQuery);
 				});
 
-				var nearQuery = {$near:'near'};
+				var nearQuery = {$near:"near"};
 				assert.throws(function(){
 					MatchDocumentSource.uassertNoDisallowedClauses(nearQuery);
 				});
 
-				var withinQuery = {$within:'within'};
+				var withinQuery = {$within:"within"};
 				assert.throws(function(){
 					MatchDocumentSource.uassertNoDisallowedClauses(withinQuery);
 				});
 
-				var nearSphereQuery = {$nearSphere:'nearSphere'};
+				var nearSphereQuery = {$nearSphere:"nearSphere"};
 				assert.throws(function(){
 					MatchDocumentSource.uassertNoDisallowedClauses(nearSphereQuery);
 				});
 			},
 
 			"should throw if invalid stage is nested in the match expression": function () {
-				var whereQuery = {$validStage:{$where:'where'}};
+				var whereQuery = {$validStage:{$where:"where"}};
 				assert.throws(function(){
 					MatchDocumentSource.uassertNoDisallowedClauses(whereQuery);
 				});
 
-				var nearQuery = {$validStage:{$near:'near'}};
+				var nearQuery = {$validStage:{$near:"near"}};
 				assert.throws(function(){
 					MatchDocumentSource.uassertNoDisallowedClauses(nearQuery);
 				});
 
-				var withinQuery = {$validStage:{$within:'within'}};
+				var withinQuery = {$validStage:{$within:"within"}};
 				assert.throws(function(){
 					MatchDocumentSource.uassertNoDisallowedClauses(withinQuery);
 				});
 
-				var nearSphereQuery = {$validStage:{$nearSphere:'nearSphere'}};
+				var nearSphereQuery = {$validStage:{$nearSphere:"nearSphere"}};
 				assert.throws(function(){
 					MatchDocumentSource.uassertNoDisallowedClauses(nearSphereQuery);
 				});
 			},
 
 			"should not throw if invalid stage is not in match expression": function () {
-				var query = {$valid:'valid'};
+				var query = {$valid:"valid"};
 				assert.doesNotThrow(function(){
 					MatchDocumentSource.uassertNoDisallowedClauses(query);
 				});
 			},
 
 			"should not throw if invalid stage is not nested in the match expression": function () {
-				var query = {$valid:{$anotherValid:'valid'}};
+				var query = {$valid:{$anotherValid:"valid"}};
 				assert.doesNotThrow(function(){
 					MatchDocumentSource.uassertNoDisallowedClauses(query);
 				});
@@ -426,6 +427,3 @@ module.exports = {
 	}
 
 };
-
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);

+ 7 - 8
test/lib/pipeline/documentSources/OutDocumentSource_test.js

@@ -1,19 +1,20 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	async = require("async"),
-	DocumentSource = require("../../../../lib/pipeline/documentSources/DocumentSource"),
 	OutDocumentSource = require("../../../../lib/pipeline/documentSources/OutDocumentSource"),
 	CursorDocumentSource = require("../../../../lib/pipeline/documentSources/CursorDocumentSource"),
 	ArrayRunner = require("../../../../lib/query/ArrayRunner");
 
-var createOut = function(ctx) {
+function createOut(ctx) {
 	var ds = new OutDocumentSource(ctx);
 	return ds;
-};
-var addSource = function addSource(ds, data) {
+}
+
+function addSource(ds, data) {
 	var cds = new CursorDocumentSource(null, new ArrayRunner(data), null);
 	ds.setSource(cds);
-};
+}
 
 module.exports = {
 
@@ -23,7 +24,7 @@ module.exports = {
 
 			"should not throw when constructing without args":function() {
 				assert.doesNotThrow(function(){
-					var ods = createOut();
+					createOut();
 				});
 			}
 
@@ -97,5 +98,3 @@ module.exports = {
 		}
 	}
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).grep(process.env.MOCHA_GREP || '').run(process.exit);

+ 19 - 22
test/lib/pipeline/documentSources/ProjectDocumentSource_test.js

@@ -1,26 +1,25 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	async = require("async"),
-	DepsTracker = require("../../../../lib/pipeline/DepsTracker"),
-	DocumentSource = require("../../../../lib/pipeline/documentSources/DocumentSource"),
-	ProjectDocumentSource = require("../../../../lib/pipeline/documentSources/ProjectDocumentSource"),
-	CursorDocumentSource = require("../../../../lib/pipeline/documentSources/CursorDocumentSource"),
-	ArrayRunner = require("../../../../lib/query/ArrayRunner"),
-	TestBase = require("./TestBase"),
-	And = require("../../../../lib/pipeline/expressions/AndExpression"),
-	Add = require("../../../../lib/pipeline/expressions/AddExpression");
+	pipeline = require("../../../../lib/pipeline/"),
+	DepsTracker = pipeline.DepsTracker,
+	DocumentSource = pipeline.documentSources.DocumentSource,
+	ProjectDocumentSource = pipeline.documentSources.ProjectDocumentSource,
+	CursorDocumentSource = pipeline.documentSources.CursorDocumentSource,
+	ArrayRunner = require("../../../../lib/query/ArrayRunner");
 
 
 /**
  *   Tests if the given rep is the same as what the pds resolves to as JSON.
  *   MUST CALL WITH A PDS AS THIS (e.g. checkJsonRepresentation.call(this, rep) where this is a PDS)
  **/
-var checkJsonRepresentation = function checkJsonRepresentation(self, rep) {
+function checkJsonRepresentation(self, rep) {
 	var pdsRep = self.serialize();
 	assert.deepEqual(pdsRep, rep);
-};
+}
 
-var createProject = function createProject(projection) {
+function createProject(projection) {
 	//let projection be optional
 	if (!projection) {
 		projection = {
@@ -34,7 +33,7 @@ var createProject = function createProject(projection) {
 		_project = ProjectDocumentSource.createFromJson(specElement);
 	checkJsonRepresentation(_project, spec);
 	return _project;
-};
+}
 
 //TESTS
 module.exports = {
@@ -227,29 +226,29 @@ module.exports = {
 		"should error if called with non-object": function testNonObjectPassed() {
 			//String as arg
 			assert.throws(function() {
-				var pds = createProject("not an object");
+				createProject("not an object");
 			});
 			//Date as arg
 			assert.throws(function() {
-				var pds = createProject(new Date());
+				createProject(new Date());
 			});
 			//Array as arg
 			assert.throws(function() {
-				var pds = createProject([]);
+				createProject([]);
 			});
 			//Empty args
 			assert.throws(function() {
-				var pds = ProjectDocumentSource.createFromJson();
+				ProjectDocumentSource.createFromJson();
 			});
 			//Top level operator
 			assert.throws(function() {
-				var pds = createProject({
+				createProject({
 					$add: []
 				});
 			});
 			//Invalid spec
 			assert.throws(function() {
-				var pds = createProject({
+				createProject({
 					a: {
 						$invalidOperator: 1
 					}
@@ -265,9 +264,9 @@ module.exports = {
 		"should properly detect dependencies in project": function testGetDependencies() {
 			var input = {
 				a: true,
-				x: '$b',
+				x: "$b",
 				y: {
-					$and: ['$c', '$d']
+					$and: ["$c", "$d"]
 				}
 			};
 			var pds = createProject(input);
@@ -284,5 +283,3 @@ module.exports = {
 	}
 
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).grep(process.env.MOCHA_GREP || '').run(process.exit);

+ 17 - 20
test/lib/pipeline/documentSources/RedactDocumentSource_test.js

@@ -1,11 +1,10 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
-	async = require("async"),
-	DocumentSource = require("../../../../lib/pipeline/documentSources/DocumentSource"),
-	RedactDocumentSource = require("../../../../lib/pipeline/documentSources/RedactDocumentSource"),
-	CursorDocumentSource = require("../../../../lib/pipeline/documentSources/CursorDocumentSource"),
-	ArrayRunner = require("../../../../lib/query/ArrayRunner"),
-	Expressions = require("../../../../lib/pipeline/expressions");
+	pipeline = require("../../../../lib/pipeline/"),
+	RedactDocumentSource = pipeline.documentSources.RedactDocumentSource,
+	CursorDocumentSource = pipeline.documentSources.CursorDocumentSource,
+	ArrayRunner = require("../../../../lib/query/ArrayRunner");
 
 var exampleRedact = {$cond:{
 	if:{$gt:[0,4]},
@@ -13,16 +12,16 @@ var exampleRedact = {$cond:{
 	else:"$$PRUNE"
 }};
 
-var createCursorDocumentSource = function createCursorDocumentSource (input) {
-	if (!input || input.constructor !== Array) throw new Error('invalid');
+function createCursorDocumentSource (input) {
+	if (!input || input.constructor !== Array) throw new Error("invalid");
 	return new CursorDocumentSource(null, new ArrayRunner(input), null);
-};
+}
 
-var createRedactDocumentSource = function createRedactDocumentSource (src, expression) {
+function createRedactDocumentSource (src, expression) {
 	var rds = RedactDocumentSource.createFromJson(expression);
 	rds.setSource(src);
 	return rds;
-};
+}
 
 module.exports = {
 
@@ -113,11 +112,11 @@ module.exports = {
 			"should error if called with non-object": function testNonObjectPassed() {
 				//Empty args
 				assert.throws(function() {
-					var rds = RedactDocumentSource.createFromJson();
+					RedactDocumentSource.createFromJson();
 				});
 				//Invalid spec
 				assert.throws(function() {
-					var rds = RedactDocumentSource.createFromJson({$invalidOperator: 1});
+					RedactDocumentSource.createFromJson({$invalidOperator: 1});
 				});
 
 			}
@@ -189,17 +188,17 @@ module.exports = {
 				var cds = createCursorDocumentSource([{
 					_id: 1,
 					level: 1,
-					acct_id: "xyz123",
+					acctId: "xyz123",
 					cc: {
 						level: 5,
 						type: "yy",
-						exp_date: new Date("2015-11-01"),
-						billing_addr: {
+						expDate: new Date("2015-11-01"),
+						billingAddr: {
 							level: 5,
 							addr1: "123 ABC Street",
 							city: "Some City"
 						},
-						shipping_addr: [
+						shippingAddr: [
 							{
 								level: 3,
 								addr1: "987 XYZ Ave",
@@ -226,7 +225,7 @@ module.exports = {
 				var result = {
 					_id:1,
 					level:1,
-					acct_id:"xyz123",
+					acctId:"xyz123",
 					status:"A"
 				};
 
@@ -242,5 +241,3 @@ module.exports = {
 	}
 
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).grep(process.env.MOCHA_GREP || '').run(process.exit);

+ 17 - 19
test/lib/pipeline/documentSources/SkipDocumentSource_test.js

@@ -1,4 +1,5 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	async = require("async"),
 	DocumentSource = require("../../../../lib/pipeline/documentSources/DocumentSource"),
@@ -6,11 +7,10 @@ var assert = require("assert"),
 	CursorDocumentSource = require("../../../../lib/pipeline/documentSources/CursorDocumentSource"),
 	ArrayRunner = require("../../../../lib/query/ArrayRunner");
 
-var addSource = function addSource(ds, data) {
+function addSource(ds, data) {
 	var cds = new CursorDocumentSource(null, new ArrayRunner(data), null);
 	ds.setSource(cds);
-};
-
+}
 
 module.exports = {
 
@@ -26,8 +26,8 @@ module.exports = {
 
 		},
 
-		'#create()': {
-			'should create a direct copy of a SkipDocumentSource created through the constructor': function () {
+		"#create()": {
+			"should create a direct copy of a SkipDocumentSource created through the constructor": function () { //TODO: fix this
 				var sds1 = new SkipDocumentSource(),
 					sds2 = SkipDocumentSource.create();
 
@@ -44,16 +44,16 @@ module.exports = {
 
 		},
 
-		'#getSkip()': {
-			'should return the skips': function () {
+		"#getSkip()": {
+			"should return the skips": function () {
 				var sds = new SkipDocumentSource();
 
 				assert.strictEqual(sds.getSkip(), 0);
 			}
 		},
 
-		'#setSkip()': {
-			'should return the skips': function () {
+		"#setSkip()": {
+			"should return the skips": function () {
 				var sds = new SkipDocumentSource();
 
 				sds.setSkip(10);
@@ -144,7 +144,7 @@ module.exports = {
 					{item:4},
 					null
 				];
-				
+
 				var input = [{item:1},{item:2},{item:3},{item:4}];
 				addSource(sds, input);
 
@@ -182,24 +182,24 @@ module.exports = {
 
 		},
 
-		'#getDependencies()': {
-			'should return 1 (GET_NEXT)': function () {
+		"#getDependencies()": {
+			"should return 1 (GET_NEXT)": function () {
 				var sds = new SkipDocumentSource();
 
-				assert.strictEqual(sds.getDependencies(), DocumentSource.GetDepsReturn.SEE_NEXT); // Hackish. We may be getting an enum in somewhere.
+				assert.strictEqual(sds.getDependencies(), DocumentSource.GetDepsReturn.SEE_NEXT); //TODO: HACK. Getting an enum?
 			}
 		},
 
-		'#getShardSource()': {
-			'should return the instance of the SkipDocumentSource': function () {
+		"#getShardSource()": {
+			"should return the instance of the SkipDocumentSource": function () {
 				var sds = new SkipDocumentSource();
 
 				assert.strictEqual(sds.getShardSource(), null);
 			}
 		},
 
-		'#getRouterSource()': {
-			'should return null': function () {
+		"#getRouterSource()": {
+			"should return null": function () {
 				var sds = new SkipDocumentSource();
 
 				assert.strictEqual(sds.getRouterSource(), sds);
@@ -208,5 +208,3 @@ module.exports = {
 	}
 
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);

+ 12 - 15
test/lib/pipeline/documentSources/SortDocumentSource_test.js

@@ -1,4 +1,5 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	async = require("async"),
 	DocumentSource = require("../../../../lib/pipeline/documentSources/DocumentSource"),
@@ -8,10 +9,9 @@ var assert = require("assert"),
 	ArrayRunner = require("../../../../lib/query/ArrayRunner"),
 	FieldPathExpression = require("../../../../lib/pipeline/expressions/FieldPathExpression");
 
-var getCursorDocumentSource = function(values) {
+function getCursorDocumentSource(values) {
 	return new CursorDocumentSource(null, new ArrayRunner(values), null);
-};
-
+}
 
 /// An assertion for `ObjectExpression` instances based on Mongo's `ExpectedResultBase` class
 function assertExpectedResult(args) {
@@ -59,7 +59,7 @@ function assertExpectedResult(args) {
 			});
 		} else {
 			assert.doesNotThrow(function(){
-				var gds = SortDocumentSource.createFromJson(args.spec);
+				SortDocumentSource.createFromJson(args.spec);
 			});
 		}
 	}
@@ -257,28 +257,28 @@ module.exports = {
 
 			"should throw an exception when not passed an object": function createTest(next){
 				assert.throws(function() {
-					var sds = SortDocumentSource.createFromJson(7);
+					SortDocumentSource.createFromJson(7);
 				});
 				return next();
 			},
 
 			"should throw an exception when passed an empty object": function createTest(next){
 				assert.throws(function() {
-					var sds = SortDocumentSource.createFromJson({});
+					SortDocumentSource.createFromJson({});
 				});
 				return next();
 			},
 
 			"should throw an exception when passed an object with a non number value": function createTest(next){
 				assert.throws(function() {
-					var sds = SortDocumentSource.createFromJson({a:"b"});
+					SortDocumentSource.createFromJson({a:"b"});
 				});
 				return next();
 			},
 
 			"should throw an exception when passed an object with a non valid number value": function createTest(next){
 				assert.throws(function() {
-					var sds = SortDocumentSource.createFromJson({a:14});
+					SortDocumentSource.createFromJson({a:14});
 				});
 				next();
 			}
@@ -531,8 +531,7 @@ module.exports = {
 
 
 			"should return limit source when coalescing a limit source": function limitSource(next) {
-				var sds = SortDocumentSource.createFromJson({a:1}),
-					lds = LimitDocumentSource.createFromJson(1);
+				var sds = SortDocumentSource.createFromJson({a:1});
 
 				// TODO: add missing test cases.
 				// array json getLimit
@@ -564,8 +563,8 @@ module.exports = {
 			"should have Dependant field paths": function dependencies(next) {
 			 	var sds = SortDocumentSource.createFromJson({sort: 1});
 
-				sds.addKey('a', true);
-			 	sds.addKey('b.c', false);
+				sds.addKey("a", true);
+			 	sds.addKey("b.c", false);
 
 				var deps = {fields: {}, needWholeDocument: false, needTextScore: false};
 
@@ -573,7 +572,7 @@ module.exports = {
 				// Sort keys are now part of deps fields.
 				assert.equal(3, Object.keys(deps.fields).length);
 			 	assert.equal(1, deps.fields.a);
-				assert.equal(1, deps.fields['b.c']);
+				assert.equal(1, deps.fields["b.c"]);
 				assert.equal(false, deps.needWholeDocument);
 				assert.equal(false, deps.needTextScore);
 				return next();
@@ -581,5 +580,3 @@ module.exports = {
 		}
 	}
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).grep(process.env.MOCHA_GREP || '').run(process.exit);

+ 0 - 47
test/lib/pipeline/documentSources/TestBase.js

@@ -1,47 +0,0 @@
-var TestBase = (function() {
-	var klass = function TestBase(overrides) {
-			//NOTE: DEVIATION FROM MONGO: using this base class to make things easier to initialize
-			for (var key in overrides){
-				this[key] = overrides[key];
-			}
-		},
-		proto = klass.prototype;
-	proto.createSource = function() {
-		//TODO: Fix this once we know proper API
-		this._source = CursorDocumentSource.create();
-	};
-	proto.source = function() {
-		return this._source;
-	};
-	proto.createProject = function(projection) {
-		projection = projection || {a:true};
-		var spec = {$project:projection};
-		this._project = new ProjectDocumentSource(spec /*,ctx()*/);
-		this.checkJsonRepresentation(spec);
-		this._project.setSource(this.source());
-	};
-	proto.project = function() {
-		return this._project;
-	};
-	proto.assertExhausted = function() {
-		var self = this;
-		self._project.getNext(function(err, input1) {
-			assert.strictEqual(input, DocumentSource.EOF);
-			self._project.getNext(function(err, input2) {
-				assert.strictEqual(input2, DocumentSource.EOF);
-				self._project.getNext(function(err, input3) {
-					assert.strictEqual(input3, DocumentSource.EOF);
-				});
-			});
-		});
-	};
-	proto.checkJsonRepresentation = function() {
-		var arr = [];
-		this._project.serializeToArray(arr);
-		var generatedSpec = arr[0];
-		assert.deepEqual(generatedSpec, spec);
-	};
-	return klass;
-})();
-
-module.exports = TestBase;

+ 18 - 25
test/lib/pipeline/documentSources/UnwindDocumentSource_test.js

@@ -1,4 +1,5 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	async = require("async"),
 	DocumentSource = require("../../../../lib/pipeline/documentSources/DocumentSource"),
@@ -8,22 +9,16 @@ var assert = require("assert"),
 	ArrayRunner = require("../../../../lib/query/ArrayRunner");
 
 
-//HELPERS
-var assertExhausted = function assertExhausted(pds) {
-	assert.ok(pds.eof());
-	assert.ok(!pds.advance());
-};
-
 /**
  * Tests if the given rep is the same as what the pds resolves to as JSON.
  * MUST CALL WITH A PDS AS THIS (e.g. checkJsonRepresentation.call(this, rep) where this is a PDS)
  **/
-var checkJsonRepresentation = function checkJsonRepresentation(self, rep) {
+function checkJsonRepresentation(self, rep) {
 	var pdsRep = self.serialize(true);
 	assert.deepEqual(pdsRep, rep);
-};
+}
 
-var createUnwind = function createUnwind(unwind) {
+function createUnwind(unwind) {
 	//let unwind be optional
 	if (!unwind) {
 		unwind = "$a";
@@ -33,14 +28,14 @@ var createUnwind = function createUnwind(unwind) {
 		unwindDs = UnwindDocumentSource.createFromJson(specElement);
 	checkJsonRepresentation(unwindDs, spec);
 	return unwindDs;
-};
+}
 
-var addSource = function addSource(unwind, data) {
+function addSource(unwind, data) {
 	var cds = new CursorDocumentSource(null, new ArrayRunner(data), null);
 	unwind.setSource(cds);
-};
+}
 
-var checkResults = function checkResults(data, expectedResults, path, next) {
+function checkResults(data, expectedResults, path, next) {
 	if (expectedResults instanceof Function)
 		next = expectedResults, expectedResults = null, path = null;
 	if (path instanceof Function)
@@ -70,13 +65,13 @@ var checkResults = function checkResults(data, expectedResults, path, next) {
 			next();
 		}
 	);
-};
+}
 
-var throwsException = function throwsException(data, path, expectedResults) {
+function throwsException(data, path, expectedResults) {
 	assert.throws(function () {
 		checkResults(data, path, expectedResults);
 	});
-};
+}
 
 
 //TESTS
@@ -275,7 +270,7 @@ module.exports = {
 					[
 						{_id:0,a:null},
 						{_id:1},
-						{_id:2,a:['a','b']},
+						{_id:2,a:["a","b"]},
 						{_id:3},
 						{_id:4,a:[1,2,3]},
 						{_id:5,a:[4,5,6]},
@@ -283,8 +278,8 @@ module.exports = {
 						{_id:7,a:[]}
 					],
 					[
-						{_id:2,a:'a'},
-						{_id:2,a:'b'},
+						{_id:2,a:"a"},
+						{_id:2,a:"b"},
 						{_id:4,a:1},
 						{_id:4,a:2},
 						{_id:4,a:3},
@@ -306,19 +301,19 @@ module.exports = {
 			"should error if called with non-string": function testNonObjectPassed() {
 				//Date as arg
 				assert.throws(function() {
-					var pds = createUnwind(new Date());
+					createUnwind(new Date());
 				});
 				//Array as arg
 				assert.throws(function() {
-					var pds = createUnwind([]);
+					createUnwind([]);
 				});
 				//Empty args
 				assert.throws(function() {
-					var pds = UnwindDocumentSource.createFromJson();
+					UnwindDocumentSource.createFromJson();
 				});
 				//Top level operator
 				assert.throws(function() {
-					var pds = createUnwind({$add: []});
+					createUnwind({$add: []});
 				});
 			}
 
@@ -338,5 +333,3 @@ module.exports = {
 	}
 
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).grep(process.env.MOCHA_GREP || '').run(process.exit);

+ 3 - 7
test/lib/pipeline/expressions/AddExpression_test.js

@@ -1,4 +1,5 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	Expression = require("../../../../lib/pipeline/expressions/Expression"),
 	AddExpression = require("../../../../lib/pipeline/expressions/AddExpression"),
@@ -7,12 +8,9 @@ var assert = require("assert"),
 	FieldPathExpression = require("../../../../lib/pipeline/expressions/FieldPathExpression"),
 	ConstantExpression = require("../../../../lib/pipeline/expressions/ConstantExpression");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 var TestBase = function TestBase(overrides) {
 		//NOTE: DEVIATION FROM MONGO: using this base class to make things easier to initialize
-		for (var key in overrides)
+		for (var key in overrides) //jshint ignore:line
 			this[key] = overrides[key];
 	},
 	ExpectedResultBase = (function() {
@@ -234,7 +232,7 @@ exports.AddExpression = {
 
 		"should optimize strings of numbers without regard to their order": function() {
 			var vps = new VariablesParseState(new VariablesIdGenerator()),
-				expr = Expression.parseOperand({$add:[1,2,3,'$a',4,5,6]}, vps).optimize();
+				expr = Expression.parseOperand({$add:[1,2,3,"$a",4,5,6]}, vps).optimize();
 			assert.strictEqual(expr.operands.length, 2, "should optimize operands away");
 			assert(expr.operands[0] instanceof FieldPathExpression);
 			assert(expr.operands[1] instanceof ConstantExpression);
@@ -244,5 +242,3 @@ exports.AddExpression = {
 	},
 
 };
-
-if (!module.parent)(new (require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);

+ 3 - 5
test/lib/pipeline/expressions/AllElementsTrueExpression_test.js

@@ -1,17 +1,15 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	VariablesIdGenerator = require("../../../../lib/pipeline/expressions/VariablesIdGenerator"),
 	VariablesParseState = require("../../../../lib/pipeline/expressions/VariablesParseState"),
 	AllElementsTrueExpression = require("../../../../lib/pipeline/expressions/AllElementsTrueExpression"),
 	Expression = require("../../../../lib/pipeline/expressions/Expression");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 var ExpectedResultBase = (function() {
 	var klass = function ExpectedResultBase(overrides) {
 		//NOTE: DEVIATION FROM MONGO: using this base class to make things easier to initialize
-		for (var key in overrides)
+		for (var key in overrides) //jshint ignore:line
 			this[key] = overrides[key];
 	}, proto = klass.prototype;
 	proto.run = function() {
@@ -19,7 +17,7 @@ var ExpectedResultBase = (function() {
 			args = spec.input;
 		if (spec.expected !== undefined && spec.expected !== null) {
 			var fields = spec.expected;
-			for (var fieldFirst in fields) {
+			for (var fieldFirst in fields) { //jshint ignore:line
 				var fieldSecond = fields[fieldFirst],
 					expected = fieldSecond;
 					// obj = {<fieldFirst>: args}; //NOTE: DEVIATION FROM MONGO: see parseExpression below

+ 2 - 4
test/lib/pipeline/expressions/AndExpression_test.js

@@ -1,4 +1,5 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	Expression = require("../../../../lib/pipeline/expressions/Expression"),
 	AndExpression = require("../../../../lib/pipeline/expressions/AndExpression"),
@@ -8,12 +9,9 @@ var assert = require("assert"),
 	constify = utils.constify,
 	expressionToJson = utils.expressionToJson;
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 var TestBase = function TestBase(overrides) {
 		//NOTE: DEVIATION FROM MONGO: using this base class to make things easier to initialize
-		for (var key in overrides)
+		for (var key in overrides) //jshint ignore:line
 			this[key] = overrides[key];
 	},
 	ExpectedResultBase = (function() {

+ 3 - 5
test/lib/pipeline/expressions/AnyElementTrueExpression_test.js

@@ -1,17 +1,15 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	VariablesIdGenerator = require("../../../../lib/pipeline/expressions/VariablesIdGenerator"),
 	VariablesParseState = require("../../../../lib/pipeline/expressions/VariablesParseState"),
 	AnyElementTrueExpression = require("../../../../lib/pipeline/expressions/AnyElementTrueExpression"),
 	Expression = require("../../../../lib/pipeline/expressions/Expression");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 var ExpectedResultBase = (function() {
 	var klass = function ExpectedResultBase(overrides) {
 		//NOTE: DEVIATION FROM MONGO: using this base class to make things easier to initialize
-		for (var key in overrides)
+		for (var key in overrides) //jshint ignore:line
 			this[key] = overrides[key];
 	}, proto = klass.prototype;
 	proto.run = function() {
@@ -19,7 +17,7 @@ var ExpectedResultBase = (function() {
 			args = spec.input;
 		if (spec.expected !== undefined && spec.expected !== null) {
 			var fields = spec.expected;
-			for (var fieldFirst in fields) {
+			for (var fieldFirst in fields) { //jshint ignore:line
 				var fieldSecond = fields[fieldFirst],
 					expected = fieldSecond;
 					// obj = {<fieldFirst>: args}; //NOTE: DEVIATION FROM MONGO: see parseExpression below

+ 1 - 2
test/lib/pipeline/expressions/CoerceToBoolExpression_test.js

@@ -1,4 +1,5 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	CoerceToBoolExpression = require("../../../../lib/pipeline/expressions/CoerceToBoolExpression"),
 	Expression = require("../../../../lib/pipeline/expressions/Expression"),
@@ -78,5 +79,3 @@ exports.CoerceToBoolExpression = {
 	},
 
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);

+ 3 - 5
test/lib/pipeline/expressions/CompareExpression_test.js

@@ -1,4 +1,5 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	expressions = require("../../../../lib/pipeline/expressions/"),
 	Expression = expressions.Expression,
@@ -9,12 +10,9 @@ var assert = require("assert"),
 	constify = utils.constify,
 	expressionToJson = utils.expressionToJson;
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 var TestBase = function TestBase(overrides) {
 		//NOTE: DEVIATION FROM MONGO: using this base class to make things easier to initialize
-		for (var key in overrides)
+		for (var key in overrides) //jshint ignore:line
 			this[key] = overrides[key];
 	},
 	OptimizeBase = (function() {
@@ -308,7 +306,7 @@ exports.CompareExpression = {
 
 		/** $cmp results are bracketed to an absolute value of 1. */
 		"CmpBracketed": function CmpBracketed() {
-			var test = new ExpectedResultBase({
+			new ExpectedResultBase({
 				spec: {$cmp:["z","a"]},
 				expectedResult: 1,
 			}).run();

+ 1 - 3
test/lib/pipeline/expressions/ConcatExpression_test.js

@@ -1,13 +1,11 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	ConcatExpression = require("../../../../lib/pipeline/expressions/ConcatExpression"),
 	VariablesParseState = require("../../../../lib/pipeline/expressions/VariablesParseState"),
 	VariablesIdGenerator = require("../../../../lib/pipeline/expressions/VariablesIdGenerator"),
 	Expression = require("../../../../lib/pipeline/expressions/Expression");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.ConcatExpression = {
 
 	beforeEach: function() {

+ 1 - 3
test/lib/pipeline/expressions/CondExpression_test.js

@@ -1,13 +1,11 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	CondExpression = require("../../../../lib/pipeline/expressions/CondExpression"),
 	VariablesParseState = require("../../../../lib/pipeline/expressions/VariablesParseState"),
 	VariablesIdGenerator = require("../../../../lib/pipeline/expressions/VariablesIdGenerator"),
 	Expression = require("../../../../lib/pipeline/expressions/Expression");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.CondExpression = {
 
 	"constructor()": {

+ 1 - 3
test/lib/pipeline/expressions/ConstantExpression_test.js

@@ -1,13 +1,11 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	ConstantExpression = require("../../../../lib/pipeline/expressions/ConstantExpression"),
 	VariablesIdGenerator = require("../../../../lib/pipeline/expressions/VariablesIdGenerator"),
 	VariablesParseState = require("../../../../lib/pipeline/expressions/VariablesParseState"),
 	DepsTracker = require("../../../../lib/pipeline/DepsTracker");
 
-// Mocha one-liner to make these tests self-hosted
-if (!module.parent)return(require.cache[__filename] = null, (new (require("mocha"))({ui: "exports", reporter: "spec", grep: process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.ConstantExpression = {
 
 	".constructor()": {

+ 1 - 3
test/lib/pipeline/expressions/DayOfMonthExpression_test.js

@@ -1,11 +1,9 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	DayOfMonthExpression = require("../../../../lib/pipeline/expressions/DayOfMonthExpression"),
 	Expression = require("../../../../lib/pipeline/expressions/Expression");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.DayOfMonthExpression = {
 
 	"constructor()": {

+ 1 - 3
test/lib/pipeline/expressions/DayOfWeekExpression_test.js

@@ -1,11 +1,9 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	DayOfWeekExpression = require("../../../../lib/pipeline/expressions/DayOfWeekExpression"),
 	Expression = require("../../../../lib/pipeline/expressions/Expression");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.DayOfWeekExpression = {
 
 	"constructor()": {

+ 1 - 3
test/lib/pipeline/expressions/DayOfYearExpression_test.js

@@ -1,11 +1,9 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	DayOfYearExpression = require("../../../../lib/pipeline/expressions/DayOfYearExpression"),
 	Expression = require("../../../../lib/pipeline/expressions/Expression");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.DayOfYearExpression = {
 
 	"constructor()": {

+ 1 - 3
test/lib/pipeline/expressions/DivideExpression_test.js

@@ -1,13 +1,11 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	DivideExpression = require("../../../../lib/pipeline/expressions/DivideExpression"),
 	VariablesIdGenerator = require("../../../../lib/pipeline/expressions/VariablesIdGenerator"),
 	VariablesParseState = require("../../../../lib/pipeline/expressions/VariablesParseState"),
 	Expression = require("../../../../lib/pipeline/expressions/Expression");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.DivideExpression = {
 
 	"constructor()": {

+ 2 - 4
test/lib/pipeline/expressions/FieldPathExpression_test.js

@@ -1,12 +1,10 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	FieldPathExpression = require("../../../../lib/pipeline/expressions/FieldPathExpression"),
 	Variables = require("../../../../lib/pipeline/expressions/Variables"),
 	DepsTracker = require("../../../../lib/pipeline/DepsTracker");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.FieldPathExpression = {
 
 	".constructor()": {
@@ -98,7 +96,7 @@ exports.FieldPathExpression = {
 			assert.deepEqual(FieldPathExpression.create("a.b").evaluateInternal(new Variables(1,{a:[{b:9}]})), [9]);
 		},
 
-		"should return Array with multiple value types if field path is within Array with multiple value types": function testMultipleArrayValues(){
+		"should return Array with multiple values if field path is within Array and multiple matches": function testMultipleArrayValues(){
 			var path = "a.b",
 				doc = {a:[{b:9},null,undefined,{g:4},{b:20},{}]},
 				expected = [9,20];

+ 1 - 3
test/lib/pipeline/expressions/HourExpression_test.js

@@ -1,11 +1,9 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	HourExpression = require("../../../../lib/pipeline/expressions/HourExpression"),
 	Expression = require("../../../../lib/pipeline/expressions/Expression");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.HourExpression = {
 
 	"constructor()": {

+ 1 - 4
test/lib/pipeline/expressions/IfNullExpression_test.js

@@ -1,14 +1,11 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	IfNullExpression = require("../../../../lib/pipeline/expressions/IfNullExpression"),
 	VariablesParseState = require("../../../../lib/pipeline/expressions/VariablesParseState"),
 	VariablesIdGenerator = require("../../../../lib/pipeline/expressions/VariablesIdGenerator"),
-	Variables = require("../../../../lib/pipeline/expressions/Variables"),
 	Expression = require("../../../../lib/pipeline/expressions/Expression");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.IfNullExpression = {
 
 	"constructor()": {

+ 19 - 20
test/lib/pipeline/expressions/LetExpression_test.js

@@ -1,4 +1,5 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	DepsTracker = require("../../../../lib/pipeline/DepsTracker"),
 	LetExpression = require("../../../../lib/pipeline/expressions/LetExpression"),
@@ -12,9 +13,6 @@ var assert = require("assert"),
 	VariablesIdGenerator = require("../../../../lib/pipeline/expressions/VariablesIdGenerator"),
 	Expression = require("../../../../lib/pipeline/expressions/Expression");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.LetExpression = {
 
 	beforeEach: function() {
@@ -48,7 +46,7 @@ exports.LetExpression = {
 		"should throw if $let isn't in expr": function() {
 			var self = this;
 			assert.throws(function() {
-				Expression.parseOperand({$xlet: ['$$a', 1]}, self.vps);
+				Expression.parseOperand({$xlet: ["$$a", 1]}, self.vps);
 			}, /15999/);
 		},
 
@@ -142,9 +140,9 @@ exports.LetExpression = {
 	"#serialize()": {
 
 		"should serialize variables and the subexpression": function() {
-			var s = Expression.parseOperand({$let: {vars: {a:{$const:1}, b:{$const:2}}, in: {$multiply: [2,3]}}}, this.vps).optimize().serialize("zoot");
-			var expected = {$let:{vars:{a:{$const:1},b:{$const:2}},in:{$const:6}}};
-			assert.deepEqual(s, expected);
+			var spec = {$let: {vars: {a:{$const:1}, b:{$const:2}}, in: {$multiply: [2,3]}}},
+				expr = Expression.parseOperand(spec, this.vps).optimize();
+			assert.deepEqual(expr.serialize(false), {$let:{vars:{a:{$const:1},b:{$const:2}},in:{$const:6}}});
 		},
 
 	},
@@ -152,7 +150,7 @@ exports.LetExpression = {
 	"#evaluate()": {
 
 		"should perform the evaluation for variables and the subexpression": function() {
-			var x = Expression.parseOperand({$let: {vars: {a: '$in1', b: '$in2'}, in: { $multiply: ["$$a", "$$b"] }}}, this.vps).optimize();
+			var x = Expression.parseOperand({$let: {vars: {a: "$in1", b: "$in2"}, in: { $multiply: ["$$a", "$$b"] }}}, this.vps).optimize();
 			var	y = x.evaluate(new Variables(10, {in1: 6, in2: 7}));
 			assert.equal(y, 42);
 		},
@@ -162,14 +160,14 @@ exports.LetExpression = {
 	"#addDependencies()": {
 
 		"should add dependencies": function() {
-			var expr = Expression.parseOperand({$let: {vars: {a: {$multiply:['$a','$b']}}, in: {$multiply: ['$c','$d']}}}, this.vps);
+			var expr = Expression.parseOperand({$let: {vars: {a: {$multiply:["$a","$b"]}}, in: {$multiply: ["$c","$d"]}}}, this.vps);
 			var deps = new DepsTracker();
 			expr.addDependencies(deps);
 			assert.equal(Object.keys(deps.fields).length, 4);
-			assert('a' in deps.fields);
-			assert('b' in deps.fields);
-			assert('c' in deps.fields);
-			assert('d' in deps.fields);
+			assert("a" in deps.fields);
+			assert("b" in deps.fields);
+			assert("c" in deps.fields);
+			assert("d" in deps.fields);
 			assert.strictEqual(deps.needWholeDocument, false);
 			assert.strictEqual(deps.needTextScore, false);
 		},
@@ -179,10 +177,14 @@ exports.LetExpression = {
 	"The Gauntlet": {
 
 		"example from http://docs.mongodb.org/manual/reference/operator/aggregation/let/": function() {
-			var x = Expression.parseOperand(
-				{$let: { vars: { total: { $add: [ '$price', '$tax' ] },	discounted: { $cond: { if: '$applyDiscount', then: 0.9, else: 1 } }}, in: { $multiply: [ '$$total', '$$discounted' ] }}},
-				this.vps).optimize();
-			var y;
+			var spec = {$let: {
+					vars: {
+						total: { $add: [ "$price", "$tax" ] },
+						discounted: { $cond: { if: "$applyDiscount", then: 0.9, else: 1 } }},
+					in: { $multiply: [ "$$total", "$$discounted" ] }
+				}},
+				x = Expression.parseOperand(spec, this.vps).optimize(),
+				y;
 			y = x.evaluate(new Variables(10, {price: 90, tax: 0.05}));
 			assert.equal(y, 90.05);
 			y = x.evaluate(new Variables(10, {price: 90, tax: 0.05, applyDiscount: 1}));
@@ -192,6 +194,3 @@ exports.LetExpression = {
 	},
 
 };
-
-
-if (!module.parent)(new (require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);

+ 1 - 3
test/lib/pipeline/expressions/MapExpression_test.js

@@ -1,4 +1,5 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	MapExpression = require("../../../../lib/pipeline/expressions/MapExpression"),
 	Expression = require("../../../../lib/pipeline/expressions/Expression"),
@@ -12,9 +13,6 @@ var assert = require("assert"),
 	constify = utils.constify,
 	expressionToJson = utils.expressionToJson;
 
-// Mocha one-liner to make these tests self-hosted
-if (!module.parent)return(require.cache[__filename] = null, (new (require("mocha"))({ui: "exports", reporter: "spec", grep: process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.MapExpression = {
 
 	"constructor()": {

+ 1 - 3
test/lib/pipeline/expressions/MillisecondExpression_test.js

@@ -1,11 +1,9 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	MillisecondExpression = require("../../../../lib/pipeline/expressions/MillisecondExpression"),
 	Expression = require("../../../../lib/pipeline/expressions/Expression");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.MillisecondExpression = {
 
 	"constructor()": {

+ 1 - 3
test/lib/pipeline/expressions/MinuteExpression_test.js

@@ -1,11 +1,9 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	MinuteExpression = require("../../../../lib/pipeline/expressions/MinuteExpression"),
 	Expression = require("../../../../lib/pipeline/expressions/Expression");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.MinuteExpression = {
 
 	"constructor()": {

+ 1 - 3
test/lib/pipeline/expressions/ModExpression_test.js

@@ -1,13 +1,11 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	ModExpression = require("../../../../lib/pipeline/expressions/ModExpression"),
 	VariablesIdGenerator = require("../../../../lib/pipeline/expressions/VariablesIdGenerator"),
 	VariablesParseState = require("../../../../lib/pipeline/expressions/VariablesParseState"),
 	Expression = require("../../../../lib/pipeline/expressions/Expression");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.ModExpression = {
 
 	"constructor()": {

+ 1 - 3
test/lib/pipeline/expressions/MonthExpression_test.js

@@ -1,11 +1,9 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	MonthExpression = require("../../../../lib/pipeline/expressions/MonthExpression"),
 	Expression = require("../../../../lib/pipeline/expressions/Expression");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.MonthExpression = {
 
 	"constructor()": {

+ 6 - 5
test/lib/pipeline/expressions/MultiplyExpression_test.js

@@ -1,4 +1,5 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	MultiplyExpression = require("../../../../lib/pipeline/expressions/MultiplyExpression"),
 	VariablesParseState = require("../../../../lib/pipeline/expressions/VariablesParseState"),
@@ -7,9 +8,6 @@ var assert = require("assert"),
 	ConstantExpression = require("../../../../lib/pipeline/expressions/ConstantExpression"),
 	Expression = require("../../../../lib/pipeline/expressions/Expression");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.MultiplyExpression = {
 
 	beforeEach: function(){
@@ -81,7 +79,10 @@ exports.MultiplyExpression = {
 		},
 
 		"should return result of multiplying large variables": function () {
-			assert.strictEqual(Expression.parseOperand({$multiply: ["$a", "$b", "$c"]}, this.vps).evaluate({a: 1.345, b: 2e45, c: 0}), 1.345 * 2e45 * 0);
+			var spec = {$multiply: ["$a", "$b", "$c"]},
+				doc = {a: 1.345, b: 2e45, c: 0},
+				expr = Expression.parseOperand(spec, this.vps);
+			assert.strictEqual(expr.evaluate(doc), 1.345 * 2e45 * 0);
 		},
 
 		"should return result of multiplying one number": function () {
@@ -99,7 +100,7 @@ exports.MultiplyExpression = {
 	"optimize": {
 
 		"should optimize out constants separated by a variable": function () {
-			var a = Expression.parseOperand({$multiply: [2, 3, 4, 5, '$a', 6, 7, 8]}, this.vps).optimize();
+			var a = Expression.parseOperand({$multiply: [2, 3, 4, 5, "$a", 6, 7, 8]}, this.vps).optimize();
 			assert(a instanceof MultiplyExpression);
 			assert.equal(a.operands.length, 2);
 			assert(a.operands[0] instanceof FieldPathExpression);

+ 1 - 5
test/lib/pipeline/expressions/NaryExpression_test.js

@@ -1,5 +1,5 @@
 "use strict";
-
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	VariablesParseState = require("../../../../lib/pipeline/expressions/VariablesParseState"),
 	VariablesIdGenerator = require("../../../../lib/pipeline/expressions/VariablesIdGenerator"),
@@ -15,10 +15,6 @@ var assert = require("assert"),
 	expressionToJson = utils.expressionToJson;
 
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
-
 // A dummy child of NaryExpression used for testing
 var Testable = (function(){
 	var klass = function Testable(isAssociativeAndCommutative){

+ 1 - 3
test/lib/pipeline/expressions/NotExpression_test.js

@@ -1,11 +1,9 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	NotExpression = require("../../../../lib/pipeline/expressions/NotExpression"),
 	Expression = require("../../../../lib/pipeline/expressions/Expression");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.NotExpression = {
 
 	"constructor()": {

+ 48 - 52
test/lib/pipeline/expressions/ObjectExpression_test.js

@@ -1,4 +1,5 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	ObjectExpression = require("../../../../lib/pipeline/expressions/ObjectExpression"),
 	Expression = require("../../../../lib/pipeline/expressions/Expression"),
@@ -6,20 +7,15 @@ var assert = require("assert"),
 	FieldPathExpression = require("../../../../lib/pipeline/expressions/FieldPathExpression"),
 	AndExpression = require("../../../../lib/pipeline/expressions/AndExpression"),
 	Variables = require("../../../../lib/pipeline/expressions/Variables"),
-	DepsTracker = require("../../../../lib/pipeline/DepsTracker"),
-	utils = require("./utils");
+	DepsTracker = require("../../../../lib/pipeline/DepsTracker");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
-var constify = utils.constify;
 //SKIPPED: assertBinaryEqual
 //SKIPPED: toJson
 function expressionToJson(expr) {
 	return expr.serialize(false);
 }
 //SKIPPED: fromJson
-//SKIPEPD: valueFromBson
+//SKIPPED: valueFromBson
 
 function assertDependencies(expectedDependencies, expression, includePath) {
 	if (includePath === undefined) includePath = true;
@@ -43,7 +39,7 @@ function assertExpectedResult(args) {
 	{// base args if none provided
 		if (args.source === undefined) args.source = {_id:0, a:1, b:2};
 		if (args.expectedIsSimple === undefined) args.expectedIsSimple = true;
-		if (args.expression === undefined) args.expression = ObjectExpression.createRoot(); //NOTE: replaces prepareExpression + _expression assignment
+		if (args.expression === undefined) args.expression = ObjectExpression.createRoot(); //NOTE: replace prepareExpression + _expression=
 	}
 	// run implementation
 	var doc = args.source,
@@ -75,7 +71,7 @@ exports.ObjectExpression = {
 
 	"#addDependencies": {
 
-		"should be able to get dependencies for non-inclusion expressions": function testNonInclusionDependencies() {
+		"should be able to get dependencies for non-inclusion expressions": function nonInclusionDependencies() {
 			/** Dependencies for non inclusion expressions. */
 			var expr = ObjectExpression.createRoot();
 			expr.addField("a", ConstantExpression.create(5));
@@ -86,7 +82,7 @@ exports.ObjectExpression = {
 			assertDependencies(["c.d"], expr, false);
 		},
 
-		"should be able to get dependencies for inclusion expressions": function testInclusionDependencies() {
+		"should be able to get dependencies for inclusion expressions": function inclusionDependencies() {
 			/** Dependencies for inclusion expressions. */
 			var expr = ObjectExpression.createRoot();
 			expr.includePath("a");
@@ -101,7 +97,7 @@ exports.ObjectExpression = {
 
 	"#serialize": {
 
-		"should be able to convert to JSON representation and have constants represented by expressions": function testJson() {
+		"should be able to convert to JSON representation and have constants represented by expressions": function json() {
 			/** Serialize to a BSONObj, with constants represented by expressions. */
 			var expr = ObjectExpression.createRoot();
 			expr.addField("foo.a", ConstantExpression.create(5));
@@ -112,7 +108,7 @@ exports.ObjectExpression = {
 
 	"#optimize": {
 
-		"should be able to optimize expression and sub-expressions": function testOptimize() {
+		"should be able to optimize expression and sub-expressions": function optimize() {
 			/** Optimizing an object expression optimizes its sub expressions. */
 			var expr = ObjectExpression.createRoot();
 			// Add inclusion.
@@ -130,7 +126,7 @@ exports.ObjectExpression = {
 
 	"#evaluate()": {
 
-		"should be able to provide an empty object": function testEmpty() {
+		"should be able to provide an empty object": function empty() {
 			/** Empty object spec. */
 			var expr = ObjectExpression.createRoot();
 			assertExpectedResult({
@@ -141,7 +137,7 @@ exports.ObjectExpression = {
 			});
 		},
 
-		"should be able to include 'a' field only": function testInclude() {
+		"should be able to include 'a' field only": function include() {
 			/** Include 'a' field only. */
 			var expr = ObjectExpression.createRoot();
 			expr.includePath("a");
@@ -153,7 +149,7 @@ exports.ObjectExpression = {
 			});
 		},
 
-		"should NOT be able to include missing 'a' field": function testMissingInclude() {
+		"should NOT be able to include missing 'a' field": function missingInclude() {
 			/** Cannot include missing 'a' field. */
 			var expr = ObjectExpression.createRoot();
 			expr.includePath("a");
@@ -166,7 +162,7 @@ exports.ObjectExpression = {
 			});
 		},
 
-		"should be able to include '_id' field only": function testIncludeId() {
+		"should be able to include '_id' field only": function includeId() {
 			/** Include '_id' field only. */
 			var expr = ObjectExpression.createRoot();
 			expr.includePath("_id");
@@ -178,7 +174,7 @@ exports.ObjectExpression = {
 			});
 		},
 
-		"should be able to exclude '_id' field": function testExcludeId() {
+		"should be able to exclude '_id' field": function excludeId() {
 			/** Exclude '_id' field. */
 			var expr = ObjectExpression.createRoot();
 			expr.includePath("b");
@@ -191,7 +187,7 @@ exports.ObjectExpression = {
 			});
 		},
 
-		"should be able to include fields in source document order regardless of inclusion order": function testSourceOrder() {
+		"should be able to include fields in source document order regardless of inclusion order": function sourceOrder() {
 			/** Result order based on source document field order, not inclusion spec field order. */
 			var expr = ObjectExpression.createRoot();
 			expr.includePath("b");
@@ -204,7 +200,7 @@ exports.ObjectExpression = {
 			});
 		},
 
-		"should be able to include a nested field": function testIncludeNested() {
+		"should be able to include a nested field": function includeNested() {
 			/** Include a nested field. */
 			var expr = ObjectExpression.createRoot();
 			expr.includePath("a.b");
@@ -217,7 +213,7 @@ exports.ObjectExpression = {
 			});
 		},
 
-		"should be able to include two nested fields": function testIncludeTwoNested() {
+		"should be able to include two nested fields": function includeTwoNested() {
 			/** Include two nested fields. */
 			var expr = ObjectExpression.createRoot();
 			expr.includePath("a.b");
@@ -231,7 +227,7 @@ exports.ObjectExpression = {
 			});
 		},
 
-		"should be able to include two fields nested within different parents": function testIncludeTwoParentNested() {
+		"should be able to include two fields nested within different parents": function includeTwoParentNested() {
 			/** Include two fields nested within different parents. */
 			var expr = ObjectExpression.createRoot();
 			expr.includePath("a.b");
@@ -245,7 +241,7 @@ exports.ObjectExpression = {
 			});
 		},
 
-		"should be able to attempt to include a missing nested field": function testIncludeMissingNested() {
+		"should be able to attempt to include a missing nested field": function includeMissingNested() {
 			/** Attempt to include a missing nested field. */
 			var expr = ObjectExpression.createRoot();
 			expr.includePath("a.b");
@@ -258,7 +254,7 @@ exports.ObjectExpression = {
 			});
 		},
 
-		"should be able to attempt to include a nested field within a non object": function testIncludeNestedWithinNonObject() {
+		"should be able to attempt to include a nested field within a non object": function includeNestedWithinNonObject() {
 			/** Attempt to include a nested field within a non object. */
 			var expr = ObjectExpression.createRoot();
 			expr.includePath("a.b");
@@ -271,7 +267,7 @@ exports.ObjectExpression = {
 			});
 		},
 
-		"should be able to include a nested field within an array": function testIncludeArrayNested() {
+		"should be able to include a nested field within an array": function includeArrayNested() {
 			/** Include a nested field within an array. */
 			var expr = ObjectExpression.createRoot();
 			expr.includePath("a.b");
@@ -284,7 +280,7 @@ exports.ObjectExpression = {
 			});
 		},
 
-		"should NOT include non-root '_id' field implicitly": function testExcludeNonRootId() {
+		"should NOT include non-root '_id' field implicitly": function excludeNonRootId() {
 			/** Don't include not root '_id' field implicitly. */
 			var expr = ObjectExpression.createRoot();
 			expr.includePath("a.b");
@@ -297,7 +293,7 @@ exports.ObjectExpression = {
 			});
 		},
 
-		"should be able to project a computed expression": function testComputed() {
+		"should project a computed expression": function computed() {
 			/** Project a computed expression. */
 			var expr = ObjectExpression.createRoot();
 			expr.addField("a", ConstantExpression.create(5));
@@ -311,7 +307,7 @@ exports.ObjectExpression = {
 			});
 		},
 
-		"should be able to project a computed expression replacing an existing field": function testComputedReplacement() {
+		"should project a computed expression replacing an existing field": function computedReplacement() {
 			/** Project a computed expression replacing an existing field. */
 			var expr = ObjectExpression.createRoot();
 			expr.addField("a", ConstantExpression.create(5));
@@ -325,7 +321,7 @@ exports.ObjectExpression = {
 			});
 		},
 
-		"should NOT be able to project an undefined value": function testComputedUndefined() {
+		"should NOT be able to project an undefined value": function computedUndefined() {
 			/** An undefined value is passed through */
 			var expr = ObjectExpression.createRoot();
 			expr.addField("a", ConstantExpression.create(undefined));
@@ -339,7 +335,7 @@ exports.ObjectExpression = {
 			});
 		},
 
-		"should be able to project a computed expression replacing an existing field with Undefined": function testComputedUndefinedReplacement() {
+		"should project a computed expression replacing an existing field with Undefined": function computedUndefinedReplacement() {
 			/** Project a computed expression replacing an existing field with Undefined. */
 			var expr = ObjectExpression.createRoot();
 			expr.addField("a", ConstantExpression.create(undefined));
@@ -353,7 +349,7 @@ exports.ObjectExpression = {
 			});
 		},
 
-		"should be able to project a null value": function testComputedNull() {
+		"should project a null value": function computedNull() {
 			/** A null value is projected. */
 			var expr = ObjectExpression.createRoot();
 			expr.addField("a", ConstantExpression.create(null));
@@ -367,7 +363,7 @@ exports.ObjectExpression = {
 			});
 		},
 
-		"should be able to project a nested value": function testComputedNested() {
+		"should project a nested value": function computedNested() {
 			/** A nested value is projected. */
 			var expr = ObjectExpression.createRoot();
 			expr.addField("a.b", ConstantExpression.create(5));
@@ -381,7 +377,7 @@ exports.ObjectExpression = {
 			});
 		},
 
-		"should be able to project a field path": function testComputedFieldPath() {
+		"should project a field path": function computedFieldPath() {
 			/** A field path is projected. */
 			var expr = ObjectExpression.createRoot();
 			expr.addField("a", FieldPathExpression.create("x"));
@@ -395,7 +391,7 @@ exports.ObjectExpression = {
 			});
 		},
 
-		"should be able to project a nested field path": function testComputedNestedFieldPath() {
+		"should project a nested field path": function computedNestedFieldPath() {
 			/** A nested field path is projected. */
 			var expr = ObjectExpression.createRoot();
 			expr.addField("a.b", FieldPathExpression.create("x.y"));
@@ -409,7 +405,7 @@ exports.ObjectExpression = {
 			});
 		},
 
-		"should NOT project an empty subobject expression for a missing field": function testEmptyNewSubobject() {
+		"should NOT project an empty subobject expression for a missing field": function emptyNewSubobject() {
 			/** An empty subobject expression for a missing field is not projected. */
 			var expr = ObjectExpression.createRoot();
 			// Create a sub expression returning an empty object.
@@ -426,7 +422,7 @@ exports.ObjectExpression = {
 			});
 		},
 
-		"should be able to project a non-empty new subobject": function testNonEmptyNewSubobject() {
+		"should project a non-empty new subobject": function nonEmptyNewSubobject() {
 			/** A non empty subobject expression for a missing field is projected. */
 			var expr = ObjectExpression.createRoot();
 			// Create a sub expression returning an empty object.
@@ -443,7 +439,7 @@ exports.ObjectExpression = {
 			});
 		},
 
-		"should be able to project two computed fields within a common parent": function testAdjacentDottedComputedFields() {
+		"should project two computed fields in a common parent": function adjacentDottedComputedFields() {
 			/** Two computed fields within a common parent. */
 			var expr = ObjectExpression.createRoot();
 			expr.addField("a.b", ConstantExpression.create(6));
@@ -458,7 +454,7 @@ exports.ObjectExpression = {
 			});
 		},
 
-		"should be able to project two computed fields within a common parent (w/ one case dotted)": function testAdjacentDottedAndNestedComputedFields() {
+		"should project two computed fields in a common parent (w/ one case dotted)": function adjacentDottedAndNestedComputedFields() {
 			/** Two computed fields within a common parent, in one case dotted. */
 			var expr = ObjectExpression.createRoot();
 			expr.addField("a.b", ConstantExpression.create(6));
@@ -475,7 +471,7 @@ exports.ObjectExpression = {
 			});
 		},
 
-		"should be able to project two computed fields within a common parent (in another case dotted)": function testAdjacentNestedAndDottedComputedFields() {
+		"should project two computed fields in a common parent (in another case dotted)": function adjacentNestedAndDottedComputedFields() {
 			/** Two computed fields within a common parent, in another case dotted. */
 			var expr = ObjectExpression.createRoot();
 			var subExpr = ObjectExpression.create();
@@ -492,7 +488,7 @@ exports.ObjectExpression = {
 			});
 		},
 
-		"should be able to project two computed fields within a common parent (nested rather than dotted)": function testAdjacentNestedComputedFields() {
+		"should project two computed fields in a common parent (nested rather than dotted)": function adjacentNestedComputedFields() {
 			/** Two computed fields within a common parent, nested rather than dotted. */
 			var expr = ObjectExpression.createRoot();
 			var subExpr1 = ObjectExpression.create();
@@ -511,7 +507,7 @@ exports.ObjectExpression = {
 			});
 		},
 
-		"should be able to project multiple nested fields out of order without affecting output order": function testAdjacentNestedOrdering() {
+		"should project multiple nested fields out of order without affecting output order": function adjacentNestedOrdering() {
 			/** Field ordering is preserved when nested fields are merged. */
 			var expr = ObjectExpression.createRoot();
 			expr.addField("a.b", ConstantExpression.create(6));
@@ -530,7 +526,7 @@ exports.ObjectExpression = {
 			});
 		},
 
-		"should be able to project adjacent fields two levels deep": function testMultipleNestedFields() {
+		"should project adjacent fields two levels deep": function multipleNestedFields() {
 			/** Adjacent fields two levels deep. */
 			var expr = ObjectExpression.createRoot();
 			expr.addField("a.b.c", ConstantExpression.create(6));
@@ -549,7 +545,7 @@ exports.ObjectExpression = {
 			});
 		},
 
-		"should throw an Error if two expressions generate the same field": function testConflictingExpressionFields() {
+		"should error if two expressions generate the same field": function conflictingExpressionFields() {
 			/** Two expressions cannot generate the same field. */
 			var expr = ObjectExpression.createRoot();
 			expr.addField("a", ConstantExpression.create(5));
@@ -558,7 +554,7 @@ exports.ObjectExpression = {
 			}, Error);
 		},
 
-		"should throw an Error if an expression field conflicts with an inclusion field": function testConflictingInclusionExpressionFields() {
+		"should error if an expression field conflicts with an inclusion field": function conflictingInclusionExpressionFields() {
 			/** An expression field conflicts with an inclusion field. */
 			var expr = ObjectExpression.createRoot();
 			expr.includePath("a");
@@ -567,7 +563,7 @@ exports.ObjectExpression = {
 			}, Error);
 		},
 
-		"should throw an Error if an inclusion field conflicts with an expression field": function testConflictingExpressionInclusionFields() {
+		"should error if an inclusion field conflicts with an expression field": function conflictingExpressionInclusionFields() {
 			/** An inclusion field conflicts with an expression field. */
 			var expr = ObjectExpression.createRoot();
 			expr.addField("a", ConstantExpression.create(5));
@@ -576,7 +572,7 @@ exports.ObjectExpression = {
 			}, Error);
 		},
 
-		"should throw an Error if an object expression conflicts with a constant expression": function testConflictingObjectConstantExpressionFields() {
+		"should error if an object expression conflicts with a constant expression": function conflictingObjectConstantExpressionFields() {
 			/** An object expression conflicts with a constant expression. */
 			var expr = ObjectExpression.createRoot();
 			var subExpr = ObjectExpression.create();
@@ -587,7 +583,7 @@ exports.ObjectExpression = {
 			}, Error);
 		},
 
-		"should throw an Error if a constant expression conflicts with an object expression": function testConflictingConstantObjectExpressionFields() {
+		"should error if a constant expression conflicts with an object expression": function conflictingConstantObjectExpressionFields() {
 			/** A constant expression conflicts with an object expression. */
 			var expr = ObjectExpression.createRoot();
 			expr.addField("a.b", ConstantExpression.create(6));
@@ -598,7 +594,7 @@ exports.ObjectExpression = {
 			}, Error);
 		},
 
-		"should throw an Error if two nested expressions cannot generate the same field": function testConflictingNestedFields() {
+		"should error if two nested expressions cannot generate the same field": function conflictingNestedFields() {
 			/** Two nested expressions cannot generate the same field. */
 			var expr = ObjectExpression.createRoot();
 			expr.addField("a.b", ConstantExpression.create(5));
@@ -607,7 +603,7 @@ exports.ObjectExpression = {
 			}, Error);
 		},
 
-		"should throw an Error if an expression is created for a subfield of another expression": function testConflictingFieldAndSubfield() {
+		"should error if an expression is created for a subfield of another expression": function conflictingFieldAndSubfield() {
 			/** An expression cannot be created for a subfield of another expression. */
 			var expr = ObjectExpression.createRoot();
 			expr.addField("a", ConstantExpression.create(5));
@@ -616,7 +612,7 @@ exports.ObjectExpression = {
 			}, Error);
 		},
 
-		"should throw an Error if an expression is created for a nested field of another expression.": function testConflictingFieldAndNestedField() {
+		"should error if an expression is created for a nested field of another expression.": function conflictingFieldAndNestedField() {
 			/** An expression cannot be created for a nested field of another expression. */
 			var expr = ObjectExpression.createRoot();
 			expr.addField("a", ConstantExpression.create(5));
@@ -627,7 +623,7 @@ exports.ObjectExpression = {
 			}, Error);
 		},
 
-		"should throw an Error if an expression is created for a parent field of another expression": function testConflictingSubfieldAndField() {
+		"should error if an expression is created for a parent field of another expression": function conflictingSubfieldAndField() {
 			/** An expression cannot be created for a parent field of another expression. */
 			var expr = ObjectExpression.createRoot();
 			expr.addField("a.b", ConstantExpression.create(5));
@@ -636,7 +632,7 @@ exports.ObjectExpression = {
 			}, Error);
 		},
 
-		"should throw an Error if an expression is created for a parent of a nested field": function testConflictingNestedFieldAndField() {
+		"should error if an expression is created for a parent of a nested field": function conflictingNestedFieldAndField() {
 			/** An expression cannot be created for a parent of a nested field. */
 			var expr = ObjectExpression.createRoot();
 			var subExpr = ObjectExpression.create();
@@ -647,7 +643,7 @@ exports.ObjectExpression = {
 			}, Error);
 		},
 
-		"should be able to evaluate expressions in general": function testEvaluate() {
+		"should be able to evaluate expressions in general": function evaluate() {
 			/**
 			 * evaluate() does not supply an inclusion document.
 			 * Inclusion spec'd fields are not included.

+ 2 - 4
test/lib/pipeline/expressions/OrExpression_test.js

@@ -1,4 +1,5 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	Expression = require("../../../../lib/pipeline/expressions/Expression"),
 	OrExpression = require("../../../../lib/pipeline/expressions/OrExpression"),
@@ -8,12 +9,9 @@ var assert = require("assert"),
 	constify = utils.constify,
 	expressionToJson = utils.expressionToJson;
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 var TestBase = function TestBase(overrides) {
 		//NOTE: DEVIATION FROM MONGO: using this base class to make things easier to initialize
-		for (var key in overrides)
+		for (var key in overrides) //jshint ignore:line
 			this[key] = overrides[key];
 	},
 	ExpectedResultBase = (function() {

+ 1 - 3
test/lib/pipeline/expressions/SecondExpression_test.js

@@ -1,11 +1,9 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	SecondExpression = require("../../../../lib/pipeline/expressions/SecondExpression"),
 	Expression = require("../../../../lib/pipeline/expressions/Expression");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.SecondExpression = {
 
 	"constructor()": {

+ 1 - 3
test/lib/pipeline/expressions/SetDifferenceExpression_test.js

@@ -1,11 +1,9 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	SetDifferenceExpression = require("../../../../lib/pipeline/expressions/SetDifferenceExpression"),
 	ExpectedResultBase = require("./SetExpectedResultBase");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.SetDifferenceExpression = {
 
 	"constructor()": {

+ 1 - 3
test/lib/pipeline/expressions/SetEqualsExpression_test.js

@@ -1,11 +1,9 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	SetEqualsExpression = require("../../../../lib/pipeline/expressions/SetEqualsExpression"),
 	ExpectedResultBase = require("./SetExpectedResultBase");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.SetEqualsExpression = {
 
 	"constructor()": {

+ 3 - 5
test/lib/pipeline/expressions/SetExpectedResultBase.js

@@ -6,13 +6,11 @@ var assert = require("assert"),
 	VariablesParseState = require("../../../../lib/pipeline/expressions/VariablesParseState"),
 	Expression = require("../../../../lib/pipeline/expressions/Expression");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 var ExpectedResultBase = module.exports = (function() { //jshint ignore:line
+
 	var klass = function ExpectedResultBase(overrides) {
 		//NOTE: DEVIATION FROM MONGO: using this base class to make things easier to initialize
-		for (var key in overrides)
+		for (var key in overrides) //jshint ignore:line
 			this[key] = overrides[key];
 	}, proto = klass.prototype;
 	proto.run = function() {
@@ -20,7 +18,7 @@ var ExpectedResultBase = module.exports = (function() { //jshint ignore:line
 			args = spec.input;
 		if (spec.expected !== undefined && spec.expected !== null) {
 			var fields = spec.expected;
-			for (var fieldFirst in fields) {
+			for (var fieldFirst in fields) { //jshint ignore:line
 				var fieldSecond = fields[fieldFirst],
 					expected = fieldSecond;
 					// obj = {<fieldFirst>: args}; //NOTE: DEVIATION FROM MONGO: see parseExpression below

+ 1 - 3
test/lib/pipeline/expressions/SetIntersectionExpression_test.js

@@ -1,11 +1,9 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	SetIntersectionExpression = require("../../../../lib/pipeline/expressions/SetIntersectionExpression"),
 	ExpectedResultBase = require("./SetExpectedResultBase");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.SetIntersectionExpression = {
 
 	"constructor()": {

+ 1 - 3
test/lib/pipeline/expressions/SetIsSubsetExpression_test.js

@@ -1,11 +1,9 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	SetIsSubsetExpression = require("../../../../lib/pipeline/expressions/SetIsSubsetExpression"),
 	ExpectedResultBase = require("./SetExpectedResultBase");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.SetIsSubsetExpression = {
 
 	"constructor()": {

+ 1 - 3
test/lib/pipeline/expressions/SetUnionExpression_test.js

@@ -1,11 +1,9 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	SetUnionExpression = require("../../../../lib/pipeline/expressions/SetUnionExpression"),
 	ExpectedResultBase = require("./SetExpectedResultBase");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.SetUnionExpression = {
 
 	"constructor()": {

+ 1 - 4
test/lib/pipeline/expressions/SizeExpression_test.js

@@ -1,14 +1,11 @@
 "use strict";
-
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	SizeExpression = require("../../../../lib/pipeline/expressions/SizeExpression"),
 	VariablesIdGenerator = require("../../../../lib/pipeline/expressions/VariablesIdGenerator"),
 	VariablesParseState = require("../../../../lib/pipeline/expressions/VariablesParseState"),
 	Expression = require("../../../../lib/pipeline/expressions/Expression");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.SizeExpression = {
 
 	"constructor()": {

+ 2 - 4
test/lib/pipeline/expressions/StrcasecmpExpression_test.js

@@ -1,4 +1,5 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	StrcasecmpExpression = require("../../../../lib/pipeline/expressions/StrcasecmpExpression"),
 	Expression = require("../../../../lib/pipeline/expressions/Expression"),
@@ -8,12 +9,9 @@ var assert = require("assert"),
 	constify = utils.constify,
 	expressionToJson = utils.expressionToJson;
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 var TestBase = function TestBase(overrides) {
 		//NOTE: DEVIATION FROM MONGO: using this base class to make things easier to initialize
-		for (var key in overrides)
+		for (var key in overrides) //jshint ignore:line
 			this[key] = overrides[key];
 	},
 	ExpectedResultBase = (function() {

+ 2 - 4
test/lib/pipeline/expressions/SubstrExpression_test.js

@@ -1,4 +1,5 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	SubstrExpression = require("../../../../lib/pipeline/expressions/SubstrExpression"),
 	Expression = require("../../../../lib/pipeline/expressions/Expression"),
@@ -8,12 +9,9 @@ var assert = require("assert"),
 	constify = utils.constify,
 	expressionToJson = utils.expressionToJson;
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 var TestBase = function TestBase(overrides) {
 		//NOTE: DEVIATION FROM MONGO: using this base class to make things easier to initialize
-		for (var key in overrides)
+		for (var key in overrides) //jshint ignore:line
 			this[key] = overrides[key];
 	},
 	ExpectedResultBase = (function() {

+ 1 - 5
test/lib/pipeline/expressions/SubtractExpression_test.js

@@ -1,13 +1,11 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 		SubtractExpression = require("../../../../lib/pipeline/expressions/SubtractExpression"),
 		Expression = require("../../../../lib/pipeline/expressions/Expression"),
 		VariablesIdGenerator = require("../../../../lib/pipeline/expressions/VariablesIdGenerator"),
 		VariablesParseState = require("../../../../lib/pipeline/expressions/VariablesParseState");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.SubtractExpression = {
 
 	"constructor()": {
@@ -125,5 +123,3 @@ exports.SubtractExpression = {
 	},
 
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);

+ 5 - 9
test/lib/pipeline/expressions/ToLowerExpression_test.js

@@ -1,4 +1,5 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	ToLowerExpression = require("../../../../lib/pipeline/expressions/ToLowerExpression"),
 	VariablesParseState = require("../../../../lib/pipeline/expressions/VariablesParseState"),
@@ -8,12 +9,9 @@ var assert = require("assert"),
 	constify = utils.constify,
 	expressionToJson = utils.expressionToJson;
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 var TestBase = function TestBase(overrides) {
 		//NOTE: DEVIATION FROM MONGO: using this base class to make things easier to initialize
-		for (var key in overrides)
+		for (var key in overrides) //jshint ignore:line
 			this[key] = overrides[key];
 	},
 	ExpectedResultBase = (function() {
@@ -61,7 +59,7 @@ exports.ToLowerExpression = {
 
 	"#evaluate()": {
 
-		"should return the lowercase version of the string if there is a null character at the beginning of the string": function NullBegin() {
+		"should return the lowercase version of the string if a null is character at the beginning of the string": function NullBegin() {
 			/** String beginning with a null character. */
 			new ExpectedResultBase({
 				str: "\0aB",
@@ -69,7 +67,7 @@ exports.ToLowerExpression = {
 			}).run();
 		},
 
-		"should return the lowercase version of the string if there is a null character in the middle of the string": function NullMiddle() {
+		"should return the lowercase version of the string if a null is character in the middle of the string": function NullMiddle() {
 			/** String containing a null character. */
 			new ExpectedResultBase({
 				str: "a\0B",
@@ -77,7 +75,7 @@ exports.ToLowerExpression = {
 			}).run();
 		},
 
-		"should return the lowercase version of the string if there is a null character at the end of the string": function NullEnd() {
+		"should return the lowercase version of the string if a null is character at the end of the string": function NullEnd() {
 			/** String ending with a null character. */
 			new ExpectedResultBase({
 				str: "aB\0",
@@ -88,5 +86,3 @@ exports.ToLowerExpression = {
 	},
 
 };
-
-if (!module.parent)(new (require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);

+ 5 - 9
test/lib/pipeline/expressions/ToUpperExpression_test.js

@@ -1,4 +1,5 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	ToUpperExpression = require("../../../../lib/pipeline/expressions/ToUpperExpression"),
 	VariablesParseState = require("../../../../lib/pipeline/expressions/VariablesParseState"),
@@ -8,12 +9,9 @@ var assert = require("assert"),
 	constify = utils.constify,
 	expressionToJson = utils.expressionToJson;
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 var TestBase = function TestBase(overrides) {
 		//NOTE: DEVIATION FROM MONGO: using this base class to make things easier to initialize
-		for (var key in overrides)
+		for (var key in overrides) //jshint ignore:line
 			this[key] = overrides[key];
 	},
 	ExpectedResultBase = (function() {
@@ -61,7 +59,7 @@ exports.ToUpperExpression = {
 
 	"#evaluate()": {
 
-		"should return the uppercase version of the string if there is a null character at the beginning of the string": function NullBegin() {
+		"should return the uppercase version of the string if a null character at the beginning of the string": function NullBegin() {
 			/** String beginning with a null character. */
 			new ExpectedResultBase({
 				str: "\0aB",
@@ -69,7 +67,7 @@ exports.ToUpperExpression = {
 			}).run();
 		},
 
-		"should return the uppercase version of the string if there is a null character in the middle of the string": function NullMiddle() {
+		"should return the uppercase version of the string if a null character in the middle of the string": function NullMiddle() {
 			/** String containing a null character. */
 			new ExpectedResultBase({
 				str: "a\0B",
@@ -77,7 +75,7 @@ exports.ToUpperExpression = {
 			}).run();
 		},
 
-		"should return the uppercase version of the string if there is a null character at the end of the string": function NullEnd() {
+		"should return the uppercase version of the string if a null character at the end of the string": function NullEnd() {
 			/** String ending with a null character. */
 			new ExpectedResultBase({
 				str: "aB\0",
@@ -88,5 +86,3 @@ exports.ToUpperExpression = {
 	},
 
 };
-
-if (!module.parent)(new (require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);

+ 2 - 3
test/lib/pipeline/expressions/VariablesIdGenerator_test.js

@@ -1,4 +1,5 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	VariablesIdGenerator = require("../../../../lib/pipeline/expressions/VariablesIdGenerator");
 
@@ -10,7 +11,7 @@ module.exports = {
 		"constructor": {
 
 			"Should be able to construct": function canConstruct() {
-				var variablesIdGenerator = new VariablesIdGenerator();
+				new VariablesIdGenerator();
 			}
 
 		},
@@ -53,5 +54,3 @@ module.exports = {
 	}
 
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);

+ 15 - 17
test/lib/pipeline/expressions/VariablesParseState_test.js

@@ -1,10 +1,10 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	Variables = require("../../../../lib/pipeline/expressions/Variables"),
 	VariablesIdGenerator = require("../../../../lib/pipeline/expressions/VariablesIdGenerator"),
 	VariablesParseState = require("../../../../lib/pipeline/expressions/VariablesParseState");
 
-
 module.exports = {
 
 	"VariablesParseState": {
@@ -12,28 +12,28 @@ module.exports = {
 		"constructor": {
 
 			"Should be able to construct": function canConstruct() {
-				var idGen = new VariablesIdGenerator(),
-					vps = new VariablesParseState(idGen);
+				var idGen = new VariablesIdGenerator();
+				new VariablesParseState(idGen);
 			},
 
 			"Should throw given invalid args": function throwsForArgs() {
 				assert.throws(function() {
-					var vps = new VariablesParseState();
+					new VariablesParseState();
 				});
 				assert.throws(function() {
-					var vps = new VariablesParseState(1);
+					new VariablesParseState(1);
 				});
 				assert.throws(function() {
-					var vps = new VariablesParseState('hi');
+					new VariablesParseState("hi");
 				});
 				assert.throws(function() {
-					var vps = new VariablesParseState({});
+					new VariablesParseState({});
 				});
 				assert.throws(function() {
-					var vps = new VariablesParseState([]);
+					new VariablesParseState([]);
 				});
 				assert.throws(function() {
-					var vps = new VariablesParseState(new Date());
+					new VariablesParseState(new Date());
 				});
 			}
 
@@ -45,15 +45,15 @@ module.exports = {
 				var idGen = new VariablesIdGenerator(),
 					vps = new VariablesParseState(idGen);
 				assert.throws(function() {
-					vps.defineVariable('ROOT', 5);
+					vps.defineVariable("ROOT", 5);
 				});
 			},
 
 			"Should return new ids": function returnsNewIds() {
 				var idGen = new VariablesIdGenerator(),
 					vps = new VariablesParseState(idGen),
-					firstId = vps.defineVariable('hi', 'bye'),
-					secondId = vps.defineVariable('bye', 'hi');
+					firstId = vps.defineVariable("hi", "bye"),
+					secondId = vps.defineVariable("bye", "hi");
 				assert.notEqual(firstId, secondId);
 			}
 
@@ -64,15 +64,15 @@ module.exports = {
 			"Can retrieve defined variables": function getVariable() {
 				var idGen = new VariablesIdGenerator(),
 					vps = new VariablesParseState(idGen),
-					firstId = vps.defineVariable('hi', 'bye'),
-					firstVariable = vps.getVariable('hi');
+					firstId = vps.defineVariable("hi", "bye"),
+					firstVariable = vps.getVariable("hi");
 				assert.equal(firstVariable, firstId);
 			},
 
 			"Can retrieve root id": function getVariable() {
 				var idGen = new VariablesIdGenerator(),
 					vps = new VariablesParseState(idGen),
-					firstVariable = vps.getVariable('ROOT');
+					firstVariable = vps.getVariable("ROOT");
 				assert.equal(firstVariable, Variables.ROOT_ID);
 			}
 		}
@@ -80,5 +80,3 @@ module.exports = {
 	}
 
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);

+ 25 - 27
test/lib/pipeline/expressions/Variables_test.js

@@ -1,10 +1,8 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	Variables = require("../../../../lib/pipeline/expressions/Variables");
 
-// Mocha one-liner to make these tests self-hosted
-if (!module.parent)return(require.cache[__filename] = null, (new (require("mocha"))({ui: "exports", reporter: "spec", grep: process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.Variables = {
 
 	"constructor": {
@@ -19,7 +17,7 @@ exports.Variables = {
 
 		"should throw if not given a number": function() {
 			assert.throws(function() {
-				new Variables('hi');
+				new Variables("hi");
 			});
 			assert.throws(function() {
 				new Variables({});
@@ -35,7 +33,7 @@ exports.Variables = {
 		"setValue throws if no args given": function() {
 			assert.throws(function() {
 				var variables = new Variables();
-				variables.setValue(1, 'hi');
+				variables.setValue(1, "hi");
 			});
 		},
 
@@ -45,14 +43,14 @@ exports.Variables = {
 
 		"should set the _root variable to the passed value": function() {
 			var variables = new Variables(),
-				root = {'hi':'hi'};
+				root = {"hi":"hi"};
 			variables.setRoot(root);
 			assert.equal(root, variables._root);
 		},
 
 		"must be an object": function mustBeObject() {
 			var variables = new Variables(),
-				root = 'hi';
+				root = "hi";
 			assert.throws(function() {
 				variables.setRoot(root);
 			});
@@ -64,7 +62,7 @@ exports.Variables = {
 
 		"should set the _root variable to empty obj": function() {
 			var variables = new Variables(),
-				root = {'hi':'hi'};
+				root = {"hi":"hi"};
 			variables.setRoot(root);
 			variables.clearRoot();
 			assert.deepEqual({}, variables._root);
@@ -76,7 +74,7 @@ exports.Variables = {
 
 		"should return the _root variable": function() {
 			var variables = new Variables(),
-				root = {'hi':'hi'};
+				root = {"hi":"hi"};
 			variables.setRoot(root);
 			assert.equal(root, variables.getRoot());
 		},
@@ -88,7 +86,7 @@ exports.Variables = {
 		"id must be number": function() {
 			assert.throws(function() {
 				var variables = new Variables();
-				variables.setValue('hi', 5);
+				variables.setValue("hi", 5);
 			});
 			assert.throws(function() {
 				var variables = new Variables();
@@ -115,25 +113,25 @@ exports.Variables = {
 		"cannot use root id": function() {
 			assert.throws(function() {
 				var variables = new Variables(5);
-				variables.setValue(Variables.ROOT_ID, 'hi');
+				variables.setValue(Variables.ROOT_ID, "hi");
 			});
 		},
 
 		"cannot use id larger than initial size": function() {
 			assert.throws(function() {
 				var variables = new Variables(5);
-				variables.setValue(5, 'hi'); //off by one check
+				variables.setValue(5, "hi"); //off by one check
 			});
 			assert.throws(function() {
 				var variables = new Variables(5);
-				variables.setValue(6, 'hi');
+				variables.setValue(6, "hi");
 			});
 		},
 
 		"sets the value": function() {
 			var variables = new Variables(5);
-			variables.setValue(1, 'hi'); //off by one check
-			assert.equal(variables._rest[1], 'hi');
+			variables.setValue(1, "hi"); //off by one check
+			assert.equal(variables._rest[1], "hi");
 		},
 
 	},
@@ -143,7 +141,7 @@ exports.Variables = {
 		"id must be number": function() {
 			assert.throws(function() {
 				var variables = new Variables();
-				variables.getValue('hi', 5);
+				variables.getValue("hi", 5);
 			});
 			assert.throws(function() {
 				var variables = new Variables();
@@ -169,7 +167,7 @@ exports.Variables = {
 
 		"returns root when given root id": function() {
 			var variables = new Variables(5),
-				root = {hi:'hi'};
+				root = {hi:"hi"};
 			variables.setRoot(root);
 			variables.getValue(Variables.ROOT_ID, root);
 		},
@@ -177,18 +175,18 @@ exports.Variables = {
 		"cannot use id larger than initial size": function() {
 			assert.throws(function() {
 				var variables = new Variables(5);
-				variables.getValue(5, 'hi'); //off by one check
+				variables.getValue(5, "hi"); //off by one check
 			});
 			assert.throws(function() {
 				var variables = new Variables(5);
-				variables.getValue(6, 'hi');
+				variables.getValue(6, "hi");
 			});
 		},
 
 		"gets the value": function() {
 			var variables = new Variables(5);
-			variables.setValue(1, 'hi');
-			assert.equal(variables.getValue(1), 'hi');
+			variables.setValue(1, "hi");
+			assert.equal(variables.getValue(1), "hi");
 		},
 
 	},
@@ -198,7 +196,7 @@ exports.Variables = {
 		"id must be number": function() {
 			assert.throws(function() {
 				var variables = new Variables();
-				variables.getDocument('hi', 5);
+				variables.getDocument("hi", 5);
 			});
 			assert.throws(function() {
 				var variables = new Variables();
@@ -224,7 +222,7 @@ exports.Variables = {
 
 		"returns root when given root id": function() {
 			var variables = new Variables(5),
-				root = {hi:'hi'};
+				root = {hi:"hi"};
 			variables.setRoot(root);
 			variables.getDocument(Variables.ROOT_ID, root);
 		},
@@ -232,24 +230,24 @@ exports.Variables = {
 		"cannot use id larger than initial size": function() {
 			assert.throws(function() {
 				var variables = new Variables(5);
-				variables.getDocument(5, 'hi'); //off by one check
+				variables.getDocument(5, "hi"); //off by one check
 			});
 			assert.throws(function() {
 				var variables = new Variables(5);
-				variables.getDocument(6, 'hi');
+				variables.getDocument(6, "hi");
 			});
 		},
 
 		"gets the value": function() {
 			var variables = new Variables(5),
-				value = {hi:'hi'};
+				value = {hi:"hi"};
 			variables.setValue(1, value);
 			assert.equal(variables.getDocument(1), value);
 		},
 
 		"only returns documents": function() {
 			var variables = new Variables(5),
-				value = 'hi';
+				value = "hi";
 			variables.setValue(1, value);
 			assert.deepEqual(variables.getDocument(1), {});
 		},

+ 1 - 3
test/lib/pipeline/expressions/WeekExpression_test.js

@@ -1,11 +1,9 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	WeekExpression = require("../../../../lib/pipeline/expressions/WeekExpression"),
 	Expression = require("../../../../lib/pipeline/expressions/Expression");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.WeekExpression = {
 
 	"constructor()": {

+ 1 - 3
test/lib/pipeline/expressions/YearExpression_test.js

@@ -1,11 +1,9 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	YearExpression = require("../../../../lib/pipeline/expressions/YearExpression"),
 	Expression = require("../../../../lib/pipeline/expressions/Expression");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.YearExpression = {
 
 	"constructor()": {

+ 3 - 3
test/lib/pipeline/expressions/utils.js

@@ -9,7 +9,7 @@ var utils = module.exports = {
 	constify: function constify(obj, parentIsArray) {
 		if (parentIsArray === undefined) parentIsArray = false;
 		var bob = parentIsArray ? [] : {};
-		for (var key in obj) {
+		for (var key in obj) { //jshint ignore:line
 			if (!obj.hasOwnProperty(key)) continue;
 			var elem = obj[key];
 			if (elem instanceof Object && elem.constructor === Object) {
@@ -17,8 +17,8 @@ var utils = module.exports = {
 			} else if (Array.isArray(elem) && !parentIsArray) {
 				// arrays within arrays are treated as constant values by the real parser
 				bob[key] = utils.constify(elem, true);
-			} else if (key == "$const" ||
-					(typeof elem == "string" && elem[0] == "$")) {
+			} else if (key === "$const" ||
+					(typeof elem === "string" && elem[0] === "$")) {
 				bob[key] = obj[key];
 			} else {
 				bob[key] = {$const: obj[key]};

+ 1 - 4
test/lib/pipeline/expressions/utils_test.js

@@ -1,11 +1,8 @@
 "use strict";
-
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	utils = require("./utils");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.utils = {
 
 	".constify()": {

+ 10 - 11
test/lib/pipeline/matcher/AllElemMatchOp_test.js

@@ -1,5 +1,7 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
+	ErrorCodes = require("../../../../lib/Errors").ErrorCodes,
 	EqualityMatchExpression = require("../../../../lib/pipeline/matcher/EqualityMatchExpression.js"),
 	ElemMatchObjectMatchExpression = require("../../../../lib/pipeline/matcher/ElemMatchObjectMatchExpression.js"),
 	ElemMatchValueMatchExpression = require("../../../../lib/pipeline/matcher/ElemMatchValueMatchExpression.js"),
@@ -8,22 +10,19 @@ var assert = require("assert"),
 	GTMatchExpression = require("../../../../lib/pipeline/matcher/GTMatchExpression.js"),
 	AllElemMatchOp = require("../../../../lib/pipeline/matcher/AllElemMatchOp.js");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.AllElemMatchOp = {
 	"Should match an element": function() {
 		var baseOperanda1={"a":1},
 			eqa1 = new EqualityMatchExpression();
 
-		assert.strictEqual(eqa1.init("a", baseOperanda1.a).code, 'OK');
+		assert.strictEqual(eqa1.init("a", baseOperanda1.a).code, ErrorCodes.OK);
 
 		var baseOperandb1={"b":1},
 			eqb1 = new EqualityMatchExpression(),
 			and1 = new AndMatchExpression(),
 			elemMatch1 = new ElemMatchObjectMatchExpression();
 
-		assert.strictEqual(eqb1.init("b", baseOperandb1.b).code, 'OK');
+		assert.strictEqual(eqb1.init("b", baseOperandb1.b).code, ErrorCodes.OK);
 
 		and1.add(eqa1);
 		and1.add(eqb1);
@@ -35,7 +34,7 @@ exports.AllElemMatchOp = {
 		var baseOperanda2={"a":2},
 			eqa2 = new EqualityMatchExpression();
 
-		assert.strictEqual(eqa2.init("a", baseOperanda2.a).code, 'OK');
+		assert.strictEqual(eqa2.init("a", baseOperanda2.a).code, ErrorCodes.OK);
 
 		var baseOperandb2={"b":2},
 			eqb2 = new EqualityMatchExpression(),
@@ -43,7 +42,7 @@ exports.AllElemMatchOp = {
 			elemMatch2 = new ElemMatchObjectMatchExpression(),
 			op = new AllElemMatchOp();
 
-		assert.strictEqual(eqb2.init("b", baseOperandb2.b).code, 'OK');
+		assert.strictEqual(eqb2.init("b", baseOperandb2.b).code, ErrorCodes.OK);
 
 		and2.add(eqa2);
 		and2.add(eqb2);
@@ -76,13 +75,13 @@ exports.AllElemMatchOp = {
 		var baseOperandgt1={"$gt":1},
 			gt1 = new GTMatchExpression();
 
-		assert.strictEqual(gt1.init("", baseOperandgt1.$gt).code, 'OK');
+		assert.strictEqual(gt1.init("", baseOperandgt1.$gt).code, ErrorCodes.OK);
 
 		var baseOperandlt1={"$lt":10},
 			lt1 = new LTMatchExpression(),
 			elemMatch1 = new ElemMatchValueMatchExpression();
 
-		assert.strictEqual(lt1.init("", baseOperandlt1.$lt).code, 'OK');
+		assert.strictEqual(lt1.init("", baseOperandlt1.$lt).code, ErrorCodes.OK);
 
 		elemMatch1.init("x");
 		elemMatch1.add(gt1);
@@ -91,14 +90,14 @@ exports.AllElemMatchOp = {
 		var baseOperandgt2={"$gt":101},
 			gt2 = new GTMatchExpression();
 
-		assert.strictEqual(gt2.init("", baseOperandgt2.$gt).code, 'OK');
+		assert.strictEqual(gt2.init("", baseOperandgt2.$gt).code, ErrorCodes.OK);
 
 		var baseOperandlt2={"$lt":110},
 			lt2 = new LTMatchExpression(),
 			elemMatch2 = new ElemMatchValueMatchExpression(),
 			op = new AllElemMatchOp();
 
-		assert.strictEqual(lt2.init("", baseOperandlt2.$lt).code, 'OK');
+		assert.strictEqual(lt2.init("", baseOperandlt2.$lt).code, ErrorCodes.OK);
 
 		elemMatch2.init("x");
 		elemMatch2.add(gt2);

+ 20 - 21
test/lib/pipeline/matcher/AndMatchExpression_test.js

@@ -1,5 +1,7 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
+	ErrorCodes = require("../../../../lib/Errors").ErrorCodes,
 	AndMatchExpression = require("../../../../lib/pipeline/matcher/AndMatchExpression.js"),
 	LTMatchExpression = require("../../../../lib/pipeline/matcher/LTMatchExpression.js"),
 	GTMatchExpression = require("../../../../lib/pipeline/matcher/GTMatchExpression.js"),
@@ -19,29 +21,29 @@ module.exports = {
 			var gt = new GTMatchExpression();
 			var rgx = new RegexMatchExpression();
 			var op = new AndMatchExpression();
-			assert.strictEqual( lt.init('a','z1').code,'OK');
-			assert.strictEqual( gt.init('a','a1').code,'OK');
-			assert.strictEqual( rgx.init('a','1','').code,'OK');
+			assert.strictEqual(lt.init("a", "z1").code, ErrorCodes.OK);
+			assert.strictEqual(gt.init("a", "a1").code, ErrorCodes.OK);
+			assert.strictEqual(rgx.init("a", "1", "").code, ErrorCodes.OK);
 			op.add(lt);
 			op.add(gt);
 			op.add(rgx);
-			assert.ok( op.matches({'a':'r1'}) );
-			assert.ok( ! op.matches({'a': 'z1'}) );
-			assert.ok( ! op.matches({'a': 'a1'}) );
-			assert.ok( ! op.matches({'a':'r'}) );
+			assert(op.matches({a:"r1"}));
+			assert(!op.matches({a:"z1"}));
+			assert(!op.matches({a:"a1"}));
+			assert(!op.matches({a:"r"}));
 		},
 		"Should match a single clause": function() {
 			var nop = new NotMatchExpression();
 			var eq = new EqualityMatchExpression();
 			var op = new AndMatchExpression();
 
-			assert.strictEqual(eq.init('a', 5).code, 'OK');
-			assert.strictEqual(nop.init(eq).code, 'OK');
+			assert.strictEqual(eq.init("a", 5).code, ErrorCodes.OK);
+			assert.strictEqual(nop.init(eq).code, ErrorCodes.OK);
 			op.add(nop);
-			assert.ok( op.matches({'a':4}) );
-			assert.ok( op.matches({'a':[4,6]}) );
-			assert.ok( !op.matches({'a':5}) );
-			assert.ok( !op.matches({'a':[4,5]}) );
+			assert(op.matches({a:4}));
+			assert(op.matches({a:[4,6]}));
+			assert(!op.matches({a:5}));
+			assert(!op.matches({a:[4,5]}));
 		},
 		"Should match three clauses": function(){
 			var baseOperand1 = {"$gt":1},
@@ -52,9 +54,9 @@ module.exports = {
 				sub3 = new LTMatchExpression(),
 				andOp = new AndMatchExpression();
 
-			assert.strictEqual(sub1.init("a", baseOperand1.$gt).code, 'OK');
-			assert.strictEqual(sub2.init("a", baseOperand2.$lt).code, 'OK');
-			assert.strictEqual(sub3.init("b", baseOperand3.$lt).code, 'OK');
+			assert.strictEqual(sub1.init("a", baseOperand1.$gt).code, ErrorCodes.OK);
+			assert.strictEqual(sub2.init("a", baseOperand2.$lt).code, ErrorCodes.OK);
+			assert.strictEqual(sub3.init("b", baseOperand3.$lt).code, ErrorCodes.OK);
 
 			andOp.add(sub1);
 			andOp.add(sub2);
@@ -74,8 +76,8 @@ module.exports = {
 				andOp = new AndMatchExpression(),
 				details = new MatchDetails();
 
-			assert.strictEqual(sub1.init("a", baseOperand1.a).code, 'OK');
-			assert.strictEqual(sub2.init("b", baseOperand2.b).code, 'OK');
+			assert.strictEqual(sub1.init("a", baseOperand1.a).code, ErrorCodes.OK);
+			assert.strictEqual(sub2.init("b", baseOperand2.b).code, ErrorCodes.OK);
 
 			andOp.add(sub1);
 			andOp.add(sub2);
@@ -94,6 +96,3 @@ module.exports = {
 
 	}
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);
-

+ 67 - 68
test/lib/pipeline/matcher/ComparisonMatchExpression_test.js

@@ -1,110 +1,109 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	bson = require("bson"),
 	MinKey = bson.BSONPure.MinKey,
 	MaxKey = bson.BSONPure.MaxKey,
+	ErrorCodes = require("../../../../lib/Errors").ErrorCodes,
 	MatchDetails = require("../../../../lib/pipeline/matcher/MatchDetails"),
 	ComparisonMatchExpression = require("../../../../lib/pipeline/matcher/ComparisonMatchExpression");
 
-// Mocha one-liner to make these tests self-hosted
-if(!module.parent)return(require.cache[__filename]=null,(new(require("mocha"))({ui:"exports",reporter:"spec",grep:process.env.TEST_GREP})).addFile(__filename).run(process.exit));
-
 exports.ComparisonMatchExpression = {
 
 	"should properly initialize with an empty path and a number": function () {
-		var e = new ComparisonMatchExpression('LT');
-		assert.strictEqual(e.init('',5).code,'OK');
+		var e = new ComparisonMatchExpression("LT");
+		assert.strictEqual(e.init("",5).code, ErrorCodes.OK);
 	},
 	"should not initialize when given an invalid operand": function() {
-		var e = new ComparisonMatchExpression('');
-		assert.strictEqual(e.init('',5).code, 'BAD_VALUE');
+		var e = new ComparisonMatchExpression("");
+		assert.strictEqual(e.init("",5).code, ErrorCodes.BAD_VALUE);
 	},
 	"should not initialize when given an undefined rhs": function() {
 		var e = new ComparisonMatchExpression();
-		assert.strictEqual(e.init('',5).code,'BAD_VALUE');
-		e._matchType = 'LT';
-		assert.strictEqual(e.init('',{}).code,'BAD_VALUE');
-		assert.strictEqual(e.init('',undefined).code,'BAD_VALUE');
-		assert.strictEqual(e.init('',{}).code,'BAD_VALUE');
+		assert.strictEqual(e.init("",5).code,ErrorCodes.BAD_VALUE);
+		e._matchType = "LT";
+		assert.strictEqual(e.init("",{}).code,ErrorCodes.BAD_VALUE);
+		assert.strictEqual(e.init("",undefined).code,ErrorCodes.BAD_VALUE);
+		assert.strictEqual(e.init("",{}).code,ErrorCodes.BAD_VALUE);
 	},
 	"should match numbers with GTE": function () {
-		var e = new ComparisonMatchExpression('GTE');
-		assert.strictEqual(e.init('',5).code,'OK');
-		assert.ok(e.matchesSingleElement(6),'6 ≥ 5');
-		assert.ok(e.matchesSingleElement(5),'5 ≥ 5');
-		assert.ok(!e.matchesSingleElement(4),'4 !≥ 5');
-		assert.ok(!e.matchesSingleElement('foo'),"'foo' !≥ 5");
+		var e = new ComparisonMatchExpression("GTE");
+		assert.strictEqual(e.init("",5).code, ErrorCodes.OK);
+		assert(e.matchesSingleElement(6),"6 ≥ 5");
+		assert(e.matchesSingleElement(5),"5 ≥ 5");
+		assert(!e.matchesSingleElement(4),"4 !≥ 5");
+		assert(!e.matchesSingleElement("foo"),"'foo' !≥ 5");
 	},
 	"should match with simple paths and GTE": function() {
-		var e = new ComparisonMatchExpression('GTE');
-		assert.strictEqual(e.init('a',5).code,'OK');
-		assert.ok(e.matches({'a':6}));
+		var e = new ComparisonMatchExpression("GTE");
+		assert.strictEqual(e.init("a",5).code, ErrorCodes.OK);
+		assert(e.matches({a:6}));
 	},
 	"should match array values with GTE": function () {
-		var e = new ComparisonMatchExpression('GTE');
-		assert.strictEqual(e.init('a',5).code,'OK');
-		assert.ok(e.matches({'a':[6,10]}),'[6,10] ≥ 5');
-		assert.ok(e.matches({'a':[4,5.5]}),'[4,5.5] ≥ 5');
-		assert.ok(!e.matches({'a':[1,2]}),'[1,2] !≥ 5');
-		assert.ok(e.matches({'a':[1,10]}),'[1,10] ≥ 5');
+		var e = new ComparisonMatchExpression("GTE");
+		assert.strictEqual(e.init("a",5).code, ErrorCodes.OK);
+		assert(e.matches({a:[6,10]}),"[6,10] ≥ 5");
+		assert(e.matches({a:[4,5.5]}),"[4,5.5] ≥ 5");
+		assert(!e.matches({a:[1,2]}),"[1,2] !≥ 5");
+		assert(e.matches({a:[1,10]}),"[1,10] ≥ 5");
 	},
 	"should match entire arrays with GTE": function() {
-		var e = new ComparisonMatchExpression('GTE');
-		assert.strictEqual(e.init('a',[5]).code,'OK');
-		assert.ok(!e.matches({'a':[4]}),'[4] !≥ [5]');
-		assert.ok(e.matches({'a':[5]}),'[5] !≥ [5]');
-		assert.ok(e.matches({'a':[6]}),'[6] !≥ [5]');
+		var e = new ComparisonMatchExpression("GTE");
+		assert.strictEqual(e.init("a",[5]).code, ErrorCodes.OK);
+		assert(!e.matches({a:[4]}),"[4] !≥ [5]");
+		assert(e.matches({a:[5]}),"[5] !≥ [5]");
+		assert(e.matches({a:[6]}),"[6] !≥ [5]");
 		// documents current behavior
-		assert.ok(e.matches({'a':[[6]]}),'[[4]] ≥ [5]');
-		assert.ok(e.matches({'a':[[6]]}),'[[5]] ≥ [5]');
-		assert.ok(e.matches({'a':[[6]]}),'[[6]] ≥ [5]');
+		assert(e.matches({a:[[6]]}),"[[4]] ≥ [5]");
+		assert(e.matches({a:[[6]]}),"[[5]] ≥ [5]");
+		assert(e.matches({a:[[6]]}),"[[6]] ≥ [5]");
 	},
 	"should match null with GTE": function() {
-		var e = new ComparisonMatchExpression('GTE');
-		e._matchType = 'GTE';
-		assert.strictEqual(e.init('a',null).code,'OK');
-		assert.ok(e.matches({}),'{} ≥ null');
-		assert.ok(e.matches({'a':null}),'null ≥ null');
-		assert.ok(!e.matches({'a':4}),'4 !≥ null');
-		assert.ok(e.matches({'b':null}),'non-existent field ≥ null');
+		var e = new ComparisonMatchExpression("GTE");
+		e._matchType = "GTE";
+		assert.strictEqual(e.init("a",null).code, ErrorCodes.OK);
+		assert(e.matches({}),"{} ≥ null");
+		assert(e.matches({a:null}),"null ≥ null");
+		assert(!e.matches({a:4}),"4 !≥ null");
+		assert(e.matches({b:null}),"non-existent field ≥ null");
 	},
 	"should match null in dotted paths with GTE": function() {
-		var e = new ComparisonMatchExpression('GTE');
-		assert.strictEqual(e.init('a.b',null).code,'OK');
-		assert.ok(e.matches({}),'{} ≥ null');
-		assert.ok(e.matches({'a':null}),'{a:null} ≥ {a.b:null}');
-		assert.ok(e.matches({'a':4}),'{a:4} ≥ {a.b:null}');
-		assert.ok(e.matches({'a':{}}),'{a:{}} ≥ {a.b:null}');
-		assert.ok(e.matches({'a':[{'b':null}]}),'{a:[{b:null}]} ≥ {a.b:null}');
-		assert.ok(e.matches({'a':[{'a':4},{'b':4}]}),'{a:[{a:4},{b:4}]} ≥ {a.b:null}');
-		assert.ok(!e.matches({'a':[4]}),'{a:[4]} !≥ {a.b:null}');
-		assert.ok(!e.matches({'a':[{'b':4}]}),'{a:[{b:4}]} !≥ {a.b:null}');
+		var e = new ComparisonMatchExpression("GTE");
+		assert.strictEqual(e.init("a.b",null).code, ErrorCodes.OK);
+		assert.ok(e.matches({}),"{} ≥ null");
+		assert.ok(e.matches({a:null}),"{a:null} ≥ {a.b:null}");
+		assert.ok(e.matches({a:4}),"{a:4} ≥ {a.b:null}");
+		assert.ok(e.matches({a:{}}),"{a:{}} ≥ {a.b:null}");
+		assert.ok(e.matches({a:[{b:null}]}),"{a:[{b:null}]} ≥ {a.b:null}");
+		assert.ok(e.matches({a:[{a:4},{b:4}]}),"{a:[{a:4},{b:4}]} ≥ {a.b:null}");
+		assert.ok(!e.matches({a:[4]}),"{a:[4]} !≥ {a.b:null}");
+		assert.ok(!e.matches({a:[{b:4}]}),"{a:[{b:4}]} !≥ {a.b:null}");
 	},
 	"should match MinKeys": function() {
-		var e = new ComparisonMatchExpression('GTE');
-		assert.strictEqual(e.init('a',new MinKey()).code,'OK');
-		assert.ok(e.matches({'a':new MinKey()}),'minKey ≥ minKey');
-		assert.ok(e.matches({'a':new MaxKey()}),'maxKey ≥ minKey');
-		assert.ok(e.matches({'a':4}),'4 ≥ minKey');
+		var e = new ComparisonMatchExpression("GTE");
+		assert.strictEqual(e.init("a",new MinKey()).code, ErrorCodes.OK);
+		assert.ok(e.matches({a:new MinKey()}),"minKey ≥ minKey");
+		assert.ok(e.matches({a:new MaxKey()}),"maxKey ≥ minKey");
+		assert.ok(e.matches({a:4}),"4 ≥ minKey");
 	},
 	"should match MaxKeys": function() {
-		var e = new ComparisonMatchExpression('GTE');
-		assert.strictEqual(e.init('a',new MaxKey()).code,'OK');
-		assert.ok(e.matches({'a':new MaxKey()}),'maxKey ≥ maxKey');
-		assert.ok(!e.matches({'a':new MinKey()}),'minKey !≥ maxKey');
-		assert.ok(!e.matches({'a':4},null),'4 !≥ maxKey');
+		var e = new ComparisonMatchExpression("GTE");
+		assert.strictEqual(e.init("a",new MaxKey()).code, ErrorCodes.OK);
+		assert.ok(e.matches({a:new MaxKey()}),"maxKey ≥ maxKey");
+		assert.ok(!e.matches({a:new MinKey()}),"minKey !≥ maxKey");
+		assert.ok(!e.matches({a:4},null),"4 !≥ maxKey");
 	},
 	"should properly set match keys": function() {
-		var e = new ComparisonMatchExpression('GTE'),
+		var e = new ComparisonMatchExpression("GTE"),
 			d = new MatchDetails();
 		d.requestElemMatchKey();
-		assert.strictEqual(e.init('a',5).code,'OK');
-		assert.ok(!e.matchesJSON({'a':4},d),'4 !≥ 5');
+		assert.strictEqual(e.init("a",5).code, ErrorCodes.OK);
+		assert.ok(!e.matchesJSON({a:4},d),"4 !≥ 5");
 		assert(!d.hasElemMatchKey());
-		assert.ok(e.matchesJSON({'a':6},d),'6 ≥ 5');
+		assert.ok(e.matchesJSON({a:6},d),"6 ≥ 5");
 		assert(!d.hasElemMatchKey());
-		assert.ok(e.matchesJSON({'a':[2,6,5]},d),'[2,6,5] ≥ 5');
+		assert.ok(e.matchesJSON({a:[2,6,5]},d),"[2,6,5] ≥ 5");
 		assert(d.hasElemMatchKey());
-		assert.strictEqual('1',d.elemMatchKey());
+		assert.strictEqual("1",d.elemMatchKey());
 	}
 };

+ 19 - 21
test/lib/pipeline/matcher/ElemMatchObjectMatchExpression_test.js

@@ -1,11 +1,12 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
+	ErrorCodes = require("../../../../lib/Errors").ErrorCodes,
 	EqualityMatchExpression = require("../../../../lib/pipeline/matcher/EqualityMatchExpression.js"),
 	ElemMatchObjectMatchExpression = require("../../../../lib/pipeline/matcher/ElemMatchObjectMatchExpression.js"),
 	AndMatchExpression = require("../../../../lib/pipeline/matcher/AndMatchExpression.js"),
 	MatchDetails = require("../../../../lib/pipeline/matcher/MatchDetails.js");
 
-
 module.exports = {
 	"ElemMatchObjectMatchExpression": {
 		"Should match a single element": function(){
@@ -15,22 +16,22 @@ module.exports = {
 				eq = new EqualityMatchExpression(),
 				op = new ElemMatchObjectMatchExpression();
 
-			assert.strictEqual(eq.init("b", baseOperand.b).code, 'OK');
+			assert.strictEqual(eq.init("b", baseOperand.b).code, ErrorCodes.OK);
 
-			assert.strictEqual(op.init("a", eq).code, 'OK');
+			assert.strictEqual(op.init("a", eq).code, ErrorCodes.OK);
 			assert.ok(op.matchesSingleElement(match.a));
 			assert.ok(!op.matchesSingleElement(notMatch.a));
 		},
 
 		"Should match an array of elements inside the array": function() {
 			var baseOperand= {"1":5},
-				match= {"a":[['s',5.0]]},
+				match= {"a":[["s",5.0]]},
 				notMatch= {"a":[[5,6]]},
 				eq = new EqualityMatchExpression(),
 				op = new ElemMatchObjectMatchExpression();
 
-			assert.strictEqual(eq.init("1", baseOperand["1"]).code, 'OK');
-			assert.strictEqual(op.init("a", eq).code, 'OK');
+			assert.strictEqual(eq.init("1", baseOperand["1"]).code, ErrorCodes.OK);
+			assert.strictEqual(op.init("a", eq).code, ErrorCodes.OK);
 			assert.ok(op.matchesSingleElement(match.a));
 			assert.ok(!op.matchesSingleElement(notMatch.a));
 		},
@@ -49,15 +50,15 @@ module.exports = {
 				eq3 = new EqualityMatchExpression(),
 				op = new ElemMatchObjectMatchExpression();
 
-			assert.strictEqual(eq1.init("b", baseOperand1.b).code, 'OK');
-			assert.strictEqual(eq2.init("b", baseOperand2.b).code, 'OK');
-			assert.strictEqual(eq3.init("c", baseOperand3.c).code, 'OK');
+			assert.strictEqual(eq1.init("b", baseOperand1.b).code, ErrorCodes.OK);
+			assert.strictEqual(eq2.init("b", baseOperand2.b).code, ErrorCodes.OK);
+			assert.strictEqual(eq3.init("c", baseOperand3.c).code, ErrorCodes.OK);
 
 			andOp.add(eq1);
 			andOp.add(eq2);
 			andOp.add(eq3);
 
-			assert.strictEqual(op.init("a", andOp).code, 'OK');
+			assert.strictEqual(op.init("a", andOp).code, ErrorCodes.OK);
 			assert.ok(!op.matchesSingleElement(notMatch1.a));
 			assert.ok(!op.matchesSingleElement(notMatch2.a));
 			assert.ok(!op.matchesSingleElement(notMatch3.a));
@@ -69,8 +70,8 @@ module.exports = {
 				eq = new EqualityMatchExpression(),
 				op = new ElemMatchObjectMatchExpression();
 
-			assert.strictEqual(eq.init("b", baseOperand.b).code, 'OK');
-			assert.strictEqual(op.init("a", eq).code, 'OK');
+			assert.strictEqual(eq.init("b", baseOperand.b).code, ErrorCodes.OK);
+			assert.strictEqual(op.init("a", eq).code, ErrorCodes.OK);
 			// Directly nested objects are not matched with $elemMatch.  An intervening array is
 			// required.
 			assert.ok(!op.matches({"a":{"b":5}},null));
@@ -83,8 +84,8 @@ module.exports = {
 				eq = new EqualityMatchExpression(),
 				op = new ElemMatchObjectMatchExpression();
 
-			assert.strictEqual(eq.init("b", baseOperand.b).code, 'OK');
-			assert.strictEqual(op.init("a", eq).code, 'OK');
+			assert.strictEqual(eq.init("b", baseOperand.b).code, ErrorCodes.OK);
+			assert.strictEqual(op.init("a", eq).code, ErrorCodes.OK);
 			assert.ok(op.matches({"a":[{"b":5}]}, null));
 			assert.ok(op.matches({"a":[4,{"b":5}]}, null));
 			assert.ok(op.matches({"a":[{},{"b":5}]}, null));
@@ -96,8 +97,8 @@ module.exports = {
 				eq = new EqualityMatchExpression(),
 				op = new ElemMatchObjectMatchExpression();
 
-			assert.strictEqual(eq.init("c", baseOperand.c).code, 'OK');
-			assert.strictEqual(op.init("a.b", eq).code, 'OK');
+			assert.strictEqual(eq.init("c", baseOperand.c).code, ErrorCodes.OK);
+			assert.strictEqual(op.init("a.b", eq).code, ErrorCodes.OK);
 			assert.ok(op.matches({"a":[{"b":[{"c":5}]}]},null));
 			assert.ok(op.matches({"a":[{"b":[{"c":1}]}, {"b":[{"c":5}]}]},null));
 		},
@@ -108,8 +109,8 @@ module.exports = {
 				op = new ElemMatchObjectMatchExpression(),
 				details = new MatchDetails();
 
-			assert.strictEqual(eq.init("c", baseOperand.c).code, 'OK');
-			assert.strictEqual(op.init("a.b", eq).code, 'OK');
+			assert.strictEqual(eq.init("c", baseOperand.c).code, ErrorCodes.OK);
+			assert.strictEqual(op.init("a.b", eq).code, ErrorCodes.OK);
 			details.requestElemMatchKey();
 			assert.ok(!op.matches({}, details));
 			assert.ok(!details.hasElemMatchKey());
@@ -126,6 +127,3 @@ module.exports = {
 		},
 	}
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);
-

+ 15 - 16
test/lib/pipeline/matcher/ElemMatchValueMatchExpression_test.js

@@ -1,5 +1,7 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
+	ErrorCodes = require("../../../../lib/Errors").ErrorCodes,
 	ElemMatchObjectMatchExpression = require("../../../../lib/pipeline/matcher/ElemMatchObjectMatchExpression.js"),
 	ElemMatchValueMatchExpression = require("../../../../lib/pipeline/matcher/ElemMatchValueMatchExpression.js"),
 	MatchDetails = require("../../../../lib/pipeline/matcher/MatchDetails.js"),
@@ -16,8 +18,8 @@ module.exports = {
 				gt = new GTMatchExpression(),
 				op = new ElemMatchValueMatchExpression();
 
-			assert.strictEqual(gt.init("", baseOperand.$gt).code, 'OK');
-			assert.strictEqual(op.init("a", gt).code, 'OK');
+			assert.strictEqual(gt.init("", baseOperand.$gt).code, ErrorCodes.OK);
+			assert.strictEqual(op.init("a", gt).code, ErrorCodes.OK);
 			assert.ok(op.matchesSingleElement(match.a));
 			assert.ok(!op.matchesSingleElement(notMatch.a));
 		},
@@ -32,10 +34,10 @@ module.exports = {
 				lt = new LTMatchExpression(),
 				op = new ElemMatchValueMatchExpression();
 
-			assert.strictEqual(gt.init("", baseOperand1.$gt).code, 'OK');
-			assert.strictEqual(lt.init("", baseOperand2.$lt).code, 'OK');
+			assert.strictEqual(gt.init("", baseOperand1.$gt).code, ErrorCodes.OK);
+			assert.strictEqual(lt.init("", baseOperand2.$lt).code, ErrorCodes.OK);
 
-			assert.strictEqual(op.init("a").code, 'OK');
+			assert.strictEqual(op.init("a").code, ErrorCodes.OK);
 			op.add(gt);
 			op.add(lt);
 
@@ -49,8 +51,8 @@ module.exports = {
 				gt = new GTMatchExpression(),
 				op = new ElemMatchObjectMatchExpression();
 
-			assert.strictEqual(gt.init("", baseOperand.$gt).code, 'OK');
-			assert.strictEqual(op.init("a", gt).code, 'OK');
+			assert.strictEqual(gt.init("", baseOperand.$gt).code, ErrorCodes.OK);
+			assert.strictEqual(op.init("a", gt).code, ErrorCodes.OK);
 			// Directly nested objects are not matched with $elemMatch.  An intervening array is
 			// required.
 			assert.ok(!op.matches({"a":6},null));
@@ -62,8 +64,8 @@ module.exports = {
 				gt = new GTMatchExpression(),
 				op = new ElemMatchValueMatchExpression();
 
-			assert.strictEqual(gt.init("", baseOperand.$gt).code, 'OK');
-			assert.strictEqual(op.init("a", gt).code, 'OK');
+			assert.strictEqual(gt.init("", baseOperand.$gt).code, ErrorCodes.OK);
+			assert.strictEqual(op.init("a", gt).code, ErrorCodes.OK);
 			assert.ok(op.matches({"a":[6]},null));
 			assert.ok(op.matches({"a":[4,6]},null));
 			assert.ok(op.matches({"a":[{},7]},null));
@@ -74,8 +76,8 @@ module.exports = {
 				gt = new GTMatchExpression(),
 				op = new ElemMatchValueMatchExpression();
 
-			assert.strictEqual(gt.init("", baseOperand.$gt).code, 'OK');
-			assert.strictEqual(op.init("a.b", gt).code, 'OK');
+			assert.strictEqual(gt.init("", baseOperand.$gt).code, ErrorCodes.OK);
+			assert.strictEqual(op.init("a.b", gt).code, ErrorCodes.OK);
 			assert.ok(op.matches({"a":[{"b":[6]}]}, null));
 			assert.ok(op.matches({"a":[{"b":[4]}, {"b":[4,6]}]}, null));
 		},
@@ -86,8 +88,8 @@ module.exports = {
 				op = new ElemMatchValueMatchExpression(),
 				details = new MatchDetails();
 
-			assert.strictEqual(gt.init("", baseOperand.$gt).code, 'OK');
-			assert.strictEqual(op.init("a.b", gt).code, 'OK');
+			assert.strictEqual(gt.init("", baseOperand.$gt).code, ErrorCodes.OK);
+			assert.strictEqual(op.init("a.b", gt).code, ErrorCodes.OK);
 			details.requestElemMatchKey();
 			assert.ok(!op.matches({}, details));
 			assert.ok(!details.hasElemMatchKey());
@@ -104,6 +106,3 @@ module.exports = {
 		}
 	}
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);
-

+ 13 - 13
test/lib/pipeline/matcher/ElementPath_test.js

@@ -1,16 +1,18 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
+	ErrorCodes = require("../../../../lib/Errors").ErrorCodes,
 	ElementPath = require("../../../../lib/pipeline/matcher/ElementPath.js");
 
 module.exports = {
 	"ElementPath": {
-		
+
 		"Should find the item at the path": function() {
 			var p = new ElementPath(),
 				doc = {"x":4, "a":5},
 				matchItems = [5];
 
-			assert.ok(p.init("a").code, 'OK');
+			assert.ok(p.init("a").code, ErrorCodes.OK);
 
 			var checker = function(element) {
 				assert.deepEqual(element, matchItems.shift());
@@ -23,7 +25,7 @@ module.exports = {
 				doc = {"x":4, "a":[5, 6]},
 				matchItems = [5,6, [5, 6]];
 
-			assert.ok(p.init("a").code, 'OK');
+			assert.ok(p.init("a").code, ErrorCodes.OK);
 
 			var checker = function(element) {
 				assert.deepEqual(element, matchItems.shift());
@@ -37,7 +39,7 @@ module.exports = {
 				doc = {"x":4, "a":[5, 6]},
 				matchItems = [[5, 6]];
 
-			assert.ok(p.init("a").code, 'OK');
+			assert.ok(p.init("a").code, ErrorCodes.OK);
 			p.setTraverseLeafArray(false);
 
 			var checker = function(element) {
@@ -51,7 +53,7 @@ module.exports = {
 				doc = {"a":[ {"b":5}, 3, {}, {"b":[9, 11]}, {"b":7}]},
 				matchItems = [5, undefined, 9, 11, [9, 11], 7];
 
-			assert.ok( p.init( "a.b" ).code, 'OK' );
+			assert.ok( p.init( "a.b" ).code, ErrorCodes.OK);
 
 			var checker = function(element) {
 				assert.deepEqual(element, matchItems.shift());
@@ -64,7 +66,7 @@ module.exports = {
 				doc = {"a":[ {"b":5}, 3, {}, {"b":[9, 11]}, {"b":7}]},
 				matchItems = [5, undefined, [9, 11], 7];
 
-			assert.ok( p.init( "a.b" ).code, 'OK' );
+			assert.ok( p.init( "a.b" ).code, ErrorCodes.OK);
 			p.setTraverseLeafArray( false );
 
 			var checker = function(element) {
@@ -78,7 +80,7 @@ module.exports = {
 				doc = {"a":[5, 7, 3]},
 				matchItems = [7];
 
-			assert.ok( p.init( "a.1" ).code, 'OK' );
+			assert.ok( p.init( "a.1" ).code, ErrorCodes.OK);
 
 			var checker = function(element) {
 				assert.deepEqual(element, matchItems.shift());
@@ -91,7 +93,7 @@ module.exports = {
 				doc = {"a":[5, [2, 4], 3]},
 				matchItems = [[2,4]];
 
-			assert.ok( p.init( "a.1" ).code, 'OK' );
+			assert.ok( p.init( "a.1" ).code, ErrorCodes.OK);
 
 			var checker = function(element) {
 				assert.deepEqual(element, matchItems.shift());
@@ -104,7 +106,7 @@ module.exports = {
 				doc = {"a":[5, {"1":4}, 3]},
 				matchItems = [4, {"1":4}];
 
-			assert.ok( p.init( "a.1" ).code, 'OK' );
+			assert.ok( p.init( "a.1" ).code, ErrorCodes.OK);
 
 			var checker = function(element) {
 				assert.deepEqual(element, matchItems.shift());
@@ -117,7 +119,7 @@ module.exports = {
 				doc = {"a":[5, {"b":4}, 3]},
 				matchItems = [undefined, 4];
 
-			assert.ok( p.init( "a.1.b" ).code, 'OK' );
+			assert.ok( p.init( "a.1.b" ).code, ErrorCodes.OK);
 
 			var checker = function(element) {
 				assert.deepEqual(element, matchItems.shift());
@@ -130,7 +132,7 @@ module.exports = {
 				doc = {"a":[5, [{"b":4}], 3]},
 				matchItems = [4];
 
-			assert.ok( p.init( "a.1.b" ).code, 'OK' );
+			assert.ok( p.init( "a.1.b" ).code, ErrorCodes.OK);
 
 			var checker = function(element) {
 				assert.deepEqual(element, matchItems.shift());
@@ -139,5 +141,3 @@ module.exports = {
 		}
 	}
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);

+ 63 - 63
test/lib/pipeline/matcher/EqualityMatchExpression_test.js

@@ -1,6 +1,8 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
-	MatchDetails = require('../../../../lib/pipeline/matcher/MatchDetails'),
+	ErrorCodes = require("../../../../lib/Errors").ErrorCodes,
+	MatchDetails = require("../../../../lib/pipeline/matcher/MatchDetails"),
 	EqualityMatchExpression = require("../../../../lib/pipeline/matcher/EqualityMatchExpression"),
 	// TODO: replace the following with a real BSONTypes at some point
 	MinKey = new (function MinKey(){/*matcher does weird stuff with empty objects*/this.foo = 'bar';})(), // jshint ignore:line
@@ -27,128 +29,128 @@ module.exports = {
 
 		"should handle invalid End of Object Operand": function testInvalidEooOperand(){
 			var e = new EqualityMatchExpression();
-			var s = e.init('',{});
+			var s = e.init("",{});
 
-			assert.ok(s.code !== 'OK');
+			assert.ok(s.code !== ErrorCodes.OK);
 		},
 		"should match a pathed number":function() {
 			var e = new EqualityMatchExpression();
-			var s = e.init('a',5);
+			var s = e.init("a",5);
 
-			assert.strictEqual(s.code, 'OK');
-			assert.ok( e.matches({'a':5}) );
-			assert.ok( ! e.matches({'a':4}) );
+			assert.strictEqual(s.code, ErrorCodes.OK);
+			assert.ok( e.matches({"a":5}) );
+			assert.ok( ! e.matches({"a":4}) );
 		},
 		"should match stuff in an array": function() {
 			var e = new EqualityMatchExpression();
-			var s = e.init('a',5);
+			var s = e.init("a",5);
 
-			assert.strictEqual(s.code, 'OK');
-			assert.ok( e.matches({'a':[5,6]}) );
-			assert.ok( ! e.matches({'a':[6,7]}) );
+			assert.strictEqual(s.code, ErrorCodes.OK);
+			assert.ok( e.matches({"a":[5,6]}) );
+			assert.ok( ! e.matches({"a":[6,7]}) );
 		},
 		"should match on a longer path": function() {
 			var e = new EqualityMatchExpression();
-			var s = e.init('a.b',5);
+			var s = e.init("a.b",5);
 
-			assert.strictEqual(s.code, 'OK');
-			assert.ok( e.matches({'a':{'b':5}}) );
-			assert.ok( e.matches({'a':{'b':[5]}}) );
-			assert.ok( e.matches({'a':[{'b':5}]}) );
+			assert.strictEqual(s.code, ErrorCodes.OK);
+			assert.ok( e.matches({"a":{"b":5}}) );
+			assert.ok( e.matches({"a":{"b":[5]}}) );
+			assert.ok( e.matches({"a":[{"b":5}]}) );
 		},
 		"should match in an array": function() {
 			var e = new EqualityMatchExpression();
-			var s = e.init('a.0',5);
+			var s = e.init("a.0",5);
 
-			assert.strictEqual(s.code, 'OK');
-			assert.ok( e.matches({'a':[5]}) );
-			assert.ok( ! e.matches({'a':[[5]]}) );
+			assert.strictEqual(s.code, ErrorCodes.OK);
+			assert.ok( e.matches({"a":[5]}) );
+			assert.ok( ! e.matches({"a":[[5]]}) );
 		},
 		"should match null" : function() {
 			var e = new EqualityMatchExpression();
-			var s = e.init('a',null);
+			var s = e.init("a",null);
 
-			assert.strictEqual(s.code, 'OK');
+			assert.strictEqual(s.code, ErrorCodes.OK);
 			assert.ok( e.matches({}) );
-			assert.ok( e.matches({'a':null}) );
-			assert.ok( ! e.matches({'a':4}) );
-			assert.ok( e.matches({'b':4}) );
+			assert.ok( e.matches({"a":null}) );
+			assert.ok( ! e.matches({"a":4}) );
+			assert.ok( e.matches({"b":4}) );
 		},
     //// This test documents how the matcher currently works,
     //// not necessarily how it should work ideally.
 		"should match nested nulls" : function(){
 			var e = new EqualityMatchExpression();
-			var s = e.init('a.b',null);
+			var s = e.init("a.b",null);
 
-			assert.strictEqual(s.code, 'OK');
+			assert.strictEqual(s.code, ErrorCodes.OK);
 			// // null matches any empty object that is on a subpath of a.b
 			assert.ok( e.matches({}) );
-			assert.ok( e.matches({'a':{}}) );
-			assert.ok( e.matches({'a':[{}]}) );
+			assert.ok( e.matches({"a":{}}) );
+			assert.ok( e.matches({"a":[{}]}) );
 
-			assert.ok( e.matches({'a':{'b':null}} ) );
+			assert.ok( e.matches({"a":{"b":null}} ) );
 			// b does not exist as an element in array under a.
-			assert.ok( !e.matches({'a':[]}) );
-			assert.ok( !e.matches({'a':[null]}) );
-			assert.ok( !e.matches({'a':[1,2]}) );
+			assert.ok( !e.matches({"a":[]}) );
+			assert.ok( !e.matches({"a":[null]}) );
+			assert.ok( !e.matches({"a":[1,2]}) );
 			// a.b exists but is not null.
-			assert.ok( !e.matches({'a':{'b':4}} ) );
-			assert.ok( !e.matches({'a':{'b':{}}} ) );
+			assert.ok( !e.matches({"a":{"b":4}} ) );
+			assert.ok( !e.matches({"a":{"b":{}}} ) );
 			// A non-existent field is treated same way as an empty bson object
-			assert.ok( e.matches({'b':4} ) );
+			assert.ok( e.matches({"b":4} ) );
 
 			assert.ok( e.matches({"b":"stuff"}) );
 		},
 		"should match MinKey" : function(){
 			var e = new EqualityMatchExpression();
-			var s = e.init('a',MinKey);
-			assert.ok( e.matches({'a': MinKey}) );
-			assert.ok( !e.matches({'a':MaxKey}) );
-			assert.ok( !e.matches({'a':4}) );
+			e.init("a",MinKey);
+			assert.ok( e.matches({"a": MinKey}) );
+			assert.ok( !e.matches({"a":MaxKey}) );
+			assert.ok( !e.matches({"a":4}) );
 		},
 		"should match MaxKey" : function(){
 			var e = new EqualityMatchExpression();
-			var s = e.init('a',MaxKey);
-			assert.ok( e.matches({'a':MaxKey}) );
-			assert.ok( !e.matches({'a': MinKey}) );
-			assert.ok( !e.matches({'a':4}) );
+			e.init("a",MaxKey);
+			assert.ok( e.matches({"a":MaxKey}) );
+			assert.ok( !e.matches({"a": MinKey}) );
+			assert.ok( !e.matches({"a":4}) );
 		},
 
 		"should match full array" : function() {
 			var e = new EqualityMatchExpression();
-			var s = e.init('a',[1,2]);
+			var s = e.init("a",[1,2]);
 
-			assert.strictEqual(s.code, 'OK');
-			assert.ok( e.matches({'a':[1,2]}) );
-			assert.ok( ! e.matches({'a':[1,2,3]}) );
-			assert.ok( ! e.matches({'a':[1]}) );
-			assert.ok( ! e.matches({'a':1}) );
+			assert.strictEqual(s.code, ErrorCodes.OK);
+			assert.ok( e.matches({"a":[1,2]}) );
+			assert.ok( ! e.matches({"a":[1,2,3]}) );
+			assert.ok( ! e.matches({"a":[1]}) );
+			assert.ok( ! e.matches({"a":1}) );
 		},
 		"should match a nested array": function() {
 			var e = new EqualityMatchExpression();
-			var s = e.init('a.b.c.d',3);
+			var s = e.init("a.b.c.d",3);
 
-			assert.strictEqual(s.code, 'OK');
+			assert.strictEqual(s.code, ErrorCodes.OK);
 			assert.ok( e.matches({a:{b:[{c:[{d:1},{d:2}]},{c:[{d:3}]}]}}) );
 		},
 		"should handle elemMatchKey":function() {
 			var e = new EqualityMatchExpression();
-			var s = e.init('a', 5);
+			var s = e.init("a", 5);
 			var m = new MatchDetails();
 
 			m.requestElemMatchKey();
 
-			assert.strictEqual( s.code, 'OK' );
+			assert.strictEqual(s.code, ErrorCodes.OK);
 
-			assert.ok( ! e.matches({'a':4}, m) );
+			assert.ok( ! e.matches({"a":4}, m) );
 			assert.ok( ! m.hasElemMatchKey() );
 
-			assert.ok( e.matches({'a':5}, m) );
+			assert.ok( e.matches({"a":5}, m) );
 			assert.ok( ! m.hasElemMatchKey() );
 
-			assert.ok( e.matches({'a':[1,2,5]}, m));
+			assert.ok( e.matches({"a":[1,2,5]}, m));
 			assert.ok( m.hasElemMatchKey());
-			assert.strictEqual('2', m.elemMatchKey());
+			assert.strictEqual("2", m.elemMatchKey());
 		},
 		"should handle equivalence":function() {
 			var a = new EqualityMatchExpression();
@@ -156,9 +158,9 @@ module.exports = {
 			var c = new EqualityMatchExpression();
 
 
-			assert.strictEqual( a.init('a',5).code, 'OK' );
-			assert.strictEqual( b.init('a',5).code, 'OK' );
-			assert.strictEqual( c.init('c',4).code, 'OK' );
+			assert.strictEqual(a.init("a",5).code, ErrorCodes.OK);
+			assert.strictEqual(b.init("a",5).code, ErrorCodes.OK);
+			assert.strictEqual(c.init("c",4).code, ErrorCodes.OK);
 
 			assert.ok( a.equivalent(a) );
 			assert.ok( a.equivalent(b) );
@@ -168,5 +170,3 @@ module.exports = {
 	}
 
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);

+ 28 - 29
test/lib/pipeline/matcher/ExistsMatchExpression_test.js

@@ -1,5 +1,7 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
+	ErrorCodes = require("../../../../lib/Errors").ErrorCodes,
 	ExistsMatchExpression = require("../../../../lib/pipeline/matcher/ExistsMatchExpression"),
 	MatchDetails = require("../../../../lib/pipeline/matcher/MatchDetails");
 
@@ -8,68 +10,65 @@ module.exports = {
 	"ExistsMatchExpression": {
 		"should match an element": function (){
 			var e = new ExistsMatchExpression();
-			var s = e.init('a');
+			var s = e.init("a");
 
-			assert.strictEqual(s.code, 'OK');
-			assert.ok( e.matches({'a':5}) );
-			assert.ok( e.matches({'a':null}) );
-			assert.ok( ! e.matches({'a':{}}) );
+			assert.strictEqual(s.code, ErrorCodes.OK);
+			assert.ok( e.matches({"a":5}) );
+			assert.ok( e.matches({"a":null}) );
+			assert.ok( ! e.matches({"a":{}}) );
 		},
 		"should match a boolean":function() {
 			var e = new ExistsMatchExpression();
-			var s = e.init('a');
+			var s = e.init("a");
 
-			assert.strictEqual( s.code, 'OK' );
-			assert.ok( e.matches({'a':5}) );
+			assert.strictEqual( s.code, ErrorCodes.OK);
+			assert.ok( e.matches({"a":5}) );
 			assert.ok( ! e.matches({}) );
 
 		},
 		"should match a number":function() {
 			var e = new ExistsMatchExpression();
-			var s = e.init('a');
+			var s = e.init("a");
 
-			assert.strictEqual( s.code, 'OK' );
-			assert.ok( e.matches({'a':1}) );
-			assert.ok( e.matches({'a':null}) );
-			assert.ok( ! e.matches({'b':1}) );
+			assert.strictEqual( s.code, ErrorCodes.OK);
+			assert.ok( e.matches({"a":1}) );
+			assert.ok( e.matches({"a":null}) );
+			assert.ok( ! e.matches({"b":1}) );
 		},
 		"should match an array":function() {
 			var e = new ExistsMatchExpression();
-			var s = e.init('a');
+			var s = e.init("a");
 
-			assert.strictEqual( s.code, 'OK' );
-			assert.ok( e.matches({'a':[4,5.5]}) );
+			assert.strictEqual( s.code, ErrorCodes.OK);
+			assert.ok( e.matches({"a":[4,5.5]}) );
 		},
 		"should yield an elemMatchKey":function() {
 			var e = new ExistsMatchExpression();
-			var s = e.init('a.b');
+			var s = e.init("a.b");
 			var m = new MatchDetails();
 			m.requestElemMatchKey();
-			assert.strictEqual( s.code, 'OK' );
+			assert.strictEqual( s.code, ErrorCodes.OK);
 
-			assert.ok( ! e.matches({'a':1}, m) );
+			assert.ok( ! e.matches({"a":1}, m) );
 			assert.ok( ! m.hasElemMatchKey() );
 
-			assert.ok( e.matches({'a':{'b':6}}));
+			assert.ok( e.matches({"a":{"b":6}}));
 			assert.ok( ! m.hasElemMatchKey() );
 
-			assert.ok( e.matches({'a':[2, {'b':7}]}, m) );
+			assert.ok( e.matches({"a":[2, {"b":7}]}, m) );
 			assert.ok( m.hasElemMatchKey() );
-			assert.strictEqual('1', m.elemMatchKey() );
+			assert.strictEqual("1", m.elemMatchKey() );
 		},
 		"should handle equivalence":function() {
 			var e = new ExistsMatchExpression();
-			var s = e.init('a');
+			var s = e.init("a");
 			var b = new ExistsMatchExpression();
-			assert.strictEqual( s.code, 'OK' );
-			s = b.init('b');
-			assert.strictEqual(s.code, 'OK' );
+			assert.strictEqual( s.code, ErrorCodes.OK);
+			s = b.init("b");
+			assert.strictEqual(s.code, ErrorCodes.OK);
 			assert.ok( e.equivalent(e) );
 			assert.ok( ! e.equivalent(b) );
 		}
 
 	}
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);
-

+ 54 - 54
test/lib/pipeline/matcher/InMatchExpression_test.js

@@ -1,18 +1,20 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
-	MatchDetails = require('../../../../lib/pipeline/matcher/MatchDetails'),
+	ErrorCodes = require("../../../../lib/Errors").ErrorCodes,
+	MatchDetails = require("../../../../lib/pipeline/matcher/MatchDetails"),
 	InMatchExpression = require("../../../../lib/pipeline/matcher/InMatchExpression"),
 	// TODO: replace the following with a real BSONTypes at some point
-	MinKey = new (function MinKey(){/*matcher does weird stuff with empty objects*/this.foo = 'bar';})(), // jshint ignore:line
-	MaxKey = new (function MaxKey(){/*matcher does weird stuff with empty objects*/this.foo = 'bar';})(); // jshint ignore:line
+	MinKey = new (function MinKey(){/*matcher does weird stuff with empty objects*/this.foo = "bar";})(), // jshint ignore:line
+	MaxKey = new (function MaxKey(){/*matcher does weird stuff with empty objects*/this.foo = "bar";})(); // jshint ignore:line
 
 
 module.exports = {
 	"InMatchExpression": {
 		"should match a single element": function (){
 			var e = new InMatchExpression();
-			var s = e.init('a');
-			assert.strictEqual( s.code,'OK' );
+			var s = e.init("a");
+			assert.strictEqual(s.code, ErrorCodes.OK);
 
 			e.getArrayFilterEntries().addEquality(1);
 
@@ -21,126 +23,124 @@ module.exports = {
 		},
 		"should not match with an empty array": function() {
 			var e = new InMatchExpression();
-			var s = e.init('a');
-			assert.strictEqual( s.code,'OK' );
+			var s = e.init("a");
+			assert.strictEqual(s.code, ErrorCodes.OK);
 
 			assert.ok( ! e.matchesSingleElement(2) );
-			assert.ok( ! e.matches({'a':null}) );
-			assert.ok( ! e.matches({'a':1}) );
+			assert.ok( ! e.matches({"a":null}) );
+			assert.ok( ! e.matches({"a":1}) );
 		},
 		"should match with multiple elements": function() {
 			var e = new InMatchExpression();
-			var s = e.init('a');
-			assert.strictEqual( s.code,'OK' );
+			var s = e.init("a");
+			assert.strictEqual(s.code, ErrorCodes.OK);
 
 			e.getArrayFilterEntries().addEquality(1);
-			e.getArrayFilterEntries().addEquality('r');
+			e.getArrayFilterEntries().addEquality("r");
 			e.getArrayFilterEntries().addEquality(true);
 			e.getArrayFilterEntries().addEquality(1);
 
 			assert.ok( e.matchesSingleElement( 1 ) );
-			assert.ok( e.matchesSingleElement( 'r' ) );
+			assert.ok( e.matchesSingleElement( "r" ) );
 			assert.ok( e.matchesSingleElement( true ) );
 			assert.ok( !e.matchesSingleElement( false ) );
 		},
 		"should match a scalar":function() {
 			var e = new InMatchExpression();
-			var s = e.init('a');
-			assert.strictEqual( s.code,'OK' );
+			var s = e.init("a");
+			assert.strictEqual(s.code, ErrorCodes.OK);
 
 			e.getArrayFilterEntries().addEquality(5);
 
-			assert.ok( e.matches({'a':5}) );
-			assert.ok( ! e.matches({'a':4}) );
+			assert.ok( e.matches({"a":5}) );
+			assert.ok( ! e.matches({"a":4}) );
 		},
 		"should match an array":function() {
 			var e = new InMatchExpression();
-			var s = e.init('a');
-			assert.strictEqual( s.code,'OK' );
+			var s = e.init("a");
+			assert.strictEqual(s.code, ErrorCodes.OK);
 
 			e.getArrayFilterEntries().addEquality(5);
 
-			assert.ok( e.matches({'a':[5,6]}) );
-			assert.ok( ! e.matches({'a':[6,7]}) );
-			assert.ok( ! e.matches({'a':[[5]]}) );
+			assert.ok( e.matches({"a":[5,6]}) );
+			assert.ok( ! e.matches({"a":[6,7]}) );
+			assert.ok( ! e.matches({"a":[[5]]}) );
 		},
 		"should match null": function() {
 			var e = new InMatchExpression();
-			var s = e.init('a');
-			assert.strictEqual( s.code,'OK' );
+			var s = e.init("a");
+			assert.strictEqual(s.code, ErrorCodes.OK);
 
 			e.getArrayFilterEntries().addEquality(null);
 
 			assert.ok( e.matches({}) );
-			assert.ok( e.matches({'a':null}) );
-			assert.ok( ! e.matches({'a':4}) );
+			assert.ok( e.matches({"a":null}) );
+			assert.ok( ! e.matches({"a":4}) );
 			// A non-existent field is treated same way as an empty bson object
-			assert.ok( e.matches({'b':4}) );
+			assert.ok( e.matches({"b":4}) );
 		},
 		"should match undefined": function() {
 			var e = new InMatchExpression();
-			var s = e.init('a');
-			assert.strictEqual( s.code,'OK' );
+			var s = e.init("a");
+			assert.strictEqual(s.code, ErrorCodes.OK);
 
-			assert( e.getArrayFilterEntries().addEquality(undefined) !== 'OK' );
+			assert( e.getArrayFilterEntries().addEquality(undefined) !==  ErrorCodes.OK);
 		},
 		"should match MinKey": function() {
 			var e = new InMatchExpression();
-			var s = e.init('a');
-			assert.strictEqual( s.code,'OK' );
+			var s = e.init("a");
+			assert.strictEqual(s.code, ErrorCodes.OK);
 
 			e._arrayEntries._equalities = [MinKey];
 
-			assert.ok( e.matches({'a':MinKey}) );
-			assert.ok( ! e.matches({'a':MaxKey}) );
-			assert.ok( ! e.matches({'a':4}) );
+			assert.ok( e.matches({"a":MinKey}) );
+			assert.ok( ! e.matches({"a":MaxKey}) );
+			assert.ok( ! e.matches({"a":4}) );
 		},
 		"should match MaxKey": function() {
 			var e = new InMatchExpression();
-			var s = e.init('a');
-			assert.strictEqual( s.code,'OK' );
+			var s = e.init("a");
+			assert.strictEqual(s.code, ErrorCodes.OK);
 
 			e._arrayEntries._equalities = [MaxKey];
 
-			assert.ok( ! e.matches({'a':MinKey}) );
-			assert.ok( e.matches({'a':MaxKey}) );
-			assert.ok( ! e.matches({'a':4}) );
+			assert.ok( ! e.matches({"a":MinKey}) );
+			assert.ok( e.matches({"a":MaxKey}) );
+			assert.ok( ! e.matches({"a":4}) );
 		},
 		"should match a full array":function() {
 			var e = new InMatchExpression();
-			var s = e.init('a');
-			assert.strictEqual( s.code,'OK' );
+			var s = e.init("a");
+			assert.strictEqual(s.code, ErrorCodes.OK);
 
 			e.getArrayFilterEntries().addEquality([1,2]);
 			e.getArrayFilterEntries().addEquality(4);
 			e.getArrayFilterEntries().addEquality(5);
 
-			assert.ok( e.matches({'a':[1,2]}) );
-			assert.ok( ! e.matches({'a':[1,2,3]}) );
-			assert.ok( ! e.matches({'a':[1]}) );
-			assert.ok( ! e.matches({'a':1}) );
+			assert.ok( e.matches({"a":[1,2]}) );
+			assert.ok( ! e.matches({"a":[1,2,3]}) );
+			assert.ok( ! e.matches({"a":[1]}) );
+			assert.ok( ! e.matches({"a":1}) );
 		},
 		"should match elemmatchKey": function() {
 			var e = new InMatchExpression();
-			var s = e.init('a');
+			var s = e.init("a");
 			var m = new MatchDetails();
 
-			assert.strictEqual( s.code,'OK' );
+			assert.strictEqual(s.code, ErrorCodes.OK);
 
 			e.getArrayFilterEntries().addEquality(5);
 			e.getArrayFilterEntries().addEquality(2);
 			m.requestElemMatchKey();
-			assert.ok( !e.matches({'a':4}, m) );
+			assert.ok( !e.matches({"a":4}, m) );
 			assert.ok( !m.hasElemMatchKey() );
-			assert.ok( e.matches({'a':5}, m) );
+			assert.ok( e.matches({"a":5}, m) );
 			assert.ok( !m.hasElemMatchKey() );
-			assert.ok( e.matches({'a':[1,2,5]}, m ));
+			assert.ok( e.matches({"a":[1,2,5]}, m ));
 			assert.ok( m.hasElemMatchKey() );
-			assert.strictEqual( m.elemMatchKey(), '1' );
+			assert.strictEqual( m.elemMatchKey(), "1" );
 
 		}
 
 	}
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);

+ 3 - 5
test/lib/pipeline/matcher/ListOfMatchExpression_test.js

@@ -1,4 +1,5 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	MatchExpression = require("../../../../lib/pipeline/matcher/MatchExpression"),
 	ListOfMatchExpression = require("../../../../lib/pipeline/matcher/ListOfMatchExpression");
@@ -8,7 +9,7 @@ module.exports = {
 	"ListOfMatchExpression": {
 
 		"Constructor": function (){
-			var e = new ListOfMatchExpression('AND');
+			var e = new ListOfMatchExpression("AND");
 			assert.equal(e._matchType, "AND");
 		},
 
@@ -59,7 +60,7 @@ module.exports = {
 		},
 
 		"Equivalent": function () {
-			var e = new ListOfMatchExpression('TEXT'),
+			var e = new ListOfMatchExpression("TEXT"),
 				f = new ListOfMatchExpression("TEXT");
 			assert.equal(e.equivalent(f), true);
 		}
@@ -67,6 +68,3 @@ module.exports = {
 	}
 
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);
-

+ 262 - 262
test/lib/pipeline/matcher/MatchExpressionParser_test.js

@@ -1,511 +1,513 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
+	ErrorCodes = require("../../../../lib/Errors").ErrorCodes,
 	MatchExpressionParser = require("../../../../lib/pipeline/matcher/MatchExpressionParser");
 
 
 module.exports = {
 	"MatchExpressionParser": {
 		"Should generate matchers that work with no operators": function (){
-			var goodQ = {'x':2},badQ = {'x':3};
+			var goodQ = {"x":2},badQ = {"x":3};
 			var parser =  new MatchExpressionParser();
 			var res = parser.parse(goodQ);
-			assert.strictEqual(res.code,'OK',res.description);
+			assert.strictEqual(res.code,ErrorCodes.OK,res.description);
 			assert.ok( res.result.matches(goodQ));
 			assert.ok( ! res.result.matches(badQ));
 		},
 		"Should parse {x:5,y:{$gt:5, :$lt:8}}": function() {
-			var q = {'x':5, 'y':{'$gt':5, '$lt':8}};
+			var q = {"x":5, "y":{"$gt":5, "$lt":8}};
 			var parser = new MatchExpressionParser();
 			var res = parser.parse( q );
-			assert.strictEqual(res.code,'OK',res.description);
-			assert.ok( res.result.matches({'x':5, 'y':7}) );
-			assert.ok( res.result.matches({'x':5, 'y':6}) );
-			assert.ok( ! res.result.matches({'x':6, 'y':7}) );
-			assert.ok( ! res.result.matches({'x':5, 'y':9}) );
-			assert.ok( ! res.result.matches({'x':5, 'y':4}) );
+			assert.strictEqual(res.code,ErrorCodes.OK,res.description);
+			assert.ok( res.result.matches({"x":5, "y":7}) );
+			assert.ok( res.result.matches({"x":5, "y":6}) );
+			assert.ok( ! res.result.matches({"x":6, "y":7}) );
+			assert.ok( ! res.result.matches({"x":5, "y":9}) );
+			assert.ok( ! res.result.matches({"x":5, "y":4}) );
 		},
 		"Should parse $isolated and $atomic appropriately": function() {
-			var q1 = {'x':5, '$atomic': {'$gt':5, '$lt':8}},
-				q2 = {'x':5, '$isolated':1},
-				q3 = {'x':5, 'y':{'$isolated':1}};
+			var q1 = {"x":5, "$atomic": {"$gt":5, "$lt":8}},
+				q2 = {"x":5, "$isolated":1},
+				q3 = {"x":5, "y":{"$isolated":1}};
 			var parser = new MatchExpressionParser();
-			var t = parser.parse(q1);
+			parser.parse(q1);
 
-			assert.strictEqual(parser.parse(q1).code, 'OK');
-			assert.strictEqual(parser.parse(q2).code, 'OK');
-			assert.strictEqual(parser.parse(q3).code, 'BAD_VALUE');
+			assert.strictEqual(parser.parse(q1).code, ErrorCodes.OK);
+			assert.strictEqual(parser.parse(q2).code, ErrorCodes.OK);
+			assert.strictEqual(parser.parse(q3).code, ErrorCodes.BAD_VALUE);
 		},
 		"Should parse and match $size with an int": function() {
 			var parser = new MatchExpressionParser();
-			var q = {'x':{'$size':2}};
+			var q = {"x":{"$size":2}};
 
 			var res = parser.parse(q);
-			assert.strictEqual(res.code,'OK',res.description);
-			assert.ok( ! res.result.matches({'x':1}) );
-			assert.ok( res.result.matches({'x':[1,2]}) );
-			assert.ok( ! res.result.matches({'x':[1]}) );
-			assert.ok( ! res.result.matches({'x':[1,2,3]}) );
+			assert.strictEqual(res.code,ErrorCodes.OK,res.description);
+			assert.ok( ! res.result.matches({"x":1}) );
+			assert.ok( res.result.matches({"x":[1,2]}) );
+			assert.ok( ! res.result.matches({"x":[1]}) );
+			assert.ok( ! res.result.matches({"x":[1,2,3]}) );
 		},
 		"Should parse and match $size with a string argument": function() {
 			var parser = new MatchExpressionParser();
-			var q = {'x':{'$size':'a'}};
+			var q = {"x":{"$size":"a"}};
 
 			var res = parser.parse( q );
-			assert.strictEqual(res.code,'OK',res.description);
-			assert.ok( ! res.result.matches({'x':1}) );
-			assert.ok( ! res.result.matches({'x':[1,2]}) );
-			assert.ok( res.result.matches({'x':[]}) );
-			assert.ok( ! res.result.matches({'x': [1]}) );
+			assert.strictEqual(res.code,ErrorCodes.OK,res.description);
+			assert.ok( ! res.result.matches({"x":1}) );
+			assert.ok( ! res.result.matches({"x":[1,2]}) );
+			assert.ok( res.result.matches({"x":[]}) );
+			assert.ok( ! res.result.matches({"x": [1]}) );
 		},
 		"Should parse and match $size with a float argument":function() {
 			var parser = new MatchExpressionParser();
-			var q = {'x': {'$size': 2.5}};
+			var q = {"x": {"$size": 2.5}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( ! res.result.matches({'x':1}) );
-			assert.ok( ! res.result.matches({'x':[1,2]}) );
-			assert.ok( ! res.result.matches({'x':[]}) );
-			assert.ok( ! res.result.matches({'x':[1,2,3]}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( ! res.result.matches({"x":1}) );
+			assert.ok( ! res.result.matches({"x":[1,2]}) );
+			assert.ok( ! res.result.matches({"x":[]}) );
+			assert.ok( ! res.result.matches({"x":[1,2,3]}) );
 		},
 		"Should not accept  null": function() {
 			var parser = new MatchExpressionParser();
-			var q = {'x':{'$size':null}};
+			var q = {"x":{"$size":null}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code, 'BAD_VALUE' );
+			assert.strictEqual( res.code, ErrorCodes.BAD_VALUE );
 		},
 		"Should parse $elemMatch : {x:1,y:2}": function() {
 			var parser = new MatchExpressionParser();
-			var q = {'x':{'$elemMatch': {'x':1,'y':2}}};
+			var q = {"x":{"$elemMatch": {"x":1,"y":2}}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( ! res.result.matches({'x':1}) );
-			assert.ok( ! res.result.matches({'x':[1,2]}) );
-			assert.ok( ! res.result.matches({'x':[{'x':1}]}) );
-			assert.ok( res.result.matches({'x': [{'x':1,'y':2}]}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( ! res.result.matches({"x":1}) );
+			assert.ok( ! res.result.matches({"x":[1,2]}) );
+			assert.ok( ! res.result.matches({"x":[{"x":1}]}) );
+			assert.ok( res.result.matches({"x": [{"x":1,"y":2}]}) );
 		},
 		"Should parse and match $elemMatch: {$gt:5}": function() {
 			var parser = new MatchExpressionParser();
-			var q = {'x': {'$elemMatch': {'$gt':5}}};
+			var q = {"x": {"$elemMatch": {"$gt":5}}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( ! res.result.matches({'x':1}) );
-			assert.ok( ! res.result.matches({'x':[4]}) );
-			assert.ok( res.result.matches({'x':[6]}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( ! res.result.matches({"x":1}) );
+			assert.ok( ! res.result.matches({"x":[4]}) );
+			assert.ok( res.result.matches({"x":[6]}) );
 		},
 		"Should parse and match $all:[1,2]" : function() {
 			var parser = new MatchExpressionParser();
-			var q = {'x':{'$all':[1,2]}};
+			var q = {"x":{"$all":[1,2]}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( ! res.result.matches({'x':1}) );
-			assert.ok( ! res.result.matches({'x':[1]}) );
-			assert.ok( ! res.result.matches({'x':[2]}) );
-			assert.ok( res.result.matches({'x':[1,2]}) );
-			assert.ok( res.result.matches({'x':[1,2,3]}) );
-			assert.ok( ! res.result.matches({'x':[2,3]}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( ! res.result.matches({"x":1}) );
+			assert.ok( ! res.result.matches({"x":[1]}) );
+			assert.ok( ! res.result.matches({"x":[2]}) );
+			assert.ok( res.result.matches({"x":[1,2]}) );
+			assert.ok( res.result.matches({"x":[1,2,3]}) );
+			assert.ok( ! res.result.matches({"x":[2,3]}) );
 		},
 		"Should not allow $all to have an element argument": function() {
 			var parser = new MatchExpressionParser();
-			var q = {'x': {'$all':1}};
+			var q = {"x": {"$all":1}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code, 'BAD_VALUE' );
+			assert.strictEqual( res.code, ErrorCodes.BAD_VALUE );
 		},
 		"Should not allow large regex patterns": function () {
 			var parser = new MatchExpressionParser();
-			var q = {'x':{'$all':[new RegExp((new Array(50*1000+1)).join('z'))] }};
+			var q = {"x":{"$all":[new RegExp((new Array(50*1000+1)).join("z"))] }};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code, 'BAD_VALUE' );
+			assert.strictEqual( res.code, ErrorCodes.BAD_VALUE );
 		},
 		"Should parse and match some simple regex patterns": function() {
 			var parser = new MatchExpressionParser();
 			var a = /^a/;
 			var b = /B/i;
-			var q = {'a': {'$all': [ a , b ]}};
+			var q = {"a": {"$all": [ a , b ]}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( ! res.result.matches({'a':'ax'}) );
-			assert.ok( ! res.result.matches({'a':'qqb'}) );
-			assert.ok( res.result.matches({'a':'ab'}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( ! res.result.matches({"a":"ax"}) );
+			assert.ok( ! res.result.matches({"a":"qqb"}) );
+			assert.ok( res.result.matches({"a":"ab"}) );
 		},
 		"Should parse and match some more simple regexes" : function(){
 			var parser = new MatchExpressionParser();
 			var a = /^a/;
 			var b = /abc/;
-			var q = {'a': {'$all': [a, b]}};
+			var q = {"a": {"$all": [a, b]}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( ! res.result.matches({'a':'ax'}) );
-			assert.ok( res.result.matches({'a':'abc'}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( ! res.result.matches({"a":"ax"}) );
+			assert.ok( res.result.matches({"a":"abc"}) );
 		},
 		"Should properly handle x:{$all:[5]}": function() {
 			var parser = new MatchExpressionParser();
-			var q = {'x':{'$all':[5]}};
+			var q = {"x":{"$all":[5]}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( res.result.matches({'x':5}) );
-			assert.ok( res.result.matches({'x':[5]}) );
-			assert.ok( ! res.result.matches({'x':4}) );
-			assert.ok( ! res.result.matches({'x':[4]}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( res.result.matches({"x":5}) );
+			assert.ok( res.result.matches({"x":[5]}) );
+			assert.ok( ! res.result.matches({"x":4}) );
+			assert.ok( ! res.result.matches({"x":[4]}) );
 		},
 		"Should handle a good $all $elemMatch query": function() {
 			var parser = new MatchExpressionParser();
-			var q = {'x':{'$all':[{'$elemMatch': {'x':1,'y':2}}]}};
+			var q = {"x":{"$all":[{"$elemMatch": {"x":1,"y":2}}]}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( ! res.result.matches({'x':1}) );
-			assert.ok( ! res.result.matches({'x':[1,2]}) );
-			assert.ok( ! res.result.matches({'x':[{'x':1}]}) );
-			assert.ok( res.result.matches({'x':[{'x':1,'y':2}]}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( ! res.result.matches({"x":1}) );
+			assert.ok( ! res.result.matches({"x":[1,2]}) );
+			assert.ok( ! res.result.matches({"x":[{"x":1}]}) );
+			assert.ok( res.result.matches({"x":[{"x":1,"y":2}]}) );
 		},
 		"Should properly not parse bad $all $elemMatch queries": function() {
 			var parser = new MatchExpressionParser();
-			var q = {'x':{'$all':[{'$elemMatch':{'x':1,'y':2}}, 5]}};
+			var q = {"x":{"$all":[{"$elemMatch":{"x":1,"y":2}}, 5]}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code, 'BAD_VALUE' );
+			assert.strictEqual( res.code, ErrorCodes.BAD_VALUE );
 
-			q = {'x':{'$all':[5,{'$elemMatch':{'x':1,'y':2}}]}};
+			q = {"x":{"$all":[5,{"$elemMatch":{"x":1,"y":2}}]}};
 			res = parser.parse( q );
-			assert.strictEqual( res.code, 'BAD_VALUE' );
+			assert.strictEqual( res.code, ErrorCodes.BAD_VALUE );
 		},
 		"Should parse and match simple $eq": function () {
 			var parser = new MatchExpressionParser();
-			var q = {'x': {'$eq': 2}};
+			var q = {"x": {"$eq": 2}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( ! res.result.matches({'x':1}) );
-			assert.ok( res.result.matches({'x':2}) );
-			assert.ok( ! res.result.matches({'x':3}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( ! res.result.matches({"x":1}) );
+			assert.ok( res.result.matches({"x":2}) );
+			assert.ok( ! res.result.matches({"x":3}) );
 		},
 		"Should parse and match simple $gt": function() {
 			var parser = new MatchExpressionParser();
-			var q = {'x': {'$gt':2}};
+			var q = {"x": {"$gt":2}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( ! res.result.matches({'x':2}) );
-			assert.ok( res.result.matches({'x':3}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( ! res.result.matches({"x":2}) );
+			assert.ok( res.result.matches({"x":3}) );
 		},
 		"Should parse and match a simple $lt": function () {
 			var parser = new MatchExpressionParser();
-			var q = {'x':{'$lt':2}};
+			var q = {"x":{"$lt":2}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( res.result.matches({'x':1}) );
-			assert.ok( ! res.result.matches({'x':2}) );
-			assert.ok( ! res.result.matches({'x':3}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( res.result.matches({"x":1}) );
+			assert.ok( ! res.result.matches({"x":2}) );
+			assert.ok( ! res.result.matches({"x":3}) );
 		},
 		"Should parse and match simple $gte": function() {
 			var parser = new MatchExpressionParser();
-			var q = {'x': {'$gte':2}};
+			var q = {"x": {"$gte":2}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( ! res.result.matches({'x':1}) );
-			assert.ok( res.result.matches({'x':2}) );
-			assert.ok( res.result.matches({'x':3}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( ! res.result.matches({"x":1}) );
+			assert.ok( res.result.matches({"x":2}) );
+			assert.ok( res.result.matches({"x":3}) );
 		},
 		"Should parse and matc simple $lte": function() {
 			var parser = new MatchExpressionParser();
-			var q = {'x': {'$lte':2}};
+			var q = {"x": {"$lte":2}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( res.result.matches({'x':1}) );
-			assert.ok( res.result.matches({'x':2}) );
-			assert.ok( ! res.result.matches({'x':3}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( res.result.matches({"x":1}) );
+			assert.ok( res.result.matches({"x":2}) );
+			assert.ok( ! res.result.matches({"x":3}) );
 		},
 		"Should parse and match simple $ne": function() {
 			var parser = new MatchExpressionParser();
-			var q = {'x': {'$ne':2}};
+			var q = {"x": {"$ne":2}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( res.result.matches({'x':1}) );
-			assert.ok( ! res.result.matches({'x':2}) );
-			assert.ok( res.result.matches({'x':3}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( res.result.matches({"x":1}) );
+			assert.ok( ! res.result.matches({"x":2}) );
+			assert.ok( res.result.matches({"x":3}) );
 		},
 		"Should parse simple $mod patterns":function(){
 			var parser = new MatchExpressionParser();
-			var q = {'x':{'$mod':[3,2]}};
+			var q = {"x":{"$mod":[3,2]}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
 
-			q = {'x':{'$mod':[3]}};
+			q = {"x":{"$mod":[3]}};
 			res = parser.parse( q );
-			assert.strictEqual( res.code, 'BAD_VALUE' );
+			assert.strictEqual( res.code, ErrorCodes.BAD_VALUE );
 
-			q = {'x':{'$mod':[3,2,4]}};
+			q = {"x":{"$mod":[3,2,4]}};
 			res = parser.parse( q );
-			assert.strictEqual( res.code, 'BAD_VALUE' );
+			assert.strictEqual( res.code, ErrorCodes.BAD_VALUE );
 
-			q = {'x':{'$mod':['q',2]}};
+			q = {"x":{"$mod":["q",2]}};
 			res = parser.parse( q );
-			assert.strictEqual( res.code, 'BAD_VALUE' );
+			assert.strictEqual( res.code, ErrorCodes.BAD_VALUE );
 
-			q = {'x':{'$mod':3}};
+			q = {"x":{"$mod":3}};
 			res = parser.parse( q );
-			assert.strictEqual( res.code, 'BAD_VALUE' );
+			assert.strictEqual( res.code, ErrorCodes.BAD_VALUE );
 
-			q = {'x':{'$mod':{'a':1,'b':2}}};
+			q = {"x":{"$mod":{"a":1,"b":2}}};
 			res = parser.parse( q );
-			assert.strictEqual( res.code, 'BAD_VALUE' );
+			assert.strictEqual( res.code, ErrorCodes.BAD_VALUE );
 		},
 		"Should parse and match simple $mod": function() {
 			var parser = new MatchExpressionParser();
-			var q = {'x':{'$mod':[3,2]}};
+			var q = {"x":{"$mod":[3,2]}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( res.result.matches({'x':5}) );
-			assert.ok( ! res.result.matches({'x':4}) );
-			assert.ok( res.result.matches({'x':8}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( res.result.matches({"x":5}) );
+			assert.ok( ! res.result.matches({"x":4}) );
+			assert.ok( res.result.matches({"x":8}) );
 		},
 		"Should parse and match a simple $in": function() {
 			var parser = new MatchExpressionParser();
-			var q = {'x': {'$in':[2,3]}};
+			var q = {"x": {"$in":[2,3]}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( ! res.result.matches({'x':1}) );
-			assert.ok( res.result.matches({'x':2}) );
-			assert.ok( res.result.matches({'x':3}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( ! res.result.matches({"x":1}) );
+			assert.ok( res.result.matches({"x":2}) );
+			assert.ok( res.result.matches({"x":3}) );
 		},
 		"Should not accept a scalar as an arg to $in" : function() {
 			var parser = new MatchExpressionParser();
-			var q = {'x':{'$in': 5}};
+			var q = {"x":{"$in": 5}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code, 'BAD_VALUE' );
+			assert.strictEqual( res.code, ErrorCodes.BAD_VALUE );
 		},
 		"Should not accept an $elemMatch as an arg to an $in": function () {
 			var parser = new MatchExpressionParser();
-			var q = {'x':{'$in':[{'$elemMatch': 1}]}};
+			var q = {"x":{"$in":[{"$elemMatch": 1}]}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code, 'BAD_VALUE' );
+			assert.strictEqual( res.code, ErrorCodes.BAD_VALUE );
 		},
 		"Should not parse regexes that are too long": function() {
 			var parser = new MatchExpressionParser();
-			var str = (new Array(50*1000+1).join('z'));
-			var q = {'x': {'$in':[new RegExp(str)]}};
+			var str = (new Array(50*1000+1).join("z"));
+			var q = {"x": {"$in":[new RegExp(str)]}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code, 'BAD_VALUE' );
+			assert.strictEqual( res.code, ErrorCodes.BAD_VALUE );
 
-			q = {'x':{'$in': [{'$regex': str}]}};
+			q = {"x":{"$in": [{"$regex": str}]}};
 			res = parser.parse( q );
-			assert.strictEqual( res.code, 'BAD_VALUE' );
+			assert.strictEqual( res.code, ErrorCodes.BAD_VALUE );
 		},
 		"Should parse and match $regex in an $in expression": function() {
 			var parser = new MatchExpressionParser();
 			var a = /^a/;
 			var b = /B/i;
-			var q = {'a': {'$in': [a,b,"2",4]}};
+			var q = {"a": {"$in": [a,b,"2",4]}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( res.result.matches({'a':'ax'}) );
-			assert.ok( res.result.matches({'a':/^a/}) );
-			assert.ok( res.result.matches({'a':'qqb'}) );
-			assert.ok( res.result.matches({'a':/B/i}) );
-			assert.ok( res.result.matches({'a':4}) );
-			assert.ok( ! res.result.matches({'a':'l'}) );
-			assert.ok( ! res.result.matches({'a':/B/}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( res.result.matches({"a":"ax"}) );
+			assert.ok( res.result.matches({"a":/^a/}) );
+			assert.ok( res.result.matches({"a":"qqb"}) );
+			assert.ok( res.result.matches({"a":/B/i}) );
+			assert.ok( res.result.matches({"a":4}) );
+			assert.ok( ! res.result.matches({"a":"l"}) );
+			assert.ok( ! res.result.matches({"a":/B/}) );
 		},
 		"Should parse and match a simple $nin": function() {
 			var parser = new MatchExpressionParser();
-			var q = {'x': {'$nin': [2,3]}};
+			var q = {"x": {"$nin": [2,3]}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( res.result.matches({'x':1}) );
-			assert.ok( ! res.result.matches({'x':2}) );
-			assert.ok( ! res.result.matches({'x':3}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( res.result.matches({"x":1}) );
+			assert.ok( ! res.result.matches({"x":2}) );
+			assert.ok( ! res.result.matches({"x":3}) );
 		},
 		"Should not accept a scalar argument to $nin":function() {
 			var parser = new MatchExpressionParser();
-			var q = {'x':{$nin: 5}};
+			var q = {"x":{$nin: 5}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code, 'BAD_VALUE' );
+			assert.strictEqual( res.code, ErrorCodes.BAD_VALUE );
 		},
 		"Should properly handle /regex/i":function() {
 			var parser = new MatchExpressionParser();
 			var a = /abc/i;
-			var q = {'x': a };
+			var q = {"x": a };
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( res.result.matches({'x':'ABC'}) );
-			assert.ok( res.result.matches({'x':'abc'}) );
-			assert.ok( ! res.result.matches({'x':'AC'}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( res.result.matches({"x":"ABC"}) );
+			assert.ok( res.result.matches({"x":"abc"}) );
+			assert.ok( ! res.result.matches({"x":"AC"}) );
 		},
 		"Should properly handle $regex x $option i": function() {
 			var parser = new MatchExpressionParser();
-			var q = {'x': {'$regex': 'abc', '$options':'i'}};
+			var q = {"x": {"$regex": "abc", "$options":"i"}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( res.result.matches({'x':'abc'}) );
-			assert.ok( res.result.matches({'x':'ABC'}) );
-			assert.ok( ! res.result.matches({'x':'AC'}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( res.result.matches({"x":"abc"}) );
+			assert.ok( res.result.matches({"x":"ABC"}) );
+			assert.ok( ! res.result.matches({"x":"AC"}) );
 		},
 		"Should properly handle $option i $regex x": function () {
 			var parser = new MatchExpressionParser();
-			var q = {'x':{'$options': 'i', '$regex': 'abc'}};
+			var q = {"x":{"$options": "i", "$regex": "abc"}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( res.result.matches({'x':'abc'}) );
-			assert.ok( res.result.matches({'x':'ABC'}) );
-			assert.ok( ! res.result.matches({'x':'AC'}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( res.result.matches({"x":"abc"}) );
+			assert.ok( res.result.matches({"x":"ABC"}) );
+			assert.ok( ! res.result.matches({"x":"AC"}) );
 		},
 		"Should not accept $optionas":function() {
 			var parser = new MatchExpressionParser();
-			var q = {'x':{'$regex':'abc', '$optionas':'i'}};
+			var q = {"x":{"$regex":"abc", "$optionas":"i"}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code, 'BAD_VALUE' );
+			assert.strictEqual( res.code, ErrorCodes.BAD_VALUE );
 
-			q = {'x':{'$optionas': 'i'}};
+			q = {"x":{"$optionas": "i"}};
 			res = parser.parse( q );
-			assert.strictEqual( res.code, 'BAD_VALUE' );
+			assert.strictEqual( res.code, ErrorCodes.BAD_VALUE );
 
-			q = {'x':{'$options':'i'}};
+			q = {"x":{"$options":"i"}};
 			res = parser.parse( q );
-			assert.strictEqual( res.code, 'BAD_VALUE' );
+			assert.strictEqual( res.code, ErrorCodes.BAD_VALUE );
 		},
 		"Should parse and match $exist true": function () {
 			var parser = new MatchExpressionParser();
-			var q = {'x':{'$exists': true}};
+			var q = {"x":{"$exists": true}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( res.result.matches({'x':'abc'}) );
-			assert.ok( ! res.result.matches({'y':'AC'}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( res.result.matches({"x":"abc"}) );
+			assert.ok( ! res.result.matches({"y":"AC"}) );
 		},
 		"Should parse and match $exists false": function() {
 			var parser = new MatchExpressionParser();
-			var q = {'x':{'$exists':false}};
+			var q = {"x":{"$exists":false}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( ! res.result.matches({'x':'abc'}) );
-			assert.ok( res.result.matches({'y':'AC'}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( ! res.result.matches({"x":"abc"}) );
+			assert.ok( res.result.matches({"y":"AC"}) );
 		},
 		"Should parse and match String $type": function() {
 			var parser = new MatchExpressionParser();
-			var q = {'x':{'$type': 2 }};
+			var q = {"x":{"$type": 2 }};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( res.result.matches({'x': 'abc'}) );
-			assert.ok( ! res.result.matches({'x': 2}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( res.result.matches({"x": "abc"}) );
+			assert.ok( ! res.result.matches({"x": 2}) );
 		},
 		"Should parse and match Number $type":function() {
 			var parser = new MatchExpressionParser();
-			var q = {'x':{'$type':1}};
+			var q = {"x":{"$type":1}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( res.result.matches({'x':2}) );
-			assert.ok( ! res.result.matches({'x': 'f'}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( res.result.matches({"x":2}) );
+			assert.ok( ! res.result.matches({"x": "f"}) );
 		},
 		"Should parse and match null $type" : function() {
 			var parser = new MatchExpressionParser();
-			var q = {'x':{'$type': 10}};
+			var q = {"x":{"$type": 10}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( ! res.result.matches({'x':{}}) );
-			assert.ok( ! res.result.matches({'x':5}) );
-			assert.ok( res.result.matches({'x':null}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( ! res.result.matches({"x":{}}) );
+			assert.ok( ! res.result.matches({"x":5}) );
+			assert.ok( res.result.matches({"x":null}) );
 		},
 		"Should parse but not match a type beyond typemax in $type": function() {
 			var parser = new MatchExpressionParser();
-			var q = {'x':{'$type': 1000}};
+			var q = {"x":{"$type": 1000}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( ! res.result.matches({'x':5}) );
-			assert.ok( ! res.result.matches({'x':'abc'}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( ! res.result.matches({"x":5}) );
+			assert.ok( ! res.result.matches({"x":"abc"}) );
 		},
 		"Should not parse a $type: Object":function() {
 			var parser = new MatchExpressionParser();
-			var q = {'x':{'$type': {'x':1}}};
+			var q = {"x":{"$type": {"x":1}}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code, 'BAD_VALUE' );
+			assert.strictEqual( res.code, ErrorCodes.BAD_VALUE );
 		},
 		"Should parse and match a simple $or": function() {
 			var parser = new MatchExpressionParser();
-			var q = {'$or':[{'x':1},{'y':2}]};
+			var q = {"$or":[{"x":1},{"y":2}]};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( res.result.matches({'x':1}) );
-			assert.ok( res.result.matches({'y':2}) );
-			assert.ok( ! res.result.matches({'x':3}) );
-			assert.ok( ! res.result.matches({'y':1}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( res.result.matches({"x":1}) );
+			assert.ok( res.result.matches({"y":2}) );
+			assert.ok( ! res.result.matches({"x":3}) );
+			assert.ok( ! res.result.matches({"y":1}) );
 		},
 		"Should parse and match with nested $or s": function() {
 			var parser = new MatchExpressionParser();
-			var q = {'$or':[{'$or':[{'x':1},{'y':2}]}]};
+			var q = {"$or":[{"$or":[{"x":1},{"y":2}]}]};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( res.result.matches({'x':1}) );
-			assert.ok( res.result.matches({'y':2}) );
-			assert.ok( ! res.result.matches({'x':3}) );
-			assert.ok( ! res.result.matches({'y':1}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( res.result.matches({"x":1}) );
+			assert.ok( res.result.matches({"y":2}) );
+			assert.ok( ! res.result.matches({"x":3}) );
+			assert.ok( ! res.result.matches({"y":1}) );
 		},
 		"Should parse and match $and": function(){
 			var parser = new MatchExpressionParser();
-			var q = {'$and':[{'x':1},{'y':2}]};
+			var q = {"$and":[{"x":1},{"y":2}]};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( ! res.result.matches({'x':1}) );
-			assert.ok( ! res.result.matches({'y':2}) );
-			assert.ok( ! res.result.matches({'x':3}) );
-			assert.ok( ! res.result.matches({'y':1}) );
-			assert.ok( res.result.matches({'x':1, 'y':2}) );
-			assert.ok( ! res.result.matches({'x':2, 'y':2}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( ! res.result.matches({"x":1}) );
+			assert.ok( ! res.result.matches({"y":2}) );
+			assert.ok( ! res.result.matches({"x":3}) );
+			assert.ok( ! res.result.matches({"y":1}) );
+			assert.ok( res.result.matches({"x":1, "y":2}) );
+			assert.ok( ! res.result.matches({"x":2, "y":2}) );
 		},
 		"Should parse and match $nor": function() {
 			var parser = new MatchExpressionParser();
-			var q = {'$nor':[{'x':1},{'y':2}]};
+			var q = {"$nor":[{"x":1},{"y":2}]};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( ! res.result.matches({'x':1}) );
-			assert.ok( ! res.result.matches({'y':2}) );
-			assert.ok( res.result.matches({'x':3}) );
-			assert.ok( res.result.matches({'y':1}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( ! res.result.matches({"x":1}) );
+			assert.ok( ! res.result.matches({"y":2}) );
+			assert.ok( res.result.matches({"x":3}) );
+			assert.ok( res.result.matches({"y":1}) );
 		},
 		"Should parse and match $not": function() {
 			var parser = new MatchExpressionParser();
-			var q = {'x':{'$not':{'$gt':5}}};
+			var q = {"x":{"$not":{"$gt":5}}};
 
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( res.result.matches({'x':2}) );
-			assert.ok( ! res.result.matches({'x':8}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( res.result.matches({"x":2}) );
+			assert.ok( ! res.result.matches({"x":8}) );
 		},
 		"should allow trees less than the maximum recursion depth": function() {
 			var parser = new MatchExpressionParser(),
@@ -514,15 +516,15 @@ module.exports = {
 				i;
 
 			for (i = 0; i < depth/2; i++) {
-				q = q + '{"$and": [{"a":3}, {"$or": [{"b":2},';
+				q = q + "{\"$and\": [{\"a\":3}, {\"$or\": [{\"b\":2},";
 			}
-			q = q + '{"b": 4}';
+			q = q + "{\"b\": 4}";
 			for (i = 0; i < depth/2; i++) {
 				q = q + "]}]}";
 			}
 
 			var res = parser.parse(JSON.parse(q));
-			assert.strictEqual(res.code, 'OK', res.description);
+			assert.strictEqual(res.code, ErrorCodes.OK, res.description);
 		},
 		"should error when depth limit is exceeded": function() {
 			var parser = new MatchExpressionParser(),
@@ -531,64 +533,62 @@ module.exports = {
 				i;
 
 			for (i = 0; i < depth/2; i++) {
-				q = q + '{"$and": [{"a":3}, {"$or": [{"b":2},';
+				q = q + "{\"$and\": [{\"a\":3}, {\"$or\": [{\"b\":2},";
 			}
-			q = q + '{"b": 4}';
+			q = q + "{\"b\": 4}";
 			for (i = 0; i < depth/2; i++) {
 				q = q + "]}]}";
 			}
 
 			var res = parser.parse(JSON.parse(q));
-			assert.strictEqual(res.description.substr(0, 43), 'exceeded maximum query tree depth of 100 at');
-			assert.strictEqual(res.code, 'BAD_VALUE');
+			assert.strictEqual(res.description.substr(0, 43), "exceeded maximum query tree depth of 100 at");
+			assert.strictEqual(res.code, ErrorCodes.BAD_VALUE);
 		},
 		"should error when depth limit is reached through a $not": function() {
 			var parser = new MatchExpressionParser(),
 				depth = 105,
-				q = '{"a": ',
+				q = "{\"a\": ",
 				i;
 
 			for (i = 0; i < depth; i++) {
-				q = q + '{"$not": ';
+				q = q + "{\"$not\": ";
 			}
-			q = q + '{"$eq": 5}';
+			q = q + "{\"$eq\": 5}";
 			for (i = 0; i < depth+1; i++) {
 				q = q + "}";
 			}
 
 			var res = parser.parse(JSON.parse(q));
-			assert.strictEqual(res.description.substr(0, 43), 'exceeded maximum query tree depth of 100 at');
-			assert.strictEqual(res.code, 'BAD_VALUE');
+			assert.strictEqual(res.description.substr(0, 43), "exceeded maximum query tree depth of 100 at");
+			assert.strictEqual(res.code, ErrorCodes.BAD_VALUE);
 		},
 		"should error when depth limit is reached through an $elemMatch": function() {
 			var parser = new MatchExpressionParser(),
 				depth = 105,
-				q = '',
+				q = "",
 				i;
 
 			for (i = 0; i < depth; i++) {
-				q = q + '{"a": {"$elemMatch": ';
+				q = q + "{\"a\": {\"$elemMatch\": ";
 			}
-			q = q + '{"b": 5}';
+			q = q + "{\"b\": 5}";
 			for (i = 0; i < depth; i++) {
 				q = q + "}}";
 			}
 
 			var res = parser.parse(JSON.parse(q));
-			assert.strictEqual(res.description.substr(0, 43), 'exceeded maximum query tree depth of 100 at');
-			assert.strictEqual(res.code, 'BAD_VALUE');
+			assert.strictEqual(res.description.substr(0, 43), "exceeded maximum query tree depth of 100 at");
+			assert.strictEqual(res.code, ErrorCodes.BAD_VALUE);
 		},
 		"Should parse $not $regex and match properly": function() {
 			var parser = new MatchExpressionParser();
 			var a = /abc/i;
-			var q = {'x':{'$not': a}};
+			var q = {"x":{"$not": a}};
 			var res = parser.parse( q );
-			assert.strictEqual( res.code,'OK',res.description );
-			assert.ok( ! res.result.matches({'x':'abc'}) );
-			assert.ok( ! res.result.matches({'x':'ABC'}) );
-			assert.ok( res.result.matches({'x':'AC'}) );
+			assert.strictEqual( res.code,ErrorCodes.OK,res.description );
+			assert.ok( ! res.result.matches({"x":"abc"}) );
+			assert.ok( ! res.result.matches({"x":"ABC"}) );
+			assert.ok( res.result.matches({"x":"AC"}) );
 		}
 	}
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);

+ 3 - 5
test/lib/pipeline/matcher/Matcher2_test.js

@@ -1,5 +1,5 @@
 "use strict";
-
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	MatchDetails = require("../../../../lib/pipeline/matcher/MatchDetails.js"),
 	Matcher2 = require("../../../../lib/pipeline/matcher/Matcher2.js");
@@ -7,7 +7,7 @@ var assert = require("assert"),
 module.exports = {
 	"Matcher2": {
 		"Constructor": function() {
-			var m = new Matcher2({"a":1});
+			new Matcher2({"a":1});
 		},
 
 		"Basic": function() {
@@ -54,7 +54,7 @@ module.exports = {
 				m = new Matcher2(query);
 			assert.ok(m.matches({"a":[1,2,3,4]}));
 			assert.ok(!m.matches({"a":[1,2,3]}));
-			assert.ok(!m.matches({"a":[1,2,3,'a','b']}));
+			assert.ok(!m.matches({"a":[1,2,3,"a","b"]}));
 			assert.ok(!m.matches({"a":[[1,2,3,4]]}));
 		},
 
@@ -82,5 +82,3 @@ module.exports = {
 		}
 		}
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);

+ 39 - 40
test/lib/pipeline/matcher/ModMatchExpression_test.js

@@ -1,5 +1,7 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
+	ErrorCodes = require("../../../../lib/Errors").ErrorCodes,
 	ModMatchExpression = require("../../../../lib/pipeline/matcher/ModMatchExpression"),
 	MatchDetails = require("../../../../lib/pipeline/matcher/MatchDetails");
 
@@ -8,88 +10,85 @@ module.exports = {
 	"ModMatchExpression": {
 		"should match a number": function (){
 			var e = new ModMatchExpression();
-			var s = e.init('',3,1);
-			
-			assert.strictEqual(s.code, 'OK');
+			var s = e.init("",3,1);
+
+			assert.strictEqual(s.code, ErrorCodes.OK);
 			assert.ok( e.matches(1) );
 			assert.ok( e.matches(4.0) );
 			assert.ok( e.matches(68719476736) );
 			assert.ok( ! e.matches(6) );
-			assert.ok( ! e.matches(-2) ); 
+			assert.ok( ! e.matches(-2) );
 		},
 		"should fail init with a zero divisor":function() {
 			var e = new ModMatchExpression();
-			var s = e.init('', 0,  1);
-			
-			assert.strictEqual( s.code, 'BAD_VALUE' );
+			var s = e.init("", 0,  1);
+
+			assert.strictEqual(s.code, ErrorCodes.BAD_VALUE);
 		},
 		"should match more numbers":function() {
 			var e = new ModMatchExpression();
-			var s = e.init('a', 5,2);
-			
-			assert.strictEqual( s.code, 'OK' );
-			assert.ok( e.matches({'a':7.0}) );	
-			assert.ok( ! e.matches({'a':4}) );
+			var s = e.init("a", 5,2);
+
+			assert.strictEqual(s.code, ErrorCodes.OK);
+			assert.ok( e.matches({"a":7.0}) );
+			assert.ok( ! e.matches({"a":4}) );
 		},
 		"should match an array":function() {
 			var e = new ModMatchExpression();
-			var s = e.init('a',5,2);
-			
-			assert.strictEqual( s.code, 'OK' );
-			assert.ok( e.matches({'a':[5,12]}) );
-			assert.ok( ! e.matches({'a':[6,8]}) );
+			var s = e.init("a",5,2);
+
+			assert.strictEqual(s.code, ErrorCodes.OK);
+			assert.ok( e.matches({"a":[5,12]}) );
+			assert.ok( ! e.matches({"a":[6,8]}) );
 		},
 		"should not match null":function() {
 			var e = new ModMatchExpression();
-			var s = e.init('a',5,2);
+			var s = e.init("a",5,2);
 
-			assert.strictEqual(s.code, 'OK');
+			assert.strictEqual(s.code, ErrorCodes.OK);
 			assert.ok( ! e.matches({}) );
-			assert.ok( ! e.matches({'a':null}) );
+			assert.ok( ! e.matches({"a":null}) );
 		},
 		"should yield an elemMatchKey":function() {
 			var e = new ModMatchExpression();
-			var s = e.init('a', 5,2);
+			var s = e.init("a", 5,2);
 			var m = new MatchDetails();
 			m.requestElemMatchKey();
-			assert.strictEqual( s.code, 'OK' );
+			assert.strictEqual(s.code, ErrorCodes.OK);
 
-			assert.ok( ! e.matches({'a':4}, m) );
+			assert.ok( ! e.matches({"a":4}, m) );
 			assert.ok( ! m.hasElemMatchKey() );
-			
-			assert.ok( e.matches({'a':2}));
+
+			assert.ok( e.matches({"a":2}));
 			assert.ok( ! m.hasElemMatchKey() );
 
-			assert.ok( e.matches({'a':[1,2,5]}, m) );
+			assert.ok( e.matches({"a":[1,2,5]}, m) );
 			assert.ok( m.hasElemMatchKey() );
-			assert.strictEqual('1', m.elemMatchKey() );
+			assert.strictEqual("1", m.elemMatchKey() );
 		},
 		"should handle equivalence":function() {
 			var e = new ModMatchExpression();
-			var s = e.init('a',1,2);
+			var s = e.init("a",1,2);
 			var b = new ModMatchExpression();
 			var c = new ModMatchExpression();
 			var d = new ModMatchExpression();
-			assert.strictEqual( s.code, 'OK' );
+			assert.strictEqual(s.code, ErrorCodes.OK);
+
+			s = b.init("a",2,2);
+			assert.strictEqual(s.code, ErrorCodes.OK);
 
-			s = b.init('a',2,2);
-			assert.strictEqual(s.code, 'OK' );
-			
-			s = c.init('a',1,1);
-			assert.strictEqual(s.code, 'OK' );
+			s = c.init("a",1,1);
+			assert.strictEqual(s.code, ErrorCodes.OK);
 
-			s = d.init('b',1,2);
-			assert.strictEqual(s.code, 'OK' );
+			s = d.init("b",1,2);
+			assert.strictEqual(s.code, ErrorCodes.OK);
 
 			assert.ok( e.equivalent(e) );
 			assert.ok( ! e.equivalent(b) );
 			assert.ok( ! e.equivalent(c) );
-			assert.ok( ! e.equivalent(d) );		
+			assert.ok( ! e.equivalent(d) );
 		}
 
 
 	}
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);
-

+ 29 - 31
test/lib/pipeline/matcher/NorMatchExpression_test.js

@@ -1,13 +1,14 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
-	NorMatchExpression = require("../../../../lib/pipeline/matcher/NorMatchExpression.js"),
-	AndMatchExpression = require("../../../../lib/pipeline/matcher/AndMatchExpression.js"),
-	LTMatchExpression = require("../../../../lib/pipeline/matcher/LTMatchExpression.js"),
-	GTMatchExpression = require("../../../../lib/pipeline/matcher/GTMatchExpression.js"),
-	MatchDetails = require("../../../../lib/pipeline/matcher/MatchDetails.js"),
-	RegexMatchExpression = require("../../../../lib/pipeline/matcher/RegexMatchExpression.js"),
-	EqualityMatchExpression = require("../../../../lib/pipeline/matcher/EqualityMatchExpression.js"),
-	NotMatchExpression = require("../../../../lib/pipeline/matcher/NotMatchExpression.js");
+	ErrorCodes = require("../../../../lib/Errors").ErrorCodes,
+	matcher = require("../../../../lib/pipeline/matcher/"),
+	NorMatchExpression = matcher.NorMatchExpression,
+	EqualityMatchExpression = matcher.EqualityMatchExpression,
+	NotMatchExpression = matcher.NotMatchExpression,
+	GTMatchExpression = matcher.GTMatchExpression,
+	LTMatchExpression = matcher.LTMatchExpression,
+	MatchDetails = matcher.MatchDetails;
 
 module.exports = {
 	"NorMatchExpression": {
@@ -20,42 +21,42 @@ module.exports = {
 			var gt = new GTMatchExpression();
 			var rgx = new RegexMatchExpression();
 			var op = new AndMatchExpression();
-			assert.strictEqual( lt.init('a','z1').code,'OK');
-			assert.strictEqual( gt.init('a','a1').code,'OK');
-			assert.strictEqual( rgx.init('a','1','').code,'OK');
+			assert.strictEqual( lt.init("a","z1").code,ErrorCodes.OK);
+			assert.strictEqual( gt.init("a","a1").code,ErrorCodes.OK);
+			assert.strictEqual( rgx.init("a","1","").code,ErrorCodes.OK);
 			op.add(lt);
 			op.add(gt);
 			op.add(rgx);
-			assert.ok( op.matches({'a':'r1'}) );
-			assert.ok( ! op.matches({'a': 'z1'}) );
-			assert.ok( ! op.matches({'a': 'a1'}) );
-			assert.ok( ! op.matches({'a':'r'}) );
+			assert.ok( op.matches({"a":"r1"}) );
+			assert.ok( ! op.matches({"a": "z1"}) );
+			assert.ok( ! op.matches({"a": "a1"}) );
+			assert.ok( ! op.matches({"a":"r"}) );
 		},*/
 		"Should match a single clause": function() {
 			var nop = new NotMatchExpression();
 			var eq = new EqualityMatchExpression();
 			var op = new NorMatchExpression();
 
-			assert.strictEqual(eq.init('a', 5).code, 'OK');
-			assert.strictEqual(nop.init(eq).code, 'OK');
+			assert.strictEqual(eq.init("a", 5).code, ErrorCodes.OK);
+			assert.strictEqual(nop.init(eq).code, ErrorCodes.OK);
 			op.add(nop);
-			assert.ok( ! op.matches({'a':4}) );
-			assert.ok( ! op.matches({'a':[4,6]}) );
-			assert.ok( op.matches({'a':5}) );
-			assert.ok( op.matches({'a':[4,5]}) );
+			assert.ok( ! op.matches({"a":4}) );
+			assert.ok( ! op.matches({"a":[4,6]}) );
+			assert.ok( op.matches({"a":5}) );
+			assert.ok( op.matches({"a":[4,5]}) );
 		},
 		"Should match three clauses": function(){
 			var baseOperand1 = {"$gt":10},
 				baseOperand2 = {"$lt":0},
-				baseOperand3 = {'b':100},
+				baseOperand3 = {"b":100},
 				sub1 = new GTMatchExpression(),
 				sub2 = new LTMatchExpression(),
 				sub3 = new EqualityMatchExpression(),
 				orOp = new NorMatchExpression();
 
-			assert.strictEqual(sub1.init("a", baseOperand1.$gt).code, 'OK');
-			assert.strictEqual(sub2.init("a", baseOperand2.$lt).code, 'OK');
-			assert.strictEqual(sub3.init("b", baseOperand3.b).code, 'OK');
+			assert.strictEqual(sub1.init("a", baseOperand1.$gt).code, ErrorCodes.OK);
+			assert.strictEqual(sub2.init("a", baseOperand2.$lt).code, ErrorCodes.OK);
+			assert.strictEqual(sub3.init("b", baseOperand3.b).code, ErrorCodes.OK);
 
 			orOp.add(sub1);
 			orOp.add(sub2);
@@ -77,14 +78,14 @@ module.exports = {
 				orOp = new NorMatchExpression(),
 				details = new MatchDetails();
 
-			assert.strictEqual(sub1.init("a", baseOperand1.a).code, 'OK');
-			assert.strictEqual(sub2.init("b", baseOperand2.b).code, 'OK');
+			assert.strictEqual(sub1.init("a", baseOperand1.a).code, ErrorCodes.OK);
+			assert.strictEqual(sub2.init("b", baseOperand2.b).code, ErrorCodes.OK);
 
 			orOp.add(sub1);
 			orOp.add(sub2);
 
 			details.requestElemMatchKey();
-			assert.ok( orOp.matchesJSON({"a":[10], 'b':[10]}, details));
+			assert.ok( orOp.matchesJSON({"a":[10], "b":[10]}, details));
 			assert.ok(!details.hasElemMatchKey());
 
 			assert.ok( ! orOp.matchesJSON({"a":[1], "b":[1, 2]}, details));
@@ -96,6 +97,3 @@ module.exports = {
 
 	}
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);
-

+ 23 - 24
test/lib/pipeline/matcher/NotMatchExpression_test.js

@@ -1,46 +1,45 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
-	NotMatchExpression = require("../../../../lib/pipeline/matcher/NotMatchExpression"),
-	LTMatchExpression = require("../../../../lib/pipeline/matcher/LTMatchExpression"), 
-	GTMatchExpression = require("../../../../lib/pipeline/matcher/GTMatchExpression"),
-	MatchDetails = require("../../../../lib/pipeline/matcher/MatchDetails");
+	ErrorCodes = require("../../../../lib/Errors").ErrorCodes,
+	matcher = require("../../../../lib/pipeline/matcher/"),
+	NotMatchExpression = matcher.NotMatchExpression,
+	LTMatchExpression = matcher.LTMatchExpression,
+	MatchDetails = matcher.MatchDetails;
 
 module.exports = {
 	"NotMatchExpression": {
 		"Should match a scalar": function (){
 			var lt = new LTMatchExpression();
-			assert.strictEqual(lt.init('a', 5).code,'OK');
+			assert.strictEqual(lt.init("a", 5).code, ErrorCodes.OK);
 			var op = new NotMatchExpression();
-			assert.strictEqual( op.init(lt).code, 'OK');
-			assert.ok( op.matches({'a':6}), '{$not: {$lt: 5}}, {a:6}' );
-			assert.ok( !op.matches({'a':4}), '{$not: {$lt: 5}}, {a:4}' );
+			assert.strictEqual( op.init(lt).code, ErrorCodes.OK);
+			assert.ok( op.matches({"a":6}), "{$not: {$lt: 5}}, {a:6}" );
+			assert.ok( !op.matches({"a":4}), "{$not: {$lt: 5}}, {a:4}" );
 		},
 		"Should match an Array": function() {
 			var lt = new LTMatchExpression();
-			assert.strictEqual(lt.init('a',5).code,'OK');
+			assert.strictEqual(lt.init("a",5).code, ErrorCodes.OK);
 			var op = new NotMatchExpression();
-			assert.strictEqual(op.init(lt).code,'OK');
-			assert.ok( op.matches({'a': [6]}) , '{$not: {$lt: 5}}, {a: [6]}');	
-			assert.ok( !op.matches({'a': [4]}) , '{$not: {$lt: 5}}, {a: [4]}');	
-			assert.ok( !op.matches({'a': [4,5,6]}) , '{$not: {$lt: 5}}, {a: [4,5,6]}');
+			assert.strictEqual(op.init(lt).code, ErrorCodes.OK);
+			assert.ok( op.matches({"a": [6]}) , "{$not: {$lt: 5}}, {a: [6]}");
+			assert.ok( !op.matches({"a": [4]}) , "{$not: {$lt: 5}}, {a: [4]}");
+			assert.ok( !op.matches({"a": [4,5,6]}) , "{$not: {$lt: 5}}, {a: [4,5,6]}");
 		},
 		"Should not have an ElemMatchKey": function() {
 			var lt = new LTMatchExpression();
-			assert.strictEqual(lt.init('a',5).code,'OK');
+			assert.strictEqual(lt.init("a",5).code, ErrorCodes.OK);
 			var op = new NotMatchExpression();
-			assert.strictEqual( op.init( lt ).code,'OK');
+			assert.strictEqual( op.init( lt ).code, ErrorCodes.OK);
 			var details = new MatchDetails();
 			details.requestElemMatchKey();
-			assert.ok( ! op.matches({'a':[1]}, details), '{$not: {a: {$lt : 5}}}, {a: [1]}' );
-			assert.ok( ! details.hasElemMatchKey() , 'ElemMatchKey Check');
-			assert.ok( op.matches({'a': 6 }, details), '{$not: {a: {$lt : 5}}},{a: 6}');
-			assert.ok( ! details.hasElemMatchKey(), 'ElemMatchKey Check');
-			assert.ok( op.matches({'a':[6]}, details), '{$not: {a: {$lt : 5}}}, {a:[6]}');
+			assert.ok( ! op.matches({"a":[1]}, details), "{$not: {a: {$lt : 5}}}, {a: [1]}" );
+			assert.ok( ! details.hasElemMatchKey() , "ElemMatchKey Check");
+			assert.ok( op.matches({"a": 6 }, details), "{$not: {a: {$lt : 5}}},{a: 6}");
+			assert.ok( ! details.hasElemMatchKey(), "ElemMatchKey Check");
+			assert.ok( op.matches({"a":[6]}, details), "{$not: {a: {$lt : 5}}}, {a:[6]}");
 			assert.ok( ! details.hasElemMatchKey() );
 		}
 	}
-		
-};
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);
 
+};

+ 29 - 31
test/lib/pipeline/matcher/OrMatchExpression_test.js

@@ -1,13 +1,14 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
-	OrMatchExpression = require("../../../../lib/pipeline/matcher/OrMatchExpression.js"),
-	AndMatchExpression = require("../../../../lib/pipeline/matcher/AndMatchExpression.js"),
-	LTMatchExpression = require("../../../../lib/pipeline/matcher/LTMatchExpression.js"),
-	GTMatchExpression = require("../../../../lib/pipeline/matcher/GTMatchExpression.js"),
-	MatchDetails = require("../../../../lib/pipeline/matcher/MatchDetails.js"),
-	RegexMatchExpression = require("../../../../lib/pipeline/matcher/RegexMatchExpression.js"),
-	EqualityMatchExpression = require("../../../../lib/pipeline/matcher/EqualityMatchExpression.js"),
-	NotMatchExpression = require("../../../../lib/pipeline/matcher/NotMatchExpression.js");
+	ErrorCodes = require("../../../../lib/Errors").ErrorCodes,
+	matcher = require("../../../../lib/pipeline/matcher/"),
+	OrMatchExpression = matcher.OrMatchExpression,
+	LTMatchExpression = matcher.LTMatchExpression,
+	GTMatchExpression = matcher.GTMatchExpression,
+	MatchDetails = matcher.MatchDetails,
+	EqualityMatchExpression = matcher.EqualityMatchExpression,
+	NotMatchExpression = matcher.NotMatchExpression;
 
 module.exports = {
 	"OrMatchExpression": {
@@ -20,42 +21,42 @@ module.exports = {
 			var gt = new GTMatchExpression();
 			var rgx = new RegexMatchExpression();
 			var op = new AndMatchExpression();
-			assert.strictEqual( lt.init('a','z1').code,'OK');
-			assert.strictEqual( gt.init('a','a1').code,'OK');
-			assert.strictEqual( rgx.init('a','1','').code,'OK');
+			assert.strictEqual( lt.init("a","z1").code, ErrorCodes.OK);
+			assert.strictEqual( gt.init("a","a1").code, ErrorCodes.OK);
+			assert.strictEqual( rgx.init("a","1","").code, ErrorCodes.OK);
 			op.add(lt);
 			op.add(gt);
 			op.add(rgx);
-			assert.ok( op.matches({'a':'r1'}) );
-			assert.ok( ! op.matches({'a': 'z1'}) );
-			assert.ok( ! op.matches({'a': 'a1'}) );
-			assert.ok( ! op.matches({'a':'r'}) );
+			assert.ok( op.matches({"a":"r1"}) );
+			assert.ok( ! op.matches({"a": "z1"}) );
+			assert.ok( ! op.matches({"a": "a1"}) );
+			assert.ok( ! op.matches({"a":"r"}) );
 		},*/
 		"Should match a single clause": function() {
 			var nop = new NotMatchExpression();
 			var eq = new EqualityMatchExpression();
 			var op = new OrMatchExpression();
 
-			assert.strictEqual(eq.init('a', 5).code, 'OK');
-			assert.strictEqual(nop.init(eq).code, 'OK');
+			assert.strictEqual(eq.init("a", 5).code, ErrorCodes.OK);
+			assert.strictEqual(nop.init(eq).code, ErrorCodes.OK);
 			op.add(nop);
-			assert.ok( op.matches({'a':4}) );
-			assert.ok( op.matches({'a':[4,6]}) );
-			assert.ok( !op.matches({'a':5}) );
-			assert.ok( !op.matches({'a':[4,5]}) );
+			assert.ok( op.matches({"a":4}) );
+			assert.ok( op.matches({"a":[4,6]}) );
+			assert.ok( !op.matches({"a":5}) );
+			assert.ok( !op.matches({"a":[4,5]}) );
 		},
 		"Should match three clauses": function(){
 			var baseOperand1 = {"$gt":10},
 				baseOperand2 = {"$lt":0},
-				baseOperand3 = {'b':100},
+				baseOperand3 = {"b":100},
 				sub1 = new GTMatchExpression(),
 				sub2 = new LTMatchExpression(),
 				sub3 = new EqualityMatchExpression(),
 				orOp = new OrMatchExpression();
 
-			assert.strictEqual(sub1.init("a", baseOperand1.$gt).code, 'OK');
-			assert.strictEqual(sub2.init("a", baseOperand2.$lt).code, 'OK');
-			assert.strictEqual(sub3.init("b", baseOperand3.b).code, 'OK');
+			assert.strictEqual(sub1.init("a", baseOperand1.$gt).code, ErrorCodes.OK);
+			assert.strictEqual(sub2.init("a", baseOperand2.$lt).code, ErrorCodes.OK);
+			assert.strictEqual(sub3.init("b", baseOperand3.b).code, ErrorCodes.OK);
 
 			orOp.add(sub1);
 			orOp.add(sub2);
@@ -77,14 +78,14 @@ module.exports = {
 				orOp = new OrMatchExpression(),
 				details = new MatchDetails();
 
-			assert.strictEqual(sub1.init("a", baseOperand1.a).code, 'OK');
-			assert.strictEqual(sub2.init("b", baseOperand2.b).code, 'OK');
+			assert.strictEqual(sub1.init("a", baseOperand1.a).code, ErrorCodes.OK);
+			assert.strictEqual(sub2.init("b", baseOperand2.b).code, ErrorCodes.OK);
 
 			orOp.add(sub1);
 			orOp.add(sub2);
 
 			details.requestElemMatchKey();
-			assert.ok(!orOp.matchesJSON({"a":[10], 'b':[10]}, details));
+			assert.ok(!orOp.matchesJSON({"a":[10], "b":[10]}, details));
 			assert.ok(!details.hasElemMatchKey());
 
 			assert.ok(orOp.matchesJSON({"a":[1], "b":[1, 2]}, details));
@@ -96,6 +97,3 @@ module.exports = {
 
 	}
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);
-

+ 54 - 53
test/lib/pipeline/matcher/RegexMatchExpression_test.js

@@ -1,8 +1,11 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	XRegExp = require("xregexp").XRegExp,
-	RegexMatchExpression = require("../../../../lib/pipeline/matcher/RegexMatchExpression"),
-	MatchDetails = require("../../../../lib/pipeline/matcher/MatchDetails");
+	ErrorCodes = require("../../../../lib/Errors").ErrorCodes,
+	matcher = require("../../../../lib/pipeline/matcher/"),
+	RegexMatchExpression = matcher.RegexMatchExpression,
+	MatchDetails = matcher.MatchDetails;
 
 
 module.exports = {
@@ -12,23 +15,23 @@ module.exports = {
 			var match = {"a":"b"},
 				notMatch = {"a":"c"};
 			var regex = new RegexMatchExpression();
-			assert.strictEqual(regex.init("", "b", "").code, 'OK');
-			
+			assert.strictEqual(regex.init("", "b", "").code, ErrorCodes.OK);
+
 			assert(regex.matchesSingleElement(match.a));
 			assert(!regex.matchesSingleElement(notMatch.a));
 		},
 		"should error if the pattern is too large": function(){
 			var tooLargePattern = "";
-			for (var i = 0; i<32765; i++){tooLargePattern += '3';}
+			for (var i = 0; i<32765; i++){tooLargePattern += "3";}
 			var regex = new RegexMatchExpression();
-			assert(regex.init("a", tooLargePattern, "").code !== 'OK');
+			assert(regex.init("a", tooLargePattern, "").code !== ErrorCodes.OK);
 		},
 		"should match an element with a simple prefix": function(){
 			var match = {"x":"abc"},
 				notMatch = {"x":"adz"};
 			var regex = new RegexMatchExpression();
-			assert.strictEqual(regex.init("", "^ab", "").code, 'OK');
-			
+			assert.strictEqual(regex.init("", "^ab", "").code, ErrorCodes.OK);
+
 			assert(regex.matchesSingleElement(match.x));
 			assert(!regex.matchesSingleElement(notMatch.x));
 		},
@@ -36,8 +39,8 @@ module.exports = {
 			var match = {"x":"abc"},
 				notMatch = {"x":"ABC"};
 			var regex = new RegexMatchExpression();
-			assert.strictEqual(regex.init("", "abc", "").code, 'OK');
-			
+			assert.strictEqual(regex.init("", "abc", "").code, ErrorCodes.OK);
+
 			assert(regex.matchesSingleElement(match.x));
 			assert(!regex.matchesSingleElement(notMatch.x));
 		},
@@ -46,8 +49,8 @@ module.exports = {
 				matchUppercase = {"x":"ABC"},
 				notMatch = {"x":"adz"};
 			var regex = new RegexMatchExpression();
-			assert.strictEqual(regex.init("", "abc", "i").code, 'OK');
-			
+			assert.strictEqual(regex.init("", "abc", "i").code, ErrorCodes.OK);
+
 			assert(regex.matchesSingleElement(match.x));
 			assert(regex.matchesSingleElement(matchUppercase.x));
 			assert(!regex.matchesSingleElement(notMatch.x));
@@ -56,8 +59,8 @@ module.exports = {
 			var match = {"x":"az"},
 				notMatch = {"x":"\naz"};
 			var regex = new RegexMatchExpression();
-			assert.strictEqual(regex.init("", "^a", "").code, 'OK');
-			
+			assert.strictEqual(regex.init("", "^a", "").code, ErrorCodes.OK);
+
 			assert(regex.matchesSingleElement(match.x));
 			assert(!regex.matchesSingleElement(notMatch.x));
 		},
@@ -66,8 +69,8 @@ module.exports = {
 				matchMultiline = {"x":"\naz"},
 				notMatch = {"x":"\n\n"};
 			var regex = new RegexMatchExpression();
-			assert.strictEqual(regex.init("", "^a", "m").code, 'OK');
-			
+			assert.strictEqual(regex.init("", "^a", "m").code, ErrorCodes.OK);
+
 			assert(regex.matchesSingleElement(match.x));
 			assert(regex.matchesSingleElement(matchMultiline.x));
 			assert(!regex.matchesSingleElement(notMatch.x));
@@ -76,8 +79,8 @@ module.exports = {
 			var match = {"x":"a b"},
 				notMatch = {"x":"ab"};
 			var regex = new RegexMatchExpression();
-			assert.strictEqual(regex.init("", "a b", "").code, 'OK');
-			
+			assert.strictEqual(regex.init("", "a b", "").code, ErrorCodes.OK);
+
 			assert(regex.matchesSingleElement(match.x));
 			assert(!regex.matchesSingleElement(notMatch.x));
 		},
@@ -85,8 +88,8 @@ module.exports = {
 			var match = {"x":"ab"},
 				notMatch = {"x":"a b"};
 			var regex = new RegexMatchExpression();
-			assert.strictEqual(regex.init("", "a b", "x").code, 'OK');
-			
+			assert.strictEqual(regex.init("", "a b", "x").code, ErrorCodes.OK);
+
 			assert(regex.matchesSingleElement(match.x));
 			assert(!regex.matchesSingleElement(notMatch.x));
 		},
@@ -94,8 +97,8 @@ module.exports = {
 			var match = {"x":"a b"},
 				notMatch = {"x":"a\nb"};
 			var regex = new RegexMatchExpression();
-			assert.strictEqual(regex.init("", "a.b", "").code, 'OK');
-			
+			assert.strictEqual(regex.init("", "a.b", "").code, ErrorCodes.OK);
+
 			assert(regex.matchesSingleElement(match.x));
 			assert(!regex.matchesSingleElement(notMatch.x));
 		},
@@ -104,8 +107,8 @@ module.exports = {
 				matchDotAll = {"x":"a\nb"},
 				notMatch = {"x":"ab"};
 			var regex = new RegexMatchExpression();
-			assert.strictEqual(regex.init("", "a.b", "s").code, 'OK');
-			
+			assert.strictEqual(regex.init("", "a.b", "s").code, ErrorCodes.OK);
+
 			assert(regex.matchesSingleElement(match.x));
 			assert(regex.matchesSingleElement(matchDotAll.x));
 			assert(!regex.matchesSingleElement(notMatch.x));
@@ -113,23 +116,23 @@ module.exports = {
 		"should match an element with multiple flags": function(){
 			var match = {"x":"\na\nb"};
 			var regex = new RegexMatchExpression();
-			assert.strictEqual(regex.init("", "^a.b", "ms").code, 'OK');
-			
+			assert.strictEqual(regex.init("", "^a.b", "ms").code, ErrorCodes.OK);
+
 			assert(regex.matchesSingleElement(match.x));
 		},
 		"should match an element with type regex": function(){
-			var match = {"x":new XRegExp('yz', 'i')},
-				notMatchPattern = {"x":new XRegExp('r', 'i')},
-				notMatchFlags = {"x":new XRegExp('yz', 's')};
+			var match = {"x":new XRegExp("yz", "i")},
+				notMatchPattern = {"x":new XRegExp("r", "i")},
+				notMatchFlags = {"x":new XRegExp("yz", "s")};
 			var regex = new RegexMatchExpression();
-			assert.strictEqual(regex.init("", "yz", "i").code, 'OK');
-			
+			assert.strictEqual(regex.init("", "yz", "i").code, ErrorCodes.OK);
+
 			assert(regex.matchesSingleElement(match.x));
 			assert(!regex.matchesSingleElement(notMatchPattern.x));
 			assert(!regex.matchesSingleElement(notMatchFlags.x));
 		},
-	
-//skipped as we don't support symbols yet	
+
+//skipped as we don"t support symbols yet
 /*
     TEST( RegexMatchExpression, MatchesElementSymbolType ) {
         BSONObj match = BSONObjBuilder().appendSymbol( "x", "yz" ).obj();
@@ -145,8 +148,8 @@ module.exports = {
 			var notMatchInt = {"x":1},
 				notMatchBool = {"x":true};
 			var regex = new RegexMatchExpression();
-			assert.strictEqual(regex.init("", "1", "").code, 'OK');
-			
+			assert.strictEqual(regex.init("", "1", "").code, ErrorCodes.OK);
+
 			assert(!regex.matchesSingleElement(notMatchInt.x));
 			assert(!regex.matchesSingleElement(notMatchBool.x));
 		},
@@ -154,38 +157,38 @@ module.exports = {
 		"should match an element that is Utf8": function(){
 			var matches = {"x":"\u03A9"};
 			var regex = new RegexMatchExpression();
-			assert.strictEqual(regex.init("", "^.*", "").code, 'OK');
-			
+			assert.strictEqual(regex.init("", "^.*", "").code, ErrorCodes.OK);
+
 			assert(regex.matchesSingleElement(matches.x));
 		},
-		
+
 		"should match an element that is scalar": function(){
 			var regex = new RegexMatchExpression();
-			assert.strictEqual(regex.init("a", "b", "").code, 'OK');
-			
+			assert.strictEqual(regex.init("a", "b", "").code, ErrorCodes.OK);
+
 			assert(regex.matches({"a":"b"}));
 			assert(!regex.matches({"a":"c"}));
 		},
 		"should match an array value": function(){
 			var regex = new RegexMatchExpression();
-			assert.strictEqual(regex.init("a", "b", "").code, 'OK');
-			
+			assert.strictEqual(regex.init("a", "b", "").code, ErrorCodes.OK);
+
 			assert(regex.matches({"a":["c","b"]}));
 			assert(!regex.matches({"a":["d","c"]}));
 		},
 		"should match null": function(){
 			var regex = new RegexMatchExpression();
-			assert.strictEqual(regex.init("a", "b", "").code, 'OK');
-			
+			assert.strictEqual(regex.init("a", "b", "").code, ErrorCodes.OK);
+
 			assert(!regex.matches({}));
 			assert(!regex.matches({"a":null}));
 		},
 		"should match element keys": function(){
 			var regex = new RegexMatchExpression();
-			assert.strictEqual(regex.init("a", "b", "").code, 'OK');
+			assert.strictEqual(regex.init("a", "b", "").code, ErrorCodes.OK);
 			var details = new MatchDetails();
 			details.requestElemMatchKey();
-			
+
 			assert(!regex.matches({"a":"c"}, details));
 			assert(!details.hasElemMatchKey());
 			assert(regex.matches({"a":"b"}, details));
@@ -199,11 +202,11 @@ module.exports = {
 				r2 = new RegexMatchExpression(),
 				r3 = new RegexMatchExpression(),
 				r4 = new RegexMatchExpression();
-			assert.strictEqual(r1.init("a", "b", "").code, 'OK');
-			assert.strictEqual(r2.init("a", "b", "x").code, 'OK');
-			assert.strictEqual(r3.init("a", "c", "").code, 'OK');
-			assert.strictEqual(r4.init("b", "b", "").code, 'OK');
-			
+			assert.strictEqual(r1.init("a", "b", "").code, ErrorCodes.OK);
+			assert.strictEqual(r2.init("a", "b", "x").code, ErrorCodes.OK);
+			assert.strictEqual(r3.init("a", "c", "").code, ErrorCodes.OK);
+			assert.strictEqual(r4.init("b", "b", "").code, ErrorCodes.OK);
+
 			assert(r1.equivalent(r1));
 			assert(!r1.equivalent(r2));
 			assert(!r1.equivalent(r3));
@@ -212,5 +215,3 @@ module.exports = {
 
 	}
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);

+ 7 - 8
test/lib/pipeline/matcher/SizeMatchExpression_test.js

@@ -1,5 +1,7 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
+	ErrorCodes = require("../../../../lib/Errors").ErrorCodes,
 	SizeMatchExpression = require("../../../../lib/pipeline/matcher/SizeMatchExpression.js"),
 	MatchDetails = require("../../../../lib/pipeline/matcher/MatchDetails.js");
 
@@ -11,7 +13,7 @@ module.exports = {
 				notMatch={"a":[5]},
 				size = new SizeMatchExpression();
 
-			assert.strictEqual(size.init("", 2).code, 'OK');
+			assert.strictEqual(size.init("", 2).code, ErrorCodes.OK);
 			assert.ok(size.matchesSingleElement(match.a));
 			assert.ok(!size.matchesSingleElement(notMatch.a));
 		},
@@ -23,7 +25,7 @@ module.exports = {
 				arrayValue={"a":[]},
 				size = new SizeMatchExpression();
 
-			assert.strictEqual(size.init("", 0).code, 'OK');
+			assert.strictEqual(size.init("", 0).code, ErrorCodes.OK);
 			assert.ok(!size.matchesSingleElement(stringValue.a));
 			assert.ok(!size.matchesSingleElement(numberValue.a));
 			assert.ok(size.matchesSingleElement(arrayValue.a));
@@ -32,7 +34,7 @@ module.exports = {
 		"Should match an array": function() {
 			var size = new SizeMatchExpression();
 
-			assert.strictEqual(size.init("a", 2).code, 'OK');
+			assert.strictEqual(size.init("a", 2).code, ErrorCodes.OK);
 			assert.ok(size.matches({"a":[4, 5.5]}, null));
 			// Arrays are not unwound to look for matching subarrays.
 			assert.ok(!size.matches({"a":[4, 5.5, [1,2]]}, null));
@@ -41,7 +43,7 @@ module.exports = {
 		"Should match a nested array": function() {
 			var size = new SizeMatchExpression();
 
-			assert.strictEqual(size.init("a.2", 2).code, 'OK');
+			assert.strictEqual(size.init("a.2", 2).code, ErrorCodes.OK);
 			// A numerically referenced nested array is matched.
 			assert.ok(size.matches({"a":[4, 5.5, [1, 2]]}, null));
 		},
@@ -50,7 +52,7 @@ module.exports = {
 			var size = new SizeMatchExpression(),
 				details = new MatchDetails();
 
-			assert.strictEqual(size.init("a.b", 3).code, 'OK');
+			assert.strictEqual(size.init("a.b", 3).code, ErrorCodes.OK);
 			details.requestElemMatchKey();
 			assert.ok(!size.matches({"a":1}, details));
 			assert.ok(!details.hasElemMatchKey());
@@ -76,6 +78,3 @@ module.exports = {
 		}
 	}
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);
-

+ 23 - 25
test/lib/pipeline/matcher/TextMatchExpression_test.js

@@ -1,59 +1,57 @@
 "use strict";
-
-var assert = require('assert'),
-	TextMatchExpression = require('../../../../lib/pipeline/matcher/TextMatchExpression.js'),
-	MatchDetails = require('../../../../lib/pipeline/matcher/MatchDetails.js');
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
+var assert = require("assert"),
+	ErrorCodes = require("../../../../lib/Errors").ErrorCodes,
+	TextMatchExpression = require("../../../../lib/pipeline/matcher/TextMatchExpression");
 
 module.exports = {
-	'TextMatchExpression': {
-		'Should match an element, regardless of what is provided.': function() {
+	"TextMatchExpression": {
+		"Should match an element, regardless of what is provided.": function() {
 			var text = new TextMatchExpression(),
 				text2 = new TextMatchExpression();
 
-			assert.strictEqual(text.init('query', 'language').code, 'OK');
-			assert.strictEqual(text2.init('query2', 'language2').code, 'OK');
+			assert.strictEqual(text.init("query", "language").code, ErrorCodes.OK);
+			assert.strictEqual(text2.init("query2", "language2").code, ErrorCodes.OK);
 
-			assert.ok(text.matchesSingleElement(text2)); // It'll always work. Just the way it is in source.
+			assert.ok(text.matchesSingleElement(text2)); // It"ll always work. Just the way it is in source.
 		},
 
-		'Should return the query provided in the init.': function() {
+		"Should return the query provided in the init.": function() {
 			var text = new TextMatchExpression();
 
-			text.init('query', 'language');
+			text.init("query", "language");
 
-			assert.strictEqual(text.getQuery(), 'query');
+			assert.strictEqual(text.getQuery(), "query");
 		},
 
-		'Should return the language provided in the init.': function() {
+		"Should return the language provided in the init.": function() {
 			var text = new TextMatchExpression();
 
-			text.init('query', 'language');
+			text.init("query", "language");
 
-			assert.strictEqual(text.getLanguage(), 'language');
+			assert.strictEqual(text.getLanguage(), "language");
 		},
 
-		'Should return equivalency.': function() {
+		"Should return equivalency.": function() {
 			var text1 = new TextMatchExpression(),
 				text2 = new TextMatchExpression(),
 				text3 = new TextMatchExpression();
 
-			text1.init('query', 'language');
-			text2.init('query', 'language');
-			text3.init('query2', 'language2');
+			text1.init("query", "language");
+			text2.init("query", "language");
+			text3.init("query2", "language2");
 
 			assert.ok(text1.equivalent(text1));
 			assert.ok(text1.equivalent(text2));
 			assert.ok(!text1.equivalent(text3));
 		},
 
-		'Should return a shallow copy of the original text match expression.': function() {
-			var text1 = new TextMatchExpression(),
-				status = text1.init('query', 'language'),
-				text2 = text1.shallowClone();
+		"Should return a shallow copy of the original text match expression.": function() {
+			var text1 = new TextMatchExpression();
+			text1.init("query", "language");
+			var text2 = text1.shallowClone();
 
 			assert.ok(text1.equivalent(text2));
 		}
 	}
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);

+ 40 - 40
test/lib/pipeline/matcher/TypeMatchExpression_test.js

@@ -1,75 +1,77 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
+	ErrorCodes = require("../../../../lib/Errors").ErrorCodes,
 	MatchDetails = require("../../../../lib/pipeline/matcher/MatchDetails"),
 	TypeMatchExpression = require("../../../../lib/pipeline/matcher/TypeMatchExpression");
 
 
 module.exports = {
-	'TypeMatchExpression': {
-		'Should match string type.': function () {
+	"TypeMatchExpression": {
+		"Should match string type.": function () {
 			var e = new TypeMatchExpression();
 
-			assert.strictEqual(e.init('', 2).code, 'OK');
+			assert.strictEqual(e.init("", 2).code, ErrorCodes.OK);
 
-			assert.ok(e.matches('abc'));
+			assert.ok(e.matches("abc"));
 			assert.ok(! e.matches(2));
 		},
 
-		'Should match null type.': function () {
+		"Should match null type.": function () {
 			var e = new TypeMatchExpression();
 
-			assert.strictEqual(e.init('', 10).code, 'OK');
+			assert.strictEqual(e.init("", 10).code, ErrorCodes.OK);
 
 			assert.ok(e.matches(null));
 			assert.ok(!e.matches(10));
 		},
 
-		'Should match unknown type.': function () {
+		"Should match unknown type.": function () {
 			var e = new TypeMatchExpression();
 
-			assert.strictEqual(e.init('', 1024).code, 'OK');
+			assert.strictEqual(e.init("", 1024).code, ErrorCodes.OK);
 
 			assert.ok(!e.matches(1024));
-			assert.ok(!e.matches('abc'));
+			assert.ok(!e.matches("abc"));
 		},
 
-		'Should match bool type.': function () {
+		"Should match bool type.": function () {
 			var e = new TypeMatchExpression();
 
-			assert.strictEqual(e.init('', 8).code, 'OK');
+			assert.strictEqual(e.init("", 8).code, ErrorCodes.OK);
 
 			assert.ok(e.matches(true));
 			assert.ok(!e.matches(8));
 		},
 
-		'Should match number type.': function () {
+		"Should match number type.": function () {
 			var e = new TypeMatchExpression();
-			var s = e.init('a',1 );
+			e.init("a", 1);
 
-			assert.strictEqual(e.init('a', 1).code, 'OK');
+			assert.strictEqual(e.init("a", 1).code, ErrorCodes.OK);
 
-			assert.ok(e.matches({'a':[4]}));
-			assert.ok(e.matches({'a':[4, 'a']}));
-			assert.ok(e.matches({'a':['a', 4]}));
-			assert.ok(!e.matches({'a':['a']}));
-			assert.ok(!e.matches({'a':[[4]]}));
+			assert.ok(e.matches({"a":[4]}));
+			assert.ok(e.matches({"a":[4, "a"]}));
+			assert.ok(e.matches({"a":["a", 4]}));
+			assert.ok(!e.matches({"a":["a"]}));
+			assert.ok(!e.matches({"a":[[4]]}));
 
 		},
 
-		'Should match array type.': function () {
+		"Should match array type.": function () {
 			var e = new TypeMatchExpression();
 
-			assert.strictEqual(e.init('a', 4).code, 'OK');
+			assert.strictEqual(e.init("a", 4).code, ErrorCodes.OK);
 
 			assert.ok(!e.matches({a: []}));
 			assert.ok(e.matches({a: [[2]]}));
-			assert.ok(!e.matches({a: 'bar'}));
+			assert.ok(!e.matches({a: "bar"}));
 		},
 
-		'Should match null type expanded.': function () {
+		"Should match null type expanded.": function () {
 			var e = new TypeMatchExpression();
 
-			assert.strictEqual(e.init('a', 10).code, 'OK');
+			assert.strictEqual(e.init("a", 10).code, ErrorCodes.OK);
 
 			assert.ok(e.matches({a: null}));
 			assert.ok(!e.matches({a: 4}));
@@ -77,38 +79,38 @@ module.exports = {
 
 		},
 
-		'Should match and preserve elemMatchKey.': function () {
+		"Should match and preserve elemMatchKey.": function () {
 			var e = new TypeMatchExpression(),
 				m = new MatchDetails();
 
 			m.requestElemMatchKey();
 
-			assert.strictEqual(e.init('a.b', 2).code, 'OK');
-			
+			assert.strictEqual(e.init("a.b", 2).code, ErrorCodes.OK);
+
 			assert.ok(!e.matches({a: 1}, m));
 			assert.ok(!m.hasElemMatchKey());
-			
-			assert.ok(e.matches({a: {b: 'string'}}, m));
+
+			assert.ok(e.matches({a: {b: "string"}}, m));
 			assert.ok(!m.hasElemMatchKey());
-			
-			assert.ok(e.matches({a: {b: ['string']}}, m));
+
+			assert.ok(e.matches({a: {b: ["string"]}}, m));
 			assert.ok(m.hasElemMatchKey());
-			assert.strictEqual('0', m.elemMatchKey());
+			assert.strictEqual("0", m.elemMatchKey());
 
-			assert.ok(e.matches({a: [2, {b: ['string']}]}, m));
+			assert.ok(e.matches({a: [2, {b: ["string"]}]}, m));
 			assert.ok(m.hasElemMatchKey());
 
-			assert.strictEqual('1', m.elemMatchKey());
+			assert.strictEqual("1", m.elemMatchKey());
 		},
 
-		'Should be equivalent.': function() {
+		"Should be equivalent.": function() {
 			var a = new TypeMatchExpression(),
 				b = new TypeMatchExpression(),
 				c = new TypeMatchExpression();
 
-			assert.strictEqual(a.init('a', 2).code, 'OK');
-			assert.strictEqual(b.init('a', 1).code, 'OK');
-			assert.strictEqual(c.init('b', 2).code, 'OK');
+			assert.strictEqual(a.init("a", 2).code, ErrorCodes.OK);
+			assert.strictEqual(b.init("a", 1).code, ErrorCodes.OK);
+			assert.strictEqual(c.init("b", 2).code, ErrorCodes.OK);
 
 			assert.ok(a.equivalent(a));
 			assert.ok(!a.equivalent(b));
@@ -116,5 +118,3 @@ module.exports = {
 		}
 	}
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);

+ 8 - 9
test/lib/query/ArrayRunner_test.js

@@ -1,4 +1,5 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	Runner = require("../../../lib/query/Runner"),
 	ArrayRunner = require("../../../lib/query/ArrayRunner");
@@ -9,22 +10,22 @@ module.exports = {
 		"#constructor": {
 			"should accept an array of data": function(){
 				assert.doesNotThrow(function(){
-					var ar = new ArrayRunner([1,2,3]);
+					new ArrayRunner([1,2,3]);
 				});
 			},
 			"should fail if not given an array": function(){
 				assert.throws(function(){
-					var ar = new ArrayRunner();
+					new ArrayRunner();
 				});
 				assert.throws(function(){
-					var ar = new ArrayRunner(123);
+					new ArrayRunner(123);
 				});
 			}
 		},
 		"#getNext": {
 			"should return the next item in the array": function(done){
 				var ar = new ArrayRunner([1,2,3]);
-				
+
 				ar.getNext(function(err, out, state){
 					assert.strictEqual(state, Runner.RunnerState.RUNNER_ADVANCED);
 					assert.strictEqual(out, 1);
@@ -41,7 +42,7 @@ module.exports = {
 			},
 			"should return EOF if there is nothing left in the array": function(done){
 				var ar = new ArrayRunner([1]);
-				
+
 				ar.getNext(function(err, out, state){
 					assert.strictEqual(state, Runner.RunnerState.RUNNER_ADVANCED);
 					assert.strictEqual(out, 1);
@@ -72,17 +73,15 @@ module.exports = {
 			"should clear out the runner": function(){
 				var ar = new ArrayRunner([1,2,3]);
 				ar.reset();
-				
+
 				assert.deepEqual(ar.getInfo(true), {
 					"type":"ArrayRunner",
 					"nDocs":0,
 					"position":0,
 					"state": Runner.RunnerState.RUNNER_DEAD
-				});				
+				});
 			}
 		}
 	}
 
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run();

+ 20 - 21
test/lib/query/DocumentSourceRunner_test.js

@@ -1,4 +1,5 @@
 "use strict";
+if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
 var assert = require("assert"),
 	Runner = require("../../../lib/query/Runner"),
 	CursorDocumentSource = require("../../../lib/pipeline/documentSources/CursorDocumentSource"),
@@ -16,30 +17,30 @@ module.exports = {
 				var cds = new CursorDocumentSource(null, new ArrayRunner([]), null),
 					pipeline = [];
 				assert.doesNotThrow(function(){
-					var ar = new DocumentSourceRunner(cds, pipeline);
+					new DocumentSourceRunner(cds, pipeline);
 				});
 			},
 			"should fail if not given a document source or pipeline": function(){
 				var cds = new CursorDocumentSource(null, new ArrayRunner([]), null);
-				
+
 				assert.throws(function(){
-					var ar = new DocumentSourceRunner();
+					new DocumentSourceRunner();
 				});
 				assert.throws(function(){
-					var ar = new DocumentSourceRunner(123);
+					new DocumentSourceRunner(123);
 				});
 				assert.throws(function(){
-					var ar = new DocumentSourceRunner(cds, 123);
+					new DocumentSourceRunner(cds, 123);
 				});
 			},
 			"should coalesce the pipeline into the given documentsource": function(){
 				var cds = new CursorDocumentSource(null, new ArrayRunner([]), null),
 					pipeline = [new LimitDocumentSource(3), new MatchDocumentSource({"a":true})],
 					expected = [{$match:{a:true}}];
-				
-				var ds = new DocumentSourceRunner(cds, pipeline);
+
+				new DocumentSourceRunner(cds, pipeline);
 				var actual = pipeline.map(function(d){return d.serialize();});
-				
+
 				assert.deepEqual(expected, actual);
 			}
 		},
@@ -47,9 +48,9 @@ module.exports = {
 			"should return the next item in the given documentsource": function(done){
 				var cds = new CursorDocumentSource(null, new ArrayRunner([1,2,3]), null),
 					pipeline = [new LimitDocumentSource(3)];
-				
+
 				var ds = new DocumentSourceRunner(cds, pipeline);
-				
+
 				ds.getNext(function(err, out, state){
 					assert.strictEqual(state, Runner.RunnerState.RUNNER_ADVANCED);
 					assert.strictEqual(out, 1);
@@ -67,9 +68,9 @@ module.exports = {
 			"should return EOF if there is nothing left in the given documentsource": function(done){
 				var cds = new CursorDocumentSource(null, new ArrayRunner([1,2,3]), null),
 					pipeline = [new LimitDocumentSource({}, 1)];
-				
+
 				var ds = new DocumentSourceRunner(cds, pipeline);
-				
+
 				ds.getNext(function(err, out, state){
 					assert.strictEqual(state, Runner.RunnerState.RUNNER_ADVANCED);
 					assert.strictEqual(out, 1);
@@ -85,7 +86,7 @@ module.exports = {
 			"should return nothing if explain flag is not set": function(){
 				var cds = new CursorDocumentSource(null, new ArrayRunner([1,2,3]), null),
 					pipeline = [new LimitDocumentSource({}, 1)];
-				
+
 				var ds = new DocumentSourceRunner(cds, pipeline);
 				assert.strictEqual(ds.getInfo(), undefined);
 			},
@@ -93,7 +94,7 @@ module.exports = {
 				var cds = new CursorDocumentSource(null, new ArrayRunner([1,2,3]), null),
 					pipeline = [new LimitDocumentSource({}, 1)];
 				var ds = new DocumentSourceRunner(cds, pipeline);
-				
+
 				assert.deepEqual(ds.getInfo(true), {
 					"type": "DocumentSourceRunner",
 					"docSrc": {
@@ -106,11 +107,11 @@ module.exports = {
 								"type": "ArrayRunner",
 								"nDocs": 3,
 								"position": 0,
-								"state": "RUNNER_ADVANCED"
+								"state": Runner.RunnerState.RUNNER_ADVANCED
 							}
 						}
 					},
-					"state": "RUNNER_ADVANCED"
+					"state": Runner.RunnerState.RUNNER_ADVANCED
 				});
 			}
 		},
@@ -119,7 +120,7 @@ module.exports = {
 				var cds = new CursorDocumentSource(null, new ArrayRunner([1,2,3]), null),
 					pipeline = [new LimitDocumentSource({}, 1)];
 				var ds = new DocumentSourceRunner(cds, pipeline);
-				
+
 				ds.reset();
 				assert.deepEqual(ds.getInfo(true), {
 					"type": "DocumentSourceRunner",
@@ -133,16 +134,14 @@ module.exports = {
 								"type": "ArrayRunner",
 								"nDocs": 0,
 								"position": 0,
-								"state": "RUNNER_DEAD"
+								"state": Runner.RunnerState.RUNNER_DEAD
 							}
 						}
 					},
-					"state": "RUNNER_DEAD"
+					"state": Runner.RunnerState.RUNNER_DEAD
 				});
 			}
 		}
 	}
 
 };
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run();