https://gcc.gnu.org/g:1bac0fcd04662138f0a91057914a1be420cb92d5

commit r16-1670-g1bac0fcd04662138f0a91057914a1be420cb92d5
Author: Tomasz KamiƄski <tkami...@redhat.com>
Date:   Tue Jun 24 13:49:26 2025 +0200

    libstdc++: Test for %S precision for durations with integral representation.
    
    Existing test are extented to cover cases where not precision is specified,
    or it is specified to zero. The precision value is ignored in all cases.
    
    libstdc++-v3/ChangeLog:
    
            * testsuite/std/time/format/precision.cc: New tests.

Diff:
---
 .../testsuite/std/time/format/precision.cc         | 104 ++++++++++++++++++++-
 1 file changed, 99 insertions(+), 5 deletions(-)

diff --git a/libstdc++-v3/testsuite/std/time/format/precision.cc 
b/libstdc++-v3/testsuite/std/time/format/precision.cc
index ccb2c77ce05e..aa266156c1ff 100644
--- a/libstdc++-v3/testsuite/std/time/format/precision.cc
+++ b/libstdc++-v3/testsuite/std/time/format/precision.cc
@@ -16,6 +16,10 @@ test_empty()
   std::basic_string<CharT> res;
 
   const duration<double> d(33.111222);
+  res = std::format(WIDEN("{:}"), d);
+  VERIFY( res == WIDEN("33.1112s") );
+  res = std::format(WIDEN("{:.0}"), d);
+  VERIFY( res == WIDEN("33.1112s") );
   res = std::format(WIDEN("{:.3}"), d);
   VERIFY( res == WIDEN("33.1112s") );
   res = std::format(WIDEN("{:.6}"), d);
@@ -25,6 +29,10 @@ test_empty()
 
   // Uses ostream operator<<
   const duration<double, std::nano> nd = d;
+  res = std::format(WIDEN("{:}"), nd);
+  VERIFY( res == WIDEN("3.31112e+10ns") );
+  res = std::format(WIDEN("{:.0}"), nd);
+  VERIFY( res == WIDEN("3.31112e+10ns") );
   res = std::format(WIDEN("{:.3}"), nd);
   VERIFY( res == WIDEN("3.31112e+10ns") );
   res = std::format(WIDEN("{:.6}"), nd);
@@ -40,6 +48,10 @@ test_Q()
   std::basic_string<CharT> res;
 
   const duration<double> d(7.111222);
+  res = std::format(WIDEN("{:%Q}"), d);
+  VERIFY( res == WIDEN("7.111222") );
+  res = std::format(WIDEN("{:.0%Q}"), d);
+  VERIFY( res == WIDEN("7.111222") );
   res = std::format(WIDEN("{:.3%Q}"), d);
   VERIFY( res == WIDEN("7.111222") );
   res = std::format(WIDEN("{:.6%Q}"), d);
@@ -47,7 +59,23 @@ test_Q()
   res = std::format(WIDEN("{:.9%Q}"), d);
   VERIFY( res == WIDEN("7.111222") );
 
+  duration<double, std::milli> md = d;
+  res = std::format(WIDEN("{:%Q}"), md);
+  VERIFY( res == WIDEN("7111.222") );
+  res = std::format(WIDEN("{:.0%Q}"), md);
+  VERIFY( res == WIDEN("7111.222") );
+  res = std::format(WIDEN("{:.3%Q}"), md);
+  VERIFY( res == WIDEN("7111.222") );
+  res = std::format(WIDEN("{:.6%Q}"), md);
+  VERIFY( res == WIDEN("7111.222") );
+  res = std::format(WIDEN("{:.9%Q}"), md);
+  VERIFY( res == WIDEN("7111.222") );
+
   const duration<double, std::nano> nd = d;
+  res = std::format(WIDEN("{:%Q}"), nd);
+  VERIFY( res == WIDEN("7111222000") );
+  res = std::format(WIDEN("{:.0%Q}"), nd);
+  VERIFY( res == WIDEN("7111222000") );
   res = std::format(WIDEN("{:.3%Q}"), nd);
   VERIFY( res == WIDEN("7111222000") );
   res = std::format(WIDEN("{:.6%Q}"), nd);
@@ -58,12 +86,16 @@ test_Q()
 
 template<typename CharT>
 void
-test_S()
+test_S_fp()
 {
   std::basic_string<CharT> res;
 
   // Precision is ignored, but period affects output
-  const duration<double> d(5.111222);
+  duration<double> d(5.111222);
+  res = std::format(WIDEN("{:%S}"), d);
+  VERIFY( res == WIDEN("05") );
+  res = std::format(WIDEN("{:.0%S}"), d);
+  VERIFY( res == WIDEN("05") );
   res = std::format(WIDEN("{:.3%S}"), d);
   VERIFY( res == WIDEN("05") );
   res = std::format(WIDEN("{:.6%S}"), d);
@@ -71,7 +103,11 @@ test_S()
   res = std::format(WIDEN("{:.9%S}"), d);
   VERIFY( res == WIDEN("05") );
 
-  const duration<double, std::milli> md = d;
+  duration<double, std::milli> md = d;
+  res = std::format(WIDEN("{:%S}"), md);
+  VERIFY( res == WIDEN("05.111") );
+  res = std::format(WIDEN("{:.0%S}"), md);
+  VERIFY( res == WIDEN("05.111") );
   res = std::format(WIDEN("{:.3%S}"), md);
   VERIFY( res == WIDEN("05.111") );
   res = std::format(WIDEN("{:.6%S}"), md);
@@ -79,13 +115,70 @@ test_S()
   res = std::format(WIDEN("{:.9%S}"), md);
   VERIFY( res == WIDEN("05.111") );
 
-  const duration<double, std::nano> nd = d;
+  duration<double, std::micro> ud = d;
+  res = std::format(WIDEN("{:%S}"), ud);
+  VERIFY( res == WIDEN("05.111222") );
+  res = std::format(WIDEN("{:.0%S}"), ud);
+  VERIFY( res == WIDEN("05.111222") );
+  res = std::format(WIDEN("{:.3%S}"), ud);
+  VERIFY( res == WIDEN("05.111222") );
+  res = std::format(WIDEN("{:.6%S}"), ud);
+  VERIFY( res == WIDEN("05.111222") );
+  res = std::format(WIDEN("{:.9%S}"), ud);
+  VERIFY( res == WIDEN("05.111222") );
+
+  duration<double, std::nano> nd = d;
+  res = std::format(WIDEN("{:%S}"), nd);
+  VERIFY( res == WIDEN("05.111222000") );
+  res = std::format(WIDEN("{:.0%S}"), nd);
+  VERIFY( res == WIDEN("05.111222000") );
   res = std::format(WIDEN("{:.3%S}"), nd);
   VERIFY( res == WIDEN("05.111222000") );
   res = std::format(WIDEN("{:.6%S}"), nd);
   VERIFY( res == WIDEN("05.111222000") );
   res = std::format(WIDEN("{:.9%S}"), nd);
   VERIFY( res == WIDEN("05.111222000") );
+
+  duration<double, std::pico> pd = d;
+  res = std::format(WIDEN("{:%S}"), pd);
+  VERIFY( res == WIDEN("05.111222000000") );
+  res = std::format(WIDEN("{:.0%S}"), pd);
+  VERIFY( res == WIDEN("05.111222000000") );
+  res = std::format(WIDEN("{:.3%S}"), pd);
+  VERIFY( res == WIDEN("05.111222000000") );
+  res = std::format(WIDEN("{:.6%S}"), pd);
+  VERIFY( res == WIDEN("05.111222000000") );
+  res = std::format(WIDEN("{:.9%S}"), pd);
+  VERIFY( res == WIDEN("05.111222000000") );
+}
+
+template<typename CharT>
+void
+test_S_int()
+{
+  std::basic_string<CharT> res;
+  const nanoseconds src(7'000'012'345);
+
+  auto d = floor<seconds>(src);
+  res = std::format(WIDEN("{:%S}"), d);
+  VERIFY( res == WIDEN("07") );
+
+  auto md = floor<milliseconds>(src);
+  res = std::format(WIDEN("{:%S}"), md);
+  VERIFY( res == WIDEN("07.000") );
+
+  auto ud = floor<microseconds>(src);
+  res = std::format(WIDEN("{:%S}"), ud);
+  VERIFY( res == WIDEN("07.000012") );
+
+  auto nd = floor<nanoseconds>(src);
+  res = std::format(WIDEN("{:%S}"), nd);
+  VERIFY( res == WIDEN("07.000012345") );
+
+  using picoseconds = duration<unsigned long long, std::pico>;
+  auto pd = floor<picoseconds>(src);
+  res = std::format(WIDEN("{:%S}"), pd);
+  VERIFY( res == WIDEN("07.000012345000") );
 }
 
 template<typename CharT>
@@ -94,7 +187,8 @@ test_all()
 {
   test_empty<CharT>();
   test_Q<CharT>();
-  test_S<CharT>();
+  test_S_int<CharT>();
+  test_S_fp<CharT>();
 }
 
 int main()

Reply via email to