1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 // UNSUPPORTED: no-localization
11 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
13 // TODO FMT This test should not require std::to_chars(floating-point)
14 // XFAIL: availability-fp_to_chars-missing
16 // REQUIRES: locale.fr_FR.UTF-8
17 // REQUIRES: locale.ja_JP.UTF-8
21 // template<class charT> struct formatter<chrono::month_day_last, charT>;
30 #include <type_traits>
32 #include "formatter_tests.h"
33 #include "make_string.h"
34 #include "platform_support.h" // locale name macros
35 #include "string_literal.h"
36 #include "test_macros.h"
38 template <class CharT
>
39 static void test_no_chrono_specs() {
41 check(SV("Jan/last"), SV("{}"), std::chrono::month_day_last
{std::chrono::month
{1}});
42 check(SV("*Jan/last*"), SV("{:*^10}"), std::chrono::month_day_last
{std::chrono::month
{1}});
43 check(SV("*Jan/last"), SV("{:*>9}"), std::chrono::month_day_last
{std::chrono::month
{1}});
46 check(SV("0 is not a valid month/last"), SV("{}"), std::chrono::month_day_last
{std::chrono::month
{0}});
47 check(SV("*0 is not a valid month/last*"), SV("{:*^29}"), std::chrono::month_day_last
{std::chrono::month
{0}});
50 template <class CharT
>
51 static void test_valid_values() {
52 // Test that %b, %h, and %B throw an exception.
53 check_exception("Formatting a month name from an invalid month number",
55 std::chrono::month_day_last
{std::chrono::month
{200}});
56 check_exception("Formatting a month name from an invalid month number",
58 std::chrono::month_day_last
{std::chrono::month
{13}});
59 check_exception("Formatting a month name from an invalid month number",
61 std::chrono::month_day_last
{std::chrono::month
{255}});
63 check_exception("Formatting a month name from an invalid month number",
65 std::chrono::month_day_last
{std::chrono::month
{0}});
66 check_exception("Formatting a month name from an invalid month number",
68 std::chrono::month_day_last
{std::chrono::month
{13}});
69 check_exception("Formatting a month name from an invalid month number",
71 std::chrono::month_day_last
{std::chrono::month
{255}});
73 check_exception("Formatting a month name from an invalid month number",
75 std::chrono::month_day_last
{std::chrono::month
{0}});
76 check_exception("Formatting a month name from an invalid month number",
78 std::chrono::month_day_last
{std::chrono::month
{13}});
79 check_exception("Formatting a month name from an invalid month number",
81 std::chrono::month_day_last
{std::chrono::month
{255}});
83 constexpr std::basic_string_view
<CharT
> fmt
= SV("{:%%b='%b'%t%%B='%B'%t%%h='%h'%t%%m='%m'%t%%Om='%Om'%n}");
84 constexpr std::basic_string_view
<CharT
> lfmt
= SV("{:L%%b='%b'%t%%B='%B'%t%%h='%h'%t%%m='%m'%t%%Om='%Om'%n}");
86 const std::locale
loc(LOCALE_ja_JP_UTF_8
);
87 std::locale::global(std::locale(LOCALE_fr_FR_UTF_8
));
89 // Non localized output using C-locale
90 check(SV("%b='Jan'\t%B='January'\t%h='Jan'\t%m='01'\t%Om='01'\n"),
92 std::chrono::month_day_last
{std::chrono::January
});
93 check(SV("%b='Feb'\t%B='February'\t%h='Feb'\t%m='02'\t%Om='02'\n"),
95 std::chrono::month_day_last
{std::chrono::February
});
97 SV("%b='Mar'\t%B='March'\t%h='Mar'\t%m='03'\t%Om='03'\n"), fmt
, std::chrono::month_day_last
{std::chrono::March
});
99 SV("%b='Apr'\t%B='April'\t%h='Apr'\t%m='04'\t%Om='04'\n"), fmt
, std::chrono::month_day_last
{std::chrono::April
});
100 check(SV("%b='May'\t%B='May'\t%h='May'\t%m='05'\t%Om='05'\n"), fmt
, std::chrono::month_day_last
{std::chrono::May
});
101 check(SV("%b='Jun'\t%B='June'\t%h='Jun'\t%m='06'\t%Om='06'\n"), fmt
, std::chrono::month_day_last
{std::chrono::June
});
102 check(SV("%b='Jul'\t%B='July'\t%h='Jul'\t%m='07'\t%Om='07'\n"), fmt
, std::chrono::month_day_last
{std::chrono::July
});
103 check(SV("%b='Aug'\t%B='August'\t%h='Aug'\t%m='08'\t%Om='08'\n"),
105 std::chrono::month_day_last
{std::chrono::August
});
106 check(SV("%b='Sep'\t%B='September'\t%h='Sep'\t%m='09'\t%Om='09'\n"),
108 std::chrono::month_day_last
{std::chrono::September
});
109 check(SV("%b='Oct'\t%B='October'\t%h='Oct'\t%m='10'\t%Om='10'\n"),
111 std::chrono::month_day_last
{std::chrono::October
});
112 check(SV("%b='Nov'\t%B='November'\t%h='Nov'\t%m='11'\t%Om='11'\n"),
114 std::chrono::month_day_last
{std::chrono::November
});
115 check(SV("%b='Dec'\t%B='December'\t%h='Dec'\t%m='12'\t%Om='12'\n"),
117 std::chrono::month_day_last
{std::chrono::December
});
119 // Use the global locale (fr_FR)
120 #if defined(__APPLE__)
121 check(SV("%b='jan'\t%B='janvier'\t%h='jan'\t%m='01'\t%Om='01'\n"),
123 std::chrono::month_day_last
{std::chrono::January
});
124 check(SV("%b='fév'\t%B='février'\t%h='fév'\t%m='02'\t%Om='02'\n"),
126 std::chrono::month_day_last
{std::chrono::February
});
128 SV("%b='mar'\t%B='mars'\t%h='mar'\t%m='03'\t%Om='03'\n"), lfmt
, std::chrono::month_day_last
{std::chrono::March
});
130 SV("%b='avr'\t%B='avril'\t%h='avr'\t%m='04'\t%Om='04'\n"), lfmt
, std::chrono::month_day_last
{std::chrono::April
});
131 check(SV("%b='mai'\t%B='mai'\t%h='mai'\t%m='05'\t%Om='05'\n"), lfmt
, std::chrono::month_day_last
{std::chrono::May
});
132 check(SV("%b='jui'\t%B='juin'\t%h='jui'\t%m='06'\t%Om='06'\n"), lfmt
, std::chrono::month_day_last
{std::chrono::June
});
133 check(SV("%b='jul'\t%B='juillet'\t%h='jul'\t%m='07'\t%Om='07'\n"),
135 std::chrono::month_day_last
{std::chrono::July
});
137 SV("%b='aoû'\t%B='août'\t%h='aoû'\t%m='08'\t%Om='08'\n"), lfmt
, std::chrono::month_day_last
{std::chrono::August
});
138 check(SV("%b='sep'\t%B='septembre'\t%h='sep'\t%m='09'\t%Om='09'\n"),
140 std::chrono::month_day_last
{std::chrono::September
});
141 check(SV("%b='oct'\t%B='octobre'\t%h='oct'\t%m='10'\t%Om='10'\n"),
143 std::chrono::month_day_last
{std::chrono::October
});
144 check(SV("%b='nov'\t%B='novembre'\t%h='nov'\t%m='11'\t%Om='11'\n"),
146 std::chrono::month_day_last
{std::chrono::November
});
147 check(SV("%b='déc'\t%B='décembre'\t%h='déc'\t%m='12'\t%Om='12'\n"),
149 std::chrono::month_day_last
{std::chrono::December
});
150 #else // defined(__APPLE__)
151 check(SV("%b='janv.'\t%B='janvier'\t%h='janv.'\t%m='01'\t%Om='01'\n"),
153 std::chrono::month_day_last
{std::chrono::January
});
154 check(SV("%b='févr.'\t%B='février'\t%h='févr.'\t%m='02'\t%Om='02'\n"),
156 std::chrono::month_day_last
{std::chrono::February
});
157 check(SV("%b='mars'\t%B='mars'\t%h='mars'\t%m='03'\t%Om='03'\n"),
159 std::chrono::month_day_last
{std::chrono::March
});
161 # if defined(_WIN32) || defined(_AIX) || defined(__FreeBSD__)
162 SV("%b='avr.'\t%B='avril'\t%h='avr.'\t%m='04'\t%Om='04'\n"),
163 # else // defined(_WIN32) || defined(_AIX) || defined(__FreeBSD__)
164 SV("%b='avril'\t%B='avril'\t%h='avril'\t%m='04'\t%Om='04'\n"),
165 # endif // defined(_WIN32) || defined(_AIX) || defined(__FreeBSD__)
167 std::chrono::month_day_last
{std::chrono::April
});
168 check(SV("%b='mai'\t%B='mai'\t%h='mai'\t%m='05'\t%Om='05'\n"), lfmt
, std::chrono::month_day_last
{std::chrono::May
});
170 SV("%b='juin'\t%B='juin'\t%h='juin'\t%m='06'\t%Om='06'\n"), lfmt
, std::chrono::month_day_last
{std::chrono::June
});
171 check(SV("%b='juil.'\t%B='juillet'\t%h='juil.'\t%m='07'\t%Om='07'\n"),
173 std::chrono::month_day_last
{std::chrono::July
});
174 check(SV("%b='août'\t%B='août'\t%h='août'\t%m='08'\t%Om='08'\n"),
176 std::chrono::month_day_last
{std::chrono::August
});
177 check(SV("%b='sept.'\t%B='septembre'\t%h='sept.'\t%m='09'\t%Om='09'\n"),
179 std::chrono::month_day_last
{std::chrono::September
});
180 check(SV("%b='oct.'\t%B='octobre'\t%h='oct.'\t%m='10'\t%Om='10'\n"),
182 std::chrono::month_day_last
{std::chrono::October
});
183 check(SV("%b='nov.'\t%B='novembre'\t%h='nov.'\t%m='11'\t%Om='11'\n"),
185 std::chrono::month_day_last
{std::chrono::November
});
186 check(SV("%b='déc.'\t%B='décembre'\t%h='déc.'\t%m='12'\t%Om='12'\n"),
188 std::chrono::month_day_last
{std::chrono::December
});
189 #endif // defined(__APPLE__)
191 // Use supplied locale (ja_JP)
194 SV("%b='1'\t%B='1月'\t%h='1'\t%m='01'\t%Om='01'\n"),
196 std::chrono::month_day_last
{std::chrono::January
});
198 SV("%b='2'\t%B='2月'\t%h='2'\t%m='02'\t%Om='02'\n"),
200 std::chrono::month_day_last
{std::chrono::February
});
202 loc
, SV("%b='3'\t%B='3月'\t%h='3'\t%m='03'\t%Om='03'\n"), lfmt
, std::chrono::month_day_last
{std::chrono::March
});
204 loc
, SV("%b='4'\t%B='4月'\t%h='4'\t%m='04'\t%Om='04'\n"), lfmt
, std::chrono::month_day_last
{std::chrono::April
});
205 check(loc
, SV("%b='5'\t%B='5月'\t%h='5'\t%m='05'\t%Om='05'\n"), lfmt
, std::chrono::month_day_last
{std::chrono::May
});
206 check(loc
, SV("%b='6'\t%B='6月'\t%h='6'\t%m='06'\t%Om='06'\n"), lfmt
, std::chrono::month_day_last
{std::chrono::June
});
207 check(loc
, SV("%b='7'\t%B='7月'\t%h='7'\t%m='07'\t%Om='07'\n"), lfmt
, std::chrono::month_day_last
{std::chrono::July
});
209 loc
, SV("%b='8'\t%B='8月'\t%h='8'\t%m='08'\t%Om='08'\n"), lfmt
, std::chrono::month_day_last
{std::chrono::August
});
211 SV("%b='9'\t%B='9月'\t%h='9'\t%m='09'\t%Om='09'\n"),
213 std::chrono::month_day_last
{std::chrono::September
});
215 SV("%b='10'\t%B='10月'\t%h='10'\t%m='10'\t%Om='10'\n"),
217 std::chrono::month_day_last
{std::chrono::October
});
219 SV("%b='11'\t%B='11月'\t%h='11'\t%m='11'\t%Om='11'\n"),
221 std::chrono::month_day_last
{std::chrono::November
});
223 SV("%b='12'\t%B='12月'\t%h='12'\t%m='12'\t%Om='12'\n"),
225 std::chrono::month_day_last
{std::chrono::December
});
226 #elif defined(__APPLE__) // defined(_WIN32)
228 SV("%b=' 1'\t%B='1月'\t%h=' 1'\t%m='01'\t%Om='01'\n"),
230 std::chrono::month_day_last
{std::chrono::January
});
232 SV("%b=' 2'\t%B='2月'\t%h=' 2'\t%m='02'\t%Om='02'\n"),
234 std::chrono::month_day_last
{std::chrono::February
});
236 SV("%b=' 3'\t%B='3月'\t%h=' 3'\t%m='03'\t%Om='03'\n"),
238 std::chrono::month_day_last
{std::chrono::March
});
240 SV("%b=' 4'\t%B='4月'\t%h=' 4'\t%m='04'\t%Om='04'\n"),
242 std::chrono::month_day_last
{std::chrono::April
});
244 loc
, SV("%b=' 5'\t%B='5月'\t%h=' 5'\t%m='05'\t%Om='05'\n"), lfmt
, std::chrono::month_day_last
{std::chrono::May
});
246 loc
, SV("%b=' 6'\t%B='6月'\t%h=' 6'\t%m='06'\t%Om='06'\n"), lfmt
, std::chrono::month_day_last
{std::chrono::June
});
248 loc
, SV("%b=' 7'\t%B='7月'\t%h=' 7'\t%m='07'\t%Om='07'\n"), lfmt
, std::chrono::month_day_last
{std::chrono::July
});
250 SV("%b=' 8'\t%B='8月'\t%h=' 8'\t%m='08'\t%Om='08'\n"),
252 std::chrono::month_day_last
{std::chrono::August
});
254 SV("%b=' 9'\t%B='9月'\t%h=' 9'\t%m='09'\t%Om='09'\n"),
256 std::chrono::month_day_last
{std::chrono::September
});
258 SV("%b='10'\t%B='10月'\t%h='10'\t%m='10'\t%Om='10'\n"),
260 std::chrono::month_day_last
{std::chrono::October
});
262 SV("%b='11'\t%B='11月'\t%h='11'\t%m='11'\t%Om='11'\n"),
264 std::chrono::month_day_last
{std::chrono::November
});
266 SV("%b='12'\t%B='12月'\t%h='12'\t%m='12'\t%Om='12'\n"),
268 std::chrono::month_day_last
{std::chrono::December
});
269 #elif defined(_AIX) // defined(_WIN32)
271 SV("%b='1月'\t%B='1月'\t%h='1月'\t%m='01'\t%Om='01'\n"),
273 std::chrono::month_day_last
{std::chrono::January
});
275 SV("%b='2月'\t%B='2月'\t%h='2月'\t%m='02'\t%Om='02'\n"),
277 std::chrono::month_day_last
{std::chrono::February
});
279 SV("%b='3月'\t%B='3月'\t%h='3月'\t%m='03'\t%Om='03'\n"),
281 std::chrono::month_day_last
{std::chrono::March
});
283 SV("%b='4月'\t%B='4月'\t%h='4月'\t%m='04'\t%Om='04'\n"),
285 std::chrono::month_day_last
{std::chrono::April
});
287 SV("%b='5月'\t%B='5月'\t%h='5月'\t%m='05'\t%Om='05'\n"),
289 std::chrono::month_day_last
{std::chrono::May
});
291 SV("%b='6月'\t%B='6月'\t%h='6月'\t%m='06'\t%Om='06'\n"),
293 std::chrono::month_day_last
{std::chrono::June
});
295 SV("%b='7月'\t%B='7月'\t%h='7月'\t%m='07'\t%Om='07'\n"),
297 std::chrono::month_day_last
{std::chrono::July
});
299 SV("%b='8月'\t%B='8月'\t%h='8月'\t%m='08'\t%Om='08'\n"),
301 std::chrono::month_day_last
{std::chrono::August
});
303 SV("%b='9月'\t%B='9月'\t%h='9月'\t%m='09'\t%Om='09'\n"),
305 std::chrono::month_day_last
{std::chrono::September
});
307 SV("%b='10月'\t%B='10月'\t%h='10月'\t%m='10'\t%Om='10'\n"),
309 std::chrono::month_day_last
{std::chrono::October
});
311 SV("%b='11月'\t%B='11月'\t%h='11月'\t%m='11'\t%Om='11'\n"),
313 std::chrono::month_day_last
{std::chrono::November
});
315 SV("%b='12月'\t%B='12月'\t%h='12月'\t%m='12'\t%Om='12'\n"),
317 std::chrono::month_day_last
{std::chrono::December
});
318 #elif defined(__FreeBSD__) // defined(_WIN32)
320 SV("%b=' 1月'\t%B='1月'\t%h=' 1月'\t%m='01'\t%Om='01'\n"),
322 std::chrono::month_day_last
{std::chrono::January
});
324 SV("%b=' 2月'\t%B='2月'\t%h=' 2月'\t%m='02'\t%Om='02'\n"),
326 std::chrono::month_day_last
{std::chrono::February
});
328 SV("%b=' 3月'\t%B='3月'\t%h=' 3月'\t%m='03'\t%Om='03'\n"),
330 std::chrono::month_day_last
{std::chrono::March
});
332 SV("%b=' 4月'\t%B='4月'\t%h=' 4月'\t%m='04'\t%Om='04'\n"),
334 std::chrono::month_day_last
{std::chrono::April
});
336 SV("%b=' 5月'\t%B='5月'\t%h=' 5月'\t%m='05'\t%Om='05'\n"),
338 std::chrono::month_day_last
{std::chrono::May
});
340 SV("%b=' 6月'\t%B='6月'\t%h=' 6月'\t%m='06'\t%Om='06'\n"),
342 std::chrono::month_day_last
{std::chrono::June
});
344 SV("%b=' 7月'\t%B='7月'\t%h=' 7月'\t%m='07'\t%Om='07'\n"),
346 std::chrono::month_day_last
{std::chrono::July
});
348 SV("%b=' 8月'\t%B='8月'\t%h=' 8月'\t%m='08'\t%Om='08'\n"),
350 std::chrono::month_day_last
{std::chrono::August
});
352 SV("%b=' 9月'\t%B='9月'\t%h=' 9月'\t%m='09'\t%Om='09'\n"),
354 std::chrono::month_day_last
{std::chrono::September
});
356 SV("%b='10月'\t%B='10月'\t%h='10月'\t%m='10'\t%Om='10'\n"),
358 std::chrono::month_day_last
{std::chrono::October
});
360 SV("%b='11月'\t%B='11月'\t%h='11月'\t%m='11'\t%Om='11'\n"),
362 std::chrono::month_day_last
{std::chrono::November
});
364 SV("%b='12月'\t%B='12月'\t%h='12月'\t%m='12'\t%Om='12'\n"),
366 std::chrono::month_day_last
{std::chrono::December
});
367 #else // defined(_WIN32)
369 SV("%b=' 1月'\t%B='1月'\t%h=' 1月'\t%m='01'\t%Om='一'\n"),
371 std::chrono::month_day_last
{std::chrono::January
});
373 SV("%b=' 2月'\t%B='2月'\t%h=' 2月'\t%m='02'\t%Om='二'\n"),
375 std::chrono::month_day_last
{std::chrono::February
});
377 SV("%b=' 3月'\t%B='3月'\t%h=' 3月'\t%m='03'\t%Om='三'\n"),
379 std::chrono::month_day_last
{std::chrono::March
});
381 SV("%b=' 4月'\t%B='4月'\t%h=' 4月'\t%m='04'\t%Om='四'\n"),
383 std::chrono::month_day_last
{std::chrono::April
});
385 SV("%b=' 5月'\t%B='5月'\t%h=' 5月'\t%m='05'\t%Om='五'\n"),
387 std::chrono::month_day_last
{std::chrono::May
});
389 SV("%b=' 6月'\t%B='6月'\t%h=' 6月'\t%m='06'\t%Om='六'\n"),
391 std::chrono::month_day_last
{std::chrono::June
});
393 SV("%b=' 7月'\t%B='7月'\t%h=' 7月'\t%m='07'\t%Om='七'\n"),
395 std::chrono::month_day_last
{std::chrono::July
});
397 SV("%b=' 8月'\t%B='8月'\t%h=' 8月'\t%m='08'\t%Om='八'\n"),
399 std::chrono::month_day_last
{std::chrono::August
});
401 SV("%b=' 9月'\t%B='9月'\t%h=' 9月'\t%m='09'\t%Om='九'\n"),
403 std::chrono::month_day_last
{std::chrono::September
});
405 SV("%b='10月'\t%B='10月'\t%h='10月'\t%m='10'\t%Om='十'\n"),
407 std::chrono::month_day_last
{std::chrono::October
});
409 SV("%b='11月'\t%B='11月'\t%h='11月'\t%m='11'\t%Om='十一'\n"),
411 std::chrono::month_day_last
{std::chrono::November
});
413 SV("%b='12月'\t%B='12月'\t%h='12月'\t%m='12'\t%Om='十二'\n"),
415 std::chrono::month_day_last
{std::chrono::December
});
416 #endif // defined(_WIN32)
418 std::locale::global(std::locale::classic());
421 template <class CharT
>
423 test_no_chrono_specs
<CharT
>();
424 test_valid_values
<CharT
>();
425 check_invalid_types
<CharT
>(
426 {SV("b"), SV("B"), SV("h"), SV("m"), SV("Om")}, std::chrono::month_day_last
{std::chrono::January
});
429 "The format specifier expects a '%' or a '}'", SV("{:A"), std::chrono::month_day_last
{std::chrono::January
});
431 "The chrono specifiers contain a '{'", SV("{:%%{"), std::chrono::month_day_last
{std::chrono::January
});
432 check_exception("End of input while parsing a conversion specifier",
434 std::chrono::month_day_last
{std::chrono::January
});
436 "End of input while parsing the modifier E", SV("{:%E"), std::chrono::month_day_last
{std::chrono::January
});
438 "End of input while parsing the modifier O", SV("{:%O"), std::chrono::month_day_last
{std::chrono::January
});
440 // Precision not allowed
442 "The format specifier expects a '%' or a '}'", SV("{:.3}"), std::chrono::month_day_last
{std::chrono::January
});
445 int main(int, char**) {
448 #ifndef TEST_HAS_NO_WIDE_CHARACTERS