1 //===-- Unittests for the scanf Parser -----------------------------------===//
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 #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"
17 #include "test/UnitTest/ScanfMatcher.h"
18 #include "test/UnitTest/Test.h"
20 using LIBC_NAMESPACE::cpp::string_view
;
21 using LIBC_NAMESPACE::internal::ArgList
;
23 void init(const char *__restrict str
, ...) {
29 LIBC_NAMESPACE::scanf_core::Parser
<ArgList
> parser(str
, v
);
32 void evaluate(LIBC_NAMESPACE::scanf_core::FormatSection
*format_arr
,
33 const char *__restrict str
, ...) {
36 LIBC_NAMESPACE::internal::ArgList
v(vlist
);
39 LIBC_NAMESPACE::scanf_core::Parser
<ArgList
> parser(str
, v
);
41 for (auto cur_section
= parser
.get_next_section();
42 !cur_section
.raw_string
.empty();
43 cur_section
= parser
.get_next_section()) {
44 *format_arr
= cur_section
;
49 TEST(LlvmLibcScanfParserTest
, Constructor
) { init("test", 1, 2); }
51 TEST(LlvmLibcScanfParserTest
, EvalRaw
) {
52 LIBC_NAMESPACE::scanf_core::FormatSection format_arr
[10];
53 const char *str
= "test";
54 evaluate(format_arr
, str
);
56 LIBC_NAMESPACE::scanf_core::FormatSection expected
;
57 expected
.has_conv
= false;
59 expected
.raw_string
= str
;
61 ASSERT_SFORMAT_EQ(expected
, format_arr
[0]);
62 // TODO: add checks that the format_arr after the last one has length 0
65 TEST(LlvmLibcScanfParserTest
, EvalSimple
) {
66 LIBC_NAMESPACE::scanf_core::FormatSection format_arr
[10];
67 const char *str
= "test %% test";
68 evaluate(format_arr
, str
);
70 LIBC_NAMESPACE::scanf_core::FormatSection expected0
, expected1
, expected2
;
71 expected0
.has_conv
= false;
73 expected0
.raw_string
= {str
, 5};
75 ASSERT_SFORMAT_EQ(expected0
, format_arr
[0]);
77 expected1
.has_conv
= true;
79 expected1
.raw_string
= {str
+ 5, 2};
80 expected1
.conv_name
= '%';
82 ASSERT_SFORMAT_EQ(expected1
, format_arr
[1]);
84 expected2
.has_conv
= false;
86 expected2
.raw_string
= {str
+ 7, 5};
88 ASSERT_SFORMAT_EQ(expected2
, format_arr
[2]);
91 TEST(LlvmLibcScanfParserTest
, EvalOneArg
) {
92 LIBC_NAMESPACE::scanf_core::FormatSection format_arr
[10];
93 const char *str
= "%d";
95 evaluate(format_arr
, str
, &arg1
);
97 LIBC_NAMESPACE::scanf_core::FormatSection expected
;
98 expected
.has_conv
= true;
100 expected
.raw_string
= str
;
101 expected
.output_ptr
= &arg1
;
102 expected
.conv_name
= 'd';
104 ASSERT_SFORMAT_EQ(expected
, format_arr
[0]);
107 TEST(LlvmLibcScanfParserTest
, EvalBadArg
) {
108 LIBC_NAMESPACE::scanf_core::FormatSection format_arr
[10];
109 const char *str
= "%\0abc";
111 evaluate(format_arr
, str
, &arg1
);
113 LIBC_NAMESPACE::scanf_core::FormatSection expected
;
114 expected
.has_conv
= false;
115 expected
.raw_string
= {str
, 1};
117 ASSERT_SFORMAT_EQ(expected
, format_arr
[0]);
120 TEST(LlvmLibcScanfParserTest
, EvalOneArgWithFlag
) {
121 LIBC_NAMESPACE::scanf_core::FormatSection format_arr
[10];
122 const char *str
= "%*d";
123 // Since NO_WRITE is set, the argument shouldn't be used, but I've included
124 // one anyways because in the case that it doesn't work it's better for it to
125 // have a real argument to check against.
127 evaluate(format_arr
, str
, &arg1
);
129 LIBC_NAMESPACE::scanf_core::FormatSection expected
;
130 expected
.has_conv
= true;
132 expected
.raw_string
= str
;
133 expected
.flags
= LIBC_NAMESPACE::scanf_core::FormatFlags::NO_WRITE
;
134 expected
.conv_name
= 'd';
136 ASSERT_SFORMAT_EQ(expected
, format_arr
[0]);
138 // If NO_WRITE is set, then the equality check ignores the pointer since it's
139 // irrelevant, but in this case I want to make sure that it hasn't been set
140 // and check it separately.
141 ASSERT_EQ(expected
.output_ptr
, format_arr
[0].output_ptr
);
144 TEST(LlvmLibcScanfParserTest
, EvalOneArgWithWidth
) {
145 LIBC_NAMESPACE::scanf_core::FormatSection format_arr
[10];
146 const char *str
= "%12d";
148 evaluate(format_arr
, str
, &arg1
);
150 LIBC_NAMESPACE::scanf_core::FormatSection expected
;
151 expected
.has_conv
= true;
153 expected
.raw_string
= str
;
154 expected
.max_width
= 12;
155 expected
.output_ptr
= &arg1
;
156 expected
.conv_name
= 'd';
158 ASSERT_SFORMAT_EQ(expected
, format_arr
[0]);
161 TEST(LlvmLibcScanfParserTest
, EvalOneArgWithShortLengthModifier
) {
162 LIBC_NAMESPACE::scanf_core::FormatSection format_arr
[10];
163 const char *str
= "%hd";
165 evaluate(format_arr
, str
, &arg1
);
167 LIBC_NAMESPACE::scanf_core::FormatSection expected
;
168 expected
.has_conv
= true;
170 expected
.raw_string
= str
;
171 expected
.length_modifier
= LIBC_NAMESPACE::scanf_core::LengthModifier::h
;
172 expected
.output_ptr
= &arg1
;
173 expected
.conv_name
= 'd';
175 ASSERT_SFORMAT_EQ(expected
, format_arr
[0]);
178 TEST(LlvmLibcScanfParserTest
, EvalOneArgWithLongLengthModifier
) {
179 LIBC_NAMESPACE::scanf_core::FormatSection format_arr
[10];
180 const char *str
= "%lld";
181 long long arg1
= 12345;
182 evaluate(format_arr
, str
, &arg1
);
184 LIBC_NAMESPACE::scanf_core::FormatSection expected
;
185 expected
.has_conv
= true;
187 expected
.raw_string
= str
;
188 expected
.length_modifier
= LIBC_NAMESPACE::scanf_core::LengthModifier::ll
;
189 expected
.output_ptr
= &arg1
;
190 expected
.conv_name
= 'd';
192 ASSERT_SFORMAT_EQ(expected
, format_arr
[0]);
195 TEST(LlvmLibcScanfParserTest
, EvalOneArgWithAllOptions
) {
196 LIBC_NAMESPACE::scanf_core::FormatSection format_arr
[10];
197 const char *str
= "%*56jd";
198 intmax_t arg1
= 12345;
199 evaluate(format_arr
, str
, &arg1
);
201 LIBC_NAMESPACE::scanf_core::FormatSection expected
;
202 expected
.has_conv
= true;
204 expected
.raw_string
= str
;
205 expected
.flags
= LIBC_NAMESPACE::scanf_core::FormatFlags::NO_WRITE
;
206 expected
.max_width
= 56;
207 expected
.length_modifier
= LIBC_NAMESPACE::scanf_core::LengthModifier::j
;
208 expected
.conv_name
= 'd';
210 ASSERT_SFORMAT_EQ(expected
, format_arr
[0]);
213 TEST(LlvmLibcScanfParserTest
, EvalSimpleBracketArg
) {
214 LIBC_NAMESPACE::scanf_core::FormatSection format_arr
[10];
215 const char *str
= "%[abc]";
217 evaluate(format_arr
, str
, &arg1
);
219 LIBC_NAMESPACE::scanf_core::FormatSection expected
;
220 expected
.has_conv
= true;
222 expected
.raw_string
= str
;
223 expected
.conv_name
= '[';
224 expected
.output_ptr
= &arg1
;
226 LIBC_NAMESPACE::cpp::bitset
<256> scan_set
;
232 expected
.scan_set
= scan_set
;
234 ASSERT_SFORMAT_EQ(expected
, format_arr
[0]);
237 TEST(LlvmLibcScanfParserTest
, EvalBracketArgRange
) {
238 LIBC_NAMESPACE::scanf_core::FormatSection format_arr
[10];
239 const char *str
= "%[A-D]";
241 evaluate(format_arr
, str
, &arg1
);
243 LIBC_NAMESPACE::scanf_core::FormatSection expected
;
244 expected
.has_conv
= true;
246 expected
.raw_string
= str
;
247 expected
.conv_name
= '[';
248 expected
.output_ptr
= &arg1
;
250 LIBC_NAMESPACE::cpp::bitset
<256> scan_set
;
257 expected
.scan_set
= scan_set
;
259 ASSERT_SFORMAT_EQ(expected
, format_arr
[0]);
262 TEST(LlvmLibcScanfParserTest
, EvalBracketArgTwoRanges
) {
263 LIBC_NAMESPACE::scanf_core::FormatSection format_arr
[10];
264 const char *str
= "%[A-De-g]";
266 evaluate(format_arr
, str
, &arg1
);
268 LIBC_NAMESPACE::scanf_core::FormatSection expected
;
269 expected
.has_conv
= true;
271 expected
.raw_string
= str
;
272 expected
.conv_name
= '[';
273 expected
.output_ptr
= &arg1
;
275 LIBC_NAMESPACE::cpp::bitset
<256> scan_set
;
281 scan_set
.set_range('e', 'g');
283 expected
.scan_set
= scan_set
;
285 ASSERT_SFORMAT_EQ(expected
, format_arr
[0]);
288 TEST(LlvmLibcScanfParserTest
, EvalBracketArgJustHyphen
) {
289 LIBC_NAMESPACE::scanf_core::FormatSection format_arr
[10];
290 const char *str
= "%[-]";
292 evaluate(format_arr
, str
, &arg1
);
294 LIBC_NAMESPACE::scanf_core::FormatSection expected
;
295 expected
.has_conv
= true;
297 expected
.raw_string
= str
;
298 expected
.conv_name
= '[';
299 expected
.output_ptr
= &arg1
;
301 LIBC_NAMESPACE::cpp::bitset
<256> scan_set
;
305 expected
.scan_set
= scan_set
;
307 ASSERT_SFORMAT_EQ(expected
, format_arr
[0]);
310 TEST(LlvmLibcScanfParserTest
, EvalBracketArgLeftHyphen
) {
311 LIBC_NAMESPACE::scanf_core::FormatSection format_arr
[10];
312 const char *str
= "%[-A]";
314 evaluate(format_arr
, str
, &arg1
);
316 LIBC_NAMESPACE::scanf_core::FormatSection expected
;
317 expected
.has_conv
= true;
319 expected
.raw_string
= str
;
320 expected
.conv_name
= '[';
321 expected
.output_ptr
= &arg1
;
323 LIBC_NAMESPACE::cpp::bitset
<256> scan_set
;
328 expected
.scan_set
= scan_set
;
330 ASSERT_SFORMAT_EQ(expected
, format_arr
[0]);
333 TEST(LlvmLibcScanfParserTest
, EvalBracketArgRightHyphen
) {
334 LIBC_NAMESPACE::scanf_core::FormatSection format_arr
[10];
335 const char *str
= "%[Z-]";
337 evaluate(format_arr
, str
, &arg1
);
339 LIBC_NAMESPACE::scanf_core::FormatSection expected
;
340 expected
.has_conv
= true;
342 expected
.raw_string
= str
;
343 expected
.conv_name
= '[';
344 expected
.output_ptr
= &arg1
;
346 LIBC_NAMESPACE::cpp::bitset
<256> scan_set
;
351 expected
.scan_set
= scan_set
;
353 ASSERT_SFORMAT_EQ(expected
, format_arr
[0]);
356 TEST(LlvmLibcScanfParserTest
, EvalBracketArgInvertSimple
) {
357 LIBC_NAMESPACE::scanf_core::FormatSection format_arr
[10];
358 const char *str
= "%[^abc]";
360 evaluate(format_arr
, str
, &arg1
);
362 LIBC_NAMESPACE::scanf_core::FormatSection expected
;
363 expected
.has_conv
= true;
365 expected
.raw_string
= str
;
366 expected
.conv_name
= '[';
367 expected
.output_ptr
= &arg1
;
369 LIBC_NAMESPACE::cpp::bitset
<256> scan_set
;
376 expected
.scan_set
= scan_set
;
378 ASSERT_SFORMAT_EQ(expected
, format_arr
[0]);
381 TEST(LlvmLibcScanfParserTest
, EvalBracketArgInvertRange
) {
382 LIBC_NAMESPACE::scanf_core::FormatSection format_arr
[10];
383 const char *str
= "%[^0-9]";
385 evaluate(format_arr
, str
, &arg1
);
387 LIBC_NAMESPACE::scanf_core::FormatSection expected
;
388 expected
.has_conv
= true;
390 expected
.raw_string
= str
;
391 expected
.conv_name
= '[';
392 expected
.output_ptr
= &arg1
;
394 LIBC_NAMESPACE::cpp::bitset
<256> scan_set
;
396 scan_set
.set_range('0', '9');
399 expected
.scan_set
= scan_set
;
401 ASSERT_SFORMAT_EQ(expected
, format_arr
[0]);
404 TEST(LlvmLibcScanfParserTest
, EvalBracketArgRightBracket
) {
405 LIBC_NAMESPACE::scanf_core::FormatSection format_arr
[10];
406 const char *str
= "%[]]";
408 evaluate(format_arr
, str
, &arg1
);
410 LIBC_NAMESPACE::scanf_core::FormatSection expected
;
411 expected
.has_conv
= true;
413 expected
.raw_string
= str
;
414 expected
.conv_name
= '[';
415 expected
.output_ptr
= &arg1
;
417 LIBC_NAMESPACE::cpp::bitset
<256> scan_set
;
421 expected
.scan_set
= scan_set
;
423 ASSERT_SFORMAT_EQ(expected
, format_arr
[0]);
426 TEST(LlvmLibcScanfParserTest
, EvalBracketArgRightBracketRange
) {
427 LIBC_NAMESPACE::scanf_core::FormatSection format_arr
[10];
428 const char *str
= "%[]-a]";
430 evaluate(format_arr
, str
, &arg1
);
432 LIBC_NAMESPACE::scanf_core::FormatSection expected
;
433 expected
.has_conv
= true;
435 expected
.raw_string
= str
;
436 expected
.conv_name
= '[';
437 expected
.output_ptr
= &arg1
;
439 LIBC_NAMESPACE::cpp::bitset
<256> scan_set
;
441 scan_set
.set_range(']', 'a');
443 expected
.scan_set
= scan_set
;
445 ASSERT_SFORMAT_EQ(expected
, format_arr
[0]);
448 TEST(LlvmLibcScanfParserTest
, EvalBracketArgRightBracketInvert
) {
449 LIBC_NAMESPACE::scanf_core::FormatSection format_arr
[10];
450 const char *str
= "%[^]]";
452 evaluate(format_arr
, str
, &arg1
);
454 LIBC_NAMESPACE::scanf_core::FormatSection expected
;
455 expected
.has_conv
= true;
457 expected
.raw_string
= str
;
458 expected
.conv_name
= '[';
459 expected
.output_ptr
= &arg1
;
461 LIBC_NAMESPACE::cpp::bitset
<256> scan_set
;
466 expected
.scan_set
= scan_set
;
468 ASSERT_SFORMAT_EQ(expected
, format_arr
[0]);
471 TEST(LlvmLibcScanfParserTest
, EvalBracketArgRightBracketInvertRange
) {
472 LIBC_NAMESPACE::scanf_core::FormatSection format_arr
[10];
473 const char *str
= "%[^]-^]";
475 evaluate(format_arr
, str
, &arg1
);
477 LIBC_NAMESPACE::scanf_core::FormatSection expected
;
478 expected
.has_conv
= true;
480 expected
.raw_string
= str
;
481 expected
.conv_name
= '[';
482 expected
.output_ptr
= &arg1
;
484 LIBC_NAMESPACE::cpp::bitset
<256> scan_set
;
486 scan_set
.set_range(']', '^');
489 expected
.scan_set
= scan_set
;
491 ASSERT_SFORMAT_EQ(expected
, format_arr
[0]);
494 // This is not part of the standard, but the hyphen's effect is always
495 // implementation defined, and I have defined it such that it will capture the
496 // correct range regardless of the order of the characters.
497 TEST(LlvmLibcScanfParserTest
, EvalBracketArgBackwardsRange
) {
498 LIBC_NAMESPACE::scanf_core::FormatSection format_arr
[10];
499 const char *str
= "%[9-0]";
501 evaluate(format_arr
, str
, &arg1
);
503 LIBC_NAMESPACE::scanf_core::FormatSection expected
;
504 expected
.has_conv
= true;
506 expected
.raw_string
= str
;
507 expected
.conv_name
= '[';
508 expected
.output_ptr
= &arg1
;
510 LIBC_NAMESPACE::cpp::bitset
<256> scan_set
;
512 scan_set
.set_range('0', '9');
514 expected
.scan_set
= scan_set
;
516 ASSERT_SFORMAT_EQ(expected
, format_arr
[0]);
519 TEST(LlvmLibcScanfParserTest
, EvalThreeArgs
) {
520 LIBC_NAMESPACE::scanf_core::FormatSection format_arr
[10];
521 const char *str
= "%d%f%s";
523 double arg2
= 123.45;
524 const char *arg3
= "12345";
525 evaluate(format_arr
, str
, &arg1
, &arg2
, &arg3
);
527 LIBC_NAMESPACE::scanf_core::FormatSection expected0
, expected1
, expected2
;
528 expected0
.has_conv
= true;
530 expected0
.raw_string
= {str
, 2};
531 expected0
.output_ptr
= &arg1
;
532 expected0
.conv_name
= 'd';
534 ASSERT_SFORMAT_EQ(expected0
, format_arr
[0]);
536 expected1
.has_conv
= true;
538 expected1
.raw_string
= {str
+ 2, 2};
539 expected1
.output_ptr
= &arg2
;
540 expected1
.conv_name
= 'f';
542 ASSERT_SFORMAT_EQ(expected1
, format_arr
[1]);
544 expected2
.has_conv
= true;
546 expected2
.raw_string
= {str
+ 4, 2};
547 expected2
.output_ptr
= &arg3
;
548 expected2
.conv_name
= 's';
550 ASSERT_SFORMAT_EQ(expected2
, format_arr
[2]);
553 #ifndef LIBC_COPT_SCANF_DISABLE_INDEX_MODE
555 TEST(LlvmLibcScanfParserTest
, IndexModeOneArg
) {
556 LIBC_NAMESPACE::scanf_core::FormatSection format_arr
[10];
557 const char *str
= "%1$d";
559 evaluate(format_arr
, str
, &arg1
);
561 LIBC_NAMESPACE::scanf_core::FormatSection expected
;
562 expected
.has_conv
= true;
564 expected
.raw_string
= {str
, 4};
565 expected
.output_ptr
= &arg1
;
566 expected
.conv_name
= 'd';
568 ASSERT_SFORMAT_EQ(expected
, format_arr
[0]);
571 TEST(LlvmLibcScanfParserTest
, IndexModeThreeArgsSequential
) {
572 LIBC_NAMESPACE::scanf_core::FormatSection format_arr
[10];
573 const char *str
= "%1$d%2$f%3$s";
575 double arg2
= 123.45;
576 const char *arg3
= "12345";
577 evaluate(format_arr
, str
, &arg1
, &arg2
, &arg3
);
579 LIBC_NAMESPACE::scanf_core::FormatSection expected0
, expected1
, expected2
;
580 expected0
.has_conv
= true;
582 expected0
.raw_string
= {str
, 4};
583 expected0
.output_ptr
= &arg1
;
584 expected0
.conv_name
= 'd';
586 ASSERT_SFORMAT_EQ(expected0
, format_arr
[0]);
588 expected1
.has_conv
= true;
590 expected1
.raw_string
= {str
+ 4, 4};
591 expected1
.output_ptr
= &arg2
;
592 expected1
.conv_name
= 'f';
594 ASSERT_SFORMAT_EQ(expected1
, format_arr
[1]);
596 expected2
.has_conv
= true;
598 expected2
.raw_string
= {str
+ 8, 4};
599 expected2
.output_ptr
= &arg3
;
600 expected2
.conv_name
= 's';
602 ASSERT_SFORMAT_EQ(expected2
, format_arr
[2]);
605 TEST(LlvmLibcScanfParserTest
, IndexModeThreeArgsReverse
) {
606 LIBC_NAMESPACE::scanf_core::FormatSection format_arr
[10];
607 const char *str
= "%3$d%2$f%1$s";
609 double arg2
= 123.45;
610 const char *arg3
= "12345";
611 evaluate(format_arr
, str
, &arg3
, &arg2
, &arg1
);
613 LIBC_NAMESPACE::scanf_core::FormatSection expected0
, expected1
, expected2
;
614 expected0
.has_conv
= true;
616 expected0
.raw_string
= {str
, 4};
617 expected0
.output_ptr
= &arg1
;
618 expected0
.conv_name
= 'd';
620 ASSERT_SFORMAT_EQ(expected0
, format_arr
[0]);
622 expected1
.has_conv
= true;
624 expected1
.raw_string
= {str
+ 4, 4};
625 expected1
.output_ptr
= &arg2
;
626 expected1
.conv_name
= 'f';
628 ASSERT_SFORMAT_EQ(expected1
, format_arr
[1]);
630 expected2
.has_conv
= true;
632 expected2
.raw_string
= {str
+ 8, 4};
633 expected2
.output_ptr
= &arg3
;
634 expected2
.conv_name
= 's';
636 ASSERT_SFORMAT_EQ(expected2
, format_arr
[2]);
639 TEST(LlvmLibcScanfParserTest
, IndexModeTenArgsRandom
) {
640 LIBC_NAMESPACE::scanf_core::FormatSection format_arr
[10];
641 const char *str
= "%6$d%3$d%7$d%2$d%8$d%1$d%4$d%9$d%5$d%10$d";
642 uintptr_t args
[10] = {6, 4, 2, 7, 9, 1, 3, 5, 8, 10};
643 evaluate(format_arr
, str
, args
[0], args
[1], args
[2], args
[3], args
[4],
644 args
[5], args
[6], args
[7], args
[8], args
[9]);
646 for (size_t i
= 0; i
< 10; ++i
) {
647 LIBC_NAMESPACE::scanf_core::FormatSection expected
;
648 expected
.has_conv
= true;
650 expected
.raw_string
= {str
+ (4 * i
),
651 static_cast<size_t>(4 + (i
>= 9 ? 1 : 0))};
652 expected
.output_ptr
= reinterpret_cast<void *>(i
+ 1);
653 expected
.conv_name
= 'd';
654 EXPECT_SFORMAT_EQ(expected
, format_arr
[i
]);
658 TEST(LlvmLibcScanfParserTest
, IndexModeComplexParsing
) {
659 LIBC_NAMESPACE::scanf_core::FormatSection format_arr
[11];
660 const char *str
= "normal text %3$llu %% %2$*f %4$d %1$1c%5$[123]";
662 double arg2
= 123.45;
663 unsigned long long arg3
= 12345;
666 evaluate(format_arr
, str
, &arg1
, &arg2
, &arg3
, &arg4
, &arg5
);
668 LIBC_NAMESPACE::scanf_core::FormatSection expected0
, expected1
, expected2
,
669 expected3
, expected4
, expected5
, expected6
, expected7
, expected8
,
670 expected9
, expected10
;
672 expected0
.has_conv
= false;
675 expected0
.raw_string
= {str
, 12};
677 EXPECT_SFORMAT_EQ(expected0
, format_arr
[0]);
679 expected1
.has_conv
= true;
681 expected1
.raw_string
= {str
+ 12, 6};
682 expected1
.length_modifier
= LIBC_NAMESPACE::scanf_core::LengthModifier::ll
;
683 expected1
.output_ptr
= &arg3
;
684 expected1
.conv_name
= 'u';
686 EXPECT_SFORMAT_EQ(expected1
, format_arr
[1]);
688 expected2
.has_conv
= false;
690 expected2
.raw_string
= {str
+ 18, 1};
692 EXPECT_SFORMAT_EQ(expected2
, format_arr
[2]);
694 expected3
.has_conv
= true;
696 expected3
.raw_string
= {str
+ 19, 2};
697 expected3
.conv_name
= '%';
699 EXPECT_SFORMAT_EQ(expected3
, format_arr
[3]);
701 expected4
.has_conv
= false;
703 expected4
.raw_string
= {str
+ 21, 1};
705 EXPECT_SFORMAT_EQ(expected4
, format_arr
[4]);
707 expected5
.has_conv
= true;
709 expected5
.raw_string
= {str
+ 22, 5};
710 expected5
.flags
= LIBC_NAMESPACE::scanf_core::FormatFlags::NO_WRITE
;
711 expected5
.conv_name
= 'f';
713 EXPECT_SFORMAT_EQ(expected5
, format_arr
[5]);
715 expected6
.has_conv
= false;
717 expected6
.raw_string
= {str
+ 27, 1};
719 EXPECT_SFORMAT_EQ(expected6
, format_arr
[6]);
721 expected7
.has_conv
= true;
724 expected7
.raw_string
= {str
+ 28, 4};
725 expected7
.output_ptr
= &arg4
;
726 expected7
.conv_name
= 'd';
728 EXPECT_SFORMAT_EQ(expected7
, format_arr
[7]);
730 expected8
.has_conv
= false;
732 expected8
.raw_string
= {str
+ 32, 1};
734 EXPECT_SFORMAT_EQ(expected8
, format_arr
[8]);
736 expected9
.has_conv
= true;
738 expected9
.raw_string
= {str
+ 33, 5};
739 expected9
.max_width
= 1;
740 expected9
.output_ptr
= &arg1
;
741 expected9
.conv_name
= 'c';
743 EXPECT_SFORMAT_EQ(expected9
, format_arr
[9]);
745 expected10
.has_conv
= true;
747 expected10
.raw_string
= {str
+ 38, 8};
748 expected10
.output_ptr
= &arg5
;
749 expected10
.conv_name
= '[';
751 LIBC_NAMESPACE::cpp::bitset
<256> scan_set
;
753 scan_set
.set_range('1', '3');
755 expected10
.scan_set
= scan_set
;
757 EXPECT_SFORMAT_EQ(expected10
, format_arr
[10]);
760 #endif // LIBC_COPT_SCANF_DISABLE_INDEX_MODE