|
|
@@ -5,28 +5,27 @@ var assert = require("assert"),
|
|
|
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));
|
|
|
+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()": {
|
|
|
|
|
|
- "should accept one argument": function() {
|
|
|
+ "should accept one argument": function () {
|
|
|
new ConstantExpression(5);
|
|
|
},
|
|
|
|
|
|
- "should not accept 0 arguments": function() {
|
|
|
- assert.throws(function() {
|
|
|
- new ConstantExpression();
|
|
|
+ "should not accept 0 arguments": function () {
|
|
|
+ assert.throws(function () {
|
|
|
+ new ConstantExpression();
|
|
|
});
|
|
|
},
|
|
|
|
|
|
- "should not accept 2 arguments": function() {
|
|
|
- assert.throws(function() {
|
|
|
+ "should not accept 2 arguments": function () {
|
|
|
+ assert.throws(function () {
|
|
|
new ConstantExpression(1, 2);
|
|
|
});
|
|
|
- },
|
|
|
-
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
".parse()": {
|
|
|
@@ -36,18 +35,15 @@ exports.ConstantExpression = {
|
|
|
vps = new VariablesParseState(idGenerator),
|
|
|
expression = ConstantExpression.parse("foo", vps);
|
|
|
assert.deepEqual("foo", expression.evaluate({}));
|
|
|
- },
|
|
|
-
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
".create()": {
|
|
|
|
|
|
"should create an expression": function testCreate() {
|
|
|
assert(ConstantExpression.create() instanceof ConstantExpression);
|
|
|
- },
|
|
|
-
|
|
|
+ }
|
|
|
//SKIPPED: testCreateFronBsonElement
|
|
|
-
|
|
|
},
|
|
|
|
|
|
"#optimize()": {
|
|
|
@@ -55,8 +51,7 @@ exports.ConstantExpression = {
|
|
|
"should not optimize anything": function testOptimize() {
|
|
|
var expr = new ConstantExpression(5);
|
|
|
assert.strictEqual(expr, expr.optimize());
|
|
|
- },
|
|
|
-
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
"#addDependencies()": {
|
|
|
@@ -68,8 +63,7 @@ exports.ConstantExpression = {
|
|
|
assert.strictEqual(deps.fields.length, 0);
|
|
|
assert.strictEqual(deps.needWholeDocument, false);
|
|
|
assert.strictEqual(deps.needTextScore, false);
|
|
|
- },
|
|
|
-
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
//TODO: AddToBsonObj
|
|
|
@@ -78,30 +72,28 @@ exports.ConstantExpression = {
|
|
|
|
|
|
"#evaluate()": {
|
|
|
|
|
|
- "should do what comes natural with an int": function() {
|
|
|
+ "should do what comes natural with an int": function () {
|
|
|
var c = 567;
|
|
|
var expr = new ConstantExpression(c);
|
|
|
assert.deepEqual(expr.evaluate(), c);
|
|
|
},
|
|
|
|
|
|
- "should do what comes natural with a float": function() {
|
|
|
+ "should do what comes natural with a float": function () {
|
|
|
var c = 567.123;
|
|
|
var expr = new ConstantExpression(c);
|
|
|
assert.deepEqual(expr.evaluate(), c);
|
|
|
},
|
|
|
|
|
|
- "should do what comes natural with a String": function() {
|
|
|
+ "should do what comes natural with a String": function () {
|
|
|
var c = "Quoth the raven";
|
|
|
var expr = new ConstantExpression(c);
|
|
|
assert.deepEqual(expr.evaluate(), c);
|
|
|
},
|
|
|
|
|
|
- "should do what comes natural with a date": function() {
|
|
|
+ "should do what comes natural with a date": function () {
|
|
|
var c = new Date();
|
|
|
var expr = new ConstantExpression(c);
|
|
|
assert.deepEqual(expr.evaluate(), c);
|
|
|
- },
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
+ }
|
|
|
+ }
|
|
|
};
|