1 /*
2  * This file was generated from printf-tests.txt included
3  * as a part of the printf test suite developed by
4  * Bart Massey:
5  *
6  * https://github.com/BartMassey/printf-tests
7  *
8  * printf-tests.txt carries the following Copyright, which
9  * probably extends to this file as well given the transformations
10  * are fairly mechanical:
11  *
12 # Various printf tests compiled from various sources
13 # Copyright © 2013 Bart Massey
14 # This program is licensed under the GPL version 2 or later.
15 # Please see the file COPYING.GPL2 in this distribution for
16 # license terms.
17 
18 */
19 
20 #ifndef __PICOLIBC__
21 # define _WANT_IO_C99_FORMATS
22 # define _WANT_IO_LONG_LONG
23 # define _WANT_IO_POS_ARGS
24 #elif defined(TINY_STDIO)
25 # ifdef _WANT_IO_PERCENT_B
26 #  define BINARY_FORMAT
27 # endif
28 # ifdef PICOLIBC_FLOAT_PRINTF_SCANF
29 #  define LOW_FLOAT
30 # endif
31 # ifdef PICOLIBC_INTEGER_PRINTF_SCANF
32 #  define NO_FLOAT
33 #  ifndef _WANT_IO_LONG_LONG
34 #   define NO_LONGLONG
35 #  endif
36 #  ifndef _WANT_IO_POS_ARGS
37 #   define NO_POS_ARGS
38 #  endif
39 # endif
40 #else
41 # ifdef NO_FLOATING_POINT
42 #  define NO_FLOAT
43 # endif
44 # ifndef _WANT_IO_LONG_LONG
45 #  define NO_LONGLONG
46 # endif
47 # ifndef _WANT_IO_POS_ARGS
48 #  define NO_POS_ARGS
49 # endif
50 # define NORMALIZED_A
51 #endif
52 
53 
54 /* XXX This code generated automatically by gen-testcases.hs
55    from ../../printf-tests.txt . You probably do not want to
56    manually edit this file. */
57 #ifndef NO_FLOAT
58     result |= test(__LINE__, "0", "%.7g", 0.0);
59     result |= test(__LINE__, "0.33", "%.*f", 2, 0.33333333);
60 #endif
61     result |= test(__LINE__, "foo", "%.3s", "foobar");
62     result |= test(__LINE__, "     00004", "%10.5d", 4);
63     result |= test(__LINE__, " 42", "% d", 42);
64     result |= test(__LINE__, "-42", "% d", -42);
65     result |= test(__LINE__, "   42", "% 5d", 42);
66     result |= test(__LINE__, "  -42", "% 5d", -42);
67     result |= test(__LINE__, "             42", "% 15d", 42);
68     result |= test(__LINE__, "            -42", "% 15d", -42);
69     result |= test(__LINE__, "+42", "%+d", 42);
70     result |= test(__LINE__, "-42", "%+d", -42);
71     result |= test(__LINE__, "  +42", "%+5d", 42);
72     result |= test(__LINE__, "  -42", "%+5d", -42);
73     result |= test(__LINE__, "            +42", "%+15d", 42);
74     result |= test(__LINE__, "            -42", "%+15d", -42);
75     result |= test(__LINE__, "42", "%0d", 42);
76     result |= test(__LINE__, "-42", "%0d", -42);
77     result |= test(__LINE__, "00042", "%05d", 42);
78     result |= test(__LINE__, "-0042", "%05d", -42);
79     result |= test(__LINE__, "000000000000042", "%015d", 42);
80     result |= test(__LINE__, "-00000000000042", "%015d", -42);
81     result |= test(__LINE__, "42", "%-d", 42);
82     result |= test(__LINE__, "-42", "%-d", -42);
83     result |= test(__LINE__, "42   ", "%-5d", 42);
84     result |= test(__LINE__, "-42  ", "%-5d", -42);
85     result |= test(__LINE__, "42             ", "%-15d", 42);
86     result |= test(__LINE__, "-42            ", "%-15d", -42);
87     result |= test(__LINE__, "42", "%-0d", 42);
88     result |= test(__LINE__, "-42", "%-0d", -42);
89     result |= test(__LINE__, "42   ", "%-05d", 42);
90     result |= test(__LINE__, "-42  ", "%-05d", -42);
91     result |= test(__LINE__, "42             ", "%-015d", 42);
92     result |= test(__LINE__, "-42            ", "%-015d", -42);
93     result |= test(__LINE__, "42", "%0-d", 42);
94     result |= test(__LINE__, "-42", "%0-d", -42);
95     result |= test(__LINE__, "42   ", "%0-5d", 42);
96     result |= test(__LINE__, "-42  ", "%0-5d", -42);
97     result |= test(__LINE__, "42             ", "%0-15d", 42);
98     result |= test(__LINE__, "-42            ", "%0-15d", -42);
99 #ifndef NO_FLOAT
100     result |= test(__LINE__, "42.90", "%.2f", 42.8952);
101     result |= test(__LINE__, "42.90", "%.2F", 42.8952);
102 #ifdef LOW_FLOAT
103     result |= test(__LINE__, "42.89520", "%.5f", 42.8952);
104 #else
105     result |= test(__LINE__, "42.8952000000", "%.10f", 42.8952);
106 #endif
107     result |= test(__LINE__, "42.90", "%1.2f", 42.8952);
108     result |= test(__LINE__, " 42.90", "%6.2f", 42.8952);
109     result |= test(__LINE__, "+42.90", "%+6.2f", 42.8952);
110 #ifdef LOW_FLOAT
111     result |= test(__LINE__, "42.89520", "%5.5f", 42.8952);
112 #else
113     result |= test(__LINE__, "42.8952000000", "%5.10f", 42.8952);
114 #endif
115 #endif /* NO_FLOAT */
116     /* 51: anti-test */
117     /* 52: anti-test */
118     /* 53: excluded for C */
119 #if !defined(NO_POS_ARGS)
120     result |= test(__LINE__, "Hot Pocket", "%1$s %2$s", "Hot", "Pocket");
121     result |= test(__LINE__, "Pocket Hot", "%2$s %1$s", "Hot", "Pocket");
122     result |= test(__LINE__, "0002   1 hi", "%2$04d %1$*3$d %4$s", 1, 2, 3, "hi");
123 #ifndef NO_FLOAT
124     result |= test(__LINE__, "12.0 Hot Pockets", "%1$.1f %2$s %3$ss", printf_float(12.0), "Hot", "Pocket");
125     result |= test(__LINE__, "12.0 Hot Pockets", "%1$.*4$f %2$s %3$ss", printf_float(12.0), "Hot", "Pocket", 1);
126     result |= test(__LINE__, " 12.0 Hot Pockets", "%1$*5$.*4$f %2$s %3$ss", printf_float(12.0), "Hot", "Pocket", 1, 5);
127     result |= test(__LINE__, " 12.0 Hot Pockets 5", "%1$5.*4$f %2$s %3$ss %5$d", printf_float(12.0), "Hot", "Pocket", 1, 5);
128 #if !defined(TINY_STDIO) || defined(_IO_FLOAT_EXACT)
129     result |= test(__LINE__,
130                    "   12345  1234    11145401322     321.765400   3.217654e+02   5    test-string",
131                    "%1$*5$d %2$*6$hi %3$*7$lo %4$*8$f %9$*12$e %10$*13$g %11$*14$s",
132                    12345, 1234, 1234567890, printf_float(321.7654), 8, 5, 14, 14,
133                    printf_float(321.7654), printf_float(5.0000001), "test-string", 14, 3, 14);
134 #endif
135 #endif
136 #endif
137     /* 58: anti-test */
138 #ifdef TINY_STDIO
139     result |= test(__LINE__, "%(foo", "%(foo");
140 #endif
141     result |= test(__LINE__, " foo", "%*s", 4, "foo");
142 #ifndef NO_FLOAT
143     result |= test(__LINE__, "      3.14", "%*.*f", 10, 2, 3.14159265);
144     result |= test(__LINE__, "3.14      ", "%-*.*f", 10, 2, 3.14159265);
145 # if !(defined(TINY_STDIO) && !defined(_IO_FLOAT_EXACT))
146 #  ifndef LOW_FLOAT
147 #   ifdef TINY_STDIO
148 #    define SQRT2_60 "1414213562373095000000000000000000000000000000000000000000000.000"
149 #   else
150 #    define SQRT2_60 "1414213562373095053224405813183213153460812619236586568024064.000"
151 #   endif
152     result |= test(__LINE__, SQRT2_60, "%.3f", 1.4142135623730950e60);
153 #  endif
154 # endif
155 #endif
156     /* 64: anti-test */
157     /* 65: anti-test */
158     result |= test(__LINE__, "+hello+", "+%s+", "hello");
159     result |= test(__LINE__, "+10+", "+%d+", 10);
160     result |= test(__LINE__, "a", "%c", 'a');
161     result |= test(__LINE__, " ", "%c", 32);
162     result |= test(__LINE__, "$", "%c", 36);
163     result |= test(__LINE__, "10", "%d", 10);
164 
165 #ifndef _NANO_FORMATTED_IO
166     result |= test(__LINE__, "1000000", "%'d", 1000000);
167 #endif
168     /* 72: anti-test */
169     /* 73: anti-test */
170     /* 74: excluded for C */
171     /* 75: excluded for C */
172 #ifndef NO_FLOAT
173 #ifdef LOW_FLOAT
174     result |= test(__LINE__, "         +7.894561e+08", "%+#22.6e", 7.89456123e8);
175     result |= test(__LINE__, "7.894561e+08          ", "%-#22.6e", 7.89456123e8);
176     result |= test(__LINE__, "          7.894561e+08", "%#22.6e", 7.89456123e8);
177 #else
178     result |= test(__LINE__, "+7.894561230000000e+08", "%+#22.15e", 7.89456123e8);
179     result |= test(__LINE__, "7.894561230000000e+08 ", "%-#22.15e", 7.89456123e8);
180     result |= test(__LINE__, " 7.894561230000000e+08", "%#22.15e", 7.89456123e8);
181 #endif
182     result |= test(__LINE__, "8.e+08", "%#1.1g", 7.89456123e8);
183 #endif
184 #ifndef NO_LONGLONG
185     result |= test(__LINE__, "    +100", "%+8lld", 100LL);
186 #if defined(TINY_STDIO) || !defined(__PICOLIBC__)
187     result |= test(__LINE__, "    +100", "%+8Ld", 100LL);
188 #endif
189     result |= test(__LINE__, "+00000100", "%+.8lld", 100LL);
190     result |= test(__LINE__, " +00000100", "%+10.8lld", 100LL);
191 #ifdef TINY_STDIO
192     result |= test(__LINE__, "%_1lld", "%_1lld", 100LL);
193 #endif
194     result |= test(__LINE__, "-00100", "%-1.5lld", -100LL);
195     result |= test(__LINE__, "  100", "%5lld", 100LL);
196     result |= test(__LINE__, " -100", "%5lld", -100LL);
197     result |= test(__LINE__, "100  ", "%-5lld", 100LL);
198     result |= test(__LINE__, "-100 ", "%-5lld", -100LL);
199     result |= test(__LINE__, "00100", "%-.5lld", 100LL);
200     result |= test(__LINE__, "-00100", "%-.5lld", -100LL);
201     result |= test(__LINE__, "00100   ", "%-8.5lld", 100LL);
202     result |= test(__LINE__, "-00100  ", "%-8.5lld", -100LL);
203     result |= test(__LINE__, "00100", "%05lld", 100LL);
204     result |= test(__LINE__, "-0100", "%05lld", -100LL);
205     result |= test(__LINE__, " 100", "% lld", 100LL);
206     result |= test(__LINE__, "-100", "% lld", -100LL);
207     result |= test(__LINE__, "  100", "% 5lld", 100LL);
208     result |= test(__LINE__, " -100", "% 5lld", -100LL);
209     result |= test(__LINE__, " 00100", "% .5lld", 100LL);
210     result |= test(__LINE__, "-00100", "% .5lld", -100LL);
211     result |= test(__LINE__, "   00100", "% 8.5lld", 100LL);
212     result |= test(__LINE__, "  -00100", "% 8.5lld", -100LL);
213     result |= test(__LINE__, "", "%.0lld", 0LL);
214     result |= test(__LINE__, " 0x00ffffffffffffff9c", "%#+21.18llx", -100LL);
215     result |= test(__LINE__, "0001777777777777777777634", "%#.25llo", -100LL);
216     result |= test(__LINE__, " 01777777777777777777634", "%#+24.20llo", -100LL);
217     result |= test(__LINE__, "0X00000FFFFFFFFFFFFFF9C", "%#+18.21llX", -100LL);
218     result |= test(__LINE__, "001777777777777777777634", "%#+20.24llo", -100LL);
219     result |= test(__LINE__, "   0018446744073709551615", "%#+25.22llu", -1LL);
220     result |= test(__LINE__, "   0018446744073709551615", "%#+25.22llu", -1LL);
221     result |= test(__LINE__, "     0000018446744073709551615", "%#+30.25llu", -1LL);
222     result |= test(__LINE__, "  -0000000000000000000001", "%+#25.22lld", -1LL);
223     result |= test(__LINE__, "00144   ", "%#-8.5llo", 100LL);
224     result |= test(__LINE__, "+00100  ", "%#-+ 08.5lld", 100LL);
225     result |= test(__LINE__, "+00100  ", "%#-+ 08.5lld", 100LL);
226     result |= test(__LINE__, "0000000000000000000000000000000000000001", "%.40lld", 1LL);
227     result |= test(__LINE__, " 0000000000000000000000000000000000000001", "% .40lld", 1LL);
228 #endif
229     result |= test(__LINE__, " 0000000000000000000000000000000000000001", "% .40d", 1);
230     /* 121: excluded for C */
231     /* 124: excluded for C */
232     result |= test(__LINE__, " 1", "% d", 1);
233     result |= test(__LINE__, "+1", "%+ d", 1);
234     result |= test(__LINE__, "0x0000000001", "%#012x", 1);
235     result |= test(__LINE__, "0x00000001", "%#04.8x", 1);
236     result |= test(__LINE__, "0x01    ", "%#-08.2x", 1);
237     result |= test(__LINE__, "00000001", "%#08o", 1);
238     result |= test(__LINE__, "0x39", "%p", (void *)57ULL);
239     result |= test(__LINE__, "0x39", "%p", (void *)57U);
240     result |= test(__LINE__, "f", "%.1s", "foo");
241     result |= test(__LINE__, "f", "%.*s", 1, "foo");
242     result |= test(__LINE__, "foo  ", "%*s", -5, "foo");
243     result |= test(__LINE__, "hello", "hello");
244 #if defined(TINY_STDIO) && !defined(_WANT_IO_PERCENT_B)
245     result |= test(__LINE__, "%b", "%b");
246 #endif
247     result |= test(__LINE__, "  a", "%3c", 'a');
248     result |= test(__LINE__, "1234", "%3d", 1234);
249     /* 150: excluded for C */
250     result |= test(__LINE__, "2", "%-1d", 2);
251 #ifndef NO_FLOAT
252     result |= test(__LINE__, "8.6000", "%2.4f", 8.6);
253     result |= test(__LINE__, "0.600000", "%0f", 0.6);
254     result |= test(__LINE__, "1", "%.0f", 0.6);
255     result |= test(__LINE__, "8.6000e+00", "%2.4e", 8.6);
256     result |= test(__LINE__, " 8.6000e+00", "% 2.4e", 8.6);
257     result |= test(__LINE__, "-8.6000e+00", "% 2.4e", -8.6);
258     result |= test(__LINE__, "+8.6000e+00", "%+2.4e", 8.6);
259     result |= test(__LINE__, "8.6", "%2.4g", 8.6);
260 #endif
261     result |= test(__LINE__, "-1", "%-i", -1);
262     result |= test(__LINE__, "1", "%-i", 1);
263     result |= test(__LINE__, "+1", "%+i", 1);
264     result |= test(__LINE__, "12", "%o", 10);
265     /* 166: excluded for C */
266     /* 167: excluded for C */
267 #ifdef TINY_STDIO
268     result |= test(__LINE__, "(null)", "%s", NULL);
269 #endif
270     result |= test(__LINE__, "%%%%", "%s", "%%%%");
271     result |= test(__LINE__, "4294967295", "%u", -1);
272 #ifdef TINY_STDIO
273     result |= test(__LINE__, "%w", "%w", -1);
274 #endif
275     /* 172: excluded for C */
276     /* 173: excluded for C */
277     /* 174: excluded for C */
278 #ifdef TINY_STDIO
279     result |= test(__LINE__, "%H", "%H", -1);
280 #endif
281     result |= test(__LINE__, "%0", "%%0");
282     result |= test(__LINE__, "2345", "%hx", 74565);
283 #ifndef _NANO_FORMATTED_IO
284     result |= test(__LINE__, "61", "%hhx", 'a');
285     result |= test(__LINE__, "61", "%hhx", 'a' + 256);
286 #endif
287     result |= test(__LINE__, "Hallo heimur", "Hallo heimur");
288     result |= test(__LINE__, "Hallo heimur", "%s", "Hallo heimur");
289     result |= test(__LINE__, "1024", "%d", 1024);
290     result |= test(__LINE__, "-1024", "%d", -1024);
291     result |= test(__LINE__, "1024", "%i", 1024);
292     result |= test(__LINE__, "-1024", "%i", -1024);
293     result |= test(__LINE__, "1024", "%u", 1024);
294     result |= test(__LINE__, "4294966272", "%u", 4294966272U);
295     result |= test(__LINE__, "777", "%o", 511);
296     result |= test(__LINE__, "37777777001", "%o", 4294966785U);
297     result |= test(__LINE__, "1234abcd", "%x", 305441741);
298     result |= test(__LINE__, "edcb5433", "%x", 3989525555U);
299     result |= test(__LINE__, "1234ABCD", "%X", 305441741);
300     result |= test(__LINE__, "EDCB5433", "%X", 3989525555U);
301 #ifdef BINARY_FORMAT
302     result |= test(__LINE__, "10010001101001010101111001101", "%b", 305441741);
303     result |= test(__LINE__, "11101101110010110101010000110011", "%b", 3989525555U);
304     result |= test(__LINE__, "10010001101001010101111001101", "%B", 305441741);
305     result |= test(__LINE__, "11101101110010110101010000110011", "%B", 3989525555U);
306 #endif
307     result |= test(__LINE__, "x", "%c", 'x');
308     result |= test(__LINE__, "%", "%%");
309     result |= test(__LINE__, "Hallo heimur", "%+s", "Hallo heimur");
310     result |= test(__LINE__, "+1024", "%+d", 1024);
311     result |= test(__LINE__, "-1024", "%+d", -1024);
312     result |= test(__LINE__, "+1024", "%+i", 1024);
313     result |= test(__LINE__, "-1024", "%+i", -1024);
314     result |= test(__LINE__, "1024", "%+u", 1024);
315     result |= test(__LINE__, "4294966272", "%+u", 4294966272U);
316     result |= test(__LINE__, "777", "%+o", 511);
317     result |= test(__LINE__, "37777777001", "%+o", 4294966785U);
318     result |= test(__LINE__, "1234abcd", "%+x", 305441741);
319     result |= test(__LINE__, "edcb5433", "%+x", 3989525555U);
320     result |= test(__LINE__, "1234ABCD", "%+X", 305441741);
321     result |= test(__LINE__, "EDCB5433", "%+X", 3989525555U);
322     result |= test(__LINE__, "x", "%+c", 'x');
323     result |= test(__LINE__, "Hallo heimur", "% s", "Hallo heimur");
324     result |= test(__LINE__, " 1024", "% d", 1024);
325     result |= test(__LINE__, "-1024", "% d", -1024);
326     result |= test(__LINE__, " 1024", "% i", 1024);
327     result |= test(__LINE__, "-1024", "% i", -1024);
328     result |= test(__LINE__, "1024", "% u", 1024);
329     result |= test(__LINE__, "4294966272", "% u", 4294966272U);
330     result |= test(__LINE__, "777", "% o", 511);
331     result |= test(__LINE__, "37777777001", "% o", 4294966785U);
332     result |= test(__LINE__, "1234abcd", "% x", 305441741);
333     result |= test(__LINE__, "edcb5433", "% x", 3989525555U);
334     result |= test(__LINE__, "1234ABCD", "% X", 305441741);
335     result |= test(__LINE__, "EDCB5433", "% X", 3989525555U);
336     result |= test(__LINE__, "x", "% c", 'x');
337     result |= test(__LINE__, "Hallo heimur", "%+ s", "Hallo heimur");
338     result |= test(__LINE__, "+1024", "%+ d", 1024);
339     result |= test(__LINE__, "-1024", "%+ d", -1024);
340     result |= test(__LINE__, "+1024", "%+ i", 1024);
341     result |= test(__LINE__, "-1024", "%+ i", -1024);
342     result |= test(__LINE__, "1024", "%+ u", 1024);
343     result |= test(__LINE__, "4294966272", "%+ u", 4294966272U);
344     result |= test(__LINE__, "777", "%+ o", 511);
345     result |= test(__LINE__, "37777777001", "%+ o", 4294966785U);
346     result |= test(__LINE__, "1234abcd", "%+ x", 305441741);
347     result |= test(__LINE__, "edcb5433", "%+ x", 3989525555U);
348     result |= test(__LINE__, "1234ABCD", "%+ X", 305441741);
349     result |= test(__LINE__, "EDCB5433", "%+ X", 3989525555U);
350     result |= test(__LINE__, "x", "%+ c", 'x');
351     result |= test(__LINE__, "0777", "%#o", 511);
352     result |= test(__LINE__, "037777777001", "%#o", 4294966785U);
353     result |= test(__LINE__, "0x1234abcd", "%#x", 305441741);
354     result |= test(__LINE__, "0xedcb5433", "%#x", 3989525555U);
355     result |= test(__LINE__, "0X1234ABCD", "%#X", 305441741);
356     result |= test(__LINE__, "0XEDCB5433", "%#X", 3989525555U);
357 #ifdef BINARY_FORMAT
358     result |= test(__LINE__, "0b10010001101001010101111001101", "%#b", 305441741);
359     result |= test(__LINE__, "0b11101101110010110101010000110011", "%#b", 3989525555U);
360     result |= test(__LINE__, "0B10010001101001010101111001101", "%#B", 305441741);
361     result |= test(__LINE__, "0B11101101110010110101010000110011", "%#B", 3989525555U);
362 #endif
363     result |= test(__LINE__, "0", "%#o", 0U);
364     result |= test(__LINE__, "0", "%#x", 0U);
365     result |= test(__LINE__, "0", "%#X", 0U);
366     result |= test(__LINE__, "Hallo heimur", "%1s", "Hallo heimur");
367     result |= test(__LINE__, "1024", "%1d", 1024);
368     result |= test(__LINE__, "-1024", "%1d", -1024);
369     result |= test(__LINE__, "1024", "%1i", 1024);
370     result |= test(__LINE__, "-1024", "%1i", -1024);
371     result |= test(__LINE__, "1024", "%1u", 1024);
372     result |= test(__LINE__, "4294966272", "%1u", 4294966272U);
373     result |= test(__LINE__, "777", "%1o", 511);
374     result |= test(__LINE__, "37777777001", "%1o", 4294966785U);
375     result |= test(__LINE__, "1234abcd", "%1x", 305441741);
376     result |= test(__LINE__, "edcb5433", "%1x", 3989525555U);
377     result |= test(__LINE__, "1234ABCD", "%1X", 305441741);
378     result |= test(__LINE__, "EDCB5433", "%1X", 3989525555U);
379     result |= test(__LINE__, "x", "%1c", 'x');
380     result |= test(__LINE__, "               Hallo", "%20s", "Hallo");
381     result |= test(__LINE__, "                1024", "%20d", 1024);
382     result |= test(__LINE__, "               -1024", "%20d", -1024);
383     result |= test(__LINE__, "                1024", "%20i", 1024);
384     result |= test(__LINE__, "               -1024", "%20i", -1024);
385     result |= test(__LINE__, "                1024", "%20u", 1024);
386     result |= test(__LINE__, "          4294966272", "%20u", 4294966272U);
387     result |= test(__LINE__, "                 777", "%20o", 511);
388     result |= test(__LINE__, "         37777777001", "%20o", 4294966785U);
389     result |= test(__LINE__, "            1234abcd", "%20x", 305441741);
390     result |= test(__LINE__, "            edcb5433", "%20x", 3989525555U);
391     result |= test(__LINE__, "            1234ABCD", "%20X", 305441741);
392     result |= test(__LINE__, "            EDCB5433", "%20X", 3989525555U);
393     result |= test(__LINE__, "                   x", "%20c", 'x');
394     result |= test(__LINE__, "Hallo               ", "%-20s", "Hallo");
395     result |= test(__LINE__, "1024                ", "%-20d", 1024);
396     result |= test(__LINE__, "-1024               ", "%-20d", -1024);
397     result |= test(__LINE__, "1024                ", "%-20i", 1024);
398     result |= test(__LINE__, "-1024               ", "%-20i", -1024);
399     result |= test(__LINE__, "1024                ", "%-20u", 1024);
400     result |= test(__LINE__, "4294966272          ", "%-20u", 4294966272U);
401     result |= test(__LINE__, "777                 ", "%-20o", 511);
402     result |= test(__LINE__, "37777777001         ", "%-20o", 4294966785U);
403     result |= test(__LINE__, "1234abcd            ", "%-20x", 305441741);
404     result |= test(__LINE__, "edcb5433            ", "%-20x", 3989525555U);
405     result |= test(__LINE__, "1234ABCD            ", "%-20X", 305441741);
406     result |= test(__LINE__, "EDCB5433            ", "%-20X", 3989525555U);
407     result |= test(__LINE__, "x                   ", "%-20c", 'x');
408     result |= test(__LINE__, "00000000000000001024", "%020d", 1024);
409     result |= test(__LINE__, "-0000000000000001024", "%020d", -1024);
410     result |= test(__LINE__, "00000000000000001024", "%020i", 1024);
411     result |= test(__LINE__, "-0000000000000001024", "%020i", -1024);
412     result |= test(__LINE__, "00000000000000001024", "%020u", 1024);
413     result |= test(__LINE__, "00000000004294966272", "%020u", 4294966272U);
414     result |= test(__LINE__, "00000000000000000777", "%020o", 511);
415     result |= test(__LINE__, "00000000037777777001", "%020o", 4294966785U);
416     result |= test(__LINE__, "0000000000001234abcd", "%020x", 305441741);
417     result |= test(__LINE__, "000000000000edcb5433", "%020x", 3989525555U);
418     result |= test(__LINE__, "0000000000001234ABCD", "%020X", 305441741);
419     result |= test(__LINE__, "000000000000EDCB5433", "%020X", 3989525555U);
420     result |= test(__LINE__, "                0777", "%#20o", 511);
421     result |= test(__LINE__, "        037777777001", "%#20o", 4294966785U);
422     result |= test(__LINE__, "          0x1234abcd", "%#20x", 305441741);
423     result |= test(__LINE__, "          0xedcb5433", "%#20x", 3989525555U);
424     result |= test(__LINE__, "          0X1234ABCD", "%#20X", 305441741);
425     result |= test(__LINE__, "          0XEDCB5433", "%#20X", 3989525555U);
426     result |= test(__LINE__, "00000000000000000777", "%#020o", 511);
427     result |= test(__LINE__, "00000000037777777001", "%#020o", 4294966785U);
428     result |= test(__LINE__, "0x00000000001234abcd", "%#020x", 305441741);
429     result |= test(__LINE__, "0x0000000000edcb5433", "%#020x", 3989525555U);
430     result |= test(__LINE__, "0X00000000001234ABCD", "%#020X", 305441741);
431     result |= test(__LINE__, "0X0000000000EDCB5433", "%#020X", 3989525555U);
432     result |= test(__LINE__, "Hallo               ", "%0-20s", "Hallo");
433     result |= test(__LINE__, "1024                ", "%0-20d", 1024);
434     result |= test(__LINE__, "-1024               ", "%0-20d", -1024);
435     result |= test(__LINE__, "1024                ", "%0-20i", 1024);
436     result |= test(__LINE__, "-1024               ", "%0-20i", -1024);
437     result |= test(__LINE__, "1024                ", "%0-20u", 1024);
438     result |= test(__LINE__, "4294966272          ", "%0-20u", 4294966272U);
439     result |= test(__LINE__, "777                 ", "%-020o", 511);
440     result |= test(__LINE__, "37777777001         ", "%-020o", 4294966785U);
441     result |= test(__LINE__, "1234abcd            ", "%-020x", 305441741);
442     result |= test(__LINE__, "edcb5433            ", "%-020x", 3989525555U);
443     result |= test(__LINE__, "1234ABCD            ", "%-020X", 305441741);
444     result |= test(__LINE__, "EDCB5433            ", "%-020X", 3989525555U);
445     result |= test(__LINE__, "x                   ", "%-020c", 'x');
446     result |= test(__LINE__, "               Hallo", "%*s", 20, "Hallo");
447     result |= test(__LINE__, "                1024", "%*d", 20, 1024);
448     result |= test(__LINE__, "               -1024", "%*d", 20, -1024);
449     result |= test(__LINE__, "                1024", "%*i", 20, 1024);
450     result |= test(__LINE__, "               -1024", "%*i", 20, -1024);
451     result |= test(__LINE__, "                1024", "%*u", 20, 1024);
452     result |= test(__LINE__, "          4294966272", "%*u", 20, 4294966272U);
453     result |= test(__LINE__, "                 777", "%*o", 20, 511);
454     result |= test(__LINE__, "         37777777001", "%*o", 20, 4294966785U);
455     result |= test(__LINE__, "            1234abcd", "%*x", 20, 305441741);
456     result |= test(__LINE__, "            edcb5433", "%*x", 20, 3989525555U);
457     result |= test(__LINE__, "            1234ABCD", "%*X", 20, 305441741);
458     result |= test(__LINE__, "            EDCB5433", "%*X", 20, 3989525555U);
459     result |= test(__LINE__, "                   x", "%*c", 20, 'x');
460     result |= test(__LINE__, "Hallo heimur", "%.20s", "Hallo heimur");
461     result |= test(__LINE__, "00000000000000001024", "%.20d", 1024);
462     result |= test(__LINE__, "-00000000000000001024", "%.20d", -1024);
463     result |= test(__LINE__, "00000000000000001024", "%.20i", 1024);
464     result |= test(__LINE__, "-00000000000000001024", "%.20i", -1024);
465     result |= test(__LINE__, "00000000000000001024", "%.20u", 1024);
466     result |= test(__LINE__, "00000000004294966272", "%.20u", 4294966272U);
467     result |= test(__LINE__, "00000000000000000777", "%.20o", 511);
468     result |= test(__LINE__, "00000000037777777001", "%.20o", 4294966785U);
469     result |= test(__LINE__, "0000000000001234abcd", "%.20x", 305441741);
470     result |= test(__LINE__, "000000000000edcb5433", "%.20x", 3989525555U);
471     result |= test(__LINE__, "0000000000001234ABCD", "%.20X", 305441741);
472     result |= test(__LINE__, "000000000000EDCB5433", "%.20X", 3989525555U);
473     result |= test(__LINE__, "               Hallo", "%20.5s", "Hallo heimur");
474     result |= test(__LINE__, "               01024", "%20.5d", 1024);
475     result |= test(__LINE__, "              -01024", "%20.5d", -1024);
476     result |= test(__LINE__, "               01024", "%20.5i", 1024);
477     result |= test(__LINE__, "              -01024", "%20.5i", -1024);
478     result |= test(__LINE__, "               01024", "%20.5u", 1024);
479     result |= test(__LINE__, "          4294966272", "%20.5u", 4294966272U);
480     result |= test(__LINE__, "               00777", "%20.5o", 511);
481     result |= test(__LINE__, "         37777777001", "%20.5o", 4294966785U);
482     result |= test(__LINE__, "            1234abcd", "%20.5x", 305441741);
483     result |= test(__LINE__, "          00edcb5433", "%20.10x", 3989525555U);
484     result |= test(__LINE__, "            1234ABCD", "%20.5X", 305441741);
485     result |= test(__LINE__, "          00EDCB5433", "%20.10X", 3989525555U);
486     result |= test(__LINE__, "               01024", "%020.5d", 1024);
487     result |= test(__LINE__, "              -01024", "%020.5d", -1024);
488     result |= test(__LINE__, "               01024", "%020.5i", 1024);
489     result |= test(__LINE__, "              -01024", "%020.5i", -1024);
490     result |= test(__LINE__, "               01024", "%020.5u", 1024);
491     result |= test(__LINE__, "          4294966272", "%020.5u", 4294966272U);
492     result |= test(__LINE__, "               00777", "%020.5o", 511);
493     result |= test(__LINE__, "         37777777001", "%020.5o", 4294966785U);
494     result |= test(__LINE__, "            1234abcd", "%020.5x", 305441741);
495     result |= test(__LINE__, "          00edcb5433", "%020.10x", 3989525555U);
496     result |= test(__LINE__, "            1234ABCD", "%020.5X", 305441741);
497     result |= test(__LINE__, "          00EDCB5433", "%020.10X", 3989525555U);
498     result |= test(__LINE__, "", "%.0s", "Hallo heimur");
499     result |= test(__LINE__, "                    ", "%20.0s", "Hallo heimur");
500     result |= test(__LINE__, "", "%.s", "Hallo heimur");
501     result |= test(__LINE__, "                    ", "%20.s", "Hallo heimur");
502     result |= test(__LINE__, "                1024", "%20.0d", 1024);
503     result |= test(__LINE__, "               -1024", "%20.d", -1024);
504     result |= test(__LINE__, "                    ", "%20.d", 0);
505     result |= test(__LINE__, "                1024", "%20.0i", 1024);
506     result |= test(__LINE__, "               -1024", "%20.i", -1024);
507     result |= test(__LINE__, "                    ", "%20.i", 0);
508     result |= test(__LINE__, "                1024", "%20.u", 1024);
509     result |= test(__LINE__, "          4294966272", "%20.0u", 4294966272U);
510     result |= test(__LINE__, "                    ", "%20.u", 0U);
511     result |= test(__LINE__, "                 777", "%20.o", 511);
512     result |= test(__LINE__, "         37777777001", "%20.0o", 4294966785U);
513     result |= test(__LINE__, "                    ", "%20.o", 0U);
514     result |= test(__LINE__, "            1234abcd", "%20.x", 305441741);
515     result |= test(__LINE__, "            edcb5433", "%20.0x", 3989525555U);
516     result |= test(__LINE__, "                    ", "%20.x", 0U);
517     result |= test(__LINE__, "            1234ABCD", "%20.X", 305441741);
518     result |= test(__LINE__, "            EDCB5433", "%20.0X", 3989525555U);
519     result |= test(__LINE__, "                    ", "%20.X", 0U);
520     result |= test(__LINE__, "Hallo               ", "% -0+*.*s", 20, 5, "Hallo heimur");
521     result |= test(__LINE__, "+01024              ", "% -0+*.*d", 20, 5, 1024);
522     result |= test(__LINE__, "-01024              ", "% -0+*.*d", 20, 5, -1024);
523     result |= test(__LINE__, "+01024              ", "% -0+*.*i", 20, 5, 1024);
524     result |= test(__LINE__, "-01024              ", "% 0-+*.*i", 20, 5, -1024);
525     result |= test(__LINE__, "01024               ", "% 0-+*.*u", 20, 5, 1024);
526     result |= test(__LINE__, "4294966272          ", "% 0-+*.*u", 20, 5, 4294966272U);
527     result |= test(__LINE__, "00777               ", "%+ -0*.*o", 20, 5, 511);
528     result |= test(__LINE__, "37777777001         ", "%+ -0*.*o", 20, 5, 4294966785U);
529     result |= test(__LINE__, "1234abcd            ", "%+ -0*.*x", 20, 5, 305441741);
530     result |= test(__LINE__, "00edcb5433          ", "%+ -0*.*x", 20, 10, 3989525555U);
531     result |= test(__LINE__, "1234ABCD            ", "% -+0*.*X", 20, 5, 305441741);
532     result |= test(__LINE__, "00EDCB5433          ", "% -+0*.*X", 20, 10, 3989525555U);
533     result |= test(__LINE__, "hi x", "%*sx", -3, "hi");
534 #ifndef NO_FLOAT
535     result |= test(__LINE__, "1.000e-38", "%.3e", 1e-38);
536 #ifndef LOW_FLOAT
537     result |= test(__LINE__, "1.000e-308", "%.3e", 1e-308);
538 #endif
539 #endif
540 #ifndef _NANO_FORMATTED_IO
541     result |= test(__LINE__, "1, 1", "%-*.llu, %-*.llu",1,(int64_t)1,1,(int64_t)1);
542 #endif
543 #ifndef NO_FLOAT
544     result |= test(__LINE__, "1e-09", "%g", 0.000000001);
545     result |= test(__LINE__, "1e-08", "%g", 0.00000001);
546     result |= test(__LINE__, "1e-07", "%g", 0.0000001);
547     result |= test(__LINE__, "1e-06", "%g", 0.000001);
548     result |= test(__LINE__, "0.0001", "%g", 0.0001);
549     result |= test(__LINE__, "0.001", "%g", 0.001);
550     result |= test(__LINE__, "0.01", "%g", 0.01);
551     result |= test(__LINE__, "0.1", "%g", 0.1);
552     result |= test(__LINE__, "1", "%g", 1.0);
553     result |= test(__LINE__, "10", "%g", 10.0);
554     result |= test(__LINE__, "100", "%g", 100.0);
555     result |= test(__LINE__, "1000", "%g", 1000.0);
556     result |= test(__LINE__, "10000", "%g", 10000.0);
557     result |= test(__LINE__, "100000", "%g", 100000.0);
558     result |= test(__LINE__, "1e+06", "%g", 1000000.0);
559     result |= test(__LINE__, "1e+07", "%g", 10000000.0);
560     result |= test(__LINE__, "1e+08", "%g", 100000000.0);
561     result |= test(__LINE__, "10.0000", "%#.6g", 10.0);
562     result |= test(__LINE__, "10", "%.6g", 10.0);
563     result |= test(__LINE__, "10.00000000000000000000", "%#.22g", 10.0);
564 #endif
565 
566     // Regression test for wrong behavior with negative precision in tinystdio
567     // this might fail for configurations not using tinystdio, so for a first
568     // PR, only run these test for tinystdio.
569     result |= test(__LINE__,         "", "%.*s",  0, "123456");
570     result |= test(__LINE__,     "1234", "%.*s",  4, "123456");
571     result |= test(__LINE__,   "123456", "%.*s", -4, "123456");
572     result |= test(__LINE__,       "42", "%.*d",  0, 42);
573     result |= test(__LINE__,   "000042", "%.*d",  6, 42);
574     result |= test(__LINE__,       "42", "%.*d", -6, 42);
575 #ifndef NO_FLOAT
576     result |= test(__LINE__,        "0", "%.*f",  0, 0.123);
577     result |= test(__LINE__,      "0.1", "%.*f",  1, 0.123);
578     result |= test(__LINE__, "0.123000", "%.*f", -1, 0.123);
579 #endif
580 #ifdef _WANT_IO_C99_FORMATS
581 {
582     char c[64];
583 #ifndef _WANT_IO_LONG_LONG
584     if (sizeof (intmax_t) <= sizeof(long))
585 #endif
586 #ifndef _NANO_FORMATTED_IO
587     result |= test(__LINE__, "  42", "%4jd", (intmax_t)42L);
588     result |= test(__LINE__, "64", "%zu", sizeof c);
589     result |= test(__LINE__, "12", "%td", (c+12) - c);
590 #else
591     (void) c;
592 #endif
593 #ifndef NO_FLOAT
594     result |= test(__LINE__, "0x1p+0", "%a", 0x1p+0);
595     result |= test(__LINE__, "0x0p+0", "%a", 0.0);
596     result |= test(__LINE__, "-0x0p+0", "%a", -0.0);
597     result |= test(__LINE__, "0x1.9p+4", "%.1a", 0x1.89p+4);
598     result |= test(__LINE__, "0x1.8p+4", "%.1a", 0x1.88p+4);
599     result |= test(__LINE__, "0x1.8p+4", "%.1a", 0x1.78p+4);
600     result |= test(__LINE__, "0x1.7p+4", "%.1a", 0x1.77p+4);
601     result |= test(__LINE__, "0x1.fffffep+126", "%a", (double) 0x1.fffffep+126f);
602     result |= test(__LINE__, "0x1.234564p-126", "%a", (double) 0x1.234564p-126f);
603     result |= test(__LINE__, "0x1.234566p-126", "%a", (double) 0x1.234566p-126f);
604     result |= test(__LINE__, "0X1.FFFFFEP+126", "%A", (double) 0x1.fffffep+126f);
605     result |= test(__LINE__, "0X1.234564P-126", "%A", (double) 0x1.234564p-126f);
606     result |= test(__LINE__, "0X1.234566P-126", "%A", (double) 0x1.234566p-126f);
607     result |= test(__LINE__, "0x1.6p+1", "%.1a", (double) 0x1.6789ap+1f);
608     result |= test(__LINE__, "0x1.68p+1", "%.2a", (double) 0x1.6789ap+1f);
609     result |= test(__LINE__, "0x1.679p+1", "%.3a", (double) 0x1.6789ap+1f);
610     result |= test(__LINE__, "0x1.678ap+1", "%.4a", (double) 0x1.6789ap+1f);
611     result |= test(__LINE__, "0x1.6789ap+1", "%.5a", (double) 0x1.6789ap+1f);
612     result |= test(__LINE__, "0x1.6789a0p+1", "%.6a", (double) 0x1.6789ap+1f);
613     result |= test(__LINE__, "0x1.ffp+1", "%.2a", (double) 0x1.ffp+1f);
614     result |= test(__LINE__, "0x2.0p+1", "%.1a", (double) 0x1.ffp+1f);
615     result |= test(__LINE__, "nan", "%a", (double) NAN);
616     result |= test(__LINE__, "inf", "%a", (double) INFINITY);
617     result |= test(__LINE__, "-inf", "%a", (double) -INFINITY);
618     result |= test(__LINE__, "NAN", "%A", (double) NAN);
619     result |= test(__LINE__, "INF", "%A", (double) INFINITY);
620     result |= test(__LINE__, "-INF", "%A", (double) -INFINITY);
621 #ifdef LOW_FLOAT
622     result |= test(__LINE__, "0x0.000002p-126", "%a", 0x1p-149);
623 #else
624 #ifdef NORMALIZED_A
625     /* newlib legacy stdio normalizes %a format */
626     result |= test(__LINE__, "0x1p-1074", "%a", 0x1p-1074);
627 #else
628     /* glibc and picolibc show denorms like this */
629     result |= test(__LINE__, "0x0.0000000000001p-1022", "%a", 0x1p-1074);
630 #endif
631     result |= test(__LINE__, "0x1.fffffffffffffp+1022", "%a", 0x1.fffffffffffffp+1022);
632     result |= test(__LINE__, "0x1.23456789abcdep-1022", "%a", 0x1.23456789abcdep-1022);
633     result |= test(__LINE__, "0x1.23456789abcdfp-1022", "%a", 0x1.23456789abcdfp-1022);
634     result |= test(__LINE__, "0X1.FFFFFFFFFFFFFP+1022", "%A", 0x1.fffffffffffffp+1022);
635     result |= test(__LINE__, "0X1.23456789ABCDEP-1022", "%A", 0x1.23456789abcdep-1022);
636     result |= test(__LINE__, "0X1.23456789ABCDFP-1022", "%A", 0x1.23456789abcdfp-1022);
637 #endif
638 #endif
639     /* test %ls for wchar_t string */
640     result |= testw(__LINE__, L"foo", L"%.3ls", L"foobar");
641     /* test %s for mbchar string */
642     result |= testw(__LINE__, L"foo", L"%.3s", "foobar");
643 
644     wchar_t wc = 0x1234;
645 
646     /* test %lc for wchar_t */
647     wchar_t wb[2] = { 0x1234, 0 };
648     result |= testw(__LINE__, wb, L"%lc", wc);
649 
650     /* make sure %c truncates to char */
651     wb[0] = 0x34;
652     result |= testw(__LINE__, wb, L"%c", wc);
653 }
654 #endif
655