libstdc++-v3/ChangeLog:

        * testsuite/std/time/format/precision.cc: New tests.
---
Merging additional tests I have added, when working on erasing chrono
types. Testing on x86_64-linux.
OK for trunk when test passes?

 .../testsuite/std/time/format/precision.cc    | 64 +++++++++++++++++--
 1 file changed, 59 insertions(+), 5 deletions(-)

diff --git a/libstdc++-v3/testsuite/std/time/format/precision.cc 
b/libstdc++-v3/testsuite/std/time/format/precision.cc
index ccb2c77ce05..b604fbfe9e9 100644
--- a/libstdc++-v3/testsuite/std/time/format/precision.cc
+++ b/libstdc++-v3/testsuite/std/time/format/precision.cc
@@ -16,6 +16,8 @@ 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("{:.3}"), d);
   VERIFY( res == WIDEN("33.1112s") );
   res = std::format(WIDEN("{:.6}"), d);
@@ -25,6 +27,8 @@ 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("{:.3}"), nd);
   VERIFY( res == WIDEN("3.31112e+10ns") );
   res = std::format(WIDEN("{:.6}"), nd);
@@ -40,6 +44,8 @@ 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("{:.3%Q}"), d);
   VERIFY( res == WIDEN("7.111222") );
   res = std::format(WIDEN("{:.6%Q}"), d);
@@ -48,6 +54,8 @@ test_Q()
   VERIFY( res == WIDEN("7.111222") );
 
   const duration<double, std::nano> nd = d;
+  res = std::format(WIDEN("{:%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 +66,14 @@ 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("{:.3%S}"), d);
   VERIFY( res == WIDEN("05") );
   res = std::format(WIDEN("{:.6%S}"), d);
@@ -71,7 +81,9 @@ 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("{:.3%S}"), md);
   VERIFY( res == WIDEN("05.111") );
   res = std::format(WIDEN("{:.6%S}"), md);
@@ -79,7 +91,19 @@ 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("{:.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("{:.3%S}"), nd);
   VERIFY( res == WIDEN("05.111222000") );
   res = std::format(WIDEN("{:.6%S}"), nd);
@@ -88,13 +112,43 @@ test_S()
   VERIFY( res == WIDEN("05.111222000") );
 }
 
+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>
 void
 test_all()
 {
   test_empty<CharT>();
   test_Q<CharT>();
-  test_S<CharT>();
+  test_S_int<CharT>();
+  test_S_fp<CharT>();
 }
 
 int main()
-- 
2.49.0

Reply via email to