|
|
@@ -1,59 +1,26 @@
|
|
|
"use strict";
|
|
|
+
|
|
|
var assert = require("assert"),
|
|
|
VariablesParseState = require("../../../../lib/pipeline/expressions/VariablesParseState"),
|
|
|
VariablesIdGenerator = require("../../../../lib/pipeline/expressions/VariablesIdGenerator"),
|
|
|
- NaryExpressionT = require("../../../../lib/pipeline/expressions/NaryExpressionT"),
|
|
|
+ NaryExpression = require("../../../../lib/pipeline/expressions/NaryExpression"),
|
|
|
ConstantExpression = require("../../../../lib/pipeline/expressions/ConstantExpression"),
|
|
|
FieldPathExpression = require("../../../../lib/pipeline/expressions/FieldPathExpression"),
|
|
|
- Expression = require("../../../../lib/pipeline/expressions/Expression");
|
|
|
-
|
|
|
-function constify(obj, parentIsArray) {
|
|
|
- parentIsArray = !parentIsArray ? false : true;
|
|
|
- var bob = parentIsArray ? [] : {};
|
|
|
- Object.keys(obj).forEach(function(key) {
|
|
|
- var elem = obj[key];
|
|
|
- if(elem.constructor === Object) {
|
|
|
- bob[key] = constify(elem, false);
|
|
|
- }
|
|
|
- else if(elem.constructor === Array && !parentIsArray) {
|
|
|
- bob[key] = constify(elem, true);
|
|
|
- }
|
|
|
- else if(key === "$const" ||
|
|
|
- elem.constructor === String && elem[0] === '$') {
|
|
|
- bob[key] = obj[key];
|
|
|
- }
|
|
|
- else {
|
|
|
- bob[key] = {$const:obj[key]}
|
|
|
- }
|
|
|
- });
|
|
|
- return bob;
|
|
|
-};
|
|
|
-
|
|
|
-function expressionToJson(expr) {
|
|
|
- return expr.serialize(false);
|
|
|
-};
|
|
|
+ Expression = require("../../../../lib/pipeline/expressions/Expression"),
|
|
|
+ utils = require("./utils");
|
|
|
|
|
|
-function assertDependencies(expectedDeps, expr) {
|
|
|
- var deps = new DepsTracker(),
|
|
|
- depsJson = [];
|
|
|
- expr.addDependencies(deps);
|
|
|
- deps.forEach(function(dep) {
|
|
|
- depsJson.push(dep);
|
|
|
- });
|
|
|
- assert.deepEqual(depsJson, expectedDeps);
|
|
|
- assert.equal(deps.needWholeDocument, false);
|
|
|
- assert.equal(deps.needTextScore, false);
|
|
|
-};
|
|
|
+// 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 TestableExpression = (function(){
|
|
|
- // CONSTRUCTOR
|
|
|
- var klass = function TestableExpression(isAssociativeAndCommutative){
|
|
|
+var Testable = (function(){
|
|
|
+ // CONSTRUCTOR
|
|
|
+ var klass = function Testable(isAssociativeAndCommutative){
|
|
|
this._isAssociativeAndCommutative = isAssociativeAndCommutative;
|
|
|
base.call(this);
|
|
|
- }, base = NaryExpressionT(TestableExpression), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
|
|
|
+ }, base = NaryExpression, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
|
|
|
|
|
|
- // PROTOTYPE MEMBERS
|
|
|
+ // MEMBERS
|
|
|
proto.evaluateInternal = function evaluateInternal(vars) {
|
|
|
// Just put all the values in a list. This is not associative/commutative so
|
|
|
// the results will change if a factory is provided and operations are reordered.
|
|
|
@@ -62,272 +29,212 @@ var TestableExpression = (function(){
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ proto.getOpName = function getOpName() {
|
|
|
+ return "$testable";
|
|
|
+ };
|
|
|
+
|
|
|
proto.isAssociativeAndCommutative = function isAssociativeAndCommutative(){
|
|
|
return this._isAssociativeAndCommutative;
|
|
|
};
|
|
|
|
|
|
klass.create = function create(associativeAndCommutative) {
|
|
|
- associativeAndCommutative = !associativeAndCommutative ? false : true; //NOTE: coercing to bool -- defaults to false
|
|
|
- return new TestableExpression(associativeAndCommutative);
|
|
|
+ return new Testable(!!associativeAndCommutative);
|
|
|
};
|
|
|
|
|
|
klass.factory = function factory() {
|
|
|
- return new TestableExpression(true);
|
|
|
- };
|
|
|
-
|
|
|
- proto.getOpName = function getOpName() {
|
|
|
- return "$testable";
|
|
|
- };
|
|
|
-
|
|
|
- proto.assertContents = function assertContents(expectedContents) {
|
|
|
- assert.deepEqual(constify({$testable:expectedContents}), expressionToJson(this));
|
|
|
+ return new Testable(true);
|
|
|
};
|
|
|
|
|
|
klass.createFromOperands = function(operands, haveFactory) {
|
|
|
- haveFactory = !haveFactory ? false : true; //NOTE: coercing to bool -- defaults to false
|
|
|
- var vps = new VariablesParseState(new VariablesIdGenerator()),
|
|
|
- testable = new TestableExpression(haveFactory);
|
|
|
- operands.forEach(function(x) {
|
|
|
- testable.addOperand(Expression.parseOperand(x, vps));
|
|
|
+ if (haveFactory === undefined) haveFactory = false;
|
|
|
+ var idGenerator = new VariablesIdGenerator(),
|
|
|
+ vps = new VariablesParseState(idGenerator),
|
|
|
+ testable = Testable.create(haveFactory);
|
|
|
+ operands.forEach(function(element) {
|
|
|
+ testable.addOperand(Expression.parseOperand(element, vps));
|
|
|
});
|
|
|
return testable;
|
|
|
};
|
|
|
|
|
|
+ proto.assertContents = function assertContents(expectedContents) {
|
|
|
+ debugger;
|
|
|
+ assert.deepEqual(utils.constify({$testable:expectedContents}), utils.expressionToJson(this));
|
|
|
+ };
|
|
|
+
|
|
|
return klass;
|
|
|
})();
|
|
|
|
|
|
+exports.NaryExpression = {
|
|
|
|
|
|
-module.exports = {
|
|
|
-
|
|
|
- "NaryExpressionT": {
|
|
|
+ ".parseArguments()": {
|
|
|
|
|
|
- "generator": {
|
|
|
-
|
|
|
- "can generate a NaryExpression class": function() {
|
|
|
- assert.doesNotThrow(function() {
|
|
|
- var NaryExpressionClass = NaryExpressionT(String),
|
|
|
- naryEpressionIntance = new NaryExpressionClass();
|
|
|
- });
|
|
|
- }
|
|
|
+ "should parse a fieldPathExpression": function() {
|
|
|
+ var vps = new VariablesParseState(new VariablesIdGenerator()),
|
|
|
+ parsedArguments = NaryExpression.parseArguments("$field.path.expression", vps);
|
|
|
+ assert.equal(parsedArguments.length, 1);
|
|
|
+ assert(parsedArguments[0] instanceof FieldPathExpression);
|
|
|
+ },
|
|
|
|
|
|
- }
|
|
|
+ "should parse an array of fieldPathExpressions": function() {
|
|
|
+ var vps = new VariablesParseState(new VariablesIdGenerator()),
|
|
|
+ parsedArguments = NaryExpression.parseArguments(["$field.path.expression", "$another.FPE"], vps);
|
|
|
+ assert.equal(parsedArguments.length, 2);
|
|
|
+ assert(parsedArguments[0] instanceof FieldPathExpression);
|
|
|
+ assert(parsedArguments[1] instanceof FieldPathExpression);
|
|
|
+ },
|
|
|
|
|
|
},
|
|
|
|
|
|
- "NaryExpression": {
|
|
|
-
|
|
|
- "statics": {
|
|
|
-
|
|
|
- "parseArguments":{
|
|
|
-
|
|
|
- "should parse a fieldPathExpression": function parsesFieldPathExpression() {
|
|
|
- var NaryExpressionClass = NaryExpressionT(String),
|
|
|
- vps = new VariablesParseState(new VariablesIdGenerator()),
|
|
|
- parsedArguments = NaryExpressionClass.parseArguments("$field.path.expression", vps);
|
|
|
- assert.equal(parsedArguments.length, 1);
|
|
|
- assert(parsedArguments[0] instanceof FieldPathExpression);
|
|
|
- },
|
|
|
+ /** Adding operands to the expression. */
|
|
|
+ "AddOperand": function testAddOperand() {
|
|
|
+ var testable = Testable.create();
|
|
|
+ testable.addOperand(new ConstantExpression(9));
|
|
|
+ testable.assertContents([9]);
|
|
|
+ testable.addOperand(new FieldPathExpression("ab.c"));
|
|
|
+ testable.assertContents([9, "$ab.c"]); //NOTE: Broken, not sure if problem with assertConents or FPE serialize
|
|
|
+ },
|
|
|
|
|
|
- "should parse an array of fieldPathExpressions": function parsesFieldPathExpression() {
|
|
|
- var NaryExpressionClass = NaryExpressionT(String),
|
|
|
- vps = new VariablesParseState(new VariablesIdGenerator()),
|
|
|
- parsedArguments = NaryExpressionClass.parseArguments(["$field.path.expression", "$another.FPE"], vps);
|
|
|
- assert.equal(parsedArguments.length, 2);
|
|
|
- assert(parsedArguments[0] instanceof FieldPathExpression);
|
|
|
- assert(parsedArguments[1] instanceof FieldPathExpression);
|
|
|
- }
|
|
|
- }
|
|
|
+ /** Dependencies of the expression. */
|
|
|
+ "Dependencies": function testDependencies() {
|
|
|
+ var testable = Testable.create();
|
|
|
+
|
|
|
+ var assertDependencies = function assertDependencies(expectedDeps, expr) {
|
|
|
+ var deps = new DepsTracker(),
|
|
|
+ depsJson = [];
|
|
|
+ expr.addDependencies(deps);
|
|
|
+ deps.forEach(function(dep) {
|
|
|
+ depsJson.push(dep);
|
|
|
+ });
|
|
|
+ assert.deepEqual(depsJson, expectedDeps);
|
|
|
+ assert.equal(deps.needWholeDocument, false);
|
|
|
+ assert.equal(deps.needTextScore, false);
|
|
|
+ };
|
|
|
+
|
|
|
+ // No arguments.
|
|
|
+ assertDependencies([], testable);
|
|
|
+
|
|
|
+ // Add a constant argument.
|
|
|
+ testable.addOperand(new ConstantExpression(1));
|
|
|
+ assertDependencies([], testable);
|
|
|
+
|
|
|
+ // Add a field path argument.
|
|
|
+ testable.addOperand(new FieldPathExpression("ab.c"));
|
|
|
+ assertDependencies(["ab.c"], testable);
|
|
|
+
|
|
|
+ // Add an object expression.
|
|
|
+ var spec = {a:"$x", q:"$r"},
|
|
|
+ specElement = spec,
|
|
|
+ ctx = new Expression.ObjectCtx({isDocumentOk:true}),
|
|
|
+ vps = new VariablesParseState(new VariablesIdGenerator());
|
|
|
+ testable.addOperand(Expression.parseObject(specElement, ctx, vps));
|
|
|
+ assertDependencies(["ab.c", "r", "x"]);
|
|
|
+ },
|
|
|
|
|
|
- },
|
|
|
+ /** Serialize to an object. */
|
|
|
+ "AddToJsonObj": function testAddToJsonObj() {
|
|
|
+ var testable = Testable.create();
|
|
|
+ testable.addOperand(new ConstantExpression(5));
|
|
|
+ assert.deepEqual(
|
|
|
+ {foo:{$testable:[{$const:5}]}},
|
|
|
+ {foo:testable.serialize(false)}
|
|
|
+ );
|
|
|
+ },
|
|
|
|
|
|
- "addOperand": {
|
|
|
- "run" : function run() {
|
|
|
- var testable = new TestableExpression.create();
|
|
|
- testable.addOperand(new ConstantExpression(9));
|
|
|
- debugger;
|
|
|
- testable.assertContents([9]);
|
|
|
- testable.addOperand(new FieldPathExpression("ab.c"));
|
|
|
- testable.assertContents([9, "$ab.c"]); //NOTE: Broken, not sure if problem with assertConents or FPE serialize
|
|
|
- }
|
|
|
- },
|
|
|
+ /** Serialize to an array. */
|
|
|
+ "AddToJsonArray": function testAddToJsonArray() {
|
|
|
+ var testable = Testable.create();
|
|
|
+ testable.addOperand(new ConstantExpression(5));
|
|
|
+ assert.deepEqual(
|
|
|
+ [{$testable:[{$const:5}]}],
|
|
|
+ [testable.serialize(false)]
|
|
|
+ );
|
|
|
+ },
|
|
|
|
|
|
- "Dependencies": {
|
|
|
- "run": function run() {
|
|
|
- var testable = new TestableExpression.create();
|
|
|
-
|
|
|
- // No arguments.
|
|
|
- assertDependencies([], testable);
|
|
|
-
|
|
|
- // Add a constant argument.
|
|
|
- testable.addOperand(new ConstantExpression(1));
|
|
|
- assertDependencies([], testable);
|
|
|
-
|
|
|
- // Add a field path argument.
|
|
|
- testable.addOperand(new FieldPathExpression("ab.c"));
|
|
|
- assertDependencies(["ab.c"], testable);
|
|
|
-
|
|
|
- // Add an object expression.
|
|
|
- var spec = {a:"$x", q:"$r"},
|
|
|
- specElement = spec,
|
|
|
- ctx = new Expression.ObjectCtx({isDocumentOk:true}),
|
|
|
- vps = new VariablesParseState(new VariablesIdGenerator());
|
|
|
- testable.addOperand(Expression.parseObject(specElement, ctx, vps));
|
|
|
- assertDependencies(["ab.c", "r", "x"]);
|
|
|
- }
|
|
|
- },
|
|
|
+ /** One operand is optimized to a constant, while another is left as is. */
|
|
|
+ "OptimizeOneOperand": function testOptimizeOneOperand() {
|
|
|
+ var spec = [{$and:[]},"$abc"],
|
|
|
+ testable = Testable.createFromOperands(spec);
|
|
|
+ testable.assertContents(spec);
|
|
|
+ assert.deepEqual(testable.serialize(), testable.optimize().serialize());
|
|
|
+ testable.assertContents([true, "$abc"]);
|
|
|
+ },
|
|
|
|
|
|
- "AddToJsonObj": {
|
|
|
- "run": function run() {
|
|
|
- var testable = new TestableExpression.create();
|
|
|
- testable.addOperand(new ConstantExpression(5));
|
|
|
- assert.deepEqual(
|
|
|
- {foo:{$testable:[{$const:5}]}},
|
|
|
- {foo:testable.serialize(false)}
|
|
|
- );
|
|
|
- }
|
|
|
- },
|
|
|
+ /** All operands are constants, and the operator is evaluated with them. */
|
|
|
+ "EvaluateAllConstantOperands": function testEvaluateAllConstantOperands() {
|
|
|
+ var spec = [1,2],
|
|
|
+ testable = Testable.createFromOperands(spec);
|
|
|
+ testable.assertContents(spec);
|
|
|
+ var optimized = testable.optimize();
|
|
|
+ assert.notDeepEqual(testable.serialize(), optimized.serialize());
|
|
|
+ assert.deepEqual({$const:[1,2]}, utils.expressionToJson(optimized));
|
|
|
+ },
|
|
|
|
|
|
- "AddToJsonArray": {
|
|
|
- "run": function run() {
|
|
|
- var testable = new TestableExpression.create();
|
|
|
- testable.addOperand(new ConstantExpression(5));
|
|
|
- assert.deepEqual(
|
|
|
- [{$testable:[{$const:5}]}],
|
|
|
- [testable.serialize(false)]
|
|
|
- );
|
|
|
- }
|
|
|
- },
|
|
|
+ "NoFactoryOptimize": {
|
|
|
+ // Without factory optimization, optimization will not produce a new expression.
|
|
|
|
|
|
- "OptimizeOneOperand": {
|
|
|
- "run": function run() {
|
|
|
- var spec = [{$and:[]},"$abc"],
|
|
|
- testable = TestableExpression.createFromOperands(spec);
|
|
|
- testable.assertContents(spec);
|
|
|
- assert.deepEqual(testable.serialize(), testable.optimize().serialize());
|
|
|
- assertContents([true, "$abc"])
|
|
|
- }
|
|
|
+ /** A string constant prevents factory optimization. */
|
|
|
+ "StringConstant": function testStringConstant() {
|
|
|
+ var testable = Testable.createFromOperands(["abc","def","$path"], true);
|
|
|
+ assert.deepEqual(testable.serialize(), testable.optimize().serialize());
|
|
|
},
|
|
|
|
|
|
- "EvaluateAllConstantOperands": {
|
|
|
- "run": function run() {
|
|
|
- var spec = [1,2],
|
|
|
- testable = TestableExpression.createFromOperands(spec);
|
|
|
- testable.assertContents(spec);
|
|
|
- var optimized = testable.optimize();
|
|
|
- assert.notDeepEqual(testable.serialize(), optimized.serialize());
|
|
|
- assert.deepEqual({$const:[1,2]}, expressionToJson(optimized));
|
|
|
- }
|
|
|
+ /** A single (instead of multiple) constant prevents optimization. SERVER-6192 */
|
|
|
+ "SingleConstant": function testSingleConstant() {
|
|
|
+ var testable = Testable.createFromOperands([55,"$path"], true);
|
|
|
+ assert.deepEqual(testable.serialize(), testable.optimize().serialize());
|
|
|
},
|
|
|
|
|
|
- "NoFactoryOptimize": {
|
|
|
- // Without factory optimization, optimization will not produce a new expression.
|
|
|
-
|
|
|
- /** A string constant prevents factory optimization. */
|
|
|
- "StringConstant": function run() {
|
|
|
- var testable = TestableExpression.createFromOperands(["abc","def","$path"], true);
|
|
|
- assert.deepEqual(testable.serialize(), testable.optimize().serialize());
|
|
|
- },
|
|
|
-
|
|
|
- /** A single (instead of multiple) constant prevents optimization. SERVER-6192 */
|
|
|
- "SingleConstant": function run() {
|
|
|
- var testable = TestableExpression.createFromOperands([55,"$path"], true);
|
|
|
- assert.deepEqual(testable.serialize(), testable.optimize().serialize());
|
|
|
- },
|
|
|
-
|
|
|
- /** Factory optimization is not used without a factory. */
|
|
|
- "NoFactory": function run() {
|
|
|
- var testable = TestableExpression.createFromOperands([55,66,"$path"], false);
|
|
|
- assert.deepEqual(testable.serialize(), testable.optimize().serialize());
|
|
|
- }
|
|
|
+ /** Factory optimization is not used without a factory. */
|
|
|
+ "NoFactory": function testNoFactory() {
|
|
|
+ var testable = Testable.createFromOperands([55,66,"$path"], false);
|
|
|
+ assert.deepEqual(testable.serialize(), testable.optimize().serialize());
|
|
|
},
|
|
|
|
|
|
- /** Factory optimization separates constant from non constant expressions. */
|
|
|
- "FactoryOptimize": {
|
|
|
+ },
|
|
|
|
|
|
- // The constant expressions are evaluated separately and placed at the end.
|
|
|
- "run": function run() {
|
|
|
- var testable = TestableExpression.createFromOperands([55,66,"$path"], false),
|
|
|
- optimized = testable.optimize();
|
|
|
- assert.deepEqual({$testable:["$path", [55,66]]}, expressionToJson(optimized));
|
|
|
- }
|
|
|
- },
|
|
|
+ /** Factory optimization separates constant from non constant expressions. */
|
|
|
+ "FactoryOptimize": function testFactoryOptimize() {
|
|
|
+ // The constant expressions are evaluated separately and placed at the end.
|
|
|
+ var testable = Testable.createFromOperands([55,66,"$path"], false),
|
|
|
+ optimized = testable.optimize();
|
|
|
+ assert.deepEqual({$testable:["$path", [55,66]]}, utils.expressionToJson(optimized));
|
|
|
+ },
|
|
|
|
|
|
- /** Factory optimization flattens nested operators of the same type. */
|
|
|
- "FlattenOptimize": {
|
|
|
- "run": function run() {
|
|
|
- var testable = TestableExpression.createFromOperands(
|
|
|
- [55,"$path",{$add:[5,6,"$q"]},66],
|
|
|
- true);
|
|
|
- testable.addOperand(Testable.createFromOperands(
|
|
|
- [99,100,"$another_path"],
|
|
|
- true));
|
|
|
- var optimized = testable.optimize();
|
|
|
- assert.deepEqual(
|
|
|
- constify({$testable:[
|
|
|
- "$path",
|
|
|
- {$add:["$q", 11]},
|
|
|
- "$another_path",
|
|
|
- [55, 66, [99, 100]]
|
|
|
- ]}),
|
|
|
- expressionToJson(optimized));
|
|
|
- }
|
|
|
- },
|
|
|
+ /** Factory optimization flattens nested operators of the same type. */
|
|
|
+ "FlattenOptimize": function testFlattenOptimize() {
|
|
|
+ var testable = Testable.createFromOperands(
|
|
|
+ [55,"$path",{$add:[5,6,"$q"]},66],
|
|
|
+ true);
|
|
|
+ testable.addOperand(Testable.createFromOperands(
|
|
|
+ [99,100,"$another_path"],
|
|
|
+ true));
|
|
|
+ var optimized = testable.optimize();
|
|
|
+ assert.deepEqual(
|
|
|
+ utils.constify({$testable:[
|
|
|
+ "$path",
|
|
|
+ {$add:["$q", 11]},
|
|
|
+ "$another_path",
|
|
|
+ [55, 66, [99, 100]]
|
|
|
+ ]}),
|
|
|
+ utils.expressionToJson(optimized));
|
|
|
+ },
|
|
|
|
|
|
- /** Three layers of factory optimization are flattened. */
|
|
|
- "FlattenThreeLayers": {
|
|
|
- "run": function run() {
|
|
|
- var top = TestableExpression.createFromOperands([1,2,"$a"], true),
|
|
|
- nested = TestableExpression.createFromOperands([3,4,"$b"], true);
|
|
|
- nested.addOperand(TestableExpression.createFromOperands([5,6,"$c"],true));
|
|
|
- top.addOperand(nested);
|
|
|
- var optimized = top.optimize();
|
|
|
- assert.deepEqual(
|
|
|
- constify({$testable:[
|
|
|
- "$a",
|
|
|
- "$b",
|
|
|
- "$c",
|
|
|
- [1,2,[3,4,[5,6]]]]}),
|
|
|
- expressionToJson(optimized));
|
|
|
- }
|
|
|
- },
|
|
|
+ /** Three layers of factory optimization are flattened. */
|
|
|
+ "FlattenThreeLayers": function testFlattenThreeLayers() {
|
|
|
+ var top = Testable.createFromOperands([1,2,"$a"], true),
|
|
|
+ nested = Testable.createFromOperands([3,4,"$b"], true);
|
|
|
+ nested.addOperand(Testable.createFromOperands([5,6,"$c"],true));
|
|
|
+ top.addOperand(nested);
|
|
|
+ var optimized = top.optimize();
|
|
|
+ assert.deepEqual(
|
|
|
+ utils.constify({$testable:[
|
|
|
+ "$a",
|
|
|
+ "$b",
|
|
|
+ "$c",
|
|
|
+ [1,2,[3,4,[5,6]]]]}),
|
|
|
+ utils.expressionToJson(optimized));
|
|
|
+ },
|
|
|
|
|
|
- "constify": {
|
|
|
- "simple": function simple() {
|
|
|
- var obj = {a:'s'},
|
|
|
- constified = constify(obj);
|
|
|
- assert.deepEqual(constified, { a: { '$const': 's' } });
|
|
|
- },
|
|
|
- "array": function array() {
|
|
|
- var obj = {a:['s']},
|
|
|
- constified = constify(obj);
|
|
|
- assert.deepEqual(constified, { a: [ { '$const': 's' } ] });
|
|
|
- },
|
|
|
- "array2": function array2() {
|
|
|
- var obj = {a:['s', [5], {a:5}]},
|
|
|
- constified = constify(obj);
|
|
|
- assert.deepEqual(constified,
|
|
|
- { a:
|
|
|
- [{ '$const': 's' },
|
|
|
- { '$const': [ 5 ] },
|
|
|
- { a: { '$const': 5 } }]
|
|
|
- });
|
|
|
- },
|
|
|
- "object": function object() {
|
|
|
- var obj = {a:{b:{c:5}, d:'hi'}},
|
|
|
- constified = constify(obj);
|
|
|
- assert.deepEqual(constified,
|
|
|
- { a:
|
|
|
- { b: { c: { '$const': 5 } },
|
|
|
- d: { '$const': 'hi' } } });
|
|
|
- },
|
|
|
- "fieldPathExpression": function fieldPathExpression() {
|
|
|
- var obj = {a:"$field.path"},
|
|
|
- constified = constify(obj);
|
|
|
- assert.deepEqual(constified, obj);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
};
|
|
|
|
|
|
if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);
|