This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
delete new accidentally branched file
[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
9f1b1f2d
GS
5BEGIN {
6 chdir 't' if -d 't';
7 unshift @INC, '../lib';
8}
9use warnings;
10
fb73857a 11print "1..4\n";
8d063cd8 12
fb73857a
PP
13$SIG{__WARN__} = sub {
14 if ($_[0] =~ /^Invalid conversion/) {
15 $w++;
16 } else {
17 warn @_;
18 }
19};
20
21$w = 0;
7481bb52
JH
22$x = sprintf("%3s %-4s%%foo %.0d%5d %#x%c%3.1f %b %x %X %#b %#x %#X","hi",123,0,456,0,ord('A'),3.0999,11,171,171,11,171,171);
23if ($x eq ' hi 123 %foo 456 0A3.1 1011 ab AB 0b1011 0xab 0XAB' && $w == 0) {
fb73857a
PP
24 print "ok 1\n";
25} else {
26 print "not ok 1 '$x'\n";
27}
28
29for $i (2 .. 4) {
30 $f = ('%6 .6s', '%6. 6s', '%6.6 s')[$i - 2];
31 $w = 0;
32 $x = sprintf($f, '');
33 if ($x eq $f && $w == 1) {
34 print "ok $i\n";
35 } else {
36 print "not ok $i '$x' '$f' '$w'\n";
37 }
38}