mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:17:44 +00:00
AK+Format: Accept unsigned long in replacement fields.
I ran into this exact but at least twenty times in Serenity alone. The C++ Standard dictates that 'unsigned long' and 'unsigned long long' are distinct types even though on most platforms they are usually both 64 bit integers. Also it wasn't possible to evaluate IsIntegral<T> for types that were not integers since it used MakeUnsigned<T> internally.
This commit is contained in:
parent
cbe0a8b403
commit
620b73b3d5
3 changed files with 42 additions and 16 deletions
|
@ -29,6 +29,12 @@
|
|||
#include <AK/String.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
|
||||
TEST_CASE(is_integral_works_properly)
|
||||
{
|
||||
EXPECT(!IsIntegral<const char*>::value);
|
||||
EXPECT(IsIntegral<unsigned long>::value);
|
||||
}
|
||||
|
||||
TEST_CASE(format_string_literals)
|
||||
{
|
||||
EXPECT_EQ(String::formatted("prefix-{}-suffix", "abc"), "prefix-abc-suffix");
|
||||
|
@ -124,6 +130,11 @@ TEST_CASE(replacement_field)
|
|||
EXPECT_EQ(String::formatted("{:0{}}", 1, 3), "001");
|
||||
}
|
||||
|
||||
TEST_CASE(replacement_field_regression)
|
||||
{
|
||||
EXPECT_EQ(String::formatted("{:{}}", "", static_cast<unsigned long>(6)), " ");
|
||||
}
|
||||
|
||||
TEST_CASE(complex_string_specifiers)
|
||||
{
|
||||
EXPECT_EQ(String::formatted("{:.8}", "123456789"), "12345678");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue