aboutsummaryrefslogtreecommitdiff
path: root/absl/strings/str_join_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'absl/strings/str_join_test.cc')
-rw-r--r--absl/strings/str_join_test.cc36
1 files changed, 36 insertions, 0 deletions
diff --git a/absl/strings/str_join_test.cc b/absl/strings/str_join_test.cc
index 449f95be..cd52e11d 100644
--- a/absl/strings/str_join_test.cc
+++ b/absl/strings/str_join_test.cc
@@ -428,6 +428,42 @@ TEST(StrJoin, InitializerList) {
}
}
+TEST(StrJoin, StringViewInitializerList) {
+ {
+ // Tests initializer_list of string_views
+ std::string b = "b";
+ EXPECT_EQ("a-b-c", absl::StrJoin({"a", b, "c"}, "-"));
+ }
+ {
+ // Tests initializer_list of string_views with a non-default formatter
+ TestingParenFormatter f;
+ std::string b = "b";
+ EXPECT_EQ("(a)-(b)-(c)", absl::StrJoin({"a", b, "c"}, "-", f));
+ }
+
+ class NoCopy {
+ public:
+ explicit NoCopy(absl::string_view view) : view_(view) {}
+ NoCopy(const NoCopy&) = delete;
+ operator absl::string_view() { return view_; } // NOLINT
+ private:
+ absl::string_view view_;
+ };
+ {
+ // Tests initializer_list of string_views preferred over initializer_list<T>
+ // for T that is implicitly convertible to string_view
+ EXPECT_EQ("a-b-c",
+ absl::StrJoin({NoCopy("a"), NoCopy("b"), NoCopy("c")}, "-"));
+ }
+ {
+ // Tests initializer_list of string_views preferred over initializer_list<T>
+ // for T that is implicitly convertible to string_view
+ TestingParenFormatter f;
+ EXPECT_EQ("(a)-(b)-(c)",
+ absl::StrJoin({NoCopy("a"), NoCopy("b"), NoCopy("c")}, "-", f));
+ }
+}
+
TEST(StrJoin, Tuple) {
EXPECT_EQ("", absl::StrJoin(std::make_tuple(), "-"));
EXPECT_EQ("hello", absl::StrJoin(std::make_tuple("hello"), "-"));