[PATCH] libstdc++: Test for formatting with empty spec for local_info and sys_info.
Tomasz Kamiński
tkaminsk@redhat.com
Thu Jun 5 14:39:42 GMT 2025
We do not test with wchar_t currently, as operator<< (and format) are
ill-formed in such case, because we do not widen abbrev member of local_info.
Adding a tests for behavior of the ostream operator and the formatting
with empty chrono-spec for the chrono types. The coverage is now
complete:
* sys_info, local_info in this commit,
* time point, zoned_time and local_time_format in r16-1107-g3cfa53aa95a19c,
* duration and hh_mm_ss in r16-1099-gac0a04b7a254fb,
* calendar types in r16-1016-g28a17985dd34b7.
Finally, the timeout for the test was increased again.
libstdc++-v3/ChangeLog:
* testsuite/std/time/format/empty_spec.cc: New tests and increased
timeout.
---
Testing on x86_64 linux? OK for trunk?
I have now full implementation or decoupling operator<<, where sys_info
just ues opereator<<. However, I think I will fix the wchar_t handling
first, by using std format with local_time_format and printing abbrev as '%Z', which
will use preexisting widening. This way may refactor patches would not
have functional changes.
Should I create a bugzilla for lack of `wchar_t`?
.../testsuite/std/time/format/empty_spec.cc | 103 +++++++++++++++++-
1 file changed, 102 insertions(+), 1 deletion(-)
diff --git a/libstdc++-v3/testsuite/std/time/format/empty_spec.cc b/libstdc++-v3/testsuite/std/time/format/empty_spec.cc
index 48f61ee13e4..4598fd1237c 100644
--- a/libstdc++-v3/testsuite/std/time/format/empty_spec.cc
+++ b/libstdc++-v3/testsuite/std/time/format/empty_spec.cc
@@ -1,6 +1,6 @@
// { dg-do run { target c++20 } }
// { dg-require-effective-target hosted }
-// { dg-timeout-factor 2 }
+// { dg-timeout-factor 4 }
#include <chrono>
#include <ranges>
@@ -732,6 +732,106 @@ test_time_points()
test_no_empty_spec<CharT, sys_time<duration<float>>>();
}
+template<typename _CharT>
+void
+test_sys_info()
+{
+ const sys_info si
+ {
+ sys_days(2024y/March/22) + 2h,
+ sys_days(2025y/April/11) + 23h + 15min + 10s,
+ 2h + 13min + 4s,
+ 15min,
+ "Zone"
+ };
+ const std::basic_string_view<_CharT> txt
+ = WIDEN("[2024-03-22 02:00:00,2025-04-11 23:15:10,02:13:04,15min,Zone]");
+
+ verify( si, txt );
+
+ std::basic_string<_CharT> res;
+ std::basic_string_view<_CharT> sv;
+
+ sv = res = std::format(WIDEN("{:65}"), si);
+ VERIFY( sv.ends_with(WIDEN(" ")) );
+ sv.remove_suffix(4);
+ VERIFY( sv == txt );
+
+ sv = res = std::format(WIDEN("{:=^67}"), si);
+ VERIFY( sv.starts_with(WIDEN("===")) );
+ VERIFY( sv.ends_with(WIDEN("===")) );
+ sv.remove_prefix(3);
+ sv.remove_suffix(3);
+ VERIFY( sv == txt );
+}
+
+template<typename _CharT>
+void test_local_info()
+{
+ using String = std::basic_string<_CharT>;
+ using StringView = std::basic_string_view<_CharT>;
+
+ const sys_info s1
+ {
+ sys_days(2015y/September/11) + 2h,
+ sys_days(2016y/March/13) + 2h,
+ -5h,
+ 0h,
+ "EET"
+ };
+ const sys_info s2
+ {
+ sys_days(2016y/March/13) + 2h,
+ sys_days(2015y/September/15) + 2h,
+ -4h,
+ 1h,
+ "EDT"
+ };
+
+ const StringView single
+ = WIDEN("[2015-09-11 02:00:00,2016-03-13 02:00:00,-05:00:00,0min,EET]");
+ const StringView both
+ = WIDEN(" local time between "
+ "[2015-09-11 02:00:00,2016-03-13 02:00:00,-05:00:00,0min,EET]"
+ " and "
+ "[2016-03-13 02:00:00,2015-09-15 02:00:00,-04:00:00,60min,EDT]");
+
+ const local_info l1{local_info::nonexistent, s1, s2};
+ auto exp = WIDEN("[nonexistent") + String(both) + WIDEN("]");
+ verify( l1, StringView(exp) );
+
+ const local_info l2{local_info::ambiguous, s1, s2};
+ exp = WIDEN("[ambiguous") + String(both) + WIDEN("]");
+ verify( l2, StringView(exp) );
+
+ const local_info l3{local_info::unique, s1, s1};
+ exp = WIDEN("[") + String(single) + WIDEN("]");
+ verify( l3, StringView(exp) );
+
+ String res;
+ StringView sv;
+
+ sv = res = std::format(WIDEN("{:65}"), l3);
+ VERIFY( sv.ends_with(WIDEN(" ")) );
+ sv.remove_suffix(3);
+ VERIFY( sv == exp );
+
+ sv = res = std::format(WIDEN("{:=^67}"), l3);
+ VERIFY( sv.starts_with(WIDEN("==")) );
+ VERIFY( sv.ends_with(WIDEN("===")) );
+ sv.remove_prefix(2);
+ sv.remove_suffix(3);
+ VERIFY( sv == exp );
+}
+
+template<typename CharT>
+void
+test_infos()
+{
+ test_sys_info<CharT>();
+ test_local_info<CharT>();
+}
+
template<typename CharT>
void
test_all()
@@ -745,6 +845,7 @@ test_all()
int main()
{
test_all<char>();
+ test_infos<char>();
#ifdef _GLIBCXX_USE_WCHAR_T
test_all<wchar_t>();
--
2.49.0
More information about the Libstdc++
mailing list