[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / libc / test / src / stdio / scanf_core / parser_test.cpp
blob2ccaf84c67552335ddeb631c0bf2e2c5a1ef170b
1 //===-- Unittests for the scanf Parser -----------------------------------===//
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 #include "src/__support/CPP/bit.h"
10 #include "src/__support/CPP/bitset.h"
11 #include "src/__support/CPP/string_view.h"
12 #include "src/__support/arg_list.h"
13 #include "src/stdio/scanf_core/parser.h"
15 #include <stdarg.h>
17 #include "test/UnitTest/ScanfMatcher.h"
18 #include "test/UnitTest/Test.h"
20 using __llvm_libc::cpp::string_view;
22 void init(const char *__restrict str, ...) {
23 va_list vlist;
24 va_start(vlist, str);
25 __llvm_libc::internal::ArgList v(vlist);
26 va_end(vlist);
28 __llvm_libc::scanf_core::Parser parser(str, v);
31 void evaluate(__llvm_libc::scanf_core::FormatSection *format_arr,
32 const char *__restrict str, ...) {
33 va_list vlist;
34 va_start(vlist, str);
35 __llvm_libc::internal::ArgList v(vlist);
36 va_end(vlist);
38 __llvm_libc::scanf_core::Parser parser(str, v);
40 for (auto cur_section = parser.get_next_section();
41 !cur_section.raw_string.empty();
42 cur_section = parser.get_next_section()) {
43 *format_arr = cur_section;
44 ++format_arr;
48 TEST(LlvmLibcScanfParserTest, Constructor) { init("test", 1, 2); }
50 TEST(LlvmLibcScanfParserTest, EvalRaw) {
51 __llvm_libc::scanf_core::FormatSection format_arr[10];
52 const char *str = "test";
53 evaluate(format_arr, str);
55 __llvm_libc::scanf_core::FormatSection expected;
56 expected.has_conv = false;
58 expected.raw_string = str;
60 ASSERT_SFORMAT_EQ(expected, format_arr[0]);
61 // TODO: add checks that the format_arr after the last one has length 0
64 TEST(LlvmLibcScanfParserTest, EvalSimple) {
65 __llvm_libc::scanf_core::FormatSection format_arr[10];
66 const char *str = "test %% test";
67 evaluate(format_arr, str);
69 __llvm_libc::scanf_core::FormatSection expected0, expected1, expected2;
70 expected0.has_conv = false;
72 expected0.raw_string = {str, 5};
74 ASSERT_SFORMAT_EQ(expected0, format_arr[0]);
76 expected1.has_conv = true;
78 expected1.raw_string = {str + 5, 2};
79 expected1.conv_name = '%';
81 ASSERT_SFORMAT_EQ(expected1, format_arr[1]);
83 expected2.has_conv = false;
85 expected2.raw_string = {str + 7, 5};
87 ASSERT_SFORMAT_EQ(expected2, format_arr[2]);
90 TEST(LlvmLibcScanfParserTest, EvalOneArg) {
91 __llvm_libc::scanf_core::FormatSection format_arr[10];
92 const char *str = "%d";
93 int arg1 = 12345;
94 evaluate(format_arr, str, &arg1);
96 __llvm_libc::scanf_core::FormatSection expected;
97 expected.has_conv = true;
99 expected.raw_string = str;
100 expected.output_ptr = &arg1;
101 expected.conv_name = 'd';
103 ASSERT_SFORMAT_EQ(expected, format_arr[0]);
106 TEST(LlvmLibcScanfParserTest, EvalBadArg) {
107 __llvm_libc::scanf_core::FormatSection format_arr[10];
108 const char *str = "%\0abc";
109 int arg1 = 12345;
110 evaluate(format_arr, str, &arg1);
112 __llvm_libc::scanf_core::FormatSection expected;
113 expected.has_conv = false;
114 expected.raw_string = {str, 1};
116 ASSERT_SFORMAT_EQ(expected, format_arr[0]);
119 TEST(LlvmLibcScanfParserTest, EvalOneArgWithFlag) {
120 __llvm_libc::scanf_core::FormatSection format_arr[10];
121 const char *str = "%*d";
122 // Since NO_WRITE is set, the argument shouldn't be used, but I've included
123 // one anyways because in the case that it doesn't work it's better for it to
124 // have a real argument to check against.
125 int arg1 = 12345;
126 evaluate(format_arr, str, &arg1);
128 __llvm_libc::scanf_core::FormatSection expected;
129 expected.has_conv = true;
131 expected.raw_string = str;
132 expected.flags = __llvm_libc::scanf_core::FormatFlags::NO_WRITE;
133 expected.conv_name = 'd';
135 ASSERT_SFORMAT_EQ(expected, format_arr[0]);
137 // If NO_WRITE is set, then the equality check ignores the pointer since it's
138 // irrelevant, but in this case I want to make sure that it hasn't been set
139 // and check it separately.
140 ASSERT_EQ(expected.output_ptr, format_arr[0].output_ptr);
143 TEST(LlvmLibcScanfParserTest, EvalOneArgWithWidth) {
144 __llvm_libc::scanf_core::FormatSection format_arr[10];
145 const char *str = "%12d";
146 int arg1 = 12345;
147 evaluate(format_arr, str, &arg1);
149 __llvm_libc::scanf_core::FormatSection expected;
150 expected.has_conv = true;
152 expected.raw_string = str;
153 expected.max_width = 12;
154 expected.output_ptr = &arg1;
155 expected.conv_name = 'd';
157 ASSERT_SFORMAT_EQ(expected, format_arr[0]);
160 TEST(LlvmLibcScanfParserTest, EvalOneArgWithShortLengthModifier) {
161 __llvm_libc::scanf_core::FormatSection format_arr[10];
162 const char *str = "%hd";
163 int arg1 = 12345;
164 evaluate(format_arr, str, &arg1);
166 __llvm_libc::scanf_core::FormatSection expected;
167 expected.has_conv = true;
169 expected.raw_string = str;
170 expected.length_modifier = __llvm_libc::scanf_core::LengthModifier::h;
171 expected.output_ptr = &arg1;
172 expected.conv_name = 'd';
174 ASSERT_SFORMAT_EQ(expected, format_arr[0]);
177 TEST(LlvmLibcScanfParserTest, EvalOneArgWithLongLengthModifier) {
178 __llvm_libc::scanf_core::FormatSection format_arr[10];
179 const char *str = "%lld";
180 long long arg1 = 12345;
181 evaluate(format_arr, str, &arg1);
183 __llvm_libc::scanf_core::FormatSection expected;
184 expected.has_conv = true;
186 expected.raw_string = str;
187 expected.length_modifier = __llvm_libc::scanf_core::LengthModifier::ll;
188 expected.output_ptr = &arg1;
189 expected.conv_name = 'd';
191 ASSERT_SFORMAT_EQ(expected, format_arr[0]);
194 TEST(LlvmLibcScanfParserTest, EvalOneArgWithAllOptions) {
195 __llvm_libc::scanf_core::FormatSection format_arr[10];
196 const char *str = "%*56jd";
197 intmax_t arg1 = 12345;
198 evaluate(format_arr, str, &arg1);
200 __llvm_libc::scanf_core::FormatSection expected;
201 expected.has_conv = true;
203 expected.raw_string = str;
204 expected.flags = __llvm_libc::scanf_core::FormatFlags::NO_WRITE;
205 expected.max_width = 56;
206 expected.length_modifier = __llvm_libc::scanf_core::LengthModifier::j;
207 expected.conv_name = 'd';
209 ASSERT_SFORMAT_EQ(expected, format_arr[0]);
212 TEST(LlvmLibcScanfParserTest, EvalSimpleBracketArg) {
213 __llvm_libc::scanf_core::FormatSection format_arr[10];
214 const char *str = "%[abc]";
215 char arg1 = 'a';
216 evaluate(format_arr, str, &arg1);
218 __llvm_libc::scanf_core::FormatSection expected;
219 expected.has_conv = true;
221 expected.raw_string = str;
222 expected.conv_name = '[';
223 expected.output_ptr = &arg1;
225 __llvm_libc::cpp::bitset<256> scan_set;
227 scan_set.set('a');
228 scan_set.set('b');
229 scan_set.set('c');
231 expected.scan_set = scan_set;
233 ASSERT_SFORMAT_EQ(expected, format_arr[0]);
236 TEST(LlvmLibcScanfParserTest, EvalBracketArgRange) {
237 __llvm_libc::scanf_core::FormatSection format_arr[10];
238 const char *str = "%[A-D]";
239 char arg1 = 'a';
240 evaluate(format_arr, str, &arg1);
242 __llvm_libc::scanf_core::FormatSection expected;
243 expected.has_conv = true;
245 expected.raw_string = str;
246 expected.conv_name = '[';
247 expected.output_ptr = &arg1;
249 __llvm_libc::cpp::bitset<256> scan_set;
251 scan_set.set('A');
252 scan_set.set('B');
253 scan_set.set('C');
254 scan_set.set('D');
256 expected.scan_set = scan_set;
258 ASSERT_SFORMAT_EQ(expected, format_arr[0]);
261 TEST(LlvmLibcScanfParserTest, EvalBracketArgTwoRanges) {
262 __llvm_libc::scanf_core::FormatSection format_arr[10];
263 const char *str = "%[A-De-g]";
264 char arg1 = 'a';
265 evaluate(format_arr, str, &arg1);
267 __llvm_libc::scanf_core::FormatSection expected;
268 expected.has_conv = true;
270 expected.raw_string = str;
271 expected.conv_name = '[';
272 expected.output_ptr = &arg1;
274 __llvm_libc::cpp::bitset<256> scan_set;
276 scan_set.set('A');
277 scan_set.set('B');
278 scan_set.set('C');
279 scan_set.set('D');
280 scan_set.set_range('e', 'g');
282 expected.scan_set = scan_set;
284 ASSERT_SFORMAT_EQ(expected, format_arr[0]);
287 TEST(LlvmLibcScanfParserTest, EvalBracketArgJustHyphen) {
288 __llvm_libc::scanf_core::FormatSection format_arr[10];
289 const char *str = "%[-]";
290 char arg1 = 'a';
291 evaluate(format_arr, str, &arg1);
293 __llvm_libc::scanf_core::FormatSection expected;
294 expected.has_conv = true;
296 expected.raw_string = str;
297 expected.conv_name = '[';
298 expected.output_ptr = &arg1;
300 __llvm_libc::cpp::bitset<256> scan_set;
302 scan_set.set('-');
304 expected.scan_set = scan_set;
306 ASSERT_SFORMAT_EQ(expected, format_arr[0]);
309 TEST(LlvmLibcScanfParserTest, EvalBracketArgLeftHyphen) {
310 __llvm_libc::scanf_core::FormatSection format_arr[10];
311 const char *str = "%[-A]";
312 char arg1 = 'a';
313 evaluate(format_arr, str, &arg1);
315 __llvm_libc::scanf_core::FormatSection expected;
316 expected.has_conv = true;
318 expected.raw_string = str;
319 expected.conv_name = '[';
320 expected.output_ptr = &arg1;
322 __llvm_libc::cpp::bitset<256> scan_set;
324 scan_set.set('-');
325 scan_set.set('A');
327 expected.scan_set = scan_set;
329 ASSERT_SFORMAT_EQ(expected, format_arr[0]);
332 TEST(LlvmLibcScanfParserTest, EvalBracketArgRightHyphen) {
333 __llvm_libc::scanf_core::FormatSection format_arr[10];
334 const char *str = "%[Z-]";
335 char arg1 = 'a';
336 evaluate(format_arr, str, &arg1);
338 __llvm_libc::scanf_core::FormatSection expected;
339 expected.has_conv = true;
341 expected.raw_string = str;
342 expected.conv_name = '[';
343 expected.output_ptr = &arg1;
345 __llvm_libc::cpp::bitset<256> scan_set;
347 scan_set.set('-');
348 scan_set.set('Z');
350 expected.scan_set = scan_set;
352 ASSERT_SFORMAT_EQ(expected, format_arr[0]);
355 TEST(LlvmLibcScanfParserTest, EvalBracketArgInvertSimple) {
356 __llvm_libc::scanf_core::FormatSection format_arr[10];
357 const char *str = "%[^abc]";
358 char arg1 = 'a';
359 evaluate(format_arr, str, &arg1);
361 __llvm_libc::scanf_core::FormatSection expected;
362 expected.has_conv = true;
364 expected.raw_string = str;
365 expected.conv_name = '[';
366 expected.output_ptr = &arg1;
368 __llvm_libc::cpp::bitset<256> scan_set;
370 scan_set.set('a');
371 scan_set.set('b');
372 scan_set.set('c');
373 scan_set.flip();
375 expected.scan_set = scan_set;
377 ASSERT_SFORMAT_EQ(expected, format_arr[0]);
380 TEST(LlvmLibcScanfParserTest, EvalBracketArgInvertRange) {
381 __llvm_libc::scanf_core::FormatSection format_arr[10];
382 const char *str = "%[^0-9]";
383 char arg1 = 'a';
384 evaluate(format_arr, str, &arg1);
386 __llvm_libc::scanf_core::FormatSection expected;
387 expected.has_conv = true;
389 expected.raw_string = str;
390 expected.conv_name = '[';
391 expected.output_ptr = &arg1;
393 __llvm_libc::cpp::bitset<256> scan_set;
395 scan_set.set_range('0', '9');
396 scan_set.flip();
398 expected.scan_set = scan_set;
400 ASSERT_SFORMAT_EQ(expected, format_arr[0]);
403 TEST(LlvmLibcScanfParserTest, EvalBracketArgRightBracket) {
404 __llvm_libc::scanf_core::FormatSection format_arr[10];
405 const char *str = "%[]]";
406 char arg1 = 'a';
407 evaluate(format_arr, str, &arg1);
409 __llvm_libc::scanf_core::FormatSection expected;
410 expected.has_conv = true;
412 expected.raw_string = str;
413 expected.conv_name = '[';
414 expected.output_ptr = &arg1;
416 __llvm_libc::cpp::bitset<256> scan_set;
418 scan_set.set(']');
420 expected.scan_set = scan_set;
422 ASSERT_SFORMAT_EQ(expected, format_arr[0]);
425 TEST(LlvmLibcScanfParserTest, EvalBracketArgRightBracketRange) {
426 __llvm_libc::scanf_core::FormatSection format_arr[10];
427 const char *str = "%[]-a]";
428 char arg1 = 'a';
429 evaluate(format_arr, str, &arg1);
431 __llvm_libc::scanf_core::FormatSection expected;
432 expected.has_conv = true;
434 expected.raw_string = str;
435 expected.conv_name = '[';
436 expected.output_ptr = &arg1;
438 __llvm_libc::cpp::bitset<256> scan_set;
440 scan_set.set_range(']', 'a');
442 expected.scan_set = scan_set;
444 ASSERT_SFORMAT_EQ(expected, format_arr[0]);
447 TEST(LlvmLibcScanfParserTest, EvalBracketArgRightBracketInvert) {
448 __llvm_libc::scanf_core::FormatSection format_arr[10];
449 const char *str = "%[^]]";
450 char arg1 = 'a';
451 evaluate(format_arr, str, &arg1);
453 __llvm_libc::scanf_core::FormatSection expected;
454 expected.has_conv = true;
456 expected.raw_string = str;
457 expected.conv_name = '[';
458 expected.output_ptr = &arg1;
460 __llvm_libc::cpp::bitset<256> scan_set;
462 scan_set.set(']');
463 scan_set.flip();
465 expected.scan_set = scan_set;
467 ASSERT_SFORMAT_EQ(expected, format_arr[0]);
470 TEST(LlvmLibcScanfParserTest, EvalBracketArgRightBracketInvertRange) {
471 __llvm_libc::scanf_core::FormatSection format_arr[10];
472 const char *str = "%[^]-^]";
473 char arg1 = 'a';
474 evaluate(format_arr, str, &arg1);
476 __llvm_libc::scanf_core::FormatSection expected;
477 expected.has_conv = true;
479 expected.raw_string = str;
480 expected.conv_name = '[';
481 expected.output_ptr = &arg1;
483 __llvm_libc::cpp::bitset<256> scan_set;
485 scan_set.set_range(']', '^');
486 scan_set.flip();
488 expected.scan_set = scan_set;
490 ASSERT_SFORMAT_EQ(expected, format_arr[0]);
493 // This is not part of the standard, but the hyphen's effect is always
494 // implementation defined, and I have defined it such that it will capture the
495 // correct range regardless of the order of the characters.
496 TEST(LlvmLibcScanfParserTest, EvalBracketArgBackwardsRange) {
497 __llvm_libc::scanf_core::FormatSection format_arr[10];
498 const char *str = "%[9-0]";
499 char arg1 = 'a';
500 evaluate(format_arr, str, &arg1);
502 __llvm_libc::scanf_core::FormatSection expected;
503 expected.has_conv = true;
505 expected.raw_string = str;
506 expected.conv_name = '[';
507 expected.output_ptr = &arg1;
509 __llvm_libc::cpp::bitset<256> scan_set;
511 scan_set.set_range('0', '9');
513 expected.scan_set = scan_set;
515 ASSERT_SFORMAT_EQ(expected, format_arr[0]);
518 TEST(LlvmLibcScanfParserTest, EvalThreeArgs) {
519 __llvm_libc::scanf_core::FormatSection format_arr[10];
520 const char *str = "%d%f%s";
521 int arg1 = 12345;
522 double arg2 = 123.45;
523 const char *arg3 = "12345";
524 evaluate(format_arr, str, &arg1, &arg2, &arg3);
526 __llvm_libc::scanf_core::FormatSection expected0, expected1, expected2;
527 expected0.has_conv = true;
529 expected0.raw_string = {str, 2};
530 expected0.output_ptr = &arg1;
531 expected0.conv_name = 'd';
533 ASSERT_SFORMAT_EQ(expected0, format_arr[0]);
535 expected1.has_conv = true;
537 expected1.raw_string = {str + 2, 2};
538 expected1.output_ptr = &arg2;
539 expected1.conv_name = 'f';
541 ASSERT_SFORMAT_EQ(expected1, format_arr[1]);
543 expected2.has_conv = true;
545 expected2.raw_string = {str + 4, 2};
546 expected2.output_ptr = &arg3;
547 expected2.conv_name = 's';
549 ASSERT_SFORMAT_EQ(expected2, format_arr[2]);
552 #ifndef LIBC_COPT_SCANF_DISABLE_INDEX_MODE
554 TEST(LlvmLibcScanfParserTest, IndexModeOneArg) {
555 __llvm_libc::scanf_core::FormatSection format_arr[10];
556 const char *str = "%1$d";
557 int arg1 = 12345;
558 evaluate(format_arr, str, &arg1);
560 __llvm_libc::scanf_core::FormatSection expected;
561 expected.has_conv = true;
563 expected.raw_string = {str, 4};
564 expected.output_ptr = &arg1;
565 expected.conv_name = 'd';
567 ASSERT_SFORMAT_EQ(expected, format_arr[0]);
570 TEST(LlvmLibcScanfParserTest, IndexModeThreeArgsSequential) {
571 __llvm_libc::scanf_core::FormatSection format_arr[10];
572 const char *str = "%1$d%2$f%3$s";
573 int arg1 = 12345;
574 double arg2 = 123.45;
575 const char *arg3 = "12345";
576 evaluate(format_arr, str, &arg1, &arg2, &arg3);
578 __llvm_libc::scanf_core::FormatSection expected0, expected1, expected2;
579 expected0.has_conv = true;
581 expected0.raw_string = {str, 4};
582 expected0.output_ptr = &arg1;
583 expected0.conv_name = 'd';
585 ASSERT_SFORMAT_EQ(expected0, format_arr[0]);
587 expected1.has_conv = true;
589 expected1.raw_string = {str + 4, 4};
590 expected1.output_ptr = &arg2;
591 expected1.conv_name = 'f';
593 ASSERT_SFORMAT_EQ(expected1, format_arr[1]);
595 expected2.has_conv = true;
597 expected2.raw_string = {str + 8, 4};
598 expected2.output_ptr = &arg3;
599 expected2.conv_name = 's';
601 ASSERT_SFORMAT_EQ(expected2, format_arr[2]);
604 TEST(LlvmLibcScanfParserTest, IndexModeThreeArgsReverse) {
605 __llvm_libc::scanf_core::FormatSection format_arr[10];
606 const char *str = "%3$d%2$f%1$s";
607 int arg1 = 12345;
608 double arg2 = 123.45;
609 const char *arg3 = "12345";
610 evaluate(format_arr, str, &arg3, &arg2, &arg1);
612 __llvm_libc::scanf_core::FormatSection expected0, expected1, expected2;
613 expected0.has_conv = true;
615 expected0.raw_string = {str, 4};
616 expected0.output_ptr = &arg1;
617 expected0.conv_name = 'd';
619 ASSERT_SFORMAT_EQ(expected0, format_arr[0]);
621 expected1.has_conv = true;
623 expected1.raw_string = {str + 4, 4};
624 expected1.output_ptr = &arg2;
625 expected1.conv_name = 'f';
627 ASSERT_SFORMAT_EQ(expected1, format_arr[1]);
629 expected2.has_conv = true;
631 expected2.raw_string = {str + 8, 4};
632 expected2.output_ptr = &arg3;
633 expected2.conv_name = 's';
635 ASSERT_SFORMAT_EQ(expected2, format_arr[2]);
638 TEST(LlvmLibcScanfParserTest, IndexModeTenArgsRandom) {
639 __llvm_libc::scanf_core::FormatSection format_arr[10];
640 const char *str = "%6$d%3$d%7$d%2$d%8$d%1$d%4$d%9$d%5$d%10$d";
641 uintptr_t args[10] = {6, 4, 2, 7, 9, 1, 3, 5, 8, 10};
642 evaluate(format_arr, str, args[0], args[1], args[2], args[3], args[4],
643 args[5], args[6], args[7], args[8], args[9]);
645 for (size_t i = 0; i < 10; ++i) {
646 __llvm_libc::scanf_core::FormatSection expected;
647 expected.has_conv = true;
649 expected.raw_string = {str + (4 * i),
650 static_cast<size_t>(4 + (i >= 9 ? 1 : 0))};
651 expected.output_ptr = reinterpret_cast<void *>(i + 1);
652 expected.conv_name = 'd';
653 EXPECT_SFORMAT_EQ(expected, format_arr[i]);
657 TEST(LlvmLibcScanfParserTest, IndexModeComplexParsing) {
658 __llvm_libc::scanf_core::FormatSection format_arr[11];
659 const char *str = "normal text %3$llu %% %2$*f %4$d %1$1c%5$[123]";
660 char arg1 = '1';
661 double arg2 = 123.45;
662 unsigned long long arg3 = 12345;
663 int arg4 = 10;
664 char arg5 = 'A';
665 evaluate(format_arr, str, &arg1, &arg2, &arg3, &arg4, &arg5);
667 __llvm_libc::scanf_core::FormatSection expected0, expected1, expected2,
668 expected3, expected4, expected5, expected6, expected7, expected8,
669 expected9, expected10;
671 expected0.has_conv = false;
673 // "normal text "
674 expected0.raw_string = {str, 12};
676 EXPECT_SFORMAT_EQ(expected0, format_arr[0]);
678 expected1.has_conv = true;
679 // "%3$llu"
680 expected1.raw_string = {str + 12, 6};
681 expected1.length_modifier = __llvm_libc::scanf_core::LengthModifier::ll;
682 expected1.output_ptr = &arg3;
683 expected1.conv_name = 'u';
685 EXPECT_SFORMAT_EQ(expected1, format_arr[1]);
687 expected2.has_conv = false;
688 // " "
689 expected2.raw_string = {str + 18, 1};
691 EXPECT_SFORMAT_EQ(expected2, format_arr[2]);
693 expected3.has_conv = true;
694 // "%%"
695 expected3.raw_string = {str + 19, 2};
696 expected3.conv_name = '%';
698 EXPECT_SFORMAT_EQ(expected3, format_arr[3]);
700 expected4.has_conv = false;
701 // " "
702 expected4.raw_string = {str + 21, 1};
704 EXPECT_SFORMAT_EQ(expected4, format_arr[4]);
706 expected5.has_conv = true;
707 // "%2$*f"
708 expected5.raw_string = {str + 22, 5};
709 expected5.flags = __llvm_libc::scanf_core::FormatFlags::NO_WRITE;
710 expected5.conv_name = 'f';
712 EXPECT_SFORMAT_EQ(expected5, format_arr[5]);
714 expected6.has_conv = false;
715 // " "
716 expected6.raw_string = {str + 27, 1};
718 EXPECT_SFORMAT_EQ(expected6, format_arr[6]);
720 expected7.has_conv = true;
722 // "%4$d"
723 expected7.raw_string = {str + 28, 4};
724 expected7.output_ptr = &arg4;
725 expected7.conv_name = 'd';
727 EXPECT_SFORMAT_EQ(expected7, format_arr[7]);
729 expected8.has_conv = false;
730 // " "
731 expected8.raw_string = {str + 32, 1};
733 EXPECT_SFORMAT_EQ(expected8, format_arr[8]);
735 expected9.has_conv = true;
736 // "%1$1c"
737 expected9.raw_string = {str + 33, 5};
738 expected9.max_width = 1;
739 expected9.output_ptr = &arg1;
740 expected9.conv_name = 'c';
742 EXPECT_SFORMAT_EQ(expected9, format_arr[9]);
744 expected10.has_conv = true;
745 // "%5$[123]"
746 expected10.raw_string = {str + 38, 8};
747 expected10.output_ptr = &arg5;
748 expected10.conv_name = '[';
750 __llvm_libc::cpp::bitset<256> scan_set;
752 scan_set.set_range('1', '3');
754 expected10.scan_set = scan_set;
756 EXPECT_SFORMAT_EQ(expected10, format_arr[10]);
759 #endif // LIBC_COPT_SCANF_DISABLE_INDEX_MODE