aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomasz Kamiński <tkaminsk@redhat.com>2025-06-12 16:36:15 +0200
committerTomasz Kamiński <tkaminsk@redhat.com>2025-06-13 08:17:27 +0200
commitcec7355d9fe2e24ccb1d82913034eebcc6c0e974 (patch)
tree293fde1958238ef561459136bc341b91c22ccca5
parent59fbc99f8ee35fc1a7bcae4bed3e7bfaec38b538 (diff)
downloadgcc-cec7355d9fe2e24ccb1d82913034eebcc6c0e974.zip
gcc-cec7355d9fe2e24ccb1d82913034eebcc6c0e974.tar.gz
gcc-cec7355d9fe2e24ccb1d82913034eebcc6c0e974.tar.bz2
libstdc++: Test chrono-spec containing only whitespaces.
libstdc++-v3/ChangeLog: * testsuite/std/time/format/whitespace.cc: New test. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
-rw-r--r--libstdc++-v3/testsuite/std/time/format/whitespace.cc56
1 files changed, 56 insertions, 0 deletions
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 0000000..debda08
--- /dev/null
+++ b/libstdc++-v3/testsuite/std/time/format/whitespace.cc
@@ -0,0 +1,56 @@
+// { dg-do run { target c++20 } }
+
+#include <chrono>
+#include <testsuite_hooks.h>
+
+using namespace std::chrono;
+
+#define WIDEN_(C, S) ::std::__format::_Widen<C>(S, L##S)
+#define WIDEN(S) WIDEN_(_CharT, S)
+
+template<typename _CharT, typename ChronoType>
+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<typename CharT>
+void
+test_all()
+{
+ test<CharT>(20s);
+ test<CharT>(10d);
+ test<CharT>(Monday);
+ test<CharT>(2020y/January/8);
+ test<CharT>(local_days(2020y/January/8));
+ test<CharT>(sys_days(2020y/January/8) + 13h + 10min + 5s);
+#if _GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI
+ test<CharT>(sys_info());
+ test<CharT>(local_info());
+#endif
+}
+
+int main()
+{
+ test_all<char>();
+
+#ifdef _GLIBCXX_USE_WCHAR_T
+ test_all<wchar_t>();
+#endif // _GLIBCXX_USE_WCHAR_T
+}