summaryrefslogtreecommitdiff
path: root/src/mongo/bson/bson_obj_test.cpp
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2015-02-13 15:55:47 -0500
committerMathias Stearn <mathias@10gen.com>2015-03-27 14:32:37 -0400
commitcfce87ebbb36f2acf63eb5a29f6aec95a55e3866 (patch)
tree1af4e2f8311205526f838b9ebaffc448dcb2ad06 /src/mongo/bson/bson_obj_test.cpp
parentcafa5d7815509e5ce4fa65f4def89cf18e087bcf (diff)
downloadmongo-cfce87ebbb36f2acf63eb5a29f6aec95a55e3866.tar.gz
Support C++11 range-based for loops over BSONObj
Diffstat (limited to 'src/mongo/bson/bson_obj_test.cpp')
-rw-r--r--src/mongo/bson/bson_obj_test.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/mongo/bson/bson_obj_test.cpp b/src/mongo/bson/bson_obj_test.cpp
index 443700f037d..6befb751760 100644
--- a/src/mongo/bson/bson_obj_test.cpp
+++ b/src/mongo/bson/bson_obj_test.cpp
@@ -31,6 +31,7 @@
#include "mongo/unittest/unittest.h"
namespace {
+ using namespace mongo;
TEST(BSONObjToString, EmptyArray) {
const char text[] = "{ x: [] }";
@@ -182,4 +183,24 @@ namespace {
}
}
+ TEST(Looping, Cpp11Basic) {
+ int count = 0;
+ for (BSONElement e : BSON("a" << 1 << "a" << 2 << "a" << 3)) {
+ ASSERT_EQUALS( e.fieldNameStringData() , "a" );
+ count += e.Int();
+ }
+
+ ASSERT_EQUALS( count , 1 + 2 + 3 );
+ }
+
+ TEST(Looping, Cpp11Auto) {
+ int count = 0;
+ for (auto e : BSON("a" << 1 << "a" << 2 << "a" << 3)) {
+ ASSERT_EQUALS( e.fieldNameStringData() , "a" );
+ count += e.Int();
+ }
+
+ ASSERT_EQUALS( count , 1 + 2 + 3 );
+ }
+
} // unnamed namespace