Debian Codegraph @

libcxx/test/std/time/time.syn/formatter.weekday_index.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 // TODO FMT Investigate Windows issues.
16 // XFAIL: msvc
17
18 // REQUIRES: locale.fr_FR.UTF-8
19 // REQUIRES: locale.ja_JP.UTF-8
20
21 // <chrono>
22
23 // template<class charT> struct formatter<chrono::weekday_index, charT>;
24
25 #include <chrono>
26 #include <format>
27
28 #include <cassert>
29 #include <concepts>
30 #include <locale>
31 #include <iostream>
32 #include <type_traits>
33
34 #include "formatter_tests.h"
35 #include "make_string.h"
36 #include "platform_support.h" // locale name macros
37 #include "test_macros.h"
38
39 template <class CharT>
40 static void test_no_chrono_specs() {
41 using namespace std::literals::chrono_literals;
42
43 // Valid weekday valid index
44 check(SV("Sun[1]"), SV("{}"), std::chrono::weekday_indexed{std::chrono::weekday(0), 1});
45
46 // Invalid weekday valid index
47 check(SV("8 is not a valid weekday[1]"), SV("{}"), std::chrono::weekday_indexed{std::chrono::weekday(8), 1});
48 check(SV("255 is not a valid weekday[1]"), SV("{}"), std::chrono::weekday_indexed{std::chrono::weekday(255), 1});
49
50 // Valid weekday invalid index
51 check(SV("Sun[0 is not a valid index]"), SV("{}"), std::chrono::weekday_indexed{std::chrono::weekday(0), 0});
52 check(SV("Sun[6 is not a valid index]"), SV("{}"), std::chrono::weekday_indexed{std::chrono::weekday(0), 6});
53 check(SV("Sun[255 is not a valid index]"), SV("{}"), std::chrono::weekday_indexed{std::chrono::weekday(0), 255});
54
55 // Invalid weekday invalid index
56 check(SV("8 is not a valid weekday[0 is not a valid index]"),
57 SV("{}"),
58 std::chrono::weekday_indexed{std::chrono::weekday(8), 0});
59 check(SV("127 is not a valid weekday[6 is not a valid index]"),
60 SV("{}"),
61 std::chrono::weekday_indexed{std::chrono::weekday(127), 6});
62 check(SV("255 is not a valid weekday[255 is not a valid index]"),
63 SV("{}"),
64 std::chrono::weekday_indexed{std::chrono::weekday(255), 255});
65 }
66
67 template <class CharT>
68 static void test_valid_values() {
69 constexpr std::basic_string_view<CharT> fmt =
70 SV("{:%%u='%u'%t%%Ou='%Ou'%t%%w='%w'%t%%Ow='%Ow'%t%%a='%a'%t%%A='%A'%n}");
71 constexpr std::basic_string_view<CharT> lfmt =
72 SV("{:L%%u='%u'%t%%Ou='%Ou'%t%%w='%w'%t%%Ow='%Ow'%t%%a='%a'%t%%A='%A'%n}");
73
74 const std::locale loc(LOCALE_ja_JP_UTF_8);
75 std::locale::global(std::locale(LOCALE_fr_FR_UTF_8));
76
77 // Non localized output using C-locale
78 check(SV("%u='7'\t%Ou='7'\t%w='0'\t%Ow='0'\t%a='Sun'\t%A='Sunday'\n"),
79 fmt,
80 std::chrono::weekday_indexed{std::chrono::weekday(0), 0});
81 check(SV("%u='1'\t%Ou='1'\t%w='1'\t%Ow='1'\t%a='Mon'\t%A='Monday'\n"),
82 fmt,
83 std::chrono::weekday_indexed{std::chrono::weekday(1), 1});
84 check(SV("%u='2'\t%Ou='2'\t%w='2'\t%Ow='2'\t%a='Tue'\t%A='Tuesday'\n"),
85 fmt,
86 std::chrono::weekday_indexed{std::chrono::weekday(2), 2});
87 check(SV("%u='3'\t%Ou='3'\t%w='3'\t%Ow='3'\t%a='Wed'\t%A='Wednesday'\n"),
88 fmt,
89 std::chrono::weekday_indexed{std::chrono::weekday(3), 3});
90 check(SV("%u='4'\t%Ou='4'\t%w='4'\t%Ow='4'\t%a='Thu'\t%A='Thursday'\n"),
91 fmt,
92 std::chrono::weekday_indexed{std::chrono::weekday(4), 4});
93 check(SV("%u='5'\t%Ou='5'\t%w='5'\t%Ow='5'\t%a='Fri'\t%A='Friday'\n"),
94 fmt,
95 std::chrono::weekday_indexed{std::chrono::weekday(5), 5});
96 check(SV("%u='6'\t%Ou='6'\t%w='6'\t%Ow='6'\t%a='Sat'\t%A='Saturday'\n"),
97 fmt,
98 std::chrono::weekday_indexed{std::chrono::weekday(6), 6});
99 check(SV("%u='7'\t%Ou='7'\t%w='0'\t%Ow='0'\t%a='Sun'\t%A='Sunday'\n"),
100 fmt,
101 std::chrono::weekday_indexed{std::chrono::weekday(7), 7});
102
103 // Use the global locale (fr_FR)
104 #if defined(__APPLE__)
105 check(SV("%u='7'\t%Ou='7'\t%w='0'\t%Ow='0'\t%a='Dim'\t%A='Dimanche'\n"),
106 lfmt,
107 std::chrono::weekday_indexed{std::chrono::weekday(0), 0});
108 check(SV("%u='1'\t%Ou='1'\t%w='1'\t%Ow='1'\t%a='Lun'\t%A='Lundi'\n"),
109 lfmt,
110 std::chrono::weekday_indexed{std::chrono::weekday(1), 1});
111 check(SV("%u='2'\t%Ou='2'\t%w='2'\t%Ow='2'\t%a='Mar'\t%A='Mardi'\n"),
112 lfmt,
113 std::chrono::weekday_indexed{std::chrono::weekday(2), 2});
114 check(SV("%u='3'\t%Ou='3'\t%w='3'\t%Ow='3'\t%a='Mer'\t%A='Mercredi'\n"),
115 lfmt,
116 std::chrono::weekday_indexed{std::chrono::weekday(3), 3});
117 check(SV("%u='4'\t%Ou='4'\t%w='4'\t%Ow='4'\t%a='Jeu'\t%A='Jeudi'\n"),
118 lfmt,
119 std::chrono::weekday_indexed{std::chrono::weekday(4), 4});
120 check(SV("%u='5'\t%Ou='5'\t%w='5'\t%Ow='5'\t%a='Ven'\t%A='Vendredi'\n"),
121 lfmt,
122 std::chrono::weekday_indexed{std::chrono::weekday(5), 5});
123 check(SV("%u='6'\t%Ou='6'\t%w='6'\t%Ow='6'\t%a='Sam'\t%A='Samedi'\n"),
124 lfmt,
125 std::chrono::weekday_indexed{std::chrono::weekday(6), 6});
126 check(SV("%u='7'\t%Ou='7'\t%w='0'\t%Ow='0'\t%a='Dim'\t%A='Dimanche'\n"),
127 lfmt,
128 std::chrono::weekday_indexed{std::chrono::weekday(7), 7});
129 #else // defined(__APPLE__)
130 check(SV("%u='7'\t%Ou='7'\t%w='0'\t%Ow='0'\t%a='dim.'\t%A='dimanche'\n"),
131 lfmt,
132 std::chrono::weekday_indexed{std::chrono::weekday(0), 0});
133 check(SV("%u='1'\t%Ou='1'\t%w='1'\t%Ow='1'\t%a='lun.'\t%A='lundi'\n"),
134 lfmt,
135 std::chrono::weekday_indexed{std::chrono::weekday(1), 1});
136 check(SV("%u='2'\t%Ou='2'\t%w='2'\t%Ow='2'\t%a='mar.'\t%A='mardi'\n"),
137 lfmt,
138 std::chrono::weekday_indexed{std::chrono::weekday(2), 2});
139 check(SV("%u='3'\t%Ou='3'\t%w='3'\t%Ow='3'\t%a='mer.'\t%A='mercredi'\n"),
140 lfmt,
141 std::chrono::weekday_indexed{std::chrono::weekday(3), 3});
142 check(SV("%u='4'\t%Ou='4'\t%w='4'\t%Ow='4'\t%a='jeu.'\t%A='jeudi'\n"),
143 lfmt,
144 std::chrono::weekday_indexed{std::chrono::weekday(4), 4});
145 check(SV("%u='5'\t%Ou='5'\t%w='5'\t%Ow='5'\t%a='ven.'\t%A='vendredi'\n"),
146 lfmt,
147 std::chrono::weekday_indexed{std::chrono::weekday(5), 5});
148 check(SV("%u='6'\t%Ou='6'\t%w='6'\t%Ow='6'\t%a='sam.'\t%A='samedi'\n"),
149 lfmt,
150 std::chrono::weekday_indexed{std::chrono::weekday(6), 6});
151 check(SV("%u='7'\t%Ou='7'\t%w='0'\t%Ow='0'\t%a='dim.'\t%A='dimanche'\n"),
152 lfmt,
153 std::chrono::weekday_indexed{std::chrono::weekday(7), 7});
154 #endif // defined(__APPLE__)
155
156 // Use supplied locale (ja_JP).
157 // This locale has a different alternate, but not on all platforms
158 #if defined(_WIN32) || defined(__APPLE__) || defined(_AIX) || defined(__FreeBSD__)
159 check(loc,
160 SV("%u='7'\t%Ou='7'\t%w='0'\t%Ow='0'\t%a='日'\t%A='日曜日'\n"),
161 lfmt,
162 std::chrono::weekday_indexed{std::chrono::weekday(0), 0});
163 check(loc,
164 SV("%u='1'\t%Ou='1'\t%w='1'\t%Ow='1'\t%a='月'\t%A='月曜日'\n"),
165 lfmt,
166 std::chrono::weekday_indexed{std::chrono::weekday(1), 1});
167 check(loc,
168 SV("%u='2'\t%Ou='2'\t%w='2'\t%Ow='2'\t%a='火'\t%A='火曜日'\n"),
169 lfmt,
170 std::chrono::weekday_indexed{std::chrono::weekday(2), 2});
171 check(loc,
172 SV("%u='3'\t%Ou='3'\t%w='3'\t%Ow='3'\t%a='水'\t%A='水曜日'\n"),
173 lfmt,
174 std::chrono::weekday_indexed{std::chrono::weekday(3), 3});
175 check(loc,
176 SV("%u='4'\t%Ou='4'\t%w='4'\t%Ow='4'\t%a='木'\t%A='木曜日'\n"),
177 lfmt,
178 std::chrono::weekday_indexed{std::chrono::weekday(4), 4});
179 check(loc,
180 SV("%u='5'\t%Ou='5'\t%w='5'\t%Ow='5'\t%a='金'\t%A='金曜日'\n"),
181 lfmt,
182 std::chrono::weekday_indexed{std::chrono::weekday(5), 5});
183 check(loc,
184 SV("%u='6'\t%Ou='6'\t%w='6'\t%Ow='6'\t%a='土'\t%A='土曜日'\n"),
185 lfmt,
186 std::chrono::weekday_indexed{std::chrono::weekday(6), 6});
187 check(loc,
188 SV("%u='7'\t%Ou='7'\t%w='0'\t%Ow='0'\t%a='日'\t%A='日曜日'\n"),
189 lfmt,
190 std::chrono::weekday_indexed{std::chrono::weekday(7), 7});
191 #else // defined(_WIN32) || defined(__APPLE__) || defined(_AIX) || defined(__FreeBSD__)
192 check(loc,
193 SV("%u='7'\t%Ou='七'\t%w='0'\t%Ow='〇'\t%a='日'\t%A='日曜日'\n"),
194 lfmt,
195 std::chrono::weekday_indexed{std::chrono::weekday(0), 0});
196 check(loc,
197 SV("%u='1'\t%Ou='一'\t%w='1'\t%Ow='一'\t%a='月'\t%A='月曜日'\n"),
198 lfmt,
199 std::chrono::weekday_indexed{std::chrono::weekday(1), 1});
200 check(loc,
201 SV("%u='2'\t%Ou='二'\t%w='2'\t%Ow='二'\t%a='火'\t%A='火曜日'\n"),
202 lfmt,
203 std::chrono::weekday_indexed{std::chrono::weekday(2), 2});
204 check(loc,
205 SV("%u='3'\t%Ou='三'\t%w='3'\t%Ow='三'\t%a='水'\t%A='水曜日'\n"),
206 lfmt,
207 std::chrono::weekday_indexed{std::chrono::weekday(3), 3});
208 check(loc,
209 SV("%u='4'\t%Ou='四'\t%w='4'\t%Ow='四'\t%a='木'\t%A='木曜日'\n"),
210 lfmt,
211 std::chrono::weekday_indexed{std::chrono::weekday(4), 4});
212 check(loc,
213 SV("%u='5'\t%Ou='五'\t%w='5'\t%Ow='五'\t%a='金'\t%A='金曜日'\n"),
214 lfmt,
215 std::chrono::weekday_indexed{std::chrono::weekday(5), 5});
216 check(loc,
217 SV("%u='6'\t%Ou='六'\t%w='6'\t%Ow='六'\t%a='土'\t%A='土曜日'\n"),
218 lfmt,
219 std::chrono::weekday_indexed{std::chrono::weekday(6), 6});
220 check(loc,
221 SV("%u='7'\t%Ou='七'\t%w='0'\t%Ow='〇'\t%a='日'\t%A='日曜日'\n"),
222 lfmt,
223 std::chrono::weekday_indexed{std::chrono::weekday(7), 7});
224 #endif // defined(_WIN32) || defined(__APPLE__) || defined(_AIX) || defined(__FreeBSD__)
225
226 std::locale::global(std::locale::classic());
227 }
228
229 template <class CharT>
230 static void test_invalid_values() {
231 // Test that %a and %A throw an exception.
232 check_exception("Formatting a weekday name needs a valid weekday",
233 SV("{:%a}"),
234 std::chrono::weekday_indexed{std::chrono::weekday(8), 1});
235 check_exception("Formatting a weekday name needs a valid weekday",
236 SV("{:%a}"),
237 std::chrono::weekday_indexed{std::chrono::weekday(255), 1});
238 check_exception("Formatting a weekday name needs a valid weekday",
239 SV("{:%A}"),
240 std::chrono::weekday_indexed{std::chrono::weekday(8), 1});
241 check_exception("Formatting a weekday name needs a valid weekday",
242 SV("{:%A}"),
243 std::chrono::weekday_indexed{std::chrono::weekday(255), 1});
244
245 const std::locale loc(LOCALE_ja_JP_UTF_8);
246 std::locale::global(std::locale(LOCALE_fr_FR_UTF_8));
247
248 { // Invalid weekday, can't test %a and %A
249 constexpr std::basic_string_view<CharT> fmt = SV("{:%%u='%u'%t%%Ou='%Ou'%t%%w='%w'%t%%Ow='%Ow'%n}");
250 constexpr std::basic_string_view<CharT> lfmt = SV("{:L%%u='%u'%t%%Ou='%Ou'%t%%w='%w'%t%%Ow='%Ow'%n}");
251 #if defined(__APPLE__) || defined(__FreeBSD__)
252 // Non localized output using C-locale
253 check(SV("%u='8'\t%Ou='8'\t%w='8'\t%Ow='8'\n"), fmt, std::chrono::weekday_indexed{std::chrono::weekday(8), 0});
254 check(SV("%u='8'\t%Ou='8'\t%w='8'\t%Ow='8'\n"), fmt, std::chrono::weekday_indexed{std::chrono::weekday(8), 1});
255 check(SV("%u='255'\t%Ou='255'\t%w='255'\t%Ow='255'\n"),
256 fmt,
257 std::chrono::weekday_indexed{std::chrono::weekday(255), 0});
258 check(SV("%u='255'\t%Ou='255'\t%w='255'\t%Ow='255'\n"),
259 fmt,
260 std::chrono::weekday_indexed{std::chrono::weekday(255), 1});
261
262 // Use the global locale (fr_FR)
263 check(SV("%u='8'\t%Ou='8'\t%w='8'\t%Ow='8'\n"), lfmt, std::chrono::weekday_indexed{std::chrono::weekday(8), 0});
264 check(SV("%u='8'\t%Ou='8'\t%w='8'\t%Ow='8'\n"), lfmt, std::chrono::weekday_indexed{std::chrono::weekday(8), 1});
265 check(SV("%u='255'\t%Ou='255'\t%w='255'\t%Ow='255'\n"),
266 lfmt,
267 std::chrono::weekday_indexed{std::chrono::weekday(255), 0});
268 check(SV("%u='255'\t%Ou='255'\t%w='255'\t%Ow='255'\n"),
269 lfmt,
270 std::chrono::weekday_indexed{std::chrono::weekday(255), 1});
271
272 // Use supplied locale (ja_JP). This locale has a different alternate.
273 check(
274 loc, SV("%u='8'\t%Ou='8'\t%w='8'\t%Ow='8'\n"), lfmt, std::chrono::weekday_indexed{std::chrono::weekday(8), 0});
275 check(
276 loc, SV("%u='8'\t%Ou='8'\t%w='8'\t%Ow='8'\n"), lfmt, std::chrono::weekday_indexed{std::chrono::weekday(8), 1});
277 check(loc,
278 SV("%u='255'\t%Ou='255'\t%w='255'\t%Ow='255'\n"),
279 lfmt,
280 std::chrono::weekday_indexed{std::chrono::weekday(255), 0});
281 check(loc,
282 SV("%u='255'\t%Ou='255'\t%w='255'\t%Ow='255'\n"),
283 lfmt,
284 std::chrono::weekday_indexed{std::chrono::weekday(255), 1});
285 #elif defined(_WIN32) // defined(__APPLE__) || defined(__FreeBSD__)
286 // Non localized output using C-locale
287 check(SV("%u=''\t%Ou=''\t%w=''\t%Ow=''\n"), fmt, std::chrono::weekday_indexed{std::chrono::weekday(8), 0});
288 check(SV("%u=''\t%Ou=''\t%w=''\t%Ow=''\n"), fmt, std::chrono::weekday_indexed{std::chrono::weekday(8), 1});
289 check(SV("%u=''\t%Ou=''\t%w=''\t%Ow=''\n"), fmt, std::chrono::weekday_indexed{std::chrono::weekday(255), 0});
290 check(SV("%u=''\t%Ou=''\t%w=''\t%Ow=''\n"), fmt, std::chrono::weekday_indexed{std::chrono::weekday(255), 1});
291
292 // Use the global locale (fr_FR)
293 check(SV("%u=''\t%Ou=''\t%w=''\t%Ow=''\n"), lfmt, std::chrono::weekday_indexed{std::chrono::weekday(8), 0});
294 check(SV("%u=''\t%Ou=''\t%w=''\t%Ow=''\n"), lfmt, std::chrono::weekday_indexed{std::chrono::weekday(8), 1});
295 check(SV("%u=''\t%Ou=''\t%w=''\t%Ow=''\n"), lfmt, std::chrono::weekday_indexed{std::chrono::weekday(255), 0});
296 check(SV("%u=''\t%Ou=''\t%w=''\t%Ow=''\n"), lfmt, std::chrono::weekday_indexed{std::chrono::weekday(255), 1});
297
298 // Use supplied locale (ja_JP). This locale has a different alternate.
299 check(loc, SV("%u=''\t%Ou=''\t%w=''\t%Ow=''\n"), lfmt, std::chrono::weekday_indexed{std::chrono::weekday(8), 0});
300 check(loc, SV("%u=''\t%Ou=''\t%w=''\t%Ow=''\n"), lfmt, std::chrono::weekday_indexed{std::chrono::weekday(8), 1});
301 check(loc, SV("%u=''\t%Ou=''\t%w=''\t%Ow=''\n"), lfmt, std::chrono::weekday_indexed{std::chrono::weekday(255), 0});
302 check(loc, SV("%u=''\t%Ou=''\t%w=''\t%Ow=''\n"), lfmt, std::chrono::weekday_indexed{std::chrono::weekday(255), 1});
303 #elif defined(_AIX) // defined(__APPLE__) || defined(__FreeBSD__)
304 // Non localized output using C-locale
305 check(SV("%u='8'\t%Ou='8'\t%w='8'\t%Ow='8'\n"), fmt, std::chrono::weekday_indexed{std::chrono::weekday(8), 0});
306 check(SV("%u='8'\t%Ou='8'\t%w='8'\t%Ow='8'\n"), fmt, std::chrono::weekday_indexed{std::chrono::weekday(8), 1});
307 check(SV("%u='5'\t%Ou='5'\t%w='5'\t%Ow='5'\n"), fmt, std::chrono::weekday_indexed{std::chrono::weekday(255), 0});
308 check(SV("%u='5'\t%Ou='5'\t%w='5'\t%Ow='5'\n"), fmt, std::chrono::weekday_indexed{std::chrono::weekday(255), 1});
309
310 // Use the global locale (fr_FR)
311 check(SV("%u='8'\t%Ou='8'\t%w='8'\t%Ow='8'\n"), lfmt, std::chrono::weekday_indexed{std::chrono::weekday(8), 0});
312 check(SV("%u='8'\t%Ou='8'\t%w='8'\t%Ow='8'\n"), lfmt, std::chrono::weekday_indexed{std::chrono::weekday(8), 1});
313 check(SV("%u='5'\t%Ou='5'\t%w='5'\t%Ow='5'\n"), lfmt, std::chrono::weekday_indexed{std::chrono::weekday(255), 0});
314 check(SV("%u='5'\t%Ou='5'\t%w='5'\t%Ow='5'\n"), lfmt, std::chrono::weekday_indexed{std::chrono::weekday(255), 1});
315
316 // Use supplied locale (ja_JP). This locale has a different alternate.
317 check(
318 loc, SV("%u='8'\t%Ou='8'\t%w='8'\t%Ow='8'\n"), lfmt, std::chrono::weekday_indexed{std::chrono::weekday(8), 0});
319 check(
320 loc, SV("%u='8'\t%Ou='8'\t%w='8'\t%Ow='8'\n"), lfmt, std::chrono::weekday_indexed{std::chrono::weekday(8), 1});
321 check(loc,
322 SV("%u='5'\t%Ou='5'\t%w='5'\t%Ow='5'\n"),
323 lfmt,
324 std::chrono::weekday_indexed{std::chrono::weekday(255), 0});
325 check(loc,
326 SV("%u='5'\t%Ou='5'\t%w='5'\t%Ow='5'\n"),
327 lfmt,
328 std::chrono::weekday_indexed{std::chrono::weekday(255), 1});
329 #else // defined(__APPLE__) || defined(__FreeBSD__)
330 // Non localized output using C-locale
331 check(SV("%u='1'\t%Ou='1'\t%w='8'\t%Ow='8'\n"), fmt, std::chrono::weekday_indexed{std::chrono::weekday(8), 0});
332 check(SV("%u='1'\t%Ou='1'\t%w='8'\t%Ow='8'\n"), fmt, std::chrono::weekday_indexed{std::chrono::weekday(8), 1});
333 check(
334 SV("%u='3'\t%Ou='3'\t%w='255'\t%Ow='255'\n"), fmt, std::chrono::weekday_indexed{std::chrono::weekday(255), 0});
335 check(
336 SV("%u='3'\t%Ou='3'\t%w='255'\t%Ow='255'\n"), fmt, std::chrono::weekday_indexed{std::chrono::weekday(255), 1});
337
338 // Use the global locale (fr_FR)
339 check(SV("%u='1'\t%Ou='1'\t%w='8'\t%Ow='8'\n"), lfmt, std::chrono::weekday_indexed{std::chrono::weekday(8), 0});
340 check(SV("%u='1'\t%Ou='1'\t%w='8'\t%Ow='8'\n"), lfmt, std::chrono::weekday_indexed{std::chrono::weekday(8), 1});
341 check(
342 SV("%u='3'\t%Ou='3'\t%w='255'\t%Ow='255'\n"), lfmt, std::chrono::weekday_indexed{std::chrono::weekday(255), 0});
343 check(
344 SV("%u='3'\t%Ou='3'\t%w='255'\t%Ow='255'\n"), lfmt, std::chrono::weekday_indexed{std::chrono::weekday(255), 1});
345
346 // Use supplied locale (ja_JP). This locale has a different alternate.
347 check(loc,
348 SV("%u='1'\t%Ou='一'\t%w='8'\t%Ow='八'\n"),
349 lfmt,
350 std::chrono::weekday_indexed{std::chrono::weekday(8), 0});
351 check(loc,
352 SV("%u='1'\t%Ou='一'\t%w='8'\t%Ow='八'\n"),
353 lfmt,
354 std::chrono::weekday_indexed{std::chrono::weekday(8), 1});
355 check(loc,
356 SV("%u='3'\t%Ou='三'\t%w='255'\t%Ow='255'\n"),
357 lfmt,
358 std::chrono::weekday_indexed{std::chrono::weekday(255), 0});
359 check(loc,
360 SV("%u='3'\t%Ou='三'\t%w='255'\t%Ow='255'\n"),
361 lfmt,
362 std::chrono::weekday_indexed{std::chrono::weekday(255), 1});
363 #endif // defined(__APPLE__) || defined(__FreeBSD__)
364 }
365
366 { // Valid weekday, tests %a and %A
367 constexpr std::basic_string_view<CharT> fmt = SV("{:%%a='%a'%t%%A='%A'%n}");
368 constexpr std::basic_string_view<CharT> lfmt = SV("{:L%%a='%a'%t%%A='%A'%n}");
369
370 // Non localized output using C-locale
371 check(SV("%a='Sun'\t%A='Sunday'\n"), fmt, std::chrono::weekday_indexed{std::chrono::weekday(0), 0});
372 check(SV("%a='Sun'\t%A='Sunday'\n"), fmt, std::chrono::weekday_indexed{std::chrono::weekday(0), 6});
373
374 // Use the global locale (fr_FR)
375 #if defined(__APPLE__)
376 check(SV("%a='Dim'\t%A='Dimanche'\n"), lfmt, std::chrono::weekday_indexed{std::chrono::weekday(0), 0});
377 check(SV("%a='Dim'\t%A='Dimanche'\n"), lfmt, std::chrono::weekday_indexed{std::chrono::weekday(0), 6});
378 #else // defined(__APPLE__)
379 check(SV("%a='dim.'\t%A='dimanche'\n"), lfmt, std::chrono::weekday_indexed{std::chrono::weekday(0), 0});
380 check(SV("%a='dim.'\t%A='dimanche'\n"), lfmt, std::chrono::weekday_indexed{std::chrono::weekday(0), 6});
381 #endif // defined(__APPLE__)
382
383 // Use supplied locale (ja_JP)
384 check(loc, SV("%a='日'\t%A='日曜日'\n"), lfmt, std::chrono::weekday_indexed{std::chrono::weekday(0), 0});
385 check(loc, SV("%a='日'\t%A='日曜日'\n"), lfmt, std::chrono::weekday_indexed{std::chrono::weekday(0), 6});
386 }
387
388 std::locale::global(std::locale::classic());
389 }
390
391 template <class CharT>
392 static void test() {
393 test_no_chrono_specs<CharT>();
394 test_valid_values<CharT>();
395 test_invalid_values<CharT>();
396 check_invalid_types<CharT>({SV("a"), SV("A"), SV("t"), SV("u"), SV("w"), SV("Ou"), SV("Ow")},
397 std::chrono::weekday_indexed{std::chrono::weekday(0), 1});
398
399 check_exception("The format specifier expects a '%' or a '}'",
400 SV("{:A"),
401 std::chrono::weekday_indexed{std::chrono::weekday(0), 1});
402 check_exception(
403 "The chrono specifiers contain a '{'", SV("{:%%{"), std::chrono::weekday_indexed{std::chrono::weekday(0), 1});
404 check_exception("End of input while parsing a conversion specifier",
405 SV("{:%"),
406 std::chrono::weekday_indexed{std::chrono::weekday(0), 1});
407 check_exception("End of input while parsing the modifier E",
408 SV("{:%E"),
409 std::chrono::weekday_indexed{std::chrono::weekday(0), 1});
410 check_exception("End of input while parsing the modifier O",
411 SV("{:%O"),
412 std::chrono::weekday_indexed{std::chrono::weekday(0), 1});
413
414 // Precision not allowed
415 check_exception("The format specifier expects a '%' or a '}'",
416 SV("{:.3}"),
417 std::chrono::weekday_indexed{std::chrono::weekday(0), 1});
418 }
419
420 int main(int, char**) {
421 test<char>();
422
423 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
424 test<wchar_t>();
425 #endif
426
427 return 0;
428 }