This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perldeltify change #4115.
[perl5.git] / t / op / sprintf.t
CommitLineData
8d063cd8
LW
1#!./perl
2
79072805 3# $RCSfile: sprintf.t,v $$Revision: 4.1 $$Date: 92/08/07 18:28:27 $
8d063cd8 4
fb73857a 5print "1..4\n";
8d063cd8 6
fb73857a
PP
7$^W = 1;
8$SIG{__WARN__} = sub {
9 if ($_[0] =~ /^Invalid conversion/) {
10 $w++;
11 } else {
12 warn @_;
13 }
14};
15
16$w = 0;
eda88b6d
JH
17$x = sprintf("%3s %-4s%%foo %.0d%5d %#x%c%3.1f %b %x %X %#b %#B %#x %#X","hi",123,0,456,0,ord('A'),3.0999,11,171,171,11,11,171,171);
18if ($x eq ' hi 123 %foo 456 0A3.1 1011 ab AB 0b1011 0B1011 0xab 0XAB' && $w == 0) {
fb73857a
PP
19 print "ok 1\n";
20} else {
21 print "not ok 1 '$x'\n";
22}
23
24for $i (2 .. 4) {
25 $f = ('%6 .6s', '%6. 6s', '%6.6 s')[$i - 2];
26 $w = 0;
27 $x = sprintf($f, '');
28 if ($x eq $f && $w == 1) {
29 print "ok $i\n";
30 } else {
31 print "not ok $i '$x' '$f' '$w'\n";
32 }
33}