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:
parent
afef05ece2
commit
2217d6b560
2 changed files with 61 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue