blob: 1eca8185ca0d9f27a147209778722ee9413b3b80 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#include <stdio.h>
2
3
4
5int
6main (void)
7{
8 int res = 0;
9 char buf[100];
10
11#define TEST(nr, result, format, args...) \
12 if (sprintf (buf, format, ## args) != result) \
13 { \
14 printf ("test %d failed (\"%s\", %d)\n", nr, buf, result); \
15 res = 1; \
16 }
17
18 TEST (1, 2, "%d", -1);
19 TEST (2, 2, "% 2d", 1);
20 TEST (3, 3, "%#x", 1);
21 TEST (4, 2, "%+d", 1);
22 TEST (5, 2, "% d", 1);
23 TEST (6, 2, "%-d", -1);
24 TEST (7, 2, "%- 2d", 1);
25 TEST (8, 3, "%-#x", 1);
26 TEST (9, 2, "%-+d", 1);
27 TEST (10, 2, "%- d", 1);
28
29 return res;
30}