Debian Codegraph @

libstdc++-v3/testsuite/std/time/year_month/io.cc

raw
1 // { dg-do run { target c++20 } }
2 // { dg-require-namedlocale "fr_FR.ISO8859-15" }
3 // { dg-timeout-factor 2 }
4
5 #include <chrono>
6 #include <sstream>
7 #include <testsuite_hooks.h>
8
9 void
10 test_ostream()
11 {
12 using std::ostringstream;
13 using namespace std::chrono;
14
15 ostringstream ss;
16 ss << 2023y/January << ' ' << 2023y/month(13);
17 VERIFY( ss.str() == "2023/Jan 2023/13 is not a valid month" );
18
19 ss.str("");
20 ss.imbue(std::locale(ISO_8859(15,fr_FR)));
21 ss << 2023y/July;
22 VERIFY( ss.str() == "2023/juil." );
23 }
24
25 void
26 test_parse()
27 {
28 using namespace std::chrono;
29 year_month ym;
30
31 std::istringstream is("20238");
32 VERIFY( is >> parse("%Y%m", ym) );
33 VERIFY( is.eof() );
34 VERIFY( ym == 2023y/August );
35
36 ym = 1y/January;
37 is.clear();
38 is.str("20238");
39 VERIFY( ! (is >> parse("%5Y%m", ym)) );
40 VERIFY( is.eof() );
41 VERIFY( ym == 1y/January );
42
43 is.clear();
44 is.str("2023");
45 VERIFY( is >> parse("%2Y%1m", ym) );
46 VERIFY( ! is.eof() );
47 VERIFY( ym == 20y/February );
48
49 is.clear();
50 is.str("2012");
51 VERIFY( is >> parse("%y%m", ym) );
52 VERIFY( ! is.eof() );
53 VERIFY( ym == 2020y/December );
54
55 minutes offset;
56 std::string abbrev;
57
58 is.clear();
59 is.str("4/1/20 25:61 +1:30 WAT"); // Invalid %H:%M doesn't matter for year_mon
60 VERIFY( is >> parse("%D %H:%M %Oz %Z", ym, abbrev, offset) );
61 VERIFY( is.eof() );
62 VERIFY( ym == 2020y/April );
63 VERIFY( abbrev == "WAT" );
64 VERIFY( offset == 90min );
65
66 is.clear();
67 is.str("02022-W052-7");
68 is >> parse("%6G-W%4V-%2u", ym);
69 VERIFY( is.eof() );
70 VERIFY( ym == 2023y/January );
71 }
72
73 int main()
74 {
75 test_ostream();
76 // TODO: test_format();
77 test_parse();
78 }