summaryrefslogtreecommitdiffstats
path: root/base/strings_test.cpp
diff options
context:
space:
mode:
authorDan Albert <danalbert@google.com>2015-03-19 13:24:26 -0700
committerDan Albert <danalbert@google.com>2015-03-23 10:23:11 -0700
commit47328c96d91ca71b57b8976df2df1fe51579a955 (patch)
tree149e519906cb870b960e7e48facd7222a7ec7232 /base/strings_test.cpp
parentd69a1c502e11d3be052d9c0bb20f0c7762428925 (diff)
downloadsystem_core-47328c96d91ca71b57b8976df2df1fe51579a955.zip
system_core-47328c96d91ca71b57b8976df2df1fe51579a955.tar.gz
system_core-47328c96d91ca71b57b8976df2df1fe51579a955.tar.bz2
Update string Split API.
Return a new vector rather than appending to the parameter. Delimiters are also a string rather than a character. Split on any character in the string. Change-Id: I039b332ace5578590df9e7ca0e8fa3db28db30a3
Diffstat (limited to 'base/strings_test.cpp')
-rw-r--r--base/strings_test.cpp35
1 files changed, 27 insertions, 8 deletions
diff --git a/base/strings_test.cpp b/base/strings_test.cpp
index 824598d..1bf07a1 100644
--- a/base/strings_test.cpp
+++ b/base/strings_test.cpp
@@ -22,21 +22,18 @@
#include <vector>
TEST(strings, split_empty) {
- std::vector<std::string> parts;
- android::base::Split("", '\0', &parts);
+ std::vector<std::string> parts = android::base::Split("", ",");
ASSERT_EQ(0U, parts.size());
}
TEST(strings, split_single) {
- std::vector<std::string> parts;
- android::base::Split("foo", ',', &parts);
+ std::vector<std::string> parts = android::base::Split("foo", ",");
ASSERT_EQ(1U, parts.size());
ASSERT_EQ("foo", parts[0]);
}
TEST(strings, split_simple) {
- std::vector<std::string> parts;
- android::base::Split("foo,bar,baz", ',', &parts);
+ std::vector<std::string> parts = android::base::Split("foo,bar,baz", ",");
ASSERT_EQ(3U, parts.size());
ASSERT_EQ("foo", parts[0]);
ASSERT_EQ("bar", parts[1]);
@@ -44,8 +41,30 @@ TEST(strings, split_simple) {
}
TEST(strings, split_with_empty_part) {
- std::vector<std::string> parts;
- android::base::Split("foo,,bar", ',', &parts);
+ std::vector<std::string> parts = android::base::Split("foo,,bar", ",");
+ ASSERT_EQ(2U, parts.size());
+ ASSERT_EQ("foo", parts[0]);
+ ASSERT_EQ("bar", parts[1]);
+}
+
+TEST(strings, split_null_char) {
+ std::vector<std::string> parts =
+ android::base::Split(std::string("foo\0bar", 7), std::string("\0", 1));
+ ASSERT_EQ(2U, parts.size());
+ ASSERT_EQ("foo", parts[0]);
+ ASSERT_EQ("bar", parts[1]);
+}
+
+TEST(strings, split_any) {
+ std::vector<std::string> parts = android::base::Split("foo:bar,baz", ",:");
+ ASSERT_EQ(3U, parts.size());
+ ASSERT_EQ("foo", parts[0]);
+ ASSERT_EQ("bar", parts[1]);
+ ASSERT_EQ("baz", parts[2]);
+}
+
+TEST(strings, split_any_with_empty_part) {
+ std::vector<std::string> parts = android::base::Split("foo:,bar", ",:");
ASSERT_EQ(2U, parts.size());
ASSERT_EQ("foo", parts[0]);
ASSERT_EQ("bar", parts[1]);