#!./perl
# Tests sprintf, excluding handling of 64-bit integers or long
# doubles (if supported), of machine-specific short and long
# integers, machine-specific floating point exceptions (infinity,
# not-a-number ...), of the effects of locale, and of features
# specific to multi-byte characters (under the utf8 pragma and such).
BEGIN {
chdir 't' if -d 't';
}
use warnings;
# we do not load %Config since this test resides in op and needs
# to run under the minitest target even without Config.pm working.
# strictness
my @tests = ();
while (<DATA>) {
s/^\s*>//; s/<\s*$//;
}
$w = ' INVALID';
$w = ' UNINIT';
} else {
warn @_;
}
};
my $Is_VMS_VAX = 0;
# We use HW_MODEL since ARCH_NAME was not in VMS V5.*
my $hw_model;
$Is_VMS_VAX = $hw_model < 1024 ? 1 : 0;
}
# No %Config.
for ($i = 1; @tests; $i++) {
}
# VAX DEC C 5.3 at least since there is no
# ccflags =~ /float=ieee/ on VAX.
# AXP is unaffected whether or not it's using ieee.
}
$w = undef;
# $x may have 3 exponent digits, not 2
my $y = $x;
# if result is left-adjusted, append extra space
$y =~ s/<$/ </;
}
# if result is zero-filled, add extra zero
$y =~ s/^>0/>00/;
}
# if result is right-adjusted, prepend extra space
$y =~ s/^>/> /;
}
}
print "ok $i\n";
}
{ # three-digit exponent
}
elsif ($result =~ /[-+]\d{3}$/ &&
# Suppress tests with modulo of exponent >= 100 on platforms
# which can't handle such magnitudes (or where we can't tell).
{
" Suppressed: exponent out of range?\n")
}
else {
}
}
# In each of the following lines, there are three required fields:
# printf template, data to be formatted (as a Perl expression), and
# expected result of formatting. An optional fourth field can contain
# a comment. Each field is delimited by a starting '>' and a
# finishing '<'; any whitespace outside these start and end marks is
# not part of the field. If formatting requires more than one data
# item (for example, if variable field widths are used), the Perl data
# expression should return a reference to an array having the requisite
# number of elements. Even so, subterfuge is sometimes required: see
# tests for %n and %p.
#
# The following tests are not currently run, for the reasons stated:
=pod
=end problematic
=cut
# template data result
>%A< >''< >%A INVALID<
>%B< >''< >%B INVALID<
>%C< >''< >%C INVALID<
>%G< >.1234567e-101< >1.23457E-102<
>%G< >12345.6789< >12345.7<
>%H< >''< >%H INVALID<
>%I< >''< >%I INVALID<
>%J< >''< >%J INVALID<
>%K< >''< >%K INVALID<
>%L< >''< >%L INVALID<
>%M< >''< >%M INVALID<
>%N< >''< >%N INVALID<
>%P< >''< >%P INVALID<
>%Q< >''< >%Q INVALID<
>%R< >''< >%R INVALID<
>%S< >''< >%S INVALID<
>%T< >''< >%T INVALID<
>%V< >''< >%V INVALID<
>%W< >''< >%W INVALID<
>%#X< >2**32-1< >0XFFFFFFFF<
>%Y< >''< >%Y INVALID<
>%Z< >''< >%Z INVALID<
>%a< >''< >%a INVALID<
>%b< >2**32-1< >11111111111111111111111111111111<
>%+b< >2**32-1< >11111111111111111111111111111111<
>%#b< >2**32-1< >0b11111111111111111111111111111111<
>%34b< >2**32-1< > 11111111111111111111111111111111<
>%034b< >2**32-1< >0011111111111111111111111111111111<
>%-34b< >2**32-1< >11111111111111111111111111111111 <
>%-034b< >2**32-1< >11111111111111111111111111111111 <
>%#10c< >ord('A')< > A< ># modifier: no effect<
>%d< >123456.789< >123456<
>%d< >-123456.789< >-123456<
>%d< >0< >0<
>%+d< >0< >+0<
>%0d< >0< >0<
>%.0d< >0< ><
>%+.0d< >0< >+<
>%.0d< >1< >1<
>%d< >1< >1<
>%+d< >1< >+1<
>%#3.2d< >1< > 01< ># modifier: no effect<
>%3.2d< >1< > 01<
>%03.2d< >1< >001<
>%-3.2d< >1< >01 <
>%d< >-1< >-1<
>%+d< >-1< >-1<
>%#vd< >chr(1)< >1<
>%v.3d< >"\01\02\03"< >001.002.003<
>%v.*d< >["\01\02\03", 3]< >001.002.003<
>%0v*d< >["\01\02\03", 3]< >001.002.003<
>%-v*d< >["\01\02\03", 3]< >1 .2 .3 <
>%+-v*d< >["\01\02\03", 3]< >+1 .2 .3 <
>%v*.*d< >["\01\02\03", 4, 3]< > 001. 002. 003<
>%0v*.*d< >["\01\02\03", 4, 3]< >0001.0002.0003<
>%0*v*d< >['-', "\0\7\13", 2]< >00-07-11<
>%e< >1234.875< >1.234875e+03<
>%e< >0.000012345< >1.234500e-05<
>%e< >0< >0.000000e+00<
>%e< >.1234567E-101< >1.234567e-102<
>%+e< >1234.875< >+1.234875e+03<
>%#e< >1234.875< >1.234875e+03<
>%e< >-1234.875< >-1.234875e+03<
>%+e< >-1234.875< >-1.234875e+03<
>%#e< >-1234.875< >-1.234875e+03<
>%.0e< >1234.875< >1e+03<
>%#.0e< >1234.875< >1.e+03<
>%.0e< >1.875< >2e+00<
>%.0e< >0.875< >9e-01<
>%.*e< >[0, 1234.875]< >1e+03<
>%.1e< >1234.875< >1.2e+03<
>%-12.4e< >1234.875< >1.2349e+03 <
>%12.4e< >1234.875< > 1.2349e+03<
>%+-12.4e< >1234.875< >+1.2349e+03 <
>%+12.4e< >1234.875< > +1.2349e+03<
>%+-12.4e< >-1234.875< >-1.2349e+03 <
>%+12.4e< >-1234.875< > -1.2349e+03<
>%f< >1234.875< >1234.875000<
>%+f< >1234.875< >+1234.875000<
>%#f< >1234.875< >1234.875000<
>%f< >-1234.875< >-1234.875000<
>%+f< >-1234.875< >-1234.875000<
>%#f< >-1234.875< >-1234.875000<
>%6f< >1234.875< >1234.875000<
>%*f< >[6, 1234.875]< >1234.875000<
>%.0f< >1234.875< >1235<
>%.1f< >1234.875< >1234.9<
>%-8.1f< >1234.875< >1234.9 <
>%8.1f< >1234.875< > 1234.9<
>%+-8.1f< >1234.875< >+1234.9 <
>%+8.1f< >1234.875< > +1234.9<
>%+-8.1f< >-1234.875< >-1234.9 <
>%+8.1f< >-1234.875< > -1234.9<
>%*.*f< >[5, 2, 12.3456]< >12.35<
>%f< >0< >0.000000<
>%.0f< >0< >0<
>%.0f< >0.1< >0<
>%.0f< >0.6< >1< >Known to fail with sfio, (irix|nonstop-ux|powerux); -DHAS_LDBL_SPRINTF_BUG may fix<
>%.0f< >-0.6< >-1< >Known to fail with sfio, (irix|nonstop-ux|powerux); -DHAS_LDBL_SPRINTF_BUG may fix<
>%.0f< >1.6< >2<
>%.0f< >-1.6< >-2<
>%.0f< >1< >1<
>%#.0f< >1< >1.<
>%g< >12345.6789< >12345.7<
>%+g< >12345.6789< >+12345.7<
>%#g< >12345.6789< >12345.7<
>%.0g< >12345.6789< >1e+04<
>%#.0g< >12345.6789< >1.e+04<
>%.2g< >12345.6789< >1.2e+04<
>%.*g< >[2, 12345.6789]< >1.2e+04<
>%.9g< >12345.6789< >12345.6789<
>%12.9g< >12345.6789< > 12345.6789<
>%012.9g< >12345.6789< >0012345.6789<
>%-12.9g< >12345.6789< >12345.6789 <
>%*.*g< >[-12, 9, 12345.6789]< >12345.6789 <
>%-012.9g< >12345.6789< >12345.6789 <
>%g< >-12345.6789< >-12345.7<
>%+g< >-12345.6789< >-12345.7<
>%g< >1234567.89< >1.23457e+06<
>%+g< >1234567.89< >+1.23457e+06<
>%#g< >1234567.89< >1.23457e+06<
>%g< >-1234567.89< >-1.23457e+06<
>%+g< >-1234567.89< >-1.23457e+06<
>%#g< >-1234567.89< >-1.23457e+06<
>%g< >0.00012345< >0.00012345<
>%g< >0.000012345< >1.2345e-05<
>%g< >.1234567E-101< >1.23457e-102<
>%g< >0< >0<
>%13g< >1234567.89< > 1.23457e+06<
>%+13g< >1234567.89< > +1.23457e+06<
>%013g< >1234567.89< >001.23457e+06<
>%-13g< >1234567.89< >1.23457e+06 <
>%h< >''< >%h INVALID<
>%j< >''< >%j INVALID<
>%k< >''< >%k INVALID<
>%l< >''< >%l INVALID<
>%m< >''< >%m INVALID<
>%o< >2**32-1< >37777777777<
>%+o< >2**32-1< >37777777777<
>%#o< >2**32-1< >037777777777<
>%+o< >642< >1202<
>%#o< >642< >01202<
>%#p< >''< >%#p INVALID<
>%q< >''< >%q INVALID<
>%r< >''< >%r INVALID<
>%s< >'string'< >string<
>%#10s< >'string'< > string<
>%t< >''< >%t INVALID<
>%u< >2**32-1< >4294967295<
>%+u< >2**32-1< >4294967295<
>%#u< >2**32-1< >4294967295<
>%12u< >2**32-1< > 4294967295<
>%012u< >2**32-1< >004294967295<
>%-12u< >2**32-1< >4294967295 <
>%-012u< >2**32-1< >4294967295 <
>%v< >''< >%v INVALID<
>%w< >''< >%w INVALID<
>%#x< >2**32-1< >0xffffffff<
>%y< >''< >%y INVALID<
>%z< >''< >%z INVALID<
>%2$d %1$d< >[12, 34]< >34 12<
>%*2$d< >[12, 3]< > 12<
>%2$d %d< >[12, 34]< >34 12<
>%2$d %d %d< >[12, 34]< >34 12 34<
>%3$d %d %d< >[12, 34, 56]< >56 12 34<
>%2$*3$d %d< >[12, 34, 3]< > 34 12<
>%v#x< >''< >%v#x INVALID<
>%#b< >0< >0<
>%#o< >0< >0<
>%#x< >0< >0<