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