diff --git a/libstdc++-v3/testsuite/std/format/functions/format.cc b/libstdc++-v3/testsuite/std/format/functions/format.cc index b8ad4f1ed29bbd2ac0904941f12270b424f7dec1..d3bac2dbd254a7b207c2b2bd5aad805461d8125c 100644 --- a/libstdc++-v3/testsuite/std/format/functions/format.cc +++ b/libstdc++-v3/testsuite/std/format/functions/format.cc @@ -257,12 +257,42 @@ test_width() } } +void +test_char() +{ + std::string s; + + s = std::format("{}", 'a'); + VERIFY( s == "a" ); + + s = std::format("{:c} {:d} {:o}", 'b', '\x17', '\x3f'); + VERIFY( s == "b 23 77" ); + + s = std::format("{:#d} {:#o}", '\x17', '\x3f'); + VERIFY( s == "23 077" ); + + s = std::format("{:04d} {:04o}", '\x17', '\x3f'); + VERIFY( s == "0023 0077" ); + + s = std::format("{:b} {:B} {:#b} {:#B}", '\xff', '\xa0', '\x17', '\x3f'); + if constexpr (std::is_unsigned_v<char>) + VERIFY( s == "11111111 10100000 0b10111 0B111111" ); + else + VERIFY( s == "-1 -1100000 0b10111 0B111111" ); + + s = std::format("{:x} {:#x} {:#X}", '\x12', '\x34', '\x45'); + VERIFY( s == "12 0x34 0X45" ); +} + void test_wchar() { using namespace std::literals; std::wstring s; + s = std::format(L"{}", L'a'); + VERIFY( s == L"a" ); + s = std::format(L"{} {} {} {} {} {}", L'0', 1, 2LL, 3.4, L"five", L"six"s); VERIFY( s == L"0 1 2 3.4 five six" ); @@ -376,6 +406,9 @@ test_pointer() const void* pc = p; std::string s, str_int; + s = std::format("{}", p); + VERIFY( s == "0x0" ); + s = std::format("{} {} {}", p, pc, nullptr); VERIFY( s == "0x0 0x0 0x0" ); s = std::format("{:p} {:p} {:p}", p, pc, nullptr); @@ -408,6 +441,27 @@ test_pointer() #endif } +void +test_bool() +{ + std::string s; + + s = std::format("{}", true); + VERIFY( s == "true" ); + s = std::format("{:} {:s}", true, false); + VERIFY( s == "true false" ); + s = std::format("{:b} {:#b}", true, false); + VERIFY( s == "1 0b0" ); + s = std::format("{:B} {:#B}", false, true); + VERIFY( s == "0 0B1" ); + s = std::format("{:d} {:#d}", false, true); + VERIFY( s == "0 1" ); + s = std::format("{:o} {:#o} {:#o}", false, true, false); + VERIFY( s == "0 01 0" ); + s = std::format("{:x} {:#x} {:#X}", false, true, false); + VERIFY( s == "0 0x1 0X0" ); +} + int main() { test_no_args(); @@ -416,9 +470,11 @@ int main() test_alternate_forms(); test_locale(); test_width(); + test_char(); test_wchar(); test_minmax(); test_p1652r1(); test_float128(); test_pointer(); + test_bool(); } diff --git a/libstdc++-v3/testsuite/std/format/string.cc b/libstdc++-v3/testsuite/std/format/string.cc index a472f8d588c213c26b7ef79f9c401c3f3634f2fa..d70a23316457fe6d774ac416c9c567469c621e69 100644 --- a/libstdc++-v3/testsuite/std/format/string.cc +++ b/libstdc++-v3/testsuite/std/format/string.cc @@ -110,6 +110,9 @@ test_format_spec() VERIFY( ! is_format_string_for("{:#?}", "str") ); VERIFY( ! is_format_string_for("{:#?}", 'c') ); + VERIFY( ! is_format_string_for("{:0c}", 'c') ); + VERIFY( ! is_format_string_for("{:0s}", true) ); + // Precision only valid for string and floating-point types. VERIFY( ! is_format_string_for("{:.3d}", 1) ); VERIFY( ! is_format_string_for("{:3.3d}", 1) );