| 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 << January/14 << ' ' << February/30 << ' ' << March/34; |
| 17 | VERIFY( ss.str() == "Jan/14 Feb/30 Mar/34 is not a valid day" ); |
| 18 | |
| 19 | ss.str(""); |
| 20 | ss.imbue(std::locale(ISO_8859(15,fr_FR))); |
| 21 | ss << July/27; |
| 22 | VERIFY( ss.str() == "juil./27" ); |
| 23 | } |
| 24 | |
| 25 | void |
| 26 | test_parse() |
| 27 | { |
| 28 | using namespace std::chrono; |
| 29 | std::istringstream is; |
| 30 | month_day md{}; |
| 31 | |
| 32 | is.str("jul 0123"); |
| 33 | VERIFY( is >> parse("%B %3e", md) ); |
| 34 | VERIFY( ! is.eof() ); |
| 35 | VERIFY( is.peek() == '3' ); |
| 36 | VERIFY( md == July/12 ); |
| 37 | |
| 38 | is.str("August 11"); |
| 39 | VERIFY( is >> parse("%b %d", md) ); |
| 40 | VERIFY( ! is.eof() ); |
| 41 | VERIFY( md == August/11 ); |
| 42 | |
| 43 | is.clear(); |
| 44 | is.str("012"); |
| 45 | VERIFY( is >> parse("%m%2d", md) ); |
| 46 | VERIFY( is.eof() ); |
| 47 | VERIFY( md == January/2 ); |
| 48 | |
| 49 | is.clear(); |
| 50 | is.str("012/311"); |
| 51 | VERIFY( is >> parse("%4m/%d", md) ); |
| 52 | VERIFY( ! is.eof() ); |
| 53 | VERIFY( md == December/31 ); |
| 54 | |
| 55 | is.clear(); |
| 56 | is.str("2023-7-31"); |
| 57 | VERIFY( is >> parse("%F", md) ); |
| 58 | VERIFY( ! is.eof() ); |
| 59 | VERIFY( md == July/31 ); |
| 60 | |
| 61 | md = month(13)/day(32); |
| 62 | is.clear(); |
| 63 | is.str("2023-13-1"); |
| 64 | VERIFY( ! (is >> parse("%F", md)) ); |
| 65 | VERIFY( is.eof() ); |
| 66 | VERIFY( md == month(13)/day(32) ); |
| 67 | |
| 68 | md = month(13)/day(33); |
| 69 | is.clear(); |
| 70 | is.str("2023-6-31"); |
| 71 | VERIFY( ! (is >> parse("%F", md)) ); // June only has 30 days. |
| 72 | VERIFY( ! is.eof() ); |
| 73 | VERIFY( md == month(13)/day(33) ); |
| 74 | |
| 75 | md = month(13)/day(34); |
| 76 | is.clear(); |
| 77 | is.str("6-31"); |
| 78 | VERIFY( ! (is >> parse("%m-%d", md)) ); // June only has 30 days in any year. |
| 79 | VERIFY( ! is.eof() ); |
| 80 | VERIFY( md == month(13)/day(34) ); |
| 81 | |
| 82 | md = month(13)/day(35); |
| 83 | is.clear(); |
| 84 | is.str("2023-2-29"); |
| 85 | VERIFY( ! (is >> parse("%Y-%m-%e", md)) ); // Feb only has 28 days in 2023. |
| 86 | VERIFY( ! is.eof() ); |
| 87 | VERIFY( md == month(13)/day(35) ); |
| 88 | |
| 89 | is.clear(); |
| 90 | is.str("2-29"); |
| 91 | VERIFY( is >> parse("%m-%d", md) ); // But Feb has 29 days in some years. |
| 92 | VERIFY( ! is.eof() ); |
| 93 | VERIFY( md == February/29 ); |
| 94 | |
| 95 | is.clear(); |
| 96 | is.str("2023-W32-5"); |
| 97 | VERIFY( is >> parse("%G-W%V-%u", md) ); |
| 98 | VERIFY( ! is.eof() ); |
| 99 | VERIFY( md == August/11 ); |
| 100 | } |
| 101 | |
| 102 | int main() |
| 103 | { |
| 104 | test_ostream(); |
| 105 | // TODO: test_format(); |
| 106 | test_parse(); |
| 107 | } |