From: Tomasz Kamiński Date: Thu, 12 Jun 2025 14:36:15 +0000 (+0200) Subject: libstdc++: Test chrono-spec containing only whitespaces. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cec7355d9fe2e24ccb1d82913034eebcc6c0e974;p=thirdparty%2Fgcc.git libstdc++: Test chrono-spec containing only whitespaces. libstdc++-v3/ChangeLog: * testsuite/std/time/format/whitespace.cc: New test. Reviewed-by: Jonathan Wakely Signed-off-by: Tomasz Kamiński --- diff --git a/libstdc++-v3/testsuite/std/time/format/whitespace.cc b/libstdc++-v3/testsuite/std/time/format/whitespace.cc new file mode 100644 index 00000000000..debda08995c --- /dev/null +++ b/libstdc++-v3/testsuite/std/time/format/whitespace.cc @@ -0,0 +1,56 @@ +// { dg-do run { target c++20 } } + +#include +#include + +using namespace std::chrono; + +#define WIDEN_(C, S) ::std::__format::_Widen(S, L##S) +#define WIDEN(S) WIDEN_(_CharT, S) + +template +void +test(const ChronoType& ct) +{ + std::basic_string<_CharT> res; + + res = std::format(WIDEN("{:%% %t %n more text}"), ct); + VERIFY( res == WIDEN("% \t \n more text") ); + + res = std::format(WIDEN("{:7%% %t %n}"), ct); + VERIFY( res == WIDEN("% \t \n ") ); + + res = std::format(WIDEN("{:>6%% %t %n}"), ct); + VERIFY( res == WIDEN(" % \t \n") ); + + res = std::format(WIDEN("{:+>7%% %t %n}"), ct); + VERIFY( res == WIDEN("++% \t \n") ); + + res = std::format(WIDEN("{:=^7%% %t %n}"), ct); + VERIFY( res == WIDEN("=% \t \n=") ); +} + +template +void +test_all() +{ + test(20s); + test(10d); + test(Monday); + test(2020y/January/8); + test(local_days(2020y/January/8)); + test(sys_days(2020y/January/8) + 13h + 10min + 5s); +#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI + test(sys_info()); + test(local_info()); +#endif +} + +int main() +{ + test_all(); + +#ifdef _GLIBCXX_USE_WCHAR_T + test_all(); +#endif // _GLIBCXX_USE_WCHAR_T +}