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