]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/duration/io.cc
1 // { dg-options "-std=gnu++20" }
2 // { dg-do run { target c++20 } }
6 #include <testsuite_hooks.h>
11 using namespace std::chrono
;
14 ss
<< 3h
+ 5min
<< '\n';
15 ss
<< duration
<long, std::ratio
<2>>(3) << '\n';
16 ss
<< duration
<long, std::ratio
<2, 3>>(9) << '\n';
21 VERIFY( s
== "185min" );
23 VERIFY( s
== "3[2]s" );
25 VERIFY( s
== "9[2/3]s" );
31 #ifdef _GLIBCXX_USE_WCHAR_T
32 using namespace std::chrono
;
33 std::wstringstream ss
;
35 ss
<< 3h
+ 5min
<< L
'\n';
36 ss
<< duration
<long, std::ratio
<2>>(3) << L
'\n';
37 ss
<< duration
<long, std::ratio
<2, 3>>(9) << L
'\n';
42 VERIFY( s
== L
"185min" );
44 VERIFY( s
== L
"3[2]s" );
46 VERIFY( s
== L
"9[2/3]s" );
53 using namespace std::chrono_literals
;
54 auto s
= std::format("{} {}", 1h
+ 23min
+ 45s
, -42min
);
55 VERIFY( s
== "5025s -42min" );
56 s
= std::format("{:%j} {:%j} {:%j}", 1h
+ 23min
+ 45s
, 75h
, -99h
);
57 VERIFY( s
== "0 3 -4" );
58 s
= std::format("{:%T = %H:%M:%S}", 1h
+ 23min
+ 45s
);
59 VERIFY( s
== "01:23:45 = 01:23:45" );
60 s
= std::format("{:%Q} {:%q} {:%Q%q}", 6min
+ 1s
, 44min
, -22h
);
61 VERIFY( s
== "361 min -22h" );
63 std::wstring ws
= std::format(L
"{:%Q%q}", 81s
);
64 VERIFY( ws
== L
"81s" );
66 // Only print '-' on numeric fields for negative durations:
67 s
= std::format("{:%Q} {:%q} {:%q%Q}", -21h
, -20h
, -19h
);
68 VERIFY( s
== "-21 h h-19" );
69 s
= std::format("{:%p} {:%p%H}", -2h
, -13h
);
70 VERIFY( s
== "AM PM-13" );
71 s
= std::format("{:%t} {:%t%M}", -2h
, -123s
);
72 VERIFY( s
== "\t \t-02" );
74 std::string_view specs
= "aAbBcCdDeFgGhHIjmMpqQrRSTuUVwWxXyYzZ";
75 std::string_view my_specs
= "HIjMpqQrRSTX";
78 char fmt
[] = { '{', ':', '%', c
, '}' };
81 (void) std::vformat(std::string_view(fmt
, 5), std::make_format_args(1s
));
82 // The call above should throw for any conversion-spec not in my_specs:
83 VERIFY(my_specs
.find(c
) != my_specs
.npos
);
85 catch (const std::format_error
& e
)
87 VERIFY(my_specs
.find(c
) == my_specs
.npos
);
88 std::string_view s
= e
.what();
89 // Libstdc++-specific message:
90 VERIFY(s
.find("format argument does not contain the information "
91 "required by the chrono-specs") != s
.npos
);
101 // TODO: test_parse();