diff options
author | asynts <asynts@gmail.com> | 2020-10-07 14:01:59 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-10-08 09:59:55 +0200 |
commit | 2217d6b560d9030d66259f5b0feb292d5e515cff (patch) | |
tree | ad7ae097e5b06d0329c856c3d800ac63d1b9ee50 /AK/Tests | |
parent | afef05ece2f878e95fd5dc678710c06b60c8c459 (diff) | |
download | serenity-2217d6b560d9030d66259f5b0feb292d5e515cff.zip |
AK+Format: Add SFINAE wrapper 'FormatIfSupported'.
Diffstat (limited to 'AK/Tests')
-rw-r--r-- | AK/Tests/TestFormat.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/AK/Tests/TestFormat.cpp b/AK/Tests/TestFormat.cpp index 0e7e9aae6a..7d426fb4e1 100644 --- a/AK/Tests/TestFormat.cpp +++ b/AK/Tests/TestFormat.cpp @@ -196,4 +196,22 @@ TEST_CASE(format_character) EXPECT_EQ(String::formatted("{}", true ? a : 'b'), "a"); } +struct A { +}; +struct B { +}; +template<> +struct AK::Formatter<B> : Formatter<StringView> { + void format(TypeErasedFormatParams& params, FormatBuilder& builder, B) + { + Formatter<StringView>::format(params, builder, "B"); + } +}; + +TEST_CASE(format_if_supported) +{ + EXPECT_EQ(String::formatted("{}", FormatIfSupported { A {} }), "?"); + EXPECT_EQ(String::formatted("{}", FormatIfSupported { B {} }), "B"); +} + TEST_MAIN(Format) |