summaryrefslogtreecommitdiff
path: root/AK/Tests
diff options
context:
space:
mode:
authorasynts <asynts@gmail.com>2020-10-07 14:01:59 +0200
committerAndreas Kling <kling@serenityos.org>2020-10-08 09:59:55 +0200
commit2217d6b560d9030d66259f5b0feb292d5e515cff (patch)
treead7ae097e5b06d0329c856c3d800ac63d1b9ee50 /AK/Tests
parentafef05ece2f878e95fd5dc678710c06b60c8c459 (diff)
downloadserenity-2217d6b560d9030d66259f5b0feb292d5e515cff.zip
AK+Format: Add SFINAE wrapper 'FormatIfSupported'.
Diffstat (limited to 'AK/Tests')
-rw-r--r--AK/Tests/TestFormat.cpp18
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)