[SLP] Make getSameOpcode support different instructions if they have same semantics...
[llvm-project.git] / libcxx / test / std / containers / container.adaptors / container.adaptors.format / format.functions.tests.h
blobeb4b7a1d2e62f0d8943929ab5e7bd5d5bbb9a97a
1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef TEST_STD_CONTAINERS_CONTAINER_ADAPTORS_CONTAINER_ADAPTORS_FORMAT_FORMAT_FUNCTIONS_TESTS_H
10 #define TEST_STD_CONTAINERS_CONTAINER_ADAPTORS_CONTAINER_ADAPTORS_FORMAT_FORMAT_FUNCTIONS_TESTS_H
12 #include <algorithm>
13 #include <array>
14 #include <charconv>
15 #include <concepts>
16 #include <format>
17 #include <list>
18 #include <queue>
19 #include <stack>
21 #include "format.functions.common.h"
22 #include "make_string.h"
23 #include "platform_support.h" // locale name macros
24 #include "test_macros.h"
27 // Char
30 template <class CharT, class TestFunction, class ExceptionTest>
31 void test_char_default(TestFunction check, ExceptionTest check_exception, auto&& input) {
32 // Note when no range-underlying-spec is present the char is escaped,
33 check(SV("['H', 'e', 'l', 'l', 'o']"), SV("{}"), input);
34 check(SV("['H', 'e', 'l', 'l', 'o']^42"), SV("{}^42"), input);
35 check(SV("['H', 'e', 'l', 'l', 'o']^42"), SV("{:}^42"), input);
37 // when one is present there is no escaping,
38 check(SV("[H, e, l, l, o]"), SV("{::}"), input);
39 check(SV("[H, e, l, l, o]"), SV("{::<}"), input);
40 // unless forced by the type specifier.
41 check(SV("['H', 'e', 'l', 'l', 'o']"), SV("{::?}"), input);
42 check(SV("['H', 'e', 'l', 'l', 'o']"), SV("{::<?}"), input);
44 // ***** underlying has no format-spec
46 // *** align-fill & width ***
47 check(SV("['H', 'e', 'l', 'l', 'o'] "), SV("{:30}"), input);
48 check(SV("['H', 'e', 'l', 'l', 'o']*****"), SV("{:*<30}"), input);
49 check(SV("__['H', 'e', 'l', 'l', 'o']___"), SV("{:_^30}"), input);
50 check(SV("#####['H', 'e', 'l', 'l', 'o']"), SV("{:#>30}"), input);
52 check(SV("['H', 'e', 'l', 'l', 'o'] "), SV("{:{}}"), input, 30);
53 check(SV("['H', 'e', 'l', 'l', 'o']*****"), SV("{:*<{}}"), input, 30);
54 check(SV("__['H', 'e', 'l', 'l', 'o']___"), SV("{:_^{}}"), input, 30);
55 check(SV("#####['H', 'e', 'l', 'l', 'o']"), SV("{:#>{}}"), input, 30);
57 check_exception("The format string contains an invalid escape sequence", SV("{:}<}"), input);
58 check_exception("The fill option contains an invalid value", SV("{:{<}"), input);
60 // *** sign ***
61 check_exception("The format specifier should consume the input or end with a '}'", SV("{:-}"), input);
62 check_exception("The format specifier should consume the input or end with a '}'", SV("{:+}"), input);
63 check_exception("The format specifier should consume the input or end with a '}'", SV("{: }"), input);
65 // *** alternate form ***
66 check_exception("The format specifier should consume the input or end with a '}'", SV("{:#}"), input);
68 // *** zero-padding ***
69 check_exception("The width option should not have a leading zero", SV("{:0}"), input);
71 // *** precision ***
72 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.}"), input);
74 // *** locale-specific form ***
75 check_exception("The format specifier should consume the input or end with a '}'", SV("{:L}"), input);
77 // *** n
78 check(SV("__'H', 'e', 'l', 'l', 'o'___"), SV("{:_^28n}"), input);
80 // *** type ***
81 check_exception("Type m requires a pair or a tuple with two elements", SV("{:m}"), input);
82 for (std::basic_string_view<CharT> fmt : fmt_invalid_types<CharT>("s"))
83 check_exception("The format specifier should consume the input or end with a '}'", fmt, input);
85 // ***** Only underlying has a format-spec
86 check(SV("[H , e , l , l , o ]"), SV("{::4}"), input);
87 check(SV("[H***, e***, l***, l***, o***]"), SV("{::*<4}"), input);
88 check(SV("[_H__, _e__, _l__, _l__, _o__]"), SV("{::_^4}"), input);
89 check(SV("[:::H, :::e, :::l, :::l, :::o]"), SV("{:::>4}"), input);
91 check(SV("[H , e , l , l , o ]"), SV("{::{}}"), input, 4);
92 check(SV("[H***, e***, l***, l***, o***]"), SV("{::*<{}}"), input, 4);
93 check(SV("[_H__, _e__, _l__, _l__, _o__]"), SV("{::_^{}}"), input, 4);
94 check(SV("[:::H, :::e, :::l, :::l, :::o]"), SV("{:::>{}}"), input, 4);
96 check_exception("The format string contains an invalid escape sequence", SV("{::}<}"), input);
97 check_exception("The fill option contains an invalid value", SV("{::{<}"), input);
99 // *** sign ***
100 check_exception("The format specifier for a character does not allow the sign option", SV("{::-}"), input);
101 check_exception("The format specifier for a character does not allow the sign option", SV("{::+}"), input);
102 check_exception("The format specifier for a character does not allow the sign option", SV("{:: }"), input);
104 check(SV("[72, 101, 108, 108, 111]"), SV("{::-d}"), input);
105 check(SV("[+72, +101, +108, +108, +111]"), SV("{::+d}"), input);
106 check(SV("[ 72, 101, 108, 108, 111]"), SV("{:: d}"), input);
108 // *** alternate form ***
109 check_exception("The format specifier for a character does not allow the alternate form option", SV("{::#}"), input);
111 check(SV("[0x48, 0x65, 0x6c, 0x6c, 0x6f]"), SV("{::#x}"), input);
113 // *** zero-padding ***
114 check_exception("The format specifier for a character does not allow the zero-padding option", SV("{::05}"), input);
116 check(SV("[00110, 00145, 00154, 00154, 00157]"), SV("{::05o}"), input);
118 // *** precision ***
119 check_exception("The format specifier should consume the input or end with a '}'", SV("{::.}"), input);
121 // *** locale-specific form ***
122 check(SV("[H, e, l, l, o]"), SV("{::L}"), input);
124 // *** type ***
125 for (std::basic_string_view<CharT> fmt : fmt_invalid_nested_types<CharT>("bBcdoxX?"))
126 check_exception("The type option contains an invalid value for a character formatting argument", fmt, input);
128 // ***** Both have a format specifier
129 check(SV("^^[:H, :e, :l, :l, :o]^^^"), SV("{:^^25::>2}"), input);
130 check(SV("^^[:H, :e, :l, :l, :o]^^^"), SV("{:^^{}::>2}"), input, 25);
131 check(SV("^^[:H, :e, :l, :l, :o]^^^"), SV("{:^^{}::>{}}"), input, 25, 2);
133 check_exception(
134 "The argument index value is too large for the number of arguments supplied", SV("{:^^{}::>2}"), input);
135 check_exception(
136 "The argument index value is too large for the number of arguments supplied", SV("{:^^{}::>{}}"), input, 25);
139 template <class CharT, class TestFunction, class ExceptionTest>
140 void test_char_string(TestFunction check, ExceptionTest check_exception, auto&& input) {
141 check(SV("Hello"), SV("{:s}"), input);
143 // ***** underlying has no format-spec
145 // *** align-fill & width ***
146 check(SV("Hello "), SV("{:8s}"), input);
147 check(SV("Hello***"), SV("{:*<8s}"), input);
148 check(SV("_Hello__"), SV("{:_^8s}"), input);
149 check(SV("###Hello"), SV("{:#>8s}"), input);
151 check(SV("Hello "), SV("{:{}s}"), input, 8);
152 check(SV("Hello***"), SV("{:*<{}s}"), input, 8);
153 check(SV("_Hello__"), SV("{:_^{}s}"), input, 8);
154 check(SV("###Hello"), SV("{:#>{}s}"), input, 8);
156 check_exception("The format string contains an invalid escape sequence", SV("{:}<s}"), input);
157 check_exception("The fill option contains an invalid value", SV("{:{<s}"), input);
159 // *** sign ***
160 check_exception("The format specifier should consume the input or end with a '}'", SV("{:-s}"), input);
161 check_exception("The format specifier should consume the input or end with a '}'", SV("{:+s}"), input);
162 check_exception("The format specifier should consume the input or end with a '}'", SV("{: s}"), input);
164 // *** alternate form ***
165 check_exception("The format specifier should consume the input or end with a '}'", SV("{:#s}"), input);
167 // *** zero-padding ***
168 check_exception("The width option should not have a leading zero", SV("{:0s}"), input);
170 // *** precision ***
171 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.s}"), input);
173 // *** locale-specific form ***
174 check_exception("The format specifier should consume the input or end with a '}'", SV("{:Ls}"), input);
176 // *** n
177 check_exception("The n option and type s can't be used together", SV("{:ns}"), input);
179 // *** type ***
180 check_exception("Type m requires a pair or a tuple with two elements", SV("{:m}"), input);
181 check_exception("The type option contains an invalid value for a character formatting argument", SV("{::<s}"), input);
183 // ***** Only underlying has a format-spec
184 check_exception("Type s and an underlying format specification can't be used together", SV("{:s:}"), input);
185 for (std::basic_string_view<CharT> fmt : fmt_invalid_nested_types<CharT>("bBcdoxX?"))
186 check_exception("The type option contains an invalid value for a character formatting argument", fmt, input);
188 // ***** Both have a format-spec
189 check_exception("Type s and an underlying format specification can't be used together", SV("{:5s:5}"), input);
192 template <class CharT, class TestFunction, class ExceptionTest>
193 void test_char_escaped_string(TestFunction check, ExceptionTest check_exception, auto&& input) {
194 check(SV(R"("Hello")"), SV("{:?s}"), input);
196 // ***** underlying has no format-spec
198 // *** align-fill & width ***
199 check(SV(R"("Hello" )"), SV("{:10?s}"), input);
200 check(SV(R"("Hello"***)"), SV("{:*<10?s}"), input);
201 check(SV(R"(_"Hello"__)"), SV("{:_^10?s}"), input);
202 check(SV(R"(###"Hello")"), SV("{:#>10?s}"), input);
204 check(SV(R"("Hello" )"), SV("{:{}?s}"), input, 10);
205 check(SV(R"("Hello"***)"), SV("{:*<{}?s}"), input, 10);
206 check(SV(R"(_"Hello"__)"), SV("{:_^{}?s}"), input, 10);
207 check(SV(R"(###"Hello")"), SV("{:#>{}?s}"), input, 10);
209 check_exception("The format string contains an invalid escape sequence", SV("{:}<?s}"), input);
210 check_exception("The fill option contains an invalid value", SV("{:{<?s}"), input);
211 check_exception("The format specifier should consume the input or end with a '}'", SV("{::<?s}"), input);
213 // *** sign ***
214 check_exception("The format specifier should consume the input or end with a '}'", SV("{:-?s}"), input);
215 check_exception("The format specifier should consume the input or end with a '}'", SV("{:+?s}"), input);
216 check_exception("The format specifier should consume the input or end with a '}'", SV("{: ?s}"), input);
218 // *** alternate form ***
219 check_exception("The format specifier should consume the input or end with a '}'", SV("{:#?s}"), input);
221 // *** zero-padding ***
222 check_exception("The width option should not have a leading zero", SV("{:0?s}"), input);
224 // *** precision ***
225 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.?s}"), input);
227 // *** locale-specific form ***
228 check_exception("The format specifier should consume the input or end with a '}'", SV("{:L?s}"), input);
230 // *** n
231 check_exception("The n option and type ?s can't be used together", SV("{:n?s}"), input);
233 // *** type ***
234 check_exception("Type m requires a pair or a tuple with two elements", SV("{:m}"), input);
236 // ***** Only underlying has a format-spec
237 check_exception("Type ?s and an underlying format specification can't be used together", SV("{:?s:}"), input);
239 // ***** Both have a format-spec
240 check_exception("Type ?s and an underlying format specification can't be used together", SV("{:5?s:5}"), input);
243 template <class CharT, class TestFunction, class ExceptionTest>
244 void test_char(TestFunction check, ExceptionTest check_exception) {
245 // These values are in numeric order when using ASCII, which is used by the priority_queue.
246 std::array input{CharT('H'), CharT('e'), CharT('l'), CharT('l'), CharT('o')};
247 test_char_default<CharT>(check, check_exception, std::queue{input.begin(), input.end()});
248 test_char_default<CharT>(check, check_exception, std::priority_queue{input.begin(), input.end(), std::greater{}});
249 test_char_default<CharT>(check, check_exception, std::stack{input.begin(), input.end()});
251 test_char_string<CharT>(check, check_exception, std::queue{input.begin(), input.end()});
252 test_char_string<CharT>(check, check_exception, std::priority_queue{input.begin(), input.end(), std::greater{}});
253 test_char_string<CharT>(check, check_exception, std::stack{input.begin(), input.end()});
255 test_char_escaped_string<CharT>(check, check_exception, std::queue{input.begin(), input.end()});
256 test_char_escaped_string<CharT>(
257 check, check_exception, std::priority_queue{input.begin(), input.end(), std::greater{}});
258 test_char_escaped_string<CharT>(check, check_exception, std::stack{input.begin(), input.end()});
260 // LWG3881 fixes formatting container adaptors backed by a std::string.
261 test_char_default<CharT>(check, check_exception, std::queue{std::basic_string<CharT>{input.begin(), input.end()}});
262 test_char_default<CharT>(
263 check,
264 check_exception,
265 std::priority_queue{std::greater{}, std::basic_string<CharT>{input.begin(), input.end()}});
266 test_char_default<CharT>(check, check_exception, std::stack{std::basic_string<CharT>{input.begin(), input.end()}});
270 // char -> wchar_t
273 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
274 template <class TestFunction, class ExceptionTest>
275 void test_char_to_wchar(TestFunction check, ExceptionTest check_exception) {
276 std::array input{'H', 'e', 'l', 'l', 'o'};
277 test_char_default<wchar_t>(check, check_exception, std::queue{input.begin(), input.end()});
278 test_char_default<wchar_t>(check, check_exception, std::priority_queue{input.begin(), input.end(), std::greater{}});
279 test_char_default<wchar_t>(check, check_exception, std::stack{input.begin(), input.end()});
281 // The types s and ?s may only be used when using range_formatter<T, charT>
282 // where the types T and charT are the same. This means this can't be used for
283 // range_formatter<wchar_t, char> even when formatter<wchar_t, char> has a
284 // debug-enabled specialization.
286 using CharT = wchar_t;
287 check_exception(
288 "Type s requires character type as formatting argument", SV("{:s}"), std::queue{input.begin(), input.end()});
289 check_exception("Type s requires character type as formatting argument",
290 SV("{:s}"),
291 std::priority_queue{input.begin(), input.end()});
292 check_exception(
293 "Type s requires character type as formatting argument", SV("{:s}"), std::stack{input.begin(), input.end()});
294 check_exception(
295 "Type ?s requires character type as formatting argument", SV("{:?s}"), std::queue{input.begin(), input.end()});
296 check_exception("Type ?s requires character type as formatting argument",
297 SV("{:?s}"),
298 std::priority_queue{input.begin(), input.end()});
299 check_exception(
300 "Type ?s requires character type as formatting argument", SV("{:?s}"), std::stack{input.begin(), input.end()});
302 #endif // TEST_HAS_NO_WIDE_CHARACTERS
305 // Bool
308 template <class CharT, class TestFunction, class ExceptionTest>
309 void test_bool(TestFunction check, ExceptionTest check_exception, auto&& input) {
310 check(SV("[true, true, false]"), SV("{}"), input);
311 check(SV("[true, true, false]^42"), SV("{}^42"), input);
312 check(SV("[true, true, false]^42"), SV("{:}^42"), input);
314 // ***** underlying has no format-spec
316 // *** align-fill & width ***
317 check(SV("[true, true, false] "), SV("{:24}"), input);
318 check(SV("[true, true, false]*****"), SV("{:*<24}"), input);
319 check(SV("__[true, true, false]___"), SV("{:_^24}"), input);
320 check(SV("#####[true, true, false]"), SV("{:#>24}"), input);
322 check(SV("[true, true, false] "), SV("{:{}}"), input, 24);
323 check(SV("[true, true, false]*****"), SV("{:*<{}}"), input, 24);
324 check(SV("__[true, true, false]___"), SV("{:_^{}}"), input, 24);
325 check(SV("#####[true, true, false]"), SV("{:#>{}}"), input, 24);
327 check_exception("The format string contains an invalid escape sequence", SV("{:}<}"), input);
328 check_exception("The fill option contains an invalid value", SV("{:{<}"), input);
330 // *** sign ***
331 check_exception("The format specifier should consume the input or end with a '}'", SV("{:-}"), input);
332 check_exception("The format specifier should consume the input or end with a '}'", SV("{:+}"), input);
333 check_exception("The format specifier should consume the input or end with a '}'", SV("{: }"), input);
335 // *** alternate form ***
336 check_exception("The format specifier should consume the input or end with a '}'", SV("{:#}"), input);
338 // *** zero-padding ***
339 check_exception("The width option should not have a leading zero", SV("{:0}"), input);
341 // *** precision ***
342 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.}"), input);
344 // *** locale-specific form ***
345 check_exception("The format specifier should consume the input or end with a '}'", SV("{:L}"), input);
347 // *** n
348 check(SV("__true, true, false___"), SV("{:_^22n}"), input);
350 // *** type ***
351 check_exception("Type m requires a pair or a tuple with two elements", SV("{:m}"), input);
352 check_exception("Type s requires character type as formatting argument", SV("{:s}"), input);
353 check_exception("Type ?s requires character type as formatting argument", SV("{:?s}"), input);
354 for (std::basic_string_view<CharT> fmt : fmt_invalid_types<CharT>("s"))
355 check_exception("The format specifier should consume the input or end with a '}'", fmt, input);
357 // ***** Only underlying has a format-spec
358 check(SV("[true , true , false ]"), SV("{::7}"), input);
359 check(SV("[true***, true***, false**]"), SV("{::*<7}"), input);
360 check(SV("[_true__, _true__, _false_]"), SV("{::_^7}"), input);
361 check(SV("[:::true, :::true, ::false]"), SV("{:::>7}"), input);
363 check(SV("[true , true , false ]"), SV("{::{}}"), input, 7);
364 check(SV("[true***, true***, false**]"), SV("{::*<{}}"), input, 7);
365 check(SV("[_true__, _true__, _false_]"), SV("{::_^{}}"), input, 7);
366 check(SV("[:::true, :::true, ::false]"), SV("{:::>{}}"), input, 7);
368 check_exception("The format string contains an invalid escape sequence", SV("{::}<}"), input);
369 check_exception("The fill option contains an invalid value", SV("{::{<}"), input);
371 // *** sign ***
372 check_exception("The format specifier for a bool does not allow the sign option", SV("{::-}"), input);
373 check_exception("The format specifier for a bool does not allow the sign option", SV("{::+}"), input);
374 check_exception("The format specifier for a bool does not allow the sign option", SV("{:: }"), input);
376 check(SV("[1, 1, 0]"), SV("{::-d}"), input);
377 check(SV("[+1, +1, +0]"), SV("{::+d}"), input);
378 check(SV("[ 1, 1, 0]"), SV("{:: d}"), input);
380 // *** alternate form ***
381 check_exception("The format specifier for a bool does not allow the alternate form option", SV("{::#}"), input);
383 check(SV("[0x1, 0x1, 0x0]"), SV("{::#x}"), input);
385 // *** zero-padding ***
386 check_exception("The format specifier for a bool does not allow the zero-padding option", SV("{::05}"), input);
388 check(SV("[00001, 00001, 00000]"), SV("{::05o}"), input);
390 // *** precision ***
391 check_exception("The format specifier should consume the input or end with a '}'", SV("{::.}"), input);
393 // *** locale-specific form ***
394 check(SV("[true, true, false]"), SV("{::L}"), input);
396 // *** type ***
397 for (std::basic_string_view<CharT> fmt : fmt_invalid_nested_types<CharT>("bBdosxX"))
398 check_exception("The type option contains an invalid value for a bool formatting argument", fmt, input);
400 // ***** Both have a format-spec
401 check(SV("^^[:::true, :::true, ::false]^^^"), SV("{:^^32::>7}"), input);
402 check(SV("^^[:::true, :::true, ::false]^^^"), SV("{:^^{}::>7}"), input, 32);
403 check(SV("^^[:::true, :::true, ::false]^^^"), SV("{:^^{}::>{}}"), input, 32, 7);
405 check_exception(
406 "The argument index value is too large for the number of arguments supplied", SV("{:^^{}::>5}"), input);
407 check_exception(
408 "The argument index value is too large for the number of arguments supplied", SV("{:^^{}::>{}}"), input, 32);
411 template <class CharT, class TestFunction, class ExceptionTest>
412 void test_bool(TestFunction check, ExceptionTest check_exception) {
413 std::array input{true, true, false};
414 test_bool<CharT>(check, check_exception, std::queue{input.begin(), input.end()});
415 test_bool<CharT>(check, check_exception, std::priority_queue{input.begin(), input.end()});
416 test_bool<CharT>(check, check_exception, std::stack{input.begin(), input.end()});
420 // Integral
423 template <class CharT, class TestFunction, class ExceptionTest>
424 void test_int(TestFunction check, ExceptionTest check_exception, auto&& input) {
425 check(SV("[-42, 1, 2, 42]"), SV("{}"), input);
426 check(SV("[-42, 1, 2, 42]^42"), SV("{}^42"), input);
427 check(SV("[-42, 1, 2, 42]^42"), SV("{:}^42"), input);
429 // ***** underlying has no format-spec
431 // *** align-fill & width ***
432 check(SV("[-42, 1, 2, 42] "), SV("{:20}"), input);
433 check(SV("[-42, 1, 2, 42]*****"), SV("{:*<20}"), input);
434 check(SV("__[-42, 1, 2, 42]___"), SV("{:_^20}"), input);
435 check(SV("#####[-42, 1, 2, 42]"), SV("{:#>20}"), input);
437 check(SV("[-42, 1, 2, 42] "), SV("{:{}}"), input, 20);
438 check(SV("[-42, 1, 2, 42]*****"), SV("{:*<{}}"), input, 20);
439 check(SV("__[-42, 1, 2, 42]___"), SV("{:_^{}}"), input, 20);
440 check(SV("#####[-42, 1, 2, 42]"), SV("{:#>{}}"), input, 20);
442 check_exception("The format string contains an invalid escape sequence", SV("{:}<}"), input);
443 check_exception("The fill option contains an invalid value", SV("{:{<}"), input);
445 // *** sign ***
446 check_exception("The format specifier should consume the input or end with a '}'", SV("{:-}"), input);
447 check_exception("The format specifier should consume the input or end with a '}'", SV("{:+}"), input);
448 check_exception("The format specifier should consume the input or end with a '}'", SV("{: }"), input);
450 // *** alternate form ***
451 check_exception("The format specifier should consume the input or end with a '}'", SV("{:#}"), input);
453 // *** zero-padding ***
454 check_exception("The width option should not have a leading zero", SV("{:0}"), input);
456 // *** precision ***
457 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.}"), input);
459 // *** locale-specific form ***
460 check_exception("The format specifier should consume the input or end with a '}'", SV("{:L}"), input);
462 // *** n
463 check(SV("__-42, 1, 2, 42___"), SV("{:_^18n}"), input);
465 // *** type ***
466 check_exception("Type m requires a pair or a tuple with two elements", SV("{:m}"), input);
467 check_exception("Type s requires character type as formatting argument", SV("{:s}"), input);
468 check_exception("Type ?s requires character type as formatting argument", SV("{:?s}"), input);
469 for (std::basic_string_view<CharT> fmt : fmt_invalid_types<CharT>("s"))
470 check_exception("The format specifier should consume the input or end with a '}'", fmt, input);
472 // ***** Only underlying has a format-spec
473 check(SV("[ -42, 1, 2, 42]"), SV("{::5}"), input);
474 check(SV("[-42**, 1****, 2****, 42***]"), SV("{::*<5}"), input);
475 check(SV("[_-42_, __1__, __2__, _42__]"), SV("{::_^5}"), input);
476 check(SV("[::-42, ::::1, ::::2, :::42]"), SV("{:::>5}"), input);
478 check(SV("[ -42, 1, 2, 42]"), SV("{::{}}"), input, 5);
479 check(SV("[-42**, 1****, 2****, 42***]"), SV("{::*<{}}"), input, 5);
480 check(SV("[_-42_, __1__, __2__, _42__]"), SV("{::_^{}}"), input, 5);
481 check(SV("[::-42, ::::1, ::::2, :::42]"), SV("{:::>{}}"), input, 5);
483 check_exception("The format string contains an invalid escape sequence", SV("{::}<}"), input);
484 check_exception("The fill option contains an invalid value", SV("{::{<}"), input);
486 // *** sign ***
487 check(SV("[-42, 1, 2, 42]"), SV("{::-}"), input);
488 check(SV("[-42, +1, +2, +42]"), SV("{::+}"), input);
489 check(SV("[-42, 1, 2, 42]"), SV("{:: }"), input);
491 // *** alternate form ***
492 check(SV("[-0x2a, 0x1, 0x2, 0x2a]"), SV("{::#x}"), input);
494 // *** zero-padding ***
495 check(SV("[-0042, 00001, 00002, 00042]"), SV("{::05}"), input);
496 check(SV("[-002a, 00001, 00002, 0002a]"), SV("{::05x}"), input);
497 check(SV("[-0x2a, 0x001, 0x002, 0x02a]"), SV("{::#05x}"), input);
499 // *** precision ***
500 check_exception("The format specifier should consume the input or end with a '}'", SV("{::.}"), input);
502 // *** locale-specific form ***
503 check(SV("[-42, 1, 2, 42]"), SV("{::L}"), input); // does nothing in this test, but is accepted.
505 // *** type ***
506 for (std::basic_string_view<CharT> fmt : fmt_invalid_nested_types<CharT>("bBcdoxX"))
507 check_exception("The type option contains an invalid value for an integer formatting argument", fmt, input);
509 // ***** Both have a format-spec
510 check(SV("^^[::-42, ::::1, ::::2, :::42]^^^"), SV("{:^^33::>5}"), input);
511 check(SV("^^[::-42, ::::1, ::::2, :::42]^^^"), SV("{:^^{}::>5}"), input, 33);
512 check(SV("^^[::-42, ::::1, ::::2, :::42]^^^"), SV("{:^^{}::>{}}"), input, 33, 5);
514 check_exception(
515 "The argument index value is too large for the number of arguments supplied", SV("{:^^{}::>5}"), input);
516 check_exception(
517 "The argument index value is too large for the number of arguments supplied", SV("{:^^{}::>{}}"), input, 33);
520 template <class CharT, class TestFunction, class ExceptionTest>
521 void test_int(TestFunction check, ExceptionTest check_exception) {
522 std::array input{-42, 1, 2, 42};
523 test_int<CharT>(check, check_exception, std::queue{input.begin(), input.end()});
524 test_int<CharT>(check, check_exception, std::priority_queue{input.begin(), input.end(), std::greater{}});
525 test_int<CharT>(check, check_exception, std::stack{input.begin(), input.end()});
529 // Floating point
532 template <class CharT, class TestFunction, class ExceptionTest>
533 void test_floating_point(TestFunction check, ExceptionTest check_exception, auto&& input) {
534 check(SV("[-42.5, 0, 1.25, 42.5]"), SV("{}"), input);
535 check(SV("[-42.5, 0, 1.25, 42.5]^42"), SV("{}^42"), input);
536 check(SV("[-42.5, 0, 1.25, 42.5]^42"), SV("{:}^42"), input);
538 // ***** underlying has no format-spec
540 // *** align-fill & width ***
541 check(SV("[-42.5, 0, 1.25, 42.5] "), SV("{:27}"), input);
542 check(SV("[-42.5, 0, 1.25, 42.5]*****"), SV("{:*<27}"), input);
543 check(SV("__[-42.5, 0, 1.25, 42.5]___"), SV("{:_^27}"), input);
544 check(SV("#####[-42.5, 0, 1.25, 42.5]"), SV("{:#>27}"), input);
546 check(SV("[-42.5, 0, 1.25, 42.5] "), SV("{:{}}"), input, 27);
547 check(SV("[-42.5, 0, 1.25, 42.5]*****"), SV("{:*<{}}"), input, 27);
548 check(SV("__[-42.5, 0, 1.25, 42.5]___"), SV("{:_^{}}"), input, 27);
549 check(SV("#####[-42.5, 0, 1.25, 42.5]"), SV("{:#>{}}"), input, 27);
551 check_exception("The format string contains an invalid escape sequence", SV("{:}<}"), input);
552 check_exception("The fill option contains an invalid value", SV("{:{<}"), input);
554 // *** sign ***
555 check_exception("The format specifier should consume the input or end with a '}'", SV("{:-}"), input);
556 check_exception("The format specifier should consume the input or end with a '}'", SV("{:+}"), input);
557 check_exception("The format specifier should consume the input or end with a '}'", SV("{: }"), input);
559 // *** alternate form ***
560 check_exception("The format specifier should consume the input or end with a '}'", SV("{:#}"), input);
562 // *** zero-padding ***
563 check_exception("The width option should not have a leading zero", SV("{:0}"), input);
565 // *** precision ***
566 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.}"), input);
568 // *** locale-specific form ***
569 check_exception("The format specifier should consume the input or end with a '}'", SV("{:L}"), input);
571 // *** n
572 check(SV("__-42.5, 0, 1.25, 42.5___"), SV("{:_^25n}"), input);
574 // *** type ***
575 check_exception("Type m requires a pair or a tuple with two elements", SV("{:m}"), input);
576 check_exception("Type s requires character type as formatting argument", SV("{:s}"), input);
577 check_exception("Type ?s requires character type as formatting argument", SV("{:?s}"), input);
578 for (std::basic_string_view<CharT> fmt : fmt_invalid_types<CharT>("s"))
579 check_exception("The format specifier should consume the input or end with a '}'", fmt, input);
581 // ***** Only underlying has a format-spec
582 check(SV("[-42.5, 0, 1.25, 42.5]"), SV("{::5}"), input);
583 check(SV("[-42.5, 0****, 1.25*, 42.5*]"), SV("{::*<5}"), input);
584 check(SV("[-42.5, __0__, 1.25_, 42.5_]"), SV("{::_^5}"), input);
585 check(SV("[-42.5, ::::0, :1.25, :42.5]"), SV("{:::>5}"), input);
587 check(SV("[-42.5, 0, 1.25, 42.5]"), SV("{::{}}"), input, 5);
588 check(SV("[-42.5, 0****, 1.25*, 42.5*]"), SV("{::*<{}}"), input, 5);
589 check(SV("[-42.5, __0__, 1.25_, 42.5_]"), SV("{::_^{}}"), input, 5);
590 check(SV("[-42.5, ::::0, :1.25, :42.5]"), SV("{:::>{}}"), input, 5);
592 check_exception("The format string contains an invalid escape sequence", SV("{::}<}"), input);
593 check_exception("The fill option contains an invalid value", SV("{::{<}"), input);
595 // *** sign ***
596 check(SV("[-42.5, 0, 1.25, 42.5]"), SV("{::-}"), input);
597 check(SV("[-42.5, +0, +1.25, +42.5]"), SV("{::+}"), input);
598 check(SV("[-42.5, 0, 1.25, 42.5]"), SV("{:: }"), input);
600 // *** alternate form ***
601 check(SV("[-42.5, 0., 1.25, 42.5]"), SV("{::#}"), input);
603 // *** zero-padding ***
604 check(SV("[-42.5, 00000, 01.25, 042.5]"), SV("{::05}"), input);
605 check(SV("[-42.5, 0000., 01.25, 042.5]"), SV("{::#05}"), input);
607 // *** precision ***
608 check(SV("[-42, 0, 1.2, 42]"), SV("{::.2}"), input);
609 check(SV("[-42.500, 0.000, 1.250, 42.500]"), SV("{::.3f}"), input);
611 check(SV("[-42, 0, 1.2, 42]"), SV("{::.{}}"), input, 2);
612 check(SV("[-42.500, 0.000, 1.250, 42.500]"), SV("{::.{}f}"), input, 3);
614 check_exception("The precision option does not contain a value or an argument index", SV("{::.}"), input);
616 // *** locale-specific form ***
617 check(SV("[-42.5, 0, 1.25, 42.5]"), SV("{::L}"), input); // does not require locales present
618 #ifndef TEST_HAS_NO_LOCALIZATION
619 // TODO FMT Enable with locale testing active
620 # if 0
621 std::locale::global(std::locale(LOCALE_fr_FR_UTF_8));
622 check(SV("[-42,5, 0, 1,25, 42,5]"), SV("{::L}"), input);
624 std::locale::global(std::locale(LOCALE_en_US_UTF_8));
625 check(SV("[-42.5, 0, 1.25, 42.5]"), SV("{::L}"), input);
627 std::locale::global(std::locale::classic());
628 # endif
629 #endif // TEST_HAS_NO_LOCALIZATION
631 // *** type ***
632 for (std::basic_string_view<CharT> fmt : fmt_invalid_nested_types<CharT>("aAeEfFgG"))
633 check_exception("The type option contains an invalid value for a floating-point formatting argument", fmt, input);
635 // ***** Both have a format-spec
636 check(SV("^^[-42.5, ::::0, :1.25, :42.5]^^^"), SV("{:^^33::>5}"), input);
637 check(SV("^^[-42.5, ::::0, :1.25, :42.5]^^^"), SV("{:^^{}::>5}"), input, 33);
638 check(SV("^^[-42.5, ::::0, :1.25, :42.5]^^^"), SV("{:^^{}::>{}}"), input, 33, 5);
640 check(SV("^^[::-42, ::::0, ::1.2, :::42]^^^"), SV("{:^^33::>5.2}"), input);
641 check(SV("^^[::-42, ::::0, ::1.2, :::42]^^^"), SV("{:^^{}::>5.2}"), input, 33);
642 check(SV("^^[::-42, ::::0, ::1.2, :::42]^^^"), SV("{:^^{}::>{}.2}"), input, 33, 5);
643 check(SV("^^[::-42, ::::0, ::1.2, :::42]^^^"), SV("{:^^{}::>{}.{}}"), input, 33, 5, 2);
645 check_exception(
646 "The argument index value is too large for the number of arguments supplied", SV("{:^^{}::>5.2}"), input);
647 check_exception(
648 "The argument index value is too large for the number of arguments supplied", SV("{:^^{}::>{}.2}"), input, 33);
649 check_exception(
650 "The argument index value is too large for the number of arguments supplied",
651 SV("{:^^{}::>{}.{}}"),
652 input,
657 template <class CharT, class TestFunction, class ExceptionTest>
658 void test_floating_point(TestFunction check, ExceptionTest check_exception) {
659 std::array input{-42.5l, 0.0l, 1.25l, 42.5l};
660 test_floating_point<CharT>(check, check_exception, std::queue{input.begin(), input.end()});
661 test_floating_point<CharT>(check, check_exception, std::priority_queue{input.begin(), input.end(), std::greater{}});
662 test_floating_point<CharT>(check, check_exception, std::stack{input.begin(), input.end()});
666 // Pointer
669 template <class CharT, class TestFunction, class ExceptionTest>
670 void test_pointer(TestFunction check, ExceptionTest check_exception, auto&& input) {
671 check(SV("[0x0]"), SV("{}"), input);
672 check(SV("[0x0]^42"), SV("{}^42"), input);
673 check(SV("[0x0]^42"), SV("{:}^42"), input);
675 // ***** underlying has no format-spec
677 // *** align-fill & width ***
678 check(SV("[0x0] "), SV("{:10}"), input);
679 check(SV("[0x0]*****"), SV("{:*<10}"), input);
680 check(SV("__[0x0]___"), SV("{:_^10}"), input);
681 check(SV("#####[0x0]"), SV("{:#>10}"), input);
683 check(SV("[0x0] "), SV("{:{}}"), input, 10);
684 check(SV("[0x0]*****"), SV("{:*<{}}"), input, 10);
685 check(SV("__[0x0]___"), SV("{:_^{}}"), input, 10);
686 check(SV("#####[0x0]"), SV("{:#>{}}"), input, 10);
688 check_exception("The format string contains an invalid escape sequence", SV("{:}<}"), input);
689 check_exception("The fill option contains an invalid value", SV("{:{<}"), input);
691 // *** sign ***
692 check_exception("The format specifier should consume the input or end with a '}'", SV("{:-}"), input);
694 // *** alternate form ***
695 check_exception("The format specifier should consume the input or end with a '}'", SV("{:#}"), input);
697 // *** zero-padding ***
698 check_exception("The width option should not have a leading zero", SV("{:0}"), input);
700 // *** precision ***
701 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.}"), input);
703 // *** locale-specific form ***
704 check_exception("The format specifier should consume the input or end with a '}'", SV("{:L}"), input);
706 // *** n
707 check(SV("_0x0_"), SV("{:_^5n}"), input);
709 // *** type ***
710 check_exception("Type m requires a pair or a tuple with two elements", SV("{:m}"), input);
711 check_exception("Type s requires character type as formatting argument", SV("{:s}"), input);
712 check_exception("Type ?s requires character type as formatting argument", SV("{:?s}"), input);
713 for (std::basic_string_view<CharT> fmt : fmt_invalid_types<CharT>("s"))
714 check_exception("The format specifier should consume the input or end with a '}'", fmt, input);
716 // ***** Only underlying has a format-spec
717 check(SV("[ 0x0]"), SV("{::5}"), input);
718 check(SV("[0x0**]"), SV("{::*<5}"), input);
719 check(SV("[_0x0_]"), SV("{::_^5}"), input);
720 check(SV("[::0x0]"), SV("{:::>5}"), input);
722 check(SV("[ 0x0]"), SV("{::{}}"), input, 5);
723 check(SV("[0x0**]"), SV("{::*<{}}"), input, 5);
724 check(SV("[_0x0_]"), SV("{::_^{}}"), input, 5);
725 check(SV("[::0x0]"), SV("{:::>{}}"), input, 5);
727 check_exception("The format string contains an invalid escape sequence", SV("{::}<}"), input);
728 check_exception("The fill option contains an invalid value", SV("{::{<}"), input);
730 // *** sign ***
731 check_exception("The format specifier should consume the input or end with a '}'", SV("{::-}"), input);
733 // *** alternate form ***
734 check_exception("The format specifier should consume the input or end with a '}'", SV("{::#}"), input);
736 // *** zero-padding ***
737 check(SV("[0x0000]"), SV("{::06}"), input);
738 check(SV("[0x0000]"), SV("{::06p}"), input);
739 check(SV("[0X0000]"), SV("{::06P}"), input);
741 // *** precision ***
742 check_exception("The format specifier should consume the input or end with a '}'", SV("{::.}"), input);
744 // *** locale-specific form ***
745 check_exception("The format specifier should consume the input or end with a '}'", SV("{::L}"), input);
747 // *** type ***
748 for (std::basic_string_view<CharT> fmt : fmt_invalid_nested_types<CharT>("pP"))
749 check_exception("The type option contains an invalid value for a pointer formatting argument", fmt, input);
751 // ***** Both have a format-spec
752 check(SV("^^[::0x0]^^^"), SV("{:^^12::>5}"), input);
753 check(SV("^^[::0x0]^^^"), SV("{:^^{}::>5}"), input, 12);
754 check(SV("^^[::0x0]^^^"), SV("{:^^{}::>{}}"), input, 12, 5);
756 check(SV("^^[::0x0]^^^"), SV("{:^^12::>5}"), input);
757 check(SV("^^[::0x0]^^^"), SV("{:^^{}::>5}"), input, 12);
758 check(SV("^^[::0x0]^^^"), SV("{:^^{}::>{}}"), input, 12, 5);
760 check_exception(
761 "The argument index value is too large for the number of arguments supplied", SV("{:^^{}::>5}"), input);
762 check_exception(
763 "The argument index value is too large for the number of arguments supplied", SV("{:^^{}::>{}}"), input, 12);
766 template <class CharT, class TestFunction, class ExceptionTest>
767 void test_pointer(TestFunction check, ExceptionTest check_exception) {
768 std::array input{static_cast<void*>(0)};
769 test_pointer<CharT>(check, check_exception, std::queue{input.begin(), input.end()});
770 test_pointer<CharT>(check, check_exception, std::priority_queue{input.begin(), input.end()});
771 test_pointer<CharT>(check, check_exception, std::stack{input.begin(), input.end()});
775 // String
778 template <class CharT, class TestFunction, class ExceptionTest>
779 void test_string(TestFunction check, ExceptionTest check_exception, auto&& input) {
780 check(SV(R"(["Hello", "world"])"), SV("{}"), input);
781 check(SV(R"(["Hello", "world"]^42)"), SV("{}^42"), input);
782 check(SV(R"(["Hello", "world"]^42)"), SV("{:}^42"), input);
784 // ***** underlying has no format-spec
786 // *** align-fill & width ***
787 check(SV(R"(["Hello", "world"] )"), SV("{:23}"), input);
788 check(SV(R"(["Hello", "world"]*****)"), SV("{:*<23}"), input);
789 check(SV(R"(__["Hello", "world"]___)"), SV("{:_^23}"), input);
790 check(SV(R"(#####["Hello", "world"])"), SV("{:#>23}"), input);
792 check(SV(R"(["Hello", "world"] )"), SV("{:{}}"), input, 23);
793 check(SV(R"(["Hello", "world"]*****)"), SV("{:*<{}}"), input, 23);
794 check(SV(R"(__["Hello", "world"]___)"), SV("{:_^{}}"), input, 23);
795 check(SV(R"(#####["Hello", "world"])"), SV("{:#>{}}"), input, 23);
797 check_exception("The format string contains an invalid escape sequence", SV("{:}<}"), input);
798 check_exception("The fill option contains an invalid value", SV("{:{<}"), input);
800 // *** sign ***
801 check_exception("The format specifier should consume the input or end with a '}'", SV("{:-}"), input);
803 // *** alternate form ***
804 check_exception("The format specifier should consume the input or end with a '}'", SV("{:#}"), input);
806 // *** zero-padding ***
807 check_exception("The width option should not have a leading zero", SV("{:0}"), input);
809 // *** precision ***
810 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.}"), input);
812 // *** locale-specific form ***
813 check_exception("The format specifier should consume the input or end with a '}'", SV("{:L}"), input);
815 // *** n
816 check(SV(R"(_"Hello", "world"_)"), SV("{:_^18n}"), input);
818 // *** type ***
819 check_exception("Type m requires a pair or a tuple with two elements", SV("{:m}"), input);
820 check_exception("Type s requires character type as formatting argument", SV("{:s}"), input);
821 check_exception("Type ?s requires character type as formatting argument", SV("{:?s}"), input);
822 for (std::basic_string_view<CharT> fmt : fmt_invalid_types<CharT>("s"))
823 check_exception("The format specifier should consume the input or end with a '}'", fmt, input);
825 // ***** Only underlying has a format-spec
826 check(SV(R"([Hello , world ])"), SV("{::8}"), input);
827 check(SV(R"([Hello***, world***])"), SV("{::*<8}"), input);
828 check(SV(R"([_Hello__, _world__])"), SV("{::_^8}"), input);
829 check(SV(R"([:::Hello, :::world])"), SV("{:::>8}"), input);
831 check(SV(R"([Hello , world ])"), SV("{::{}}"), input, 8);
832 check(SV(R"([Hello***, world***])"), SV("{::*<{}}"), input, 8);
833 check(SV(R"([_Hello__, _world__])"), SV("{::_^{}}"), input, 8);
834 check(SV(R"([:::Hello, :::world])"), SV("{:::>{}}"), input, 8);
836 check_exception("The format string contains an invalid escape sequence", SV("{::}<}"), input);
837 check_exception("The fill option contains an invalid value", SV("{::{<}"), input);
839 // *** sign ***
840 check_exception("The format specifier should consume the input or end with a '}'", SV("{::-}"), input);
842 // *** alternate form ***
843 check_exception("The format specifier should consume the input or end with a '}'", SV("{::#}"), input);
845 // *** zero-padding ***
846 check_exception("The width option should not have a leading zero", SV("{::05}"), input);
848 // *** precision ***
849 check(SV(R"([Hel, wor])"), SV("{::.3}"), input);
851 check(SV(R"([Hel, wor])"), SV("{::.{}}"), input, 3);
853 check_exception("The precision option does not contain a value or an argument index", SV("{::.}"), input);
855 // *** locale-specific form ***
856 check_exception("The format specifier should consume the input or end with a '}'", SV("{::L}"), input);
858 // *** type ***
859 for (std::basic_string_view<CharT> fmt : fmt_invalid_nested_types<CharT>("s?"))
860 check_exception("The type option contains an invalid value for a string formatting argument", fmt, input);
862 // ***** Both have a format-spec
863 check(SV(R"(^^[:::Hello, :::world]^^^)"), SV("{:^^25::>8}"), input);
864 check(SV(R"(^^[:::Hello, :::world]^^^)"), SV("{:^^{}::>8}"), input, 25);
865 check(SV(R"(^^[:::Hello, :::world]^^^)"), SV("{:^^{}::>{}}"), input, 25, 8);
867 check(SV(R"(^^[:::Hello, :::world]^^^)"), SV("{:^^25::>8}"), input);
868 check(SV(R"(^^[:::Hello, :::world]^^^)"), SV("{:^^{}::>8}"), input, 25);
869 check(SV(R"(^^[:::Hello, :::world]^^^)"), SV("{:^^{}::>{}}"), input, 25, 8);
871 check_exception(
872 "The argument index value is too large for the number of arguments supplied", SV("{:^^{}::>8}"), input);
873 check_exception(
874 "The argument index value is too large for the number of arguments supplied", SV("{:^^{}::>{}}"), input, 25);
877 template <class CharT, class TestFunction, class ExceptionTest>
878 void test_string(TestFunction check, ExceptionTest check_exception) {
879 std::array input{STR("Hello"), STR("world")};
880 test_string<CharT>(check, check_exception, std::queue{input.begin(), input.end()});
881 test_string<CharT>(check, check_exception, std::priority_queue{input.begin(), input.end(), std::greater{}});
882 test_string<CharT>(check, check_exception, std::stack{input.begin(), input.end()});
886 // Handle
889 template <class CharT, class TestFunction, class ExceptionTest>
890 void test_status(TestFunction check, ExceptionTest check_exception, auto&& input) {
891 check(SV("[0xaaaa, 0x5555, 0xaa55]"), SV("{}"), input);
892 check(SV("[0xaaaa, 0x5555, 0xaa55]^42"), SV("{}^42"), input);
893 check(SV("[0xaaaa, 0x5555, 0xaa55]^42"), SV("{:}^42"), input);
895 // ***** underlying has no format-spec
897 // *** align-fill & width ***
898 check(SV("[0xaaaa, 0x5555, 0xaa55] "), SV("{:29}"), input);
899 check(SV("[0xaaaa, 0x5555, 0xaa55]*****"), SV("{:*<29}"), input);
900 check(SV("__[0xaaaa, 0x5555, 0xaa55]___"), SV("{:_^29}"), input);
901 check(SV("#####[0xaaaa, 0x5555, 0xaa55]"), SV("{:#>29}"), input);
903 check(SV("[0xaaaa, 0x5555, 0xaa55] "), SV("{:{}}"), input, 29);
904 check(SV("[0xaaaa, 0x5555, 0xaa55]*****"), SV("{:*<{}}"), input, 29);
905 check(SV("__[0xaaaa, 0x5555, 0xaa55]___"), SV("{:_^{}}"), input, 29);
906 check(SV("#####[0xaaaa, 0x5555, 0xaa55]"), SV("{:#>{}}"), input, 29);
908 check_exception("The format string contains an invalid escape sequence", SV("{:}<}"), input);
909 check_exception("The fill option contains an invalid value", SV("{:{<}"), input);
911 // *** sign ***
912 check_exception("The format specifier should consume the input or end with a '}'", SV("{:-}"), input);
913 check_exception("The format specifier should consume the input or end with a '}'", SV("{:+}"), input);
914 check_exception("The format specifier should consume the input or end with a '}'", SV("{: }"), input);
916 // *** alternate form ***
917 check_exception("The format specifier should consume the input or end with a '}'", SV("{:#}"), input);
919 // *** zero-padding ***
920 check_exception("The width option should not have a leading zero", SV("{:0}"), input);
922 // *** precision ***
923 check_exception("The format specifier should consume the input or end with a '}'", SV("{:.}"), input);
925 // *** locale-specific form ***
926 check_exception("The format specifier should consume the input or end with a '}'", SV("{:L}"), input);
928 // *** n
929 check(SV("__0xaaaa, 0x5555, 0xaa55___"), SV("{:_^27n}"), input);
931 // *** type ***
932 check_exception("Type m requires a pair or a tuple with two elements", SV("{:m}"), input);
933 check_exception("Type s requires character type as formatting argument", SV("{:s}"), input);
934 check_exception("Type ?s requires character type as formatting argument", SV("{:?s}"), input);
935 for (std::basic_string_view<CharT> fmt : fmt_invalid_types<CharT>("s"))
936 check_exception("The format specifier should consume the input or end with a '}'", fmt, input);
938 // ***** Only underlying has a format-spec
939 check_exception("The type option contains an invalid value for a status formatting argument", SV("{::*<7}"), input);
940 for (std::basic_string_view<CharT> fmt : fmt_invalid_nested_types<CharT>("sxX"))
941 check_exception("The type option contains an invalid value for a status formatting argument", fmt, input);
943 check(SV("[0xaaaa, 0x5555, 0xaa55]"), SV("{::x}"), input);
944 check(SV("[0XAAAA, 0X5555, 0XAA55]"), SV("{::X}"), input);
945 check(SV("[foo, bar, foobar]"), SV("{::s}"), input);
947 // ***** Both have a format-spec
948 check(SV("^^[0XAAAA, 0X5555, 0XAA55]^^^"), SV("{:^^29:X}"), input);
949 check(SV("^^[0XAAAA, 0X5555, 0XAA55]^^^"), SV("{:^^{}:X}"), input, 29);
951 check_exception("The argument index value is too large for the number of arguments supplied", SV("{:^^{}:X}"), input);
954 template <class CharT, class TestFunction, class ExceptionTest>
955 void test_status(TestFunction check, ExceptionTest check_exception) {
956 std::array input{status::foo, status::bar, status::foobar};
957 test_status<CharT>(check, check_exception, std::queue{input.begin(), input.end()});
958 test_status<CharT>(check, check_exception, std::priority_queue{input.begin(), input.end(), std::less{}});
959 test_status<CharT>(check, check_exception, std::stack{input.begin(), input.end()});
963 // Driver
966 template <class CharT, class TestFunction, class ExceptionTest>
967 void format_tests(TestFunction check, ExceptionTest check_exception) {
968 test_char<CharT>(check, check_exception);
969 #if _LIBCPP_HAS_WIDE_CHARACTERS
970 if (std::same_as<CharT, wchar_t>) // avoid testing twice
971 test_char_to_wchar(check, check_exception);
972 #endif
973 test_bool<CharT>(check, check_exception);
974 test_int<CharT>(check, check_exception);
975 test_floating_point<CharT>(check, check_exception);
976 test_pointer<CharT>(check, check_exception);
977 test_string<CharT>(check, check_exception);
979 test_status<CharT>(check, check_exception); // Has its own handler with its own parser
982 #endif // TEST_STD_CONTAINERS_CONTAINER_ADAPTORS_CONTAINER_ADAPTORS_FORMAT_FORMAT_FUNCTIONS_TESTS_H