diff options
author | Abseil Team <absl-team@google.com> | 2022-11-09 17:53:22 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2022-11-09 17:54:00 -0800 |
commit | db8cd47898082fa47bff41fd76575630132669d3 (patch) | |
tree | 9c6f17975c359eaea397e1b2329045690ec1156d /absl/strings/str_format_test.cc | |
parent | 1687dbf814eceb93de2d93f91b31acaab404091c (diff) |
Add support for enum types with AbslStringify
PiperOrigin-RevId: 487394692
Change-Id: I55e9b57055483dc921e9773c3643ea9be4f9bdf6
Diffstat (limited to 'absl/strings/str_format_test.cc')
-rw-r--r-- | absl/strings/str_format_test.cc | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/absl/strings/str_format_test.cc b/absl/strings/str_format_test.cc index 62ed262d..2aa22b0d 100644 --- a/absl/strings/str_format_test.cc +++ b/absl/strings/str_format_test.cc @@ -1135,6 +1135,18 @@ TEST_F(FormatExtensionTest, AbslStringifyExampleUsingFormat) { EXPECT_EQ(absl::StrFormat("a %v z", p), "a (10, 20) z"); } +enum class EnumWithStringify { Many = 0, Choices = 1 }; + +template <typename Sink> +void AbslStringify(Sink& sink, EnumWithStringify e) { + absl::Format(&sink, "%s", e == EnumWithStringify::Many ? "Many" : "Choices"); +} + +TEST_F(FormatExtensionTest, AbslStringifyWithEnum) { + const auto e = EnumWithStringify::Choices; + EXPECT_EQ(absl::StrFormat("My choice is %v", e), "My choice is Choices"); +} + } // namespace // Some codegen thunks that we can use to easily dump the generated assembly for |