summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/document_source_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/pipeline/document_source_test.cpp')
-rw-r--r--src/mongo/db/pipeline/document_source_test.cpp70
1 files changed, 42 insertions, 28 deletions
diff --git a/src/mongo/db/pipeline/document_source_test.cpp b/src/mongo/db/pipeline/document_source_test.cpp
index e0c6782883e..b5ed007d1f9 100644
--- a/src/mongo/db/pipeline/document_source_test.cpp
+++ b/src/mongo/db/pipeline/document_source_test.cpp
@@ -40,9 +40,9 @@
#include "mongo/db/storage/storage_options.h"
#include "mongo/dbtests/dbtests.h"
#include "mongo/stdx/memory.h"
+#include "mongo/unittest/temp_dir.h"
#include "mongo/util/clock_source_mock.h"
#include "mongo/util/tick_source_mock.h"
-#include "mongo/unittest/temp_dir.h"
namespace mongo {
bool isMongos() {
@@ -117,7 +117,7 @@ TEST(TruncateSort, TruncateSortDedupsSortCorrectly) {
}
template <size_t ArrayLen>
-set<string> arrayToSet(const char*(&array)[ArrayLen]) {
+set<string> arrayToSet(const char* (&array)[ArrayLen]) {
set<string> out;
for (size_t i = 0; i < ArrayLen; i++)
out.insert(array[i]);
@@ -837,8 +837,9 @@ class TwoValuesTwoKeys : public CheckResultsBase {
virtual BSONObj groupSpec() {
return BSON("_id"
<< "$_id"
- << "a" << BSON("$push"
- << "$a"));
+ << "a"
+ << BSON("$push"
+ << "$a"));
}
virtual string expectedResultSetString() {
return "[{_id:0,a:[1]},{_id:1,a:[2]}]";
@@ -856,8 +857,9 @@ class FourValuesTwoKeys : public CheckResultsBase {
virtual BSONObj groupSpec() {
return BSON("_id"
<< "$id"
- << "a" << BSON("$push"
- << "$a"));
+ << "a"
+ << BSON("$push"
+ << "$a"));
}
virtual string expectedResultSetString() {
return "[{_id:0,a:[1,3]},{_id:1,a:[2,4]}]";
@@ -875,8 +877,10 @@ class FourValuesTwoKeysTwoAccumulators : public CheckResultsBase {
virtual BSONObj groupSpec() {
return BSON("_id"
<< "$id"
- << "list" << BSON("$push"
- << "$a") << "sum"
+ << "list"
+ << BSON("$push"
+ << "$a")
+ << "sum"
<< BSON("$sum" << BSON("$divide" << BSON_ARRAY("$a" << 2))));
}
virtual string expectedResultSetString() {
@@ -892,8 +896,9 @@ class GroupNullUndefinedIds : public CheckResultsBase {
virtual BSONObj groupSpec() {
return BSON("_id"
<< "$a"
- << "sum" << BSON("$sum"
- << "$b"));
+ << "sum"
+ << BSON("$sum"
+ << "$b"));
}
virtual string expectedResultSetString() {
return "[{_id:null,sum:110}]";
@@ -957,8 +962,9 @@ public:
// Create a group source.
createGroup(BSON("_id"
<< "$x"
- << "list" << BSON("$push"
- << "$y")));
+ << "list"
+ << BSON("$push"
+ << "$y")));
// Create a merger version of the source.
intrusive_ptr<DocumentSource> group = createMerger();
// Attach the merger to the synthetic shard results.
@@ -2348,7 +2354,8 @@ private:
void createUnwind(bool preserveNullAndEmptyArrays, bool includeArrayIndex) {
auto specObj =
DOC("$unwind" << DOC("path" << unwindFieldPath() << "preserveNullAndEmptyArrays"
- << preserveNullAndEmptyArrays << "includeArrayIndex"
+ << preserveNullAndEmptyArrays
+ << "includeArrayIndex"
<< (includeArrayIndex ? Value(indexPath()) : Value())));
_unwind = static_cast<DocumentSourceUnwind*>(
DocumentSourceUnwind::createFromBson(specObj.toBson().firstElement(), ctx()).get());
@@ -2396,11 +2403,12 @@ private:
}
BSONObj expectedSerialization(bool preserveNullAndEmptyArrays, bool includeArrayIndex) const {
- return DOC("$unwind" << DOC(
- "path" << Value(unwindFieldPath()) << "preserveNullAndEmptyArrays"
- << (preserveNullAndEmptyArrays ? Value(true) : Value())
- << "includeArrayIndex"
- << (includeArrayIndex ? Value(indexPath()) : Value()))).toBson();
+ return DOC("$unwind" << DOC("path" << Value(unwindFieldPath())
+ << "preserveNullAndEmptyArrays"
+ << (preserveNullAndEmptyArrays ? Value(true) : Value())
+ << "includeArrayIndex"
+ << (includeArrayIndex ? Value(indexPath()) : Value())))
+ .toBson();
}
/** Assert that iterator state accessors consistently report the source is exhausted. */
@@ -2911,7 +2919,8 @@ TEST_F(InvalidUnwindSpec, NonDollarPrefixedPath) {
TEST_F(InvalidUnwindSpec, NonBoolPreserveNullAndEmptyArrays) {
ASSERT_THROWS_CODE(createUnwind(BSON("$unwind" << BSON("path"
<< "$x"
- << "preserveNullAndEmptyArrays" << 2))),
+ << "preserveNullAndEmptyArrays"
+ << 2))),
UserException,
28809);
}
@@ -2919,7 +2928,8 @@ TEST_F(InvalidUnwindSpec, NonBoolPreserveNullAndEmptyArrays) {
TEST_F(InvalidUnwindSpec, NonStringIncludeArrayIndex) {
ASSERT_THROWS_CODE(createUnwind(BSON("$unwind" << BSON("path"
<< "$x"
- << "includeArrayIndex" << 2))),
+ << "includeArrayIndex"
+ << 2))),
UserException,
28810);
}
@@ -2951,13 +2961,16 @@ TEST_F(InvalidUnwindSpec, DollarPrefixedIncludeArrayIndex) {
TEST_F(InvalidUnwindSpec, UnrecognizedOption) {
ASSERT_THROWS_CODE(createUnwind(BSON("$unwind" << BSON("path"
<< "$x"
- << "preserveNullAndEmptyArrays" << true
- << "foo" << 3))),
+ << "preserveNullAndEmptyArrays"
+ << true
+ << "foo"
+ << 3))),
UserException,
28811);
ASSERT_THROWS_CODE(createUnwind(BSON("$unwind" << BSON("path"
<< "$x"
- << "foo" << 3))),
+ << "foo"
+ << 3))),
UserException,
28811);
}
@@ -3306,9 +3319,8 @@ public:
match1->optimizeAt(container.begin(), &container);
ASSERT_EQUALS(container.size(), 1U);
ASSERT_EQUALS(match1->getQuery(),
- fromjson(
- "{'$and': [{'$and': [{a:1}, {b:1}]},"
- "{c:1}]}"));
+ fromjson("{'$and': [{'$and': [{a:1}, {b:1}]},"
+ "{c:1}]}"));
}
};
@@ -3367,7 +3379,8 @@ public:
<< "foreignField"
<< "c"
<< "as"
- << "d.e")).firstElement(),
+ << "d.e"))
+ .firstElement(),
ctx());
lookup->setSource(source.get());
@@ -3391,7 +3404,8 @@ public:
<< "foreignField"
<< "c"
<< "as"
- << "d")).firstElement(),
+ << "d"))
+ .firstElement(),
ctx());
lookup->setSource(source.get());