Просмотр исходного кода

EAGLESIX-2892 fixed whitespace

Austin Meagher 11 лет назад
Родитель
Сommit
b999404e09
4 измененных файлов с 240 добавлено и 240 удалено
  1. 75 75
      lib/pipeline/DepsTracker.js
  2. 33 33
      lib/pipeline/ParsedDeps.js
  3. 66 66
      test/lib/pipeline/DepsTracker.js
  4. 66 66
      test/lib/pipeline/ParsedDeps.js

+ 75 - 75
lib/pipeline/DepsTracker.js

@@ -9,10 +9,10 @@
  * @constructor
  */
 var DepsTracker = module.exports = function DepsTracker() {
-    /* fields is a set of strings */
-    this.fields = {};
-    this.needWholeDocument = false;
-    this.needTextScore = false;
+	/* fields is a set of strings */
+	this.fields = {};
+	this.needWholeDocument = false;
+	this.needTextScore = false;
 }, klass = DepsTracker, base = Object, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 
 var ParsedDeps = require("./ParsedDeps");
@@ -24,52 +24,52 @@ var ParsedDeps = require("./ParsedDeps");
  * @return {Object} projection of caller's dependencies
  */
 proto.toProjection = function toProjection() {
-    var proj = {};
-
-    // if(this.needTextScore) {
-        // bb.append(Document::metaFieldTextScore, BSON("$meta" << "textScore"));
-    // }
-
-    if (this.needWholeDocument) {
-        return proj;
-    }
-
-    if (Object.keys(this.fields).length === 0) {
-        // Projection language lacks good a way to say no fields needed. This fakes it.
-        proj._id = 0;
-        proj.$noFieldsNeeded = 1;
-        return proj;
-    }
-
-    var last = "",
-        needId = false;
-
-    Object.keys(this.fields).sort().forEach(function (it) {
-        if (it.slice(0,3) == "_id" && (it.length == 3 || it.charAt(3) == ".")) {
-            // _id and subfields are handled specially due in part to SERVER-7502
-            needId = true;
-            return;
-        }
-
-        if (last !== "" && it.slice(0, last.length) === last) {
-            // we are including a parent of *it so we don't need to include this
-            // field explicitly. In fact, due to SERVER-6527 if we included this
-            // field, the parent wouldn't be fully included. This logic relies
-            // on on set iterators going in lexicographic order so that a string
-            // is always directly before of all fields it prefixes.
-            return;
-        }
-
-        last = it + ".";
-        proj[it] = 1;
-    });
-
-    if (needId)
-        proj._id = 1;
-    else
-        proj._id = 0;
-
-    return proj;
+	var proj = {};
+
+	// if(this.needTextScore) {
+		// bb.append(Document::metaFieldTextScore, BSON("$meta" << "textScore"));
+	// }
+
+	if (this.needWholeDocument) {
+		return proj;
+	}
+
+	if (Object.keys(this.fields).length === 0) {
+		// Projection language lacks good a way to say no fields needed. This fakes it.
+		proj._id = 0;
+		proj.$noFieldsNeeded = 1;
+		return proj;
+	}
+
+	var last = "",
+		needId = false;
+
+	Object.keys(this.fields).sort().forEach(function (it) {
+		if (it.slice(0,3) == "_id" && (it.length == 3 || it.charAt(3) == ".")) {
+			// _id and subfields are handled specially due in part to SERVER-7502
+			needId = true;
+			return;
+		}
+
+		if (last !== "" && it.slice(0, last.length) === last) {
+			// we are including a parent of *it so we don't need to include this
+			// field explicitly. In fact, due to SERVER-6527 if we included this
+			// field, the parent wouldn't be fully included. This logic relies
+			// on on set iterators going in lexicographic order so that a string
+			// is always directly before of all fields it prefixes.
+			return;
+		}
+
+		last = it + ".";
+		proj[it] = 1;
+	});
+
+	if (needId)
+		proj._id = 1;
+	else
+		proj._id = 0;
+
+	return proj;
 };
 
 /**
@@ -79,29 +79,29 @@ proto.toProjection = function toProjection() {
  * @return {ParsedDeps}
  */
 proto.toParsedDeps = function toParsedDeps() {
-    var doc = {};
-
-    if(this.needWholeDocument || this.needTextScore) {
-        // can't use ParsedDeps in this case
-        // TODO: not sure what appropriate equivalent to boost::none is
-        return;
-    }
-
-    var last = "";
-    Object.keys(this.fields).sort().forEach(function (it) {
-        if (last !== "" && it.slice(0, last.length) === last) {
-            // we are including a parent of *it so we don't need to include this
-            // field explicitly. In fact, due to SERVER-6527 if we included this
-            // field, the parent wouldn't be fully included. This logic relies
-            // on on set iterators going in lexicographic order so that a string
-            // is always directly before of all fields it prefixes.
-            return;
-        }
-
-        last = it + ".";
-        // TODO: set nested field to true; i.e. a.b.c = true, not a = true
-        doc[it] = true;
-    });
-
-    return new ParsedDeps(doc);
+	var doc = {};
+
+	if(this.needWholeDocument || this.needTextScore) {
+		// can't use ParsedDeps in this case
+		// TODO: not sure what appropriate equivalent to boost::none is
+		return;
+	}
+
+	var last = "";
+	Object.keys(this.fields).sort().forEach(function (it) {
+		if (last !== "" && it.slice(0, last.length) === last) {
+			// we are including a parent of *it so we don't need to include this
+			// field explicitly. In fact, due to SERVER-6527 if we included this
+			// field, the parent wouldn't be fully included. This logic relies
+			// on on set iterators going in lexicographic order so that a string
+			// is always directly before of all fields it prefixes.
+			return;
+		}
+
+		last = it + ".";
+		// TODO: set nested field to true; i.e. a.b.c = true, not a = true
+		doc[it] = true;
+	});
+
+	return new ParsedDeps(doc);
 };

+ 33 - 33
lib/pipeline/ParsedDeps.js

@@ -8,74 +8,74 @@
  * @namespace mungedb-aggregate.pipeline
  * @module mungedb-aggregate
  * @constructor
- * @param {Object} fields    The fields needed in a Document
+ * @param {Object} fields	The fields needed in a Document
  */
 var ParsedDeps = module.exports = function ParsedDeps(fields) {
-    this._fields = fields;
+	this._fields = fields;
 }, klass = ParsedDeps, base = Object, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 
 /**
  * Extracts fields from the input into a new Document, based on the caller.
  *
  * @method extractFields
- * @param {Object} input    The JSON object to extract from
+ * @param {Object} input	The JSON object to extract from
  * @return {Document}
  */
 proto.extractFields = function extractFields(input) {
-    return proto._documentHelper(input, this._fields);
+	return proto._documentHelper(input, this._fields);
 };
 
 /**
  * Private: Handles array-type values for extractFields()
  *
  * @method _arrayHelper
- * @param {Object} array    Array to iterate over
+ * @param {Object} array	Array to iterate over
  * @param {Object} neededFields
  * @return {Array}
  */
 proto._arrayHelper = function _arrayHelper(array, neededFields) {
-    var values = [];
+	var values = [];
 
-    array.sort().forEach(function (it) {
-        if (it instanceof Array)
-            values.push(_arrayHelper(it, neededFields));
-        else if (it instanceof Object)
-            values.push(proto._documentHelper(it, neededFields));
-    });
+	array.sort().forEach(function (it) {
+		if (it instanceof Array)
+			values.push(_arrayHelper(it, neededFields));
+		else if (it instanceof Object)
+			values.push(proto._documentHelper(it, neededFields));
+	});
 
-    return values;
+	return values;
 };
 
 /**
  * Private: Handles object-type values for extractFields()
  *
  * @method _documentHelper
- * @param {Object} json    Object to iterate over and filter
- * @param {Object} neededFields    Fields to not exclude
+ * @param {Object} json	Object to iterate over and filter
+ * @param {Object} neededFields	Fields to not exclude
  * @return {Document}
  */
 proto._documentHelper = function _documentHelper(json, neededFields) {
-    var doc = {};
+	var doc = {};
 
-    Object.keys(json).sort().forEach(function (it) {
-        var jsonElement = json[it],
-            isNeeded = neededFields[it];
+	Object.keys(json).sort().forEach(function (it) {
+		var jsonElement = json[it],
+			isNeeded = neededFields[it];
 
-        if (!isNeeded)
-            return;
+		if (!isNeeded)
+			return;
 
-        if (typeof(isNeeded) === 'boolean') {
-            doc[it] = jsonElement;
-            return;
-        }
+		if (typeof(isNeeded) === 'boolean') {
+			doc[it] = jsonElement;
+			return;
+		}
 
-        if (typeof(isNeeded) === 'object') {
-            if (jsonElement instanceof Array)
-                doc[it] = proto._arrayHelper(jsonElement, isNeeded);
-            if (jsonElement instanceof Object)
-                doc[it] = proto._documentHelper(jsonElement, isNeeded);
-        }
-    });
+		if (typeof(isNeeded) === 'object') {
+			if (jsonElement instanceof Array)
+				doc[it] = proto._arrayHelper(jsonElement, isNeeded);
+			if (jsonElement instanceof Object)
+				doc[it] = proto._documentHelper(jsonElement, isNeeded);
+		}
+	});
 
-    return doc;
+	return doc;
 };

+ 66 - 66
test/lib/pipeline/DepsTracker.js

@@ -1,83 +1,83 @@
 "use strict";
 var assert = require("assert"),
-    DepsTracker = require("../../../lib/pipeline/DepsTracker");
+	DepsTracker = require("../../../lib/pipeline/DepsTracker");
 
 module.exports = {
-    "DepsTracker": {
-        "#toProjection()": {
-            "should be able to convert dependencies to a projection": function(){
-                var deps = new DepsTracker(),
-                    expected = {"_id":0,"a":1,"b":1};
-                deps.fields = {'a':1,'b':1};
+	"DepsTracker": {
+		"#toProjection()": {
+			"should be able to convert dependencies to a projection": function(){
+				var deps = new DepsTracker(),
+					expected = {"_id":0,"a":1,"b":1};
+				deps.fields = {'a':1,'b':1};
 
-                assert.deepEqual(expected, deps.toProjection());
-            },
-            "should be able to convert dependencies with subfields to a projection": function(){
-                var deps = new DepsTracker(),
-                    expected = {"_id":0,"a":1};
-                deps.fields = {'a':1,'a.b':1};
+				assert.deepEqual(expected, deps.toProjection());
+			},
+			"should be able to convert dependencies with subfields to a projection": function(){
+				var deps = new DepsTracker(),
+					expected = {"_id":0,"a":1};
+				deps.fields = {'a':1,'a.b':1};
 
-                assert.deepEqual(expected, deps.toProjection());
-            },
-            "should be able to convert dependencies with _id to a projection": function(){
-                var deps = new DepsTracker(),
-                    expected = {"a":1,"b":1,"_id":1};
-                deps.fields = {"_id":1,'a':1,'b':1};
+				assert.deepEqual(expected, deps.toProjection());
+			},
+			"should be able to convert dependencies with _id to a projection": function(){
+				var deps = new DepsTracker(),
+					expected = {"a":1,"b":1,"_id":1};
+				deps.fields = {"_id":1,'a':1,'b':1};
 
-                assert.deepEqual(expected, deps.toProjection());
-            },
-            "should be able to convert dependencies with id and subfields to a projection": function(){
-                var deps = new DepsTracker(),
-                    expected = {"_id":1,"b":1};
-                deps.fields = {'_id.a':1,'b':1};
+				assert.deepEqual(expected, deps.toProjection());
+			},
+			"should be able to convert dependencies with id and subfields to a projection": function(){
+				var deps = new DepsTracker(),
+					expected = {"_id":1,"b":1};
+				deps.fields = {'_id.a':1,'b':1};
 
-                assert.deepEqual(expected, deps.toProjection());
-            },
-            "should return empty object if needWholeDocument is true": function() {
-                var deps = new DepsTracker(),
-                    expected = {};
-                deps.needWholeDocument = true;
+				assert.deepEqual(expected, deps.toProjection());
+			},
+			"should return empty object if needWholeDocument is true": function() {
+				var deps = new DepsTracker(),
+					expected = {};
+				deps.needWholeDocument = true;
 
-                assert.deepEqual(expected, deps.toProjection());
-            },
-            "should return $noFieldsNeeded if there are no dependencies": function() {
-                var deps = new DepsTracker(),
-                    expected = {"_id":0,"$noFieldsNeeded":1};
+				assert.deepEqual(expected, deps.toProjection());
+			},
+			"should return $noFieldsNeeded if there are no dependencies": function() {
+				var deps = new DepsTracker(),
+					expected = {"_id":0,"$noFieldsNeeded":1};
 
-                assert.deepEqual(expected, deps.toProjection());
-            }
-        },
-        "#toParsedDeps()": {
-            "should not parse if needWholeDocument is true": function() {
-                var deps = new DepsTracker(),
-                    expected;
-                deps.needWholeDocument = true;
+				assert.deepEqual(expected, deps.toProjection());
+			}
+		},
+		"#toParsedDeps()": {
+			"should not parse if needWholeDocument is true": function() {
+				var deps = new DepsTracker(),
+					expected;
+				deps.needWholeDocument = true;
 
-                assert.deepEqual(expected, deps.toParsedDeps());
-            },
-            "should not parse if needTextScore is true": function() {
-                var deps = new DepsTracker(),
-                    expected;
-                deps.needTextScore = true;
+				assert.deepEqual(expected, deps.toParsedDeps());
+			},
+			"should not parse if needTextScore is true": function() {
+				var deps = new DepsTracker(),
+					expected;
+				deps.needTextScore = true;
 
-                assert.deepEqual(expected, deps.toParsedDeps());
-            },
-            "should be able to parse dependencies": function() {
-                var deps = new DepsTracker(),
-                    expected = {"_fields":{"a":true,"b":true}};
-                deps.fields = {'a':1,'b':1};
+				assert.deepEqual(expected, deps.toParsedDeps());
+			},
+			"should be able to parse dependencies": function() {
+				var deps = new DepsTracker(),
+					expected = {"_fields":{"a":true,"b":true}};
+				deps.fields = {'a':1,'b':1};
 
-                assert.deepEqual(expected, deps.toParsedDeps());
-            },
-            "should be able to parse dependencies with subfields": function() {
-                var deps = new DepsTracker(),
-                    expected = {"_fields":{"a.b":true}};
-                deps.fields = {'a.b':1};
+				assert.deepEqual(expected, deps.toParsedDeps());
+			},
+			"should be able to parse dependencies with subfields": function() {
+				var deps = new DepsTracker(),
+					expected = {"_fields":{"a.b":true}};
+				deps.fields = {'a.b':1};
 
-                assert.deepEqual(expected, deps.toParsedDeps());
-            }
-        }
-    }
+				assert.deepEqual(expected, deps.toParsedDeps());
+			}
+		}
+	}
 };
 
 if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run();

+ 66 - 66
test/lib/pipeline/ParsedDeps.js

@@ -1,74 +1,74 @@
 "use strict";
 var assert = require("assert"),
-    ParsedDeps = require("../../../lib/pipeline/ParsedDeps");
+	ParsedDeps = require("../../../lib/pipeline/ParsedDeps");
 
 module.exports = {
-    "ParsedDeps": {
-        "#extractFields": {
-            "should be able to convert a document to its projected form": function() {
-                var deps = {'a': true, 'b': true},
-                    doc = {a:23, b:64, c:92},
-                    parse = new ParsedDeps(deps);
+	"ParsedDeps": {
+		"#extractFields": {
+			"should be able to convert a document to its projected form": function() {
+				var deps = {'a': true, 'b': true},
+					doc = {a:23, b:64, c:92},
+					parse = new ParsedDeps(deps);
 
-                var proj = parse.extractFields(doc);
-                assert.deepEqual({a:23,b:64}, proj);
-            }
-        },
-        "#_documentHelper": {
-            "should skip fields that are not needed": function() {
-                var json = {'foo':'bar'},
-                    neededFields = {},
-                    parse = new ParsedDeps(),
-                    expected = {};
-                assert.deepEqual(expected, parse._documentHelper(json, neededFields));
-            },
-            "should return values that are booleans": function() {
-                var json = {'foo':'bar'},
-                    neededFields = {'foo':true},
-                    parse = new ParsedDeps(),
-                    expected = {'foo':'bar'};
-                assert.deepEqual(expected, parse._documentHelper(json, neededFields));
-            },
-            "should call _arrayHelper on values that are arrays": function() {
-                var json = {'foo':[{'bar':'baz'}]},
-                    neededFields = {'foo':true},
-                    parse = new ParsedDeps(),
-                    expected = {'foo':true};
-                // TODO: mock out _arrayHelper to return true
-                parse._arrayHelper = function() {
-                    return true;
-                };
-                assert.deepEqual(expected, parse._documentHelper(json, neededFields));
-            },
-            "should recurse on values that are objects": function() {
-                var json = {'foo':{'bar':'baz'}},
-                    neededFields = {'foo':true},
-                    parse = new ParsedDeps(),
-                    expected = {'foo':{'bar':'baz'}};
-                assert.deepEqual(expected, parse._documentHelper(json, neededFields));
-            }
-        },
-        "#_arrayHelper": {
-            "should call _documentHelper on values that are objects": function() {
-                var array = [{'foo':'bar'}],
-                    neededFields = {'foo':true},
-                    parse = new ParsedDeps(),
-                    expected = [true];
-                // TODO: mock out _documentHelper to return true
-                parse._documentHelper = function() {
-                    return true;
-                };
-                assert.deepEqual(expected, parse._arrayHelper(array, neededFields));
-            },
-            "should recurse on values that are arrays": function() {
-                var array = [[{'foo':'bar'}]],
-                    neededFields = {'foo':true},
-                    parse = new ParsedDeps(),
-                    expected = [[{'foo':'bar'}]];
-                assert.deepEqual(expected, parse._arrayHelper(array, neededFields));
-            }
-        }
-    }
+				var proj = parse.extractFields(doc);
+				assert.deepEqual({a:23,b:64}, proj);
+			}
+		},
+		"#_documentHelper": {
+			"should skip fields that are not needed": function() {
+				var json = {'foo':'bar'},
+					neededFields = {},
+					parse = new ParsedDeps(),
+					expected = {};
+				assert.deepEqual(expected, parse._documentHelper(json, neededFields));
+			},
+			"should return values that are booleans": function() {
+				var json = {'foo':'bar'},
+					neededFields = {'foo':true},
+					parse = new ParsedDeps(),
+					expected = {'foo':'bar'};
+				assert.deepEqual(expected, parse._documentHelper(json, neededFields));
+			},
+			"should call _arrayHelper on values that are arrays": function() {
+				var json = {'foo':[{'bar':'baz'}]},
+					neededFields = {'foo':true},
+					parse = new ParsedDeps(),
+					expected = {'foo':true};
+				// TODO: mock out _arrayHelper to return true
+				parse._arrayHelper = function() {
+					return true;
+				};
+				assert.deepEqual(expected, parse._documentHelper(json, neededFields));
+			},
+			"should recurse on values that are objects": function() {
+				var json = {'foo':{'bar':'baz'}},
+					neededFields = {'foo':true},
+					parse = new ParsedDeps(),
+					expected = {'foo':{'bar':'baz'}};
+				assert.deepEqual(expected, parse._documentHelper(json, neededFields));
+			}
+		},
+		"#_arrayHelper": {
+			"should call _documentHelper on values that are objects": function() {
+				var array = [{'foo':'bar'}],
+					neededFields = {'foo':true},
+					parse = new ParsedDeps(),
+					expected = [true];
+				// TODO: mock out _documentHelper to return true
+				parse._documentHelper = function() {
+					return true;
+				};
+				assert.deepEqual(expected, parse._arrayHelper(array, neededFields));
+			},
+			"should recurse on values that are arrays": function() {
+				var array = [[{'foo':'bar'}]],
+					neededFields = {'foo':true},
+					parse = new ParsedDeps(),
+					expected = [[{'foo':'bar'}]];
+				assert.deepEqual(expected, parse._arrayHelper(array, neededFields));
+			}
+		}
+	}
 };
 
 if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run();