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