Debian Codegraph @

libcxx/test/std/time/time.syn/formatter.year_month_weekday_last.pass.cpp

raw
1 //===----------------------------------------------------------------------===//
2 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3 // See https://llvm.org/LICENSE.txt for license information.
4 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 //
6 //===----------------------------------------------------------------------===//
7
8 // UNSUPPORTED: c++03, c++11, c++14, c++17
9 // UNSUPPORTED: no-localization
10 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
11
12 // TODO FMT This test should not require std::to_chars(floating-point)
13 // XFAIL: availability-fp_to_chars-missing
14
15 // REQUIRES: locale.fr_FR.UTF-8
16 // REQUIRES: locale.ja_JP.UTF-8
17
18 // <chrono>
19
20 // template<class charT> struct formatter<chrono::year_month_weekday_last, charT>;
21
22 #include <chrono>
23 #include <format>
24
25 #include <cassert>
26 #include <concepts>
27 #include <locale>
28 #include <iostream>
29 #include <type_traits>
30
31 #include "formatter_tests.h"
32 #include "make_string.h"
33 #include "platform_support.h" // locale name macros
34 #include "string_literal.h"
35 #include "test_macros.h"
36
37 template <class CharT>
38 static void test_no_chrono_specs() {
39 // Valid
40 check(SV("1970/Jan/Mon[last]"),
41 SV("{}"),
42 std::chrono::year_month_weekday_last{
43 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{1}}});
44 check(SV("*1970/Jan/Mon[last]*"),
45 SV("{:*^20}"),
46 std::chrono::year_month_weekday_last{
47 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{1}}});
48 check(SV("*1970/Jan/Mon[last]"),
49 SV("{:*>19}"),
50 std::chrono::year_month_weekday_last{
51 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{1}}});
52
53 // Invalid
54 check(SV("1970/Jan/8 is not a valid weekday[last]"),
55 SV("{}"),
56 std::chrono::year_month_weekday_last{
57 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{8}}});
58 check(SV("1970/0 is not a valid month/Mon[last]"),
59 SV("{}"),
60 std::chrono::year_month_weekday_last{
61 std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_last{std::chrono::weekday{1}}});
62 check(SV("-32768 is not a valid year/Jan/Mon[last]"),
63 SV("{}"),
64 std::chrono::year_month_weekday_last{
65 std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{1}}});
66 }
67
68 template <class CharT>
69 static void test_invalid_values() {
70 // *** Invalid weekday ***
71
72 // Weekday name conversion
73 check_exception(
74 "Formatting a weekday name needs a valid weekday",
75 SV("{:%a}"),
76 std::chrono::year_month_weekday_last{
77 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{8}}});
78 check_exception(
79 "Formatting a weekday name needs a valid weekday",
80 SV("{:%A}"),
81 std::chrono::year_month_weekday_last{
82 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{8}}});
83
84 // Weekday conversion
85 check_exception(
86 "Formatting a weekday needs a valid weekday",
87 SV("{:%u}"),
88 std::chrono::year_month_weekday_last{
89 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{8}}});
90 check_exception(
91 "Formatting a weekday needs a valid weekday",
92 SV("{:%w}"),
93 std::chrono::year_month_weekday_last{
94 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{8}}});
95 check_exception(
96 "Formatting a weekday needs a valid weekday",
97 SV("{:%Ou}"),
98 std::chrono::year_month_weekday_last{
99 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{8}}});
100 check_exception(
101 "Formatting a weekday needs a valid weekday",
102 SV("{:%Ow}"),
103 std::chrono::year_month_weekday_last{
104 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{8}}});
105
106 // Day of year field
107 check_exception(
108 "Formatting a day of year needs a valid date",
109 SV("{:%j}"),
110 std::chrono::year_month_weekday_last{
111 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{8}}});
112
113 // Month name conversion
114 check(SV("Jan"),
115 SV("{:%b}"),
116 std::chrono::year_month_weekday_last{
117 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{8}}});
118 check(SV("Jan"),
119 SV("{:%h}"),
120 std::chrono::year_month_weekday_last{
121 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{8}}});
122 check(SV("January"),
123 SV("{:%B}"),
124 std::chrono::year_month_weekday_last{
125 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{8}}});
126
127 // *** Invalid month ***
128
129 // Weekday name conversion
130 check(SV("Mon"),
131 SV("{:%a}"),
132 std::chrono::year_month_weekday_last{
133 std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_last{std::chrono::weekday{1}}});
134 check(SV("Monday"),
135 SV("{:%A}"),
136 std::chrono::year_month_weekday_last{
137 std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_last{std::chrono::weekday{1}}});
138 // Weekday conversion
139 check(SV("1"),
140 SV("{:%u}"),
141 std::chrono::year_month_weekday_last{
142 std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_last{std::chrono::weekday{1}}});
143 check(SV("1"),
144 SV("{:%w}"),
145 std::chrono::year_month_weekday_last{
146 std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_last{std::chrono::weekday{1}}});
147 check(SV("1"),
148 SV("{:%Ou}"),
149 std::chrono::year_month_weekday_last{
150 std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_last{std::chrono::weekday{1}}});
151 check(SV("1"),
152 SV("{:%Ow}"),
153 std::chrono::year_month_weekday_last{
154 std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_last{std::chrono::weekday{1}}});
155
156 // Day of year field
157 check_exception(
158 "Formatting a day of year needs a valid date",
159 SV("{:%j}"),
160 std::chrono::year_month_weekday_last{
161 std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_last{std::chrono::weekday{1}}});
162
163 // Month name conversion
164 check_exception(
165 "Formatting a month name from an invalid month number",
166 SV("{:%b}"),
167 std::chrono::year_month_weekday_last{
168 std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_last{std::chrono::weekday{1}}});
169 check_exception(
170 "Formatting a month name from an invalid month number",
171 SV("{:%h}"),
172 std::chrono::year_month_weekday_last{
173 std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_last{std::chrono::weekday{1}}});
174 check_exception(
175 "Formatting a month name from an invalid month number",
176 SV("{:%B}"),
177 std::chrono::year_month_weekday_last{
178 std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_last{std::chrono::weekday{1}}});
179
180 // *** Invalid year ***
181
182 // Weekday name conversion
183 check(SV("Mon"),
184 SV("{:%a}"),
185 std::chrono::year_month_weekday_last{
186 std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{1}}});
187 check(SV("Monday"),
188 SV("{:%A}"),
189 std::chrono::year_month_weekday_last{
190 std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{1}}});
191
192 // Weekday conversion
193 check(SV("1"),
194 SV("{:%u}"),
195 std::chrono::year_month_weekday_last{
196 std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{1}}});
197 check(SV("1"),
198 SV("{:%w}"),
199 std::chrono::year_month_weekday_last{
200 std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{1}}});
201 check(SV("1"),
202 SV("{:%Ou}"),
203 std::chrono::year_month_weekday_last{
204 std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{1}}});
205 check(SV("1"),
206 SV("{:%Ow}"),
207 std::chrono::year_month_weekday_last{
208 std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{1}}});
209
210 // Day of year field
211 check_exception(
212 "Formatting a day of year needs a valid date",
213 SV("{:%j}"),
214 std::chrono::year_month_weekday_last{
215 std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{1}}});
216
217 // Month name conversion
218 check(SV("Jan"),
219 SV("{:%b}"),
220 std::chrono::year_month_weekday_last{
221 std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{1}}});
222 check(SV("Jan"),
223 SV("{:%h}"),
224 std::chrono::year_month_weekday_last{
225 std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{1}}});
226 check(SV("January"),
227 SV("{:%B}"),
228 std::chrono::year_month_weekday_last{
229 std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::weekday_last{std::chrono::weekday{1}}});
230 }
231
232 template <class CharT>
233 static void test() {
234 test_no_chrono_specs<CharT>();
235 test_invalid_values<CharT>();
236 }
237
238 int main(int, char**) {
239 test<char>();
240
241 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
242 test<wchar_t>();
243 #endif
244
245 return 0;
246 }