1 /* -*-comment-start: "//";comment-end:""-*-
2 * Mes --- Maxwell Equations of Software
3 * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
5 * This file is part of Mes.
7 * Mes is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or (at
10 * your option) any later version.
12 * Mes is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Mes. If not, see <http://www.gnu.org/licenses/>.
35 sprintf (buf, "c=%c\n", c);
36 if (strcmp (buf, "c=m\n"))
39 if (i != 3) return 15;
41 sprintf (buf, "i=%d\n", i);
42 if (strcmp (buf, "i=3\n"))
46 sprintf (buf, "s=%s\n", s);
47 if (strcmp (buf, "s=mes\n"))
50 sprintf (buf, ">%3d<", 11);
51 eputs (buf); eputs ("\n");
52 if (strcmp (buf, "> 11<"))
55 sprintf (buf, ">%03d<", 22);
56 eputs (buf); eputs ("\n");
57 if (strcmp (buf, ">022<"))
60 sprintf (buf, ">%-10d<", 33);
61 eputs (buf); eputs ("\n");
62 if (strcmp (buf, ">33 <"))
65 sprintf (buf, ">%0d<", 44);
66 eputs (buf); eputs ("\n");
67 if (strcmp (buf, ">44<"))
70 printf (">>%.*s<<\n", 5, "hello, world");
71 printf (">>%.*s<<\n", 20, "hello, world");
73 printf (">>%.*s<<\n", 10, "foo");
74 printf (">>%*s<<\n", 10, "bar");
75 printf (">>%-*s<<\n", 10, "baz");
77 sprintf (buf, "%ld", 42);
78 eputs ("buf="); eputs (buf); eputs ("\n");
79 if (strcmp (buf, "42"))
82 sprintf (buf, "%u", -1);
83 eputs ("buf="); eputs (buf); eputs ("\n");
84 if (strcmp (buf, "4294967295"))
87 sprintf (buf, ">>%.5s<<\n", "hello, world");
88 eputs ("buf="); eputs (buf);
89 if (strcmp (buf, ">>hello<<\n"))
92 sprintf (buf, ">>%.*s<<\n", 5, "hello, world");
93 eputs ("buf="); eputs (buf);
94 if (strcmp (buf, ">>hello<<\n"))
97 sprintf (buf, ">>%.*s<<\n", 20, "hello, world");
98 eputs ("buf="); eputs (buf);
99 if (strcmp (buf, ">>hello, world<<\n"))
102 sprintf (buf, ">>%.*s<<\n", 10, "foo");
103 eputs ("buf="); eputs (buf);
104 if (strcmp (buf, ">>foo<<\n"))
107 sprintf (buf, ">>%*s<<\n", 10, "bar");
108 eputs ("buf="); eputs (buf);
109 if (strcmp (buf, ">> bar<<\n"))
112 sprintf (buf, ">>%-*s<<\n", 10, "baz");
113 eputs ("buf="); eputs (buf);
114 if (strcmp (buf, ">>baz <<\n"))
117 sprintf (buf, ">>%ld<<\n", 12);
118 eputs ("buf="); eputs (buf);
119 if (strcmp (buf, ">>12<<\n"))
122 sprintf (buf, ">>%o<<\n", 12);
123 eputs ("buf="); eputs (buf);
124 if (strcmp (buf, ">>14<<\n"))
127 sprintf (buf, ">>%x<<\n", 12);
128 eputs ("buf="); eputs (buf);
129 if (strcmp (buf, ">>c<<\n"))
132 sprintf (buf, ">>%X<<\n", 12);
133 eputs ("buf="); eputs (buf);
134 if (strcmp (buf, ">>C<<\n"))
138 fprintf (stderr, "foo bar\n%n", &n);
142 sprintf (buf, "foo%nbar\n", &n);
143 eputs ("buf="); eputs (buf); eputs ("\n");
144 if (strcmp (buf, "foobar\n"))