summaryrefslogtreecommitdiff
path: root/src/mongo/base/string_data_test.cpp
diff options
context:
space:
mode:
authorJason Carey <jcarey@argv.me>2016-05-10 14:17:00 -0400
committerJason Carey <jcarey@argv.me>2016-06-17 17:56:11 -0400
commit907182f4672ab2dcea1e16da5366518a4e44fa8d (patch)
treeb74d4d9f97a3797b409db0f428ac05462501fa73 /src/mongo/base/string_data_test.cpp
parent737d557b1729d8d6c2892832b75630f045787ec1 (diff)
downloadmongo-907182f4672ab2dcea1e16da5366518a4e44fa8d.tar.gz
SERVER-24651 Add and use string data literals
Replace StringData("foo", StringData::LiteralTag()) with "foo"_sd
Diffstat (limited to 'src/mongo/base/string_data_test.cpp')
-rw-r--r--src/mongo/base/string_data_test.cpp34
1 files changed, 21 insertions, 13 deletions
diff --git a/src/mongo/base/string_data_test.cpp b/src/mongo/base/string_data_test.cpp
index 5dc19df3dd8..2c5e6c4019f 100644
--- a/src/mongo/base/string_data_test.cpp
+++ b/src/mongo/base/string_data_test.cpp
@@ -33,9 +33,8 @@
#include "mongo/base/string_data.h"
#include "mongo/unittest/unittest.h"
-namespace {
+namespace mongo {
-using mongo::StringData;
using std::string;
TEST(Construction, Empty) {
@@ -65,10 +64,22 @@ TEST(Construction, FromNullCString) {
ASSERT_TRUE(strData.rawData() == NULL);
}
-TEST(Construction, FromLiteral) {
- StringData strData("ccc", StringData::LiteralTag());
- ASSERT_EQUALS(strData.size(), 3U);
- ASSERT_EQUALS(strData.toString(), string("ccc"));
+TEST(Construction, FromUserDefinedLiteral) {
+ const auto strData = "cc\0c"_sd;
+ ASSERT_EQUALS(strData.size(), 4U);
+ ASSERT_EQUALS(strData.toString(), string("cc\0c", 4));
+}
+
+TEST(Construction, FromUserDefinedRawLiteral) {
+ const auto strData = R"("")"_sd;
+ ASSERT_EQUALS(strData.size(), 2U);
+ ASSERT_EQUALS(strData.toString(), string("\"\"", 2));
+}
+
+TEST(Construction, FromEmptyUserDefinedLiteral) {
+ const auto strData = ""_sd;
+ ASSERT_EQUALS(strData.size(), 0U);
+ ASSERT_EQUALS(strData.toString(), string(""));
}
TEST(Comparison, BothEmpty) {
@@ -266,8 +277,7 @@ TEST(EndsWith, Simple) {
TEST(ConstIterator, StdCopy) {
std::vector<char> chars;
- const char rawData[] = "This is some raw data.";
- StringData data(rawData, StringData::LiteralTag());
+ auto data = "This is some raw data."_sd;
chars.resize(data.size());
std::copy(data.begin(), data.end(), chars.begin());
@@ -279,8 +289,7 @@ TEST(ConstIterator, StdCopy) {
TEST(ConstIterator, StdReverseCopy) {
std::vector<char> chars;
- const char rawData[] = "This is some raw data.";
- StringData data(rawData, StringData::LiteralTag());
+ auto data = "This is some raw data."_sd;
chars.resize(data.size());
std::reverse_copy(data.begin(), data.end(), chars.begin());
@@ -294,8 +303,7 @@ TEST(ConstIterator, StdReverseCopy) {
TEST(ConstIterator, StdReplaceCopy) {
std::vector<char> chars;
- const char rawData[] = "This is some raw data.";
- StringData data(rawData, StringData::LiteralTag());
+ auto data = "This is some raw data."_sd;
chars.resize(data.size());
std::replace_copy(data.begin(), data.end(), chars.begin(), ' ', '_');
@@ -307,4 +315,4 @@ TEST(ConstIterator, StdReplaceCopy) {
}
}
-} // unnamed namespace
+} // namespace mongo