mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:17:35 +00:00
AK: Add Formatter<FormatString> as helper class.
This commit is contained in:
parent
9a842ec419
commit
1160817a9e
13 changed files with 64 additions and 94 deletions
|
@ -274,4 +274,20 @@ TEST_CASE(format_nullptr)
|
|||
EXPECT_EQ(String::formatted("{}", nullptr), String::formatted("{:p}", static_cast<FlatPtr>(0)));
|
||||
}
|
||||
|
||||
struct C {
|
||||
int i;
|
||||
};
|
||||
template<>
|
||||
struct AK::Formatter<C> : AK::Formatter<FormatString> {
|
||||
void format(FormatBuilder& builder, C c)
|
||||
{
|
||||
return AK::Formatter<FormatString>::format(builder, "C(i={})", c.i);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_CASE(use_format_string_formatter)
|
||||
{
|
||||
EXPECT_EQ(String::formatted("{:*<10}", C { 42 }), "C(i=42)***");
|
||||
}
|
||||
|
||||
TEST_MAIN(Format)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue