This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Deprecate above \xFF in bitwise string ops
[perl5.git] / t / op / sprintf.t
1 #!./perl
2
3 # Tests sprintf, excluding handling of 64-bit integers or long
4 # doubles (if supported), of machine-specific short and long
5 # integers, machine-specific floating point exceptions (infinity,
6 # not-a-number ...), of the effects of locale, and of features
7 # specific to multi-byte characters (under the utf8 pragma and such).
8
9 # For tests that do not fit this format, use sprintf2.t.
10
11 BEGIN {
12     chdir 't' if -d 't';
13     require './test.pl';
14     set_up_inc(qw '../lib ../cpan/version/lib');
15 }
16 use warnings;
17 use version;
18 use Config;
19 use strict;
20
21
22 my @tests = ();
23 my ($template, $data, $result, $comment, $w, $x, $evalData, $n, $p);
24
25 my $Is_VMS_VAX = 0;
26 # We use HW_MODEL since ARCH_NAME was not in VMS V5.*
27 if ($^O eq 'VMS') {
28     my $hw_model;
29     chomp($hw_model = `write sys\$output f\$getsyi("HW_MODEL")`);
30     $Is_VMS_VAX = $hw_model < 1024 ? 1 : 0;
31 }
32
33 # No %Config.
34 my $Is_Ultrix_VAX = $^O eq 'ultrix' && `uname -m` =~ /^VAX$/;
35
36 # The most generic VAX catcher.
37 my $Is_VAX_Float = (pack("d", 1) =~ /^[\x80\x10]\x40/);
38
39 our $IS_EBCDIC = $::IS_EBCDIC;  # Solely to avoid the 'used once' warning
40 our $IS_ASCII = $::IS_ASCII;   # Solely to avoid the 'used once' warning
41
42 while (<DATA>) {
43     s/<\s*$//;
44
45     # An initial 'a' or 'e' marks the test as being only for ASCII or EBCDIC
46     # platforms respectively.
47     s/^\s* ( [ae] )? >//x;
48     next if defined $1 && $1 eq 'a' && $::IS_EBCDIC;
49     next if defined $1 && $1 eq 'e' && $::IS_ASCII;
50
51     ($template, $data, $result, $comment) = split(/<\s*>/, $_, 4);
52     if ($^O eq 'os390' || $^O eq 's390') { # non-IEEE (s390 is UTS)
53         $data   =~ s/([eE])96$/${1}63/;      # smaller exponents
54         $result =~ s/([eE]\+)102$/${1}69/;   #  "       "
55         $data   =~ s/([eE])\-101$/${1}-56/;  # larger exponents
56         $result =~ s/([eE])\-102$/${1}-57/;  #  "       "
57     }
58     if ($Is_VMS_VAX || $Is_Ultrix_VAX || $Is_VAX_Float) {
59         # VAX DEC C 5.3 at least since there is no
60         # ccflags =~ /float=ieee/ on VAX.
61         # AXP is unaffected whether or not it is using ieee.
62         $data   =~ s/([eE])96$/${1}26/;      # smaller exponents
63         $result =~ s/([eE]\+)102$/${1}32/;   #  "       "
64         $data   =~ s/([eE])\-101$/${1}-24/;  # larger exponents
65         $result =~ s/([eE])\-102$/${1}-25/;  #  "       "
66     }
67
68     $evalData = eval $data;
69     $evalData = ref $evalData ? $evalData : [$evalData];
70     push @tests, [$template, $evalData, $result, $comment, $data];
71 }
72
73 plan(scalar @tests);
74
75 $SIG{__WARN__} = sub {
76     if ($_[0] =~ /^Invalid conversion/) {
77         $w .= ' INVALID';
78     } elsif ($_[0] =~ /^Use of uninitialized value/) {
79         $w .= ' UNINIT';
80     } elsif ($_[0] =~ /^Missing argument/) {
81         $w .= ' MISSING';
82     } elsif ($_[0] =~ /^Redundant argument/) {
83         $w .= ' REDUNDANT';
84     } elsif ($_[0]=~/^vector argument not supported with alpha versions/) {
85         $w .= ' ALPHA';
86     } else {
87         warn @_;
88     }
89 };
90
91 for (@tests) {
92     ($template, $evalData, $result, $comment, $data) = @$_;
93     $w = undef;
94     $x = sprintf($template, @$evalData);
95     $x = ">$x<" if defined $x;
96     substr($x, -1, 0) = $w if $w;
97     # $x may have 3 exponent digits, not 2
98     my $y = $x;
99     if ($y =~ s/([Ee][-+])0(\d)/$1$2/) {
100         # if result is left-adjusted, append extra space
101         if ($template =~ /%\+?\-/ and $result =~ / $/) {
102             $y =~ s/<$/ </;
103         }
104         # if result is zero-filled, add extra zero
105         elsif ($template =~ /%\+?0/ and $result =~ /^0/) {
106             $y =~ s/^>0/>00/;
107         }
108         # if result is right-adjusted, prepend extra space
109         elsif ($result =~ /^ /) {
110             $y =~ s/^>/> /;
111         }
112     }
113
114     my $skip = 0;
115     if ($comment =~ s/\s+skip:\s*(.*)//) {
116         my $os  = $1;
117         my $osv = exists $Config{osvers} ? $Config{osvers} : "0";
118         my $archname = $Config{archname};
119         # >comment skip: all<
120         # >comment skip: solaris<
121         # >comment skip: x86_64-linux-ld<
122         if ($os =~ /\b(?:all|\Q$^O\E|\Q$archname\E)\b/i) {
123             $skip = 1;
124         } elsif ($os =~ /\b\Q$^O\E(?::(\S+))\b/i) {
125             # We can have the $^O followed by an optional condition.
126             # The condition, if present, can be one of:
127             # (1) starts with a digit...
128             #     the first pair of dot-separated digits is
129             #     tested numerically against $Config{osvers}
130             # (2) otherwise...
131             #     tested as a \b/i regex against $Config{archname}
132             my $cond = $1;
133             if ($cond =~ /^\d/) {
134                 # >comment skip: hpux:10.20<
135                 my $vsn = $cond;
136                 # Only compare on the the first pair of digits, as numeric
137                 # compares do not like 2.6.10-3mdksmp or 2.6.8-24.10-default
138                 s/^(\d+(\.\d+)?).*/$1/ for $osv, $vsn;
139                 $skip = $vsn ? ($osv <= $vsn ? 1 : 0) : 1;
140             } else {
141                 # >comment skip: netbsd:vax-netbsd<
142                 $skip = $archname =~ /\b\Q$cond\E\b/i;
143             }
144         }
145         $skip and $comment =~ s/$/, failure expected on $^O $osv $archname/;
146     }
147
148     if ($x eq ">$result<") {
149         ok(1, join ' ', grep length, ">$result<", $comment);
150     }
151     elsif ($skip) {
152       SKIP: { skip($comment, 1) }
153     }
154     elsif ($y eq ">$result<")   # Some C libraries always give
155     {                           # three-digit exponent
156                 ok(1, ">$result< $x three-digit exponent accepted");
157     }
158         elsif ($result =~ /[-+]\d{3}$/ &&
159                    # Suppress tests with modulo of exponent >= 100 on platforms
160                    # which cannot handle such magnitudes (or where we cannot tell).
161                    ((!eval {require POSIX}) || # Costly: only do this if we must!
162                         (length(&POSIX::DBL_MAX) - rindex(&POSIX::DBL_MAX, '+')) == 3))
163         {
164         ok(1,
165          ">$template< >$data< >$result< Suppressed: exponent out of range?\n");
166         }
167     else {
168         $y = ($x eq $y ? "" : " => $y");
169         ok(0, ">$template< >$data< >$result< $x$y $comment");
170     }
171 }
172
173 # In each of the following lines, there are three required fields:
174 # printf template, data to be formatted (as a Perl expression), and
175 # expected result of formatting.  An optional fourth field can contain
176 # a comment.  Each field is delimited by a starting '>' and a
177 # finishing '<'; any whitespace outside these start and end marks is
178 # not part of the field.  If formatting requires more than one data
179 # item (for example, if variable field widths are used), the Perl data
180 # expression should return a reference to an array having the requisite
181 # number of elements.  Even so, subterfuge is sometimes required: see
182 # tests for %n and %p.
183 #
184 # Tests that are expected to fail on a certain OS can be marked as such
185 # by trailing the comment with a skip: section. Skips are tags separated
186 # by space consisting of a $^O optionally trailed with :osvers or :archname.
187 # In the osvers case, all os-levels below that are expected to fail.
188 # In the archname case, an exact match is expected, unless the archname
189 # begins (and ends) with a "/", in which case a regexp is expected.
190 # A special tag 'all' is allowed for todo tests that should fail on any system
191 #
192 # >%G<   >1234567e96<  >1.23457E+102<   >exponent too big skip: os390<
193 # >%.0g< >-0.0<        >-0<             >No minus skip: MSWin32 VMS hpux:10.20<
194 # >%d<   >4<           >1<              >4 != 1 skip: all<
195 #
196 # The following tests are not currently run, for the reasons stated:
197
198 =pod
199
200 =begin problematic
201
202 >%.0f<      >1.5<         >2<   >Standard vague: no rounding rules<
203 >%.0f<      >2.5<         >2<   >Standard vague: no rounding rules<
204
205 =end problematic
206
207 =cut
208
209 # template    data          result
210 __END__
211 >%6. 6s<    >''<          >%6. 6s INVALID< >(See use of $w in code above)<
212 >%6 .6s<    >''<          >%6 .6s INVALID<
213 >%6.6 s<    >''<          >%6.6 s INVALID<
214 >%A<        >0<           ><     >%A tested in sprintf2.t skip: all<
215 >%B<        >2**32-1<     >11111111111111111111111111111111<
216 >%+B<       >2**32-1<     >11111111111111111111111111111111<
217 >%#B<       >2**32-1<     >0B11111111111111111111111111111111<
218 >%C<        >''<          >%C INVALID<
219 >%D<        >0x7fffffff<  >2147483647<     >Synonym for %ld<
220 >%E<        >123456.789<  >1.234568E+05<   >Like %e, but using upper-case "E"<
221 >%F<        >123456.789<  >123456.789000<  >Synonym for %f<
222 >%G<        >1234567.89<  >1.23457E+06<    >Like %g, but using upper-case "E"<
223 >%G<        >1234567e96<  >1.23457E+102<
224 >%G<        >.1234567e-101< >1.23457E-102<
225 >%G<        >12345.6789<  >12345.7<
226 >%G<        >1234567e96<  >1.23457E+102<        >exponent too big skip: os390<
227 >%G<        >.1234567e-101< >1.23457E-102<      >exponent too small skip: os390<
228 >%H<        >''<          >%H INVALID<
229 >%I<        >''<          >%I INVALID<
230 >%J<        >''<          >%J INVALID<
231 >%K<        >''<          >%K INVALID<
232 >%L<        >''<          >%L INVALID<
233 >%M<        >''<          >%M INVALID<
234 >%N<        >''<          >%N INVALID<
235 >%O<        >2**32-1<     >37777777777<    >Synonym for %lo<
236 >%P<        >''<          >%P INVALID<
237 >%Q<        >''<          >%Q INVALID<
238 >%R<        >''<          >%R INVALID<
239 >%S<        >''<          >%S INVALID<
240 >%T<        >''<          >%T INVALID<
241 >%U<        >2**32-1<     >4294967295<     >Synonym for %lu<
242 >%V<        >''<          >%V INVALID<
243 >%W<        >''<          >%W INVALID<
244 >%X<        >2**32-1<     >FFFFFFFF<       >Like %x, but with u/c letters<
245 >%#X<       >2**32-1<     >0XFFFFFFFF<
246 >%Y<        >''<          >%Y INVALID<
247 >%Z<        >''<          >%Z INVALID<
248 >%a<        >0<           ><     >%a tested in sprintf2.t skip: all<
249 >%b<        >2**32-1<     >11111111111111111111111111111111<
250 >%+b<       >2**32-1<     >11111111111111111111111111111111<
251 >%#b<       >2**32-1<     >0b11111111111111111111111111111111<
252 >%34b<      >2**32-1<     >  11111111111111111111111111111111<
253 >%034b<     >2**32-1<     >0011111111111111111111111111111111<
254 >%-34b<     >2**32-1<     >11111111111111111111111111111111  <
255 >%-034b<    >2**32-1<     >11111111111111111111111111111111  <
256 >%6b<       >12<          >  1100<
257 >%6.5b<     >12<          > 01100<
258 >%-6.5b<    >12<          >01100 <
259 >%+6.5b<    >12<          > 01100<
260 >% 6.5b<    >12<          > 01100<
261 >%06.5b<    >12<          > 01100<         >0 flag with precision: no effect<
262 >%.5b<      >12<          >01100<
263 >%.0b<      >0<           ><
264 >%+.0b<     >0<           ><
265 >% .0b<     >0<           ><
266 >%-.0b<     >0<           ><
267 >%#.0b<     >0<           ><
268 >%#3.0b<    >0<           >   <
269 >%#3.1b<    >0<           >  0<
270 >%#3.2b<    >0<           > 00<
271 >%#3.3b<    >0<           >000<
272 >%#3.4b<    >0<           >0000<
273 >%.0b<      >1<           >1<
274 >%+.0b<     >1<           >1<
275 >% .0b<     >1<           >1<
276 >%-.0b<     >1<           >1<
277 >%#.0b<     >1<           >0b1<
278 >%#3.0b<    >1<           >0b1<
279 >%#3.1b<    >1<           >0b1<
280 >%#3.2b<    >1<           >0b01<
281 >%#3.3b<    >1<           >0b001<
282 >%#3.4b<    >1<           >0b0001<
283 >%c<        >ord('A')<    >A<
284 >%10c<      >ord('A')<    >         A<
285 >%#10c<     >ord('A')<    >         A<     ># modifier: no effect<
286 >%010c<     >ord('A')<    >000000000A<
287 >%10lc<     >ord('A')<    >         A<     >l modifier: no effect<
288 >%10hc<     >ord('A')<    >         A<     >h modifier: no effect<
289 >%10.5c<    >ord('A')<    >         A<     >precision: no effect<
290 >%-10c<     >ord('A')<    >A         <
291 >%d<        >123456.789<  >123456<
292 >%d<        >-123456.789< >-123456<
293 >%d<        >0<           >0<
294 >%-d<       >0<           >0<
295 >%+d<       >0<           >+0<
296 >% d<       >0<           > 0<
297 >%0d<       >0<           >0<
298 >%-3d<      >1<           >1  <
299 >%+3d<      >1<           > +1<
300 >% 3d<      >1<           >  1<
301 >%03d<      >1<           >001<
302 >%+ 3d<     >1<           > +1<
303 >% +3d<     >1<           > +1<
304 >%.0d<      >0<           ><
305 >%+.0d<     >0<           >+<
306 >% .0d<     >0<           > <
307 >%-.0d<     >0<           ><
308 >%#.0d<     >0<           ><
309 >%.0d<      >1<           >1<
310 >%d<        >1<           >1<
311 >%+d<       >1<           >+1<
312 >%#3.2d<    >1<           > 01<            ># modifier: no effect<
313 >%3.2d<     >1<           > 01<
314 >%03.2d<    >1<           > 01<            >0 flag with precision: no effect<
315 >%-3.2d<    >1<           >01 <
316 >%+3.2d<    >1<           >+01<
317 >% 3.2d<    >1<           > 01<
318 >%-03.2d<   >1<           >01 <            >zero pad + left just.: no effect<
319 >%3.*d<     >[2,1]<       > 01<
320 >%3.*d<     >[1,1]<       >  1<
321 >%3.*d<     >[0,1]<       >  1<
322 >%3.*d<     >[-1,1]<      >  1<
323 >%.*d<      >[0,0]<       ><
324 >%-.*d<     >[0,0]<       ><
325 >%+.*d<     >[0,0]<       >+<
326 >% .*d<     >[0,0]<       > <
327 >%0.*d<     >[0,0]<       ><
328 >%.*d<      >[-2,0]<      >0<
329 >%-.*d<     >[-2,0]<      >0<
330 >%+.*d<     >[-2,0]<      >+0<
331 >% .*d<     >[-2,0]<      > 0<
332 >%0.*d<     >[-2,0]<      >0<
333 >%.*2$d<    >[5,3]<       >005<           >reordered precision arg<
334 >%4.*2$d<   >[5,3]<       > 005<          >width with reordered precision<
335 >%*3$.*2$d< >[5,3,4]<     > 005<          >reordered width with reordered precision<
336 >%3$*2$.*1$d< >[3,4,5]<   > 005<          >reordered param, width, precision<
337 >%*1$.*f<   >[4, 5, 10]<  >5.0000<        >perl #125956: reordered param, width, precision, floating point<
338 >%d<        >-1<          >-1<
339 >%-d<       >-1<          >-1<
340 >%+d<       >-1<          >-1<
341 >% d<       >-1<          >-1<
342 >%-3d<      >-1<          >-1 <
343 >%+3d<      >-1<          > -1<
344 >% 3d<      >-1<          > -1<
345 >%03d<      >-1<          >-01<
346 >%hd<       >1<           >1<              >More extensive testing of<
347 >%hhd<      >1<           >1<              >length modifiers would be<
348 >%ld<       >1<           >1<              >platform-specific<
349 >%Vd<       >1<           >1<
350 >%zd<       >1<           >1<
351 >%td<       >1<           >1<
352 >%vd<       >chr(1)<      >1<
353 >%+vd<      >chr(1)<      >+1<
354 >%#vd<      >chr(1)<      >1<
355 >%vd<       >"\01\02\03"< >1.2.3<
356 >%vd<       >v1.2.3<      >1.2.3<
357 >%vd<       >[version::qv("1.2.3")]< >1.2.3<
358 >%vd<       >[version->new("1.2")]< >1.2<
359 >%vd<       >[version->new("1.02")]< >1.2<
360 >%vd<       >[version->new("1.002")]< >1.2<
361 >%vd<       >[version->new("1048576.5")]< >1048576.5<
362 >%vd<       >[version->new("50")]< >50<
363 >%v.3d<     >"\01\02\03"< >001.002.003<
364 >%0v3d<     >"\01\02\03"< >001.002.003<
365 >%v.3d<     >[version::qv("1.2.3")]< >001.002.003<
366 >%-v3d<     >"\01\02\03"< >1  .2  .3  <
367 >%+-v3d<    >"\01\02\03"< >+1 .2  .3  <
368 >%+-v3d<    >[version::qv("1.2.3")]< >+1 .2  .3  <
369 >%v4.3d<    >"\01\02\03"< > 001. 002. 003<
370 >%0v4.3d<   >"\01\02\03"< > 001. 002. 003<
371 >%0*v2d<    >['-', "\0\7\14"]< >00-07-12<
372 >%v.*d<     >[3, "\01\02\03"]< >001.002.003< >cf perl #83194<
373 >%0v*d<     >[3, "\01\02\03"]< >001.002.003< >cf perl #83194<
374 >%-v*d<     >[3, "\01\02\03"]< >1  .2  .3  < >cf perl #83194<
375 >%+-v*d<    >[3, "\01\02\03"]< >+1 .2  .3  < >cf perl #83194<
376 >%v*.*d<    >[4, 3, "\01\02\03"]< > 001. 002. 003< >cf perl #83194<
377 >%0v*.*d<   >[4, 3, "\01\02\03"]< > 001. 002. 003< >cf perl #83194<
378 >%0*v*d<    >['-', 2, "\0\7\13"]< >00-07-11< >cf perl #83194<
379 >%0*v*d<    >['-', 2, version::qv("0.7.11")]< >00-07-11< >cf perl #83194<
380 >%e<        >1234.875<    >1.234875e+03<
381 >%e<        >0.000012345< >1.234500e-05<
382 >%e<        >1234567E96<  >1.234567e+102<
383 >%e<        >0<           >0.000000e+00<
384 >%e<        >.1234567E-101< >1.234567e-102<
385 >%+e<       >1234.875<    >+1.234875e+03<
386 >%#e<       >1234.875<    >1.234875e+03<
387 >%e<        >-1234.875<   >-1.234875e+03<
388 >%+e<       >-1234.875<   >-1.234875e+03<
389 >%#e<       >-1234.875<   >-1.234875e+03<
390 >%.0e<      >1234.875<    >1e+03<
391 >%#.0e<     >1234.875<    >1.e+03<
392 >%.0e<      >1.875<       >2e+00<
393 >%.0e<      >0.875<       >9e-01<
394 >%.*e<      >[0, 1234.875]< >1e+03<
395 >%.1e<      >1234.875<    >1.2e+03<
396 >%-12.4e<   >1234.875<    >1.2349e+03  <
397 >%12.4e<    >1234.875<    >  1.2349e+03<
398 >%+-12.4e<  >1234.875<    >+1.2349e+03 <
399 >%+12.4e<   >1234.875<    > +1.2349e+03<
400 >%+-12.4e<  >-1234.875<   >-1.2349e+03 <
401 >%+12.4e<   >-1234.875<   > -1.2349e+03<
402 >%e<        >1234567E96<  >1.234567e+102<       >exponent too big skip: os390<
403 >%e<        >.1234567E-101< >1.234567e-102<     >exponent too small skip: os390<
404 >%f<        >1234.875<    >1234.875000<
405 >%+f<       >1234.875<    >+1234.875000<
406 >%#f<       >1234.875<    >1234.875000<
407 >%f<        >-1234.875<   >-1234.875000<
408 >%+f<       >-1234.875<   >-1234.875000<
409 >%#f<       >-1234.875<   >-1234.875000<
410 >%6f<       >1234.875<    >1234.875000<
411 >%*f<       >[6, 1234.875]< >1234.875000<
412 >%.0f<      >-0.1<        >-0<  >C library bug: no minus skip: VMS<
413 >%.0f<      >1234.875<    >1235<
414 >%.1f<      >1234.875<    >1234.9<
415 >%-8.1f<    >1234.875<    >1234.9  <
416 >%8.1f<     >1234.875<    >  1234.9<
417 >%+-8.1f<   >1234.875<    >+1234.9 <
418 >%+8.1f<    >1234.875<    > +1234.9<
419 >%+-8.1f<   >-1234.875<   >-1234.9 <
420 >%+8.1f<    >-1234.875<   > -1234.9<
421 >%*.*f<     >[5, 2, 12.3456]< >12.35<
422 >%f<        >0<           >0.000000<
423 >%.0f<      >[]<          >0 MISSING<
424 > %.0f<     >[]<          > 0 MISSING<
425 >%.2f<      >[]<          >0.00 MISSING<
426 >%.2fC<      >[]<          >0.00C MISSING<
427 >%.0f<      >0<           >0<
428 >%.0f<      >2**38<       >274877906944<   >Should have exact int'l rep'n<
429 >%.0f<      >0.1<         >0<
430 >%.0f<      >0.6<         >1<              >Known to fail with (irix|nonstop-ux); -DHAS_LDBL_SPRINTF_BUG may fix<
431 >%.0f<      >-0.6<        >-1<             >Known to fail with (irix|nonstop-ux); -DHAS_LDBL_SPRINTF_BUG may fix<
432 >%.0f<      >1.6<         >2<
433 >%.0f<      >-1.6<        >-2<
434 >%.0f<      >1<           >1<
435 >%#.0f<     >1<           >1.<
436 >%.0lf<     >1<           >1<              >'l' should have no effect<
437 >%.0hf<     >1<           >%.0hf INVALID<  >'h' should be rejected<
438 >%g<        >12345.6789<  >12345.7<
439 >%+g<       >12345.6789<  >+12345.7<
440 >%#g<       >12345.6789<  >12345.7<
441 >%.0g<      >[]<          >0 MISSING<
442 > %.0g<     >[]<          > 0 MISSING<
443 >%.2g<      >[]<          >0 MISSING<
444 >%.2gC<      >[]<          >0C MISSING<
445 >%.0g<      >-0.0<        >-0<             >C99 standard mandates minus sign but C89 does not skip: MSWin32 VMS netbsd:vax-netbsd hpux:10.20 openbsd netbsd:1.5 irix darwin freebsd:4.9 android<
446 >%.0g<      >12345.6789<  >1e+04<
447 >%#.0g<     >12345.6789<  >1.e+04<
448 >%.2g<      >12345.6789<  >1.2e+04<
449 >%.*g<      >[2, 12345.6789]< >1.2e+04<
450 >%.9g<      >12345.6789<  >12345.6789<
451 >%12.9g<    >12345.6789<  >  12345.6789<
452 >%012.9g<   >12345.6789<  >0012345.6789<
453 >%-12.9g<   >12345.6789<  >12345.6789  <
454 >%*.*g<     >[-12, 9, 12345.6789]< >12345.6789  <
455 >%-012.9g<  >12345.6789<  >12345.6789  <
456 >%g<        >-12345.6789< >-12345.7<
457 >%+g<       >-12345.6789< >-12345.7<
458 >%g<        >1234567.89<  >1.23457e+06<
459 >%+g<       >1234567.89<  >+1.23457e+06<
460 >%#g<       >1234567.89<  >1.23457e+06<
461 >%g<        >-1234567.89< >-1.23457e+06<
462 >%+g<       >-1234567.89< >-1.23457e+06<
463 >%#g<       >-1234567.89< >-1.23457e+06<
464 >%g<        >0.00012345<  >0.00012345<
465 >%g<        >0.000012345< >1.2345e-05<
466 >%g<        >1234567E96<  >1.23457e+102<
467 >%g<        >.1234567E-101< >1.23457e-102<
468 >%g<        >0<           >0<
469 >%13g<      >1234567.89<  >  1.23457e+06<
470 >%+13g<     >1234567.89<  > +1.23457e+06<
471 >%013g<     >1234567.89<  >001.23457e+06<
472 >%-13g<     >1234567.89<  >1.23457e+06  <
473 >%g<        >.1234567E-101< >1.23457e-102<      >exponent too small skip: os390<
474 >%g<        >1234567E96<  >1.23457e+102<        >exponent too big skip: os390<
475 >%h<        >''<          >%h INVALID<
476 >%i<        >123456.789<  >123456<         >Synonym for %d<
477 >%j<        >''<          >%j INVALID<
478 >%k<        >''<          >%k INVALID<
479 >%l<        >''<          >%l INVALID<
480 >%m<        >''<          >%m INVALID<
481 >%s< >sprintf('%%n%n %d', $n, $n)< >%n 2< >Slight sneakiness to test %n<
482 >%s< >$n="abc"; sprintf(' %n%s', substr($n,1,1), $n)< > a1c< >%n w/magic<
483 >%s< >no warnings; sprintf('%s%n', chr(256)x5, $n),$n< >5< >Unicode %n<
484 >%o<        >2**32-1<     >37777777777<
485 >%+o<       >2**32-1<     >37777777777<
486 >%#o<       >2**32-1<     >037777777777<
487 >%o<        >642<         >1202<          >check smaller octals across platforms<
488 >%+o<       >642<         >1202<
489 >% o<       >642<         >1202<
490 >%#o<       >642<         >01202<
491 >%4o<       >18<          >  22<
492 >%4.3o<     >18<          > 022<
493 >%-4.3o<    >18<          >022 <
494 >%+4.3o<    >18<          > 022<
495 >% 4.3o<    >18<          > 022<
496 >%04.3o<    >18<          > 022<          >0 flag with precision: no effect<
497 >%4.o<      >36<          >  44<
498 >%-4.o<     >36<          >44  <
499 >%+4.o<     >36<          >  44<
500 >% 4.o<     >36<          >  44<
501 >%04.o<     >36<          >  44<          >0 flag with precision: no effect<
502 >%.3o<      >18<          >022<
503 >%.0o<      >0<           ><
504 >%+.0o<     >0<           ><
505 >% .0o<     >0<           ><
506 >%-.0o<     >0<           ><
507 >%#.0o<     >0<           >0<
508 >%#3.0o<    >0<           >  0<
509 >%#3.1o<    >0<           >  0<
510 >%#3.2o<    >0<           > 00<
511 >%#3.3o<    >0<           >000<
512 >%#3.4o<    >0<           >0000<
513 >%.0o<      >1<           >1<
514 >%+.0o<     >1<           >1<
515 >% .0o<     >1<           >1<
516 >%-.0o<     >1<           >1<
517 >%#.0o<     >1<           >01<
518 >%#3.0o<    >1<           > 01<
519 >%#3.1o<    >1<           > 01<
520 >%#3.2o<    >1<           > 01<
521 >%#3.3o<    >1<           >001<
522 >%#3.4o<    >1<           >0001<
523 >%#.5o<     >012345<      >012345<
524 >%#.5o<     >012<         >00012<
525 >%#4o<      >17<          > 021<
526 >%#-4o<     >17<          >021 <
527 >%-#4o<     >17<          >021 <
528 >%#+4o<     >17<          > 021<
529 >%# 4o<     >17<          > 021<
530 >%#04o<     >17<          >0021<
531 >%#4.o<     >16<          > 020<
532 >%#-4.o<    >16<          >020 <
533 >%-#4.o<    >16<          >020 <
534 >%#+4.o<    >16<          > 020<
535 >%# 4.o<    >16<          > 020<
536 >%#04.o<    >16<          > 020<          >0 flag with precision: no effect<
537 >%#4.3o<    >18<          > 022<
538 >%#-4.3o<   >18<          >022 <
539 >%-#4.3o<   >18<          >022 <
540 >%#+4.3o<   >18<          > 022<
541 >%# 4.3o<   >18<          > 022<
542 >%#04.3o<   >18<          > 022<          >0 flag with precision: no effect<
543 >%#6.4o<    >18<          >  0022<
544 >%#-6.4o<   >18<          >0022  <
545 >%-#6.4o<   >18<          >0022  <
546 >%#+6.4o<   >18<          >  0022<
547 >%# 6.4o<   >18<          >  0022<
548 >%#06.4o<   >18<          >  0022<        >0 flag with precision: no effect<
549 >%d< >$p=sprintf('%p',$p);$p=~/^[0-9a-f]+$/< >1< >Coarse hack: hex from %p?<
550 >%d< >$p=sprintf('%-8p',$p);$p=~/^[0-9a-f]+\s*$/< >1< >Coarse hack: hex from %p?<
551 >%#p<       >''<          >%#p INVALID<
552 >%q<        >''<          >%q INVALID<
553 >%r<        >''<          >%r INVALID<
554 >%s<        >[]<          > MISSING<
555 > %s<       >[]<          >  MISSING<
556 >%s<        >'string'<    >string<
557 >%10s<      >'string'<    >    string<
558 >%+10s<     >'string'<    >    string<
559 >%#10s<     >'string'<    >    string<
560 >%010s<     >'string'<    >0000string<
561 >%0*s<      >[10, 'string']< >0000string<
562 >%-10s<     >'string'<    >string    <
563 >%3s<       >'string'<    >string<
564 >%.3s<      >'string'<    >str<
565 >%.*s<      >[3, 'string']< >str<
566 >%.*s<      >[2, 'string']< >st<
567 >%.*s<      >[1, 'string']< >s<
568 >%.*s<      >[0, 'string']< ><
569 >%.*s<      >[-1,'string']< >string<  >negative precision to be ignored<
570 >%3.*s<     >[3, 'string']< >str<
571 >%3.*s<     >[2, 'string']< > st<
572 >%3.*s<     >[1, 'string']< >  s<
573 >%3.*s<     >[0, 'string']< >   <
574 >%3.*s<     >[-1,'string']< >string<  >negative precision to be ignored<
575 >%t<        >''<          >%t INVALID<
576 >%u<        >2**32-1<     >4294967295<
577 >%+u<       >2**32-1<     >4294967295<
578 >%#u<       >2**32-1<     >4294967295<
579 >%12u<      >2**32-1<     >  4294967295<
580 >%012u<     >2**32-1<     >004294967295<
581 >%-12u<     >2**32-1<     >4294967295  <
582 >%-012u<    >2**32-1<     >4294967295  <
583 >%4u<       >18<          >  18<
584 >%4.3u<     >18<          > 018<
585 >%-4.3u<    >18<          >018 <
586 >%+4.3u<    >18<          > 018<
587 >% 4.3u<    >18<          > 018<
588 >%04.3u<    >18<          > 018<         >0 flag with precision: no effect<
589 >%.3u<      >18<          >018<
590 >%v<        >''<          >%v INVALID<
591 >%w<        >''<          >%w INVALID<
592 >%x<        >2**32-1<     >ffffffff<
593 >%+x<       >2**32-1<     >ffffffff<
594 >%#x<       >2**32-1<     >0xffffffff<
595 >%10x<      >2**32-1<     >  ffffffff<
596 >%010x<     >2**32-1<     >00ffffffff<
597 >%-10x<     >2**32-1<     >ffffffff  <
598 >%-010x<    >2**32-1<     >ffffffff  <
599 >%0-10x<    >2**32-1<     >ffffffff  <
600 >%4x<       >18<          >  12<
601 >%4.3x<     >18<          > 012<
602 >%-4.3x<    >18<          >012 <
603 >%+4.3x<    >18<          > 012<
604 >% 4.3x<    >18<          > 012<
605 >%04.3x<    >18<          > 012<         >0 flag with precision: no effect<
606 >%.3x<      >18<          >012<
607 >%4X<       >28<          >  1C<
608 >%4.3X<     >28<          > 01C<
609 >%-4.3X<    >28<          >01C <
610 >%+4.3X<    >28<          > 01C<
611 >% 4.3X<    >28<          > 01C<
612 >%04.3X<    >28<          > 01C<         >0 flag with precision: no effect<
613 >%.3X<      >28<          >01C<
614 >%.0x<      >0<           ><
615 >%+.0x<     >0<           ><
616 >% .0x<     >0<           ><
617 >%-.0x<     >0<           ><
618 >%#.0x<     >0<           ><
619 >%#3.0x<    >0<           >   <
620 >%#3.1x<    >0<           >  0<
621 >%#3.2x<    >0<           > 00<
622 >%#3.3x<    >0<           >000<
623 >%#3.4x<    >0<           >0000<
624 >%.0x<      >1<           >1<
625 >%+.0x<     >1<           >1<
626 >% .0x<     >1<           >1<
627 >%-.0x<     >1<           >1<
628 >%#.0x<     >1<           >0x1<
629 >%#3.0x<    >1<           >0x1<
630 >%#3.1x<    >1<           >0x1<
631 >%#3.2x<    >1<           >0x01<
632 >%#3.3x<    >1<           >0x001<
633 >%#3.4x<    >1<           >0x0001<
634 >%#.5x<     >0x12345<     >0x12345<
635 >%#.5x<     >0x12<        >0x00012<
636 >%#4x<      >28<          >0x1c<
637 >%#4.3x<    >28<          >0x01c<
638 >%#-4.3x<   >28<          >0x01c<
639 >%#+4.3x<   >28<          >0x01c<
640 >%# 4.3x<   >28<          >0x01c<
641 >%#04.3x<   >28<          >0x01c<         >0 flag with precision: no effect<
642 >%#.3x<     >28<          >0x01c<
643 >%#6.3x<    >28<          > 0x01c<
644 >%#-6.3x<   >28<          >0x01c <
645 >%-#6.3x<   >28<          >0x01c <
646 >%#+6.3x<   >28<          > 0x01c<
647 >%+#6.3x<   >28<          > 0x01c<
648 >%# 6.3x<   >28<          > 0x01c<
649 >% #6.3x<   >28<          > 0x01c<
650 >%0*x<      >[-10, ,2**32-1]< >ffffffff  <
651 >%vx<       >[version::qv("1.2.3")]< >1.2.3<
652 >%vx<       >[version::qv("1.20.300")]< >1.14.12c<
653 >%.*x<      >[0,0]<       ><
654 >%-.*x<     >[0,0]<       ><
655 >%+.*x<     >[0,0]<       ><
656 >% .*x<     >[0,0]<       ><
657 >%0.*x<     >[0,0]<       ><
658 >%.*x<      >[-3,0]<      >0<
659 >%-.*x<     >[-3,0]<      >0<
660 >%+.*x<     >[-3,0]<      >0<
661 >% .*x<     >[-3,0]<      >0<
662 >%0.*x<     >[-3,0]<      >0<
663 >%#.*x<     >[0,0]<       ><
664 >%#-.*x<    >[0,0]<       ><
665 >%#+.*x<    >[0,0]<       ><
666 >%# .*x<    >[0,0]<       ><
667 >%#0.*x<    >[0,0]<       ><
668 >%#.*x<     >[-1,0]<      >0<
669 >%#-.*x<    >[-1,0]<      >0<
670 >%#+.*x<    >[-1,0]<      >0<
671 >%# .*x<    >[-1,0]<      >0<
672 >%#0.*x<    >[-1,0]<      >0<
673 >%y<        >''<          >%y INVALID<
674 >%z<        >''<          >%z INVALID<
675 >%2$d %1$d<     >[12, 34]<      >34 12<
676 >%*2$d<         >[12, 3]<       > 12<             >RT#125469<
677 >%*3$d<         >[12, 9, 3]<    > 12<             >related to RT#125469<
678 >%2$d %d<       >[12, 34]<      >34 12<
679 >%2$d %d %d<    >[12, 34]<      >34 12 34<
680 >%3$d %d %d<    >[12, 34, 56]<  >56 12 34<
681 >%2$*3$d %d<    >[12, 34, 3]<   > 34 12<
682 >%*3$2$d %d<    >[12, 34, 3]<   >%*3$2$d 12 INVALID<
683 >%2$d<          >12<    >0 MISSING<
684 >%0$d<          >12<    >%0$d INVALID<
685 >%1$$d<         >12<    >%1$$d INVALID<
686 >%1$1$d<        >12<    >%1$1$d INVALID<
687 >%*2$*2$d<      >[12, 3]<       >%*2$*2$d INVALID<
688 >%*2*2$d<       >[12, 3]<       >%*2*2$d INVALID<
689 >%*2$1d<        >[12, 3]<       >%*2$1d INVALID<
690 >%0v2.2d<       >''<    ><
691 >%vc,%d<        >[63, 64, 65]<  >%vc,63 INVALID<
692 >%v%,%d<        >[63, 64, 65]<  >%v%,63 INVALID INVALID<
693 >%vd,%d<        >["\x1", 2, 3]< >1,2 REDUNDANT<
694 >%vf,%d<        >[1, 2, 3]<     >%vf,1 INVALID<
695 >%vF,%d<        >[1, 2, 3]<     >%vF,1 INVALID<
696 >%ve,%d<        >[1, 2, 3]<     >%ve,1 INVALID<
697 >%vE,%d<        >[1, 2, 3]<     >%vE,1 INVALID<
698 >%vg,%d<        >[1, 2, 3]<     >%vg,1 INVALID<
699 >%vG,%d<        >[1, 2, 3]<     >%vG,1 INVALID<
700 >%vp<   >''<    >%vp INVALID<
701 >%vn<   >''<    >%vn INVALID<
702 >%vs,%d<        >[1, 2, 3]<     >%vs,1 INVALID<
703 >%v_<   >''<    >%v_ INVALID<
704 >%v#x<  >''<    >%v#x INVALID<
705 >%v02x< >"\x66\x6f\x6f\012"<    >66.6f.6f.0a<
706 >%#v.8b<        >"\141\000\142"<        >0b01100001.00000000.0b01100010<        >perl #39530<
707 >%#v.0o<        >"\001\000\002\000"<    >01.0.02.0<
708 >%#v.1o<        >"\001\000\002\000"<    >01.0.02.0<
709 >%#v.4o<        >"\141\000\142"<        >0141.0000.0142<        >perl #39530<
710 >%#v.3i<        >"\141\000\142"<        >097.000.098<   >perl #39530<
711 >%#v.0x<        >"\001\000\002\000"<    >0x1..0x2.<
712 >%#v.1x<        >"\001\000\002\000"<    >0x1.0.0x2.0<
713 >%#v.2x<        >"\141\000\142"<        >0x61.00.0x62<  >perl #39530<
714 >%#v.2X<        >"\141\000\142"<        >0X61.00.0X62<  >perl #39530<
715 >%#v.8b<        >"\141\017\142"<        >0b01100001.0b00001111.0b01100010<      >perl #39530<
716 >%#v.4o<        >"\141\017\142"<        >0141.0017.0142<        >perl #39530<
717 >%#v.3i<        >"\141\017\142"<        >097.015.098<   >perl #39530<
718 >%#v.2x<        >"\141\017\142"<        >0x61.0x0f.0x62<        >perl #39530<
719 >%#v.2X<        >"\141\017\142"<        >0X61.0X0F.0X62<        >perl #39530<
720 >%#*v.8b<       >["][", "\141\000\142"]<        >0b01100001][00000000][0b01100010<      >perl #39530<
721 >%#*v.4o<       >["][", "\141\000\142"]<        >0141][0000][0142<      >perl #39530<
722 >%#*v.3i<       >["][", "\141\000\142"]<        >097][000][098< >perl #39530<
723 >%#*v.2x<       >["][", "\141\000\142"]<        >0x61][00][0x62<        >perl #39530<
724 >%#*v.2X<       >["][", "\141\000\142"]<        >0X61][00][0X62<        >perl #39530<
725 >%#*v.8b<       >["][", "\141\017\142"]<        >0b01100001][0b00001111][0b01100010<    >perl #39530<
726 >%#*v.4o<       >["][", "\141\017\142"]<        >0141][0017][0142<      >perl #39530<
727 >%#*v.3i<       >["][", "\141\017\142"]<        >097][015][098< >perl #39530<
728 >%#*v.2x<       >["][", "\141\017\142"]<        >0x61][0x0f][0x62<      >perl #39530<
729 >%#*v.2X<       >["][", "\141\017\142"]<        >0X61][0X0F][0X62<      >perl #39530<
730 >%#v.8b<        >"\141\x{1e01}\000\142\x{1e03}"<        >0b01100001.0b1111000000001.00000000.0b01100010.0b1111000000011<        >perl #39530<
731 >%#v.4o<        >"\141\x{1e01}\000\142\x{1e03}"<        >0141.017001.0000.0142.017003<  >perl #39530<
732 >%#v.3i<        >"\141\x{1e01}\000\142\x{1e03}"<        >097.7681.000.098.7683< >perl #39530<
733 >%#v.2x<        >"\141\x{1e01}\000\142\x{1e03}"<        >0x61.0x1e01.00.0x62.0x1e03<    >perl #39530<
734 >%#v.2X<        >"\141\x{1e01}\000\142\x{1e03}"<        >0X61.0X1E01.00.0X62.0X1E03<    >perl #39530<
735 >%#v.8b<        >"\141\x{1e01}\017\142\x{1e03}"<        >0b01100001.0b1111000000001.0b00001111.0b01100010.0b1111000000011<      >perl #39530<
736 >%#v.4o<        >"\141\x{1e01}\017\142\x{1e03}"<        >0141.017001.0017.0142.017003<  >perl #39530<
737 >%#v.3i<        >"\141\x{1e01}\017\142\x{1e03}"<        >097.7681.015.098.7683< >perl #39530<
738 >%#v.2x<        >"\141\x{1e01}\017\142\x{1e03}"<        >0x61.0x1e01.0x0f.0x62.0x1e03<  >perl #39530<
739 >%#v.2X<        >"\141\x{1e01}\017\142\x{1e03}"<        >0X61.0X1E01.0X0F.0X62.0X1E03<  >perl #39530<
740 >%V-%s<         >["Hello"]<     >%V-Hello INVALID<
741 >%K %d %d<      >[13, 29]<      >%K 13 29 INVALID<
742 >%*.*K %d<      >[13, 29, 76]<  >%*.*K 13 INVALID<
743 >%4$K %d<       >[45, 67]<      >%4$K 45 INVALID<
744 >%d %K %d<      >[23, 45]<      >23 %K 45 INVALID<
745 >%*v*999\$d %d %d<      >[11, 22, 33]<  >%*v*999\$d 11 22 INVALID<
746 >%#b<           >0<     >0<
747 >%#o<           >0<     >0<
748 >%#x<           >0<     >0<
749 >%1073741819$v2d<       >''<    > MISSING<
750 >%*1073741819$v2d<      >''<    > MISSING<
751 >%.3X<          >[11]<                  >00B<           >perl #83194: hex, zero-padded to 3 places<
752 >%.*X<          >[3, 11]<               >00B<           >perl #83194: dynamic precision<
753 a>%vX<          >['012']<               >30.31.32<      >perl #83194: vector flag<
754 e>%vX<          >['012']<               >F0.F1.F2<      >perl #83194: vector flag<
755 a>%*vX<         >[':', '012']<          >30:31:32<      >perl #83194: vector flag + custom separator<
756 e>%*vX<         >[':', '012']<          >F0:F1:F2<      >perl #83194: vector flag + custom separator<
757 a>%v.3X<                >['012']<               >030.031.032<   >perl #83194: vector flag + static precision<
758 e>%v.3X<                >['012']<               >0F0.0F1.0F2<   >perl #83194: vector flag + static precision<
759 a>%v.*X<                >[3, '012']<            >030.031.032<   >perl #83194: vector flag + dynamic precision<
760 e>%v.*X<                >[3, '012']<            >0F0.0F1.0F2<   >perl #83194: vector flag + dynamic precision<
761 a>%*v.3X<       >[':', '012']<          >030:031:032<   >perl #83194: vector flag + custom separator + static precision<
762 e>%*v.3X<       >[':', '012']<          >0F0:0F1:0F2<   >perl #83194: vector flag + custom separator + static precision<
763 a>%*v.*X<       >[':', 3, '012']<       >030:031:032<   >perl #83194: vector flag + custom separator + dynamic precision<
764 e>%*v.*X<       >[':', 3, '012']<       >0F0:0F1:0F2<   >perl #83194: vector flag + custom separator + dynamic precision<
765 a>%vd<  >"version"<     >118.101.114.115.105.111.110<   >perl #102586: vector flag + "version"<
766 e>%vd<   >"version"<    >165.133.153.162.137.150.149<   >perl #102586: vector flag + "version"<
767 >%3$*4$v*2$.*1$x<  >[3, 4, "\x11\x22\x33", "/"]< > 011/ 022/ 033< >four reordered args<
768 >%*%<   >[]<    >% MISSING<
769 >%*1$%< >[]<    >% MISSING<
770 >%*2$d< >123<   >123 MISSING<
771 >%2$vd<>123<    > MISSING<
772 >%.f<   >123.432<   >123<   >by tradition, empty precision == 0 <
773 >%.001f<   >123.432<   >123.4<   >by tradition, leading zeroes ignored in precison<
774 >%.0f<   >[1.2, 3.4]<   >1 REDUNDANT<   >special-cased "%.0f" should check count<
775 >%.0f<   >[]<   >0 MISSING<   >special-cased "%.0f" should check count<
776 >%53.0f<   >69.0<   >                                                   69<   >#131659<