summaryrefslogtreecommitdiff
path: root/src/mongo/bson/bsonobjbuilder_test.cpp
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2017-03-14 17:26:40 -0400
committerMathias Stearn <mathias@10gen.com>2017-03-20 18:38:42 -0400
commit20e5b17371591f2a72ee9cd3d9b18a3db8d192c8 (patch)
tree7b755e160c14caac3c0f4a8ce3e1e97b1346ec54 /src/mongo/bson/bsonobjbuilder_test.cpp
parent59b3e96b9d2782f044d1113b05c6268ff2ae221b (diff)
downloadmongo-20e5b17371591f2a72ee9cd3d9b18a3db8d192c8.tar.gz
SERVER-28311 Make BSONObjBuilder returnable
Diffstat (limited to 'src/mongo/bson/bsonobjbuilder_test.cpp')
-rw-r--r--src/mongo/bson/bsonobjbuilder_test.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/mongo/bson/bsonobjbuilder_test.cpp b/src/mongo/bson/bsonobjbuilder_test.cpp
index 003f40c27dd..3cc75b50560 100644
--- a/src/mongo/bson/bsonobjbuilder_test.cpp
+++ b/src/mongo/bson/bsonobjbuilder_test.cpp
@@ -331,5 +331,35 @@ TEST(BSONObjBuilderTest, ResetToEmptyForNestedBuilderOnlyResetsInnerObj) {
ASSERT_BSONOBJ_EQ(BSON("a" << 3 << "nestedObj" << BSONObj()), bob.obj());
}
+TEST(BSONObjBuilderTest, ReturningAnOwningBSONObjBuilderWorks) {
+ BSONObjBuilder bob = ([] {
+ BSONObjBuilder initial;
+ initial.append("a", 1);
+ return initial;
+ })();
+ ASSERT(bob.owned());
+
+ bob.append("b", 2);
+
+ ASSERT_BSONOBJ_EQ(bob.obj(), BSON("a" << 1 << "b" << 2));
+}
+
+TEST(BSONObjBuilderTest, ReturningANonOwningBSONObjBuilderWorks) {
+ BSONObjBuilder outer;
+ {
+ BSONObjBuilder bob = ([&] {
+ BSONObjBuilder initial(outer.subobjStart("nested"));
+ initial.append("a", 1);
+ return initial;
+ })();
+ ASSERT(!bob.owned());
+ ASSERT_EQ(&bob.bb(), &outer.bb());
+
+ bob.append("b", 2);
+ }
+
+ ASSERT_BSONOBJ_EQ(outer.obj(), BSON("nested" << BSON("a" << 1 << "b" << 2)));
+}
+
} // unnamed namespace
} // namespace mongo