summaryrefslogtreecommitdiff
path: root/src/mongo/base/string_data_test.cpp
diff options
context:
space:
mode:
authorEric Daniels <eric.daniels@10gen.com>2013-07-23 14:42:55 -0400
committerAndrew Morrow <acm@10gen.com>2013-07-29 10:38:17 -0400
commit0240a87080bb00b273900d965c13731f931f624d (patch)
treec8f530fe3adc028ce4c6a9f9bedb0559b06c9e2e /src/mongo/base/string_data_test.cpp
parent1a072fc6cce47088804db327d98d4c56d5416450 (diff)
downloadmongo-0240a87080bb00b273900d965c13731f931f624d.tar.gz
Added const_iterator to StringData. Supports all operations that a const char* can support
Signed-off-by: Andrew Morrow <acm@10gen.com>
Diffstat (limited to 'src/mongo/base/string_data_test.cpp')
-rw-r--r--src/mongo/base/string_data_test.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/mongo/base/string_data_test.cpp b/src/mongo/base/string_data_test.cpp
index bbd40011002..dbab573fe08 100644
--- a/src/mongo/base/string_data_test.cpp
+++ b/src/mongo/base/string_data_test.cpp
@@ -14,7 +14,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <algorithm>
#include <string>
+#include <vector>
#include "mongo/base/string_data.h"
#include "mongo/unittest/unittest.h"
@@ -224,4 +226,47 @@ namespace {
ASSERT(!StringData("abcde").substr(0, 3).endsWith("cde"));
}
+ TEST(ConstIterator, StdCopy) {
+ std::vector<char> chars;
+ const char rawData[] = "This is some raw data.";
+ StringData data(rawData, StringData::LiteralTag());
+
+ chars.resize(data.size());
+ std::copy(data.begin(), data.end(), chars.begin());
+
+ for (size_t i = 0; i < data.size(); ++i) {
+ ASSERT_EQUALS(data[i], chars[i]);
+ }
+ }
+
+ TEST(ConstIterator, StdReverseCopy) {
+ std::vector<char> chars;
+ const char rawData[] = "This is some raw data.";
+ StringData data(rawData, StringData::LiteralTag());
+
+ chars.resize(data.size());
+ std::reverse_copy(data.begin(), data.end(), chars.begin());
+
+ const char rawDataExpected[] = ".atad war emos si sihT";
+
+ for (size_t i = 0; i < data.size(); ++i) {
+ ASSERT_EQUALS(rawDataExpected[i], chars[i]);
+ }
+ }
+
+ TEST(ConstIterator, StdReplaceCopy) {
+ std::vector<char> chars;
+ const char rawData[] = "This is some raw data.";
+ StringData data(rawData, StringData::LiteralTag());
+
+ chars.resize(data.size());
+ std::replace_copy(data.begin(), data.end(), chars.begin(), ' ', '_');
+
+ const char rawDataExpected[] = "This_is_some_raw_data.";
+
+ for (size_t i = 0; i < data.size(); ++i) {
+ ASSERT_EQUALS(rawDataExpected[i], chars[i]);
+ }
+ }
+
} // unnamed namespace