summaryrefslogtreecommitdiff
path: root/absl/strings/str_cat_test.cc
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2022-09-30 12:11:27 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2022-09-30 12:12:26 -0700
commit7f3c0d781134d25b24e0b55346482a2d366bf59b (patch)
tree922945db62ad94b4aaad106e88454e196a9c1f16 /absl/strings/str_cat_test.cc
parente8304a5c62576cdad9d9265449ab5575115fd4f2 (diff)
Allows absl::StrCat to accept types that implement AbslStringify()
PiperOrigin-RevId: 478050535 Change-Id: I8e4a4b01aceb8d712476101633eac0ce8647823a
Diffstat (limited to 'absl/strings/str_cat_test.cc')
-rw-r--r--absl/strings/str_cat_test.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/absl/strings/str_cat_test.cc b/absl/strings/str_cat_test.cc
index 69df2502..868b9bce 100644
--- a/absl/strings/str_cat_test.cc
+++ b/absl/strings/str_cat_test.cc
@@ -612,4 +612,24 @@ TEST(Numbers, TestFunctionsMovedOverFromNumbersMain) {
TestFastPrints();
}
+struct PointStringify {
+ template <typename FormatSink>
+ friend void AbslStringify(FormatSink& sink, const PointStringify& p) {
+ sink.Append("(");
+ sink.Append(absl::StrCat(p.x));
+ sink.Append(", ");
+ sink.Append(absl::StrCat(p.y));
+ sink.Append(")");
+ }
+
+ double x = 10.0;
+ double y = 20.0;
+};
+
+TEST(StrCat, AbslStringifyExample) {
+ PointStringify p;
+ EXPECT_EQ(absl::StrCat(p), "(10, 20)");
+ EXPECT_EQ(absl::StrCat("a ", p, " z"), "a (10, 20) z");
+}
+
} // namespace