Generalize Join to work for any container/element.
This is more scalable than explicitly instantiating templates for the
cross product of containers and element types.
Specifically I'm adding this so I can join an unordered_set in adb.
Change-Id: I0055f3390a0ff26a886a0d41bbf0d4fe3d210f9c
diff --git a/strings_test.cpp b/strings_test.cpp
index 46a1ab5..5f67575 100644
--- a/strings_test.cpp
+++ b/strings_test.cpp
@@ -20,6 +20,8 @@
#include <string>
#include <vector>
+#include <set>
+#include <unordered_set>
TEST(strings, split_empty) {
std::vector<std::string> parts = android::base::Split("", ",");
@@ -121,6 +123,17 @@
ASSERT_EQ(",,,", android::base::Join(list, ','));
}
+TEST(strings, join_simple_ints) {
+ std::set<int> list = {1, 2, 3};
+ ASSERT_EQ("1,2,3", android::base::Join(list, ','));
+}
+
+TEST(strings, join_unordered_set) {
+ std::unordered_set<int> list = {1, 2};
+ ASSERT_TRUE("1,2" == android::base::Join(list, ',') ||
+ "2,1" == android::base::Join(list, ','));
+}
+
TEST(strings, startswith_empty) {
ASSERT_FALSE(android::base::StartsWith("", "foo"));
ASSERT_TRUE(android::base::StartsWith("", ""));