1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 07:07:44 +00:00

AK+Format: Add SFINAE wrapper 'FormatIfSupported'.

This commit is contained in:
asynts 2020-10-07 14:01:59 +02:00 committed by Andreas Kling
parent afef05ece2
commit 2217d6b560
2 changed files with 61 additions and 1 deletions

View file

@ -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)