From cec7355d9fe2e24ccb1d82913034eebcc6c0e974 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tomasz=20Kami=C5=84ski?= Date: Thu, 12 Jun 2025 16:36:15 +0200 Subject: [PATCH] libstdc++: Test chrono-spec containing only whitespaces. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit libstdc++-v3/ChangeLog: * testsuite/std/time/format/whitespace.cc: New test. Reviewed-by: Jonathan Wakely Signed-off-by: Tomasz Kamiński --- .../testsuite/std/time/format/whitespace.cc | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 libstdc++-v3/testsuite/std/time/format/whitespace.cc 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 +} -- 2.47.2