summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharlie Swanson <charlie.swanson@mongodb.com>2017-01-19 13:15:05 -0500
committerCharlie Swanson <charlie.swanson@mongodb.com>2017-01-20 15:35:07 -0500
commit2c6c114e3952e952de1a395f987f1c5b83d209fe (patch)
treeed7c8bb69f61af42a1ece21fba8dac319ac5c09b
parent32fab3f75af439dc9ef0e95b6107d5bbf7021de4 (diff)
downloadmongo-2c6c114e3952e952de1a395f987f1c5b83d209fe.tar.gz
SERVER-27437 Modernize field_path_test.cpp
-rw-r--r--src/mongo/db/pipeline/field_path_test.cpp200
1 files changed, 65 insertions, 135 deletions
diff --git a/src/mongo/db/pipeline/field_path_test.cpp b/src/mongo/db/pipeline/field_path_test.cpp
index b81b99e7ef6..63e0584def3 100644
--- a/src/mongo/db/pipeline/field_path_test.cpp
+++ b/src/mongo/db/pipeline/field_path_test.cpp
@@ -29,179 +29,109 @@
#include "mongo/platform/basic.h"
#include "mongo/db/pipeline/field_path.h"
-#include "mongo/dbtests/dbtests.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/assert_util.h"
namespace mongo {
-
namespace {
using std::string;
using std::vector;
/** FieldPath constructed from empty string. */
-class Empty {
-public:
- void run() {
- ASSERT_THROWS(FieldPath path(""), UserException);
- }
-};
+TEST(FieldPathTest, Empty) {
+ ASSERT_THROWS(FieldPath path(""), UserException);
+}
/** FieldPath constructed from a simple string (without dots). */
-class Simple {
-public:
- void run() {
- FieldPath path("foo");
- ASSERT_EQUALS(1U, path.getPathLength());
- ASSERT_EQUALS("foo", path.getFieldName(0));
- ASSERT_EQUALS("foo", path.fullPath());
- ASSERT_EQUALS("$foo", path.fullPathWithPrefix());
- }
-};
+TEST(FieldPathTest, Simple) {
+ FieldPath path("foo");
+ ASSERT_EQUALS(1U, path.getPathLength());
+ ASSERT_EQUALS("foo", path.getFieldName(0));
+ ASSERT_EQUALS("foo", path.fullPath());
+ ASSERT_EQUALS("$foo", path.fullPathWithPrefix());
+}
/** FieldPath consisting of a '$' character. */
-class DollarSign {
-public:
- void run() {
- ASSERT_THROWS(FieldPath path("$"), UserException);
- }
-};
+TEST(FieldPathTest, DollarSign) {
+ ASSERT_THROWS(FieldPath path("$"), UserException);
+}
/** FieldPath with a '$' prefix. */
-class DollarSignPrefix {
-public:
- void run() {
- ASSERT_THROWS(FieldPath path("$a"), UserException);
- }
-};
+TEST(FieldPathTest, DollarSignPrefix) {
+ ASSERT_THROWS(FieldPath path("$a"), UserException);
+}
/** FieldPath constructed from a string with one dot. */
-class Dotted {
-public:
- void run() {
- FieldPath path("foo.bar");
- ASSERT_EQUALS(2U, path.getPathLength());
- ASSERT_EQUALS("foo", path.getFieldName(0));
- ASSERT_EQUALS("bar", path.getFieldName(1));
- ASSERT_EQUALS("foo.bar", path.fullPath());
- ASSERT_EQUALS("$foo.bar", path.fullPathWithPrefix());
- }
-};
+TEST(FieldPathTest, Dotted) {
+ FieldPath path("foo.bar");
+ ASSERT_EQUALS(2U, path.getPathLength());
+ ASSERT_EQUALS("foo", path.getFieldName(0));
+ ASSERT_EQUALS("bar", path.getFieldName(1));
+ ASSERT_EQUALS("foo.bar", path.fullPath());
+ ASSERT_EQUALS("$foo.bar", path.fullPathWithPrefix());
+}
/** FieldPath with a '$' prefix in the second field. */
-class DollarSignPrefixSecondField {
-public:
- void run() {
- ASSERT_THROWS(FieldPath path("a.$b"), UserException);
- }
-};
+TEST(FieldPathTest, DollarSignPrefixSecondField) {
+ ASSERT_THROWS(FieldPath path("a.$b"), UserException);
+}
/** FieldPath constructed from a string with two dots. */
-class TwoDotted {
-public:
- void run() {
- FieldPath path("foo.bar.baz");
- ASSERT_EQUALS(3U, path.getPathLength());
- ASSERT_EQUALS("foo", path.getFieldName(0));
- ASSERT_EQUALS("bar", path.getFieldName(1));
- ASSERT_EQUALS("baz", path.getFieldName(2));
- ASSERT_EQUALS("foo.bar.baz", path.fullPath());
- }
-};
+TEST(FieldPathTest, TwoDotted) {
+ FieldPath path("foo.bar.baz");
+ ASSERT_EQUALS(3U, path.getPathLength());
+ ASSERT_EQUALS("foo", path.getFieldName(0));
+ ASSERT_EQUALS("bar", path.getFieldName(1));
+ ASSERT_EQUALS("baz", path.getFieldName(2));
+ ASSERT_EQUALS("foo.bar.baz", path.fullPath());
+}
/** FieldPath constructed from a string ending in a dot. */
-class TerminalDot {
-public:
- void run() {
- ASSERT_THROWS(FieldPath path("foo."), UserException);
- }
-};
+TEST(FieldPathTest, TerminalDot) {
+ ASSERT_THROWS(FieldPath path("foo."), UserException);
+}
/** FieldPath constructed from a string beginning with a dot. */
-class PrefixDot {
-public:
- void run() {
- ASSERT_THROWS(FieldPath path(".foo"), UserException);
- }
-};
+TEST(FieldPathTest, PrefixDot) {
+ ASSERT_THROWS(FieldPath path(".foo"), UserException);
+}
/** FieldPath constructed from a string with adjacent dots. */
-class AdjacentDots {
-public:
- void run() {
- ASSERT_THROWS(FieldPath path("foo..bar"), UserException);
- }
-};
+TEST(FieldPathTest, AdjacentDots) {
+ ASSERT_THROWS(FieldPath path("foo..bar"), UserException);
+}
/** FieldPath constructed with only dots. */
-class OnlyDots {
-public:
- void run() {
- ASSERT_THROWS(FieldPath path("..."), UserException);
- }
-};
+TEST(FieldPathTest, OnlyDots) {
+ ASSERT_THROWS(FieldPath path("..."), UserException);
+}
/** FieldPath constructed from a string with one letter between two dots. */
-class LetterBetweenDots {
-public:
- void run() {
- FieldPath path("foo.a.bar");
- ASSERT_EQUALS(3U, path.getPathLength());
- ASSERT_EQUALS("foo.a.bar", path.fullPath());
- }
-};
+TEST(FieldPathTest, LetterBetweenDots) {
+ FieldPath path("foo.a.bar");
+ ASSERT_EQUALS(3U, path.getPathLength());
+ ASSERT_EQUALS("foo.a.bar", path.fullPath());
+}
/** FieldPath containing a null character. */
-class NullCharacter {
-public:
- void run() {
- ASSERT_THROWS(FieldPath path(string("foo.b\0r", 7)), UserException);
- }
-};
+TEST(FieldPathTest, NullCharacter) {
+ ASSERT_THROWS(FieldPath path(string("foo.b\0r", 7)), UserException);
+}
/** Tail of a FieldPath. */
-class Tail {
-public:
- void run() {
- FieldPath path = FieldPath("foo.bar").tail();
- ASSERT_EQUALS(1U, path.getPathLength());
- ASSERT_EQUALS("bar", path.fullPath());
- }
-};
+TEST(FieldPathTest, Tail) {
+ FieldPath path = FieldPath("foo.bar").tail();
+ ASSERT_EQUALS(1U, path.getPathLength());
+ ASSERT_EQUALS("bar", path.fullPath());
+}
/** Tail of a FieldPath with three fields. */
-class TailThreeFields {
-public:
- void run() {
- FieldPath path = FieldPath("foo.bar.baz").tail();
- ASSERT_EQUALS(2U, path.getPathLength());
- ASSERT_EQUALS("bar.baz", path.fullPath());
- }
-};
-
-class All : public Suite {
-public:
- All() : Suite("field_path") {}
- void setupTests() {
- add<Empty>();
- add<Simple>();
- add<DollarSign>();
- add<DollarSignPrefix>();
- add<Dotted>();
- add<DollarSignPrefixSecondField>();
- add<TwoDotted>();
- add<TerminalDot>();
- add<PrefixDot>();
- add<AdjacentDots>();
- add<OnlyDots>();
- add<LetterBetweenDots>();
- add<NullCharacter>();
- add<Tail>();
- add<TailThreeFields>();
- }
-};
-SuiteInstance<All> myall;
+TEST(FieldPathTest, TailThreeFields) {
+ FieldPath path = FieldPath("foo.bar.baz").tail();
+ ASSERT_EQUALS(2U, path.getPathLength());
+ ASSERT_EQUALS("bar.baz", path.fullPath());
+}
} // namespace
} // namespace mongo