12 sprintf("%.40g ",0.01),
13 sprintf("%.40g", 0.01)." ",
14 q(the sprintf "%.<number>g" optimization)
17 sprintf("%.40f ",0.01),
18 sprintf("%.40f", 0.01)." ",
19 q(the sprintf "%.<number>f" optimization)
22 chop(my $utf8_format = "%-3s\x{100}");
24 sprintf($utf8_format, "\xe4"),
26 q(width calculation under utf8 upgrade)
30 # Used to mangle PL_sv_undef
32 'print sprintf "xxx%n\n"; print undef',
33 'Modification of a read-only value attempted at - line 1.',
34 { switches => [ '-w' ] },
35 q(%n should not be able to modify read-only constants),
39 for (int(~0/2+1), ~0, "9999999999999999999") {
40 is(eval {sprintf "%${_}d", 0}, undef, "no sprintf result expected %${_}d");
41 like($@, qr/^Integer overflow in format string for sprintf /, "overflow in sprintf");
42 is(eval {printf "%${_}d\n", 0}, undef, "no printf result expected %${_}d");
43 like($@, qr/^Integer overflow in format string for prtf /, "overflow in printf");
46 # check %NNN$ for range bounds
48 my ($warn, $bad) = (0,0);
49 local $SIG{__WARN__} = sub {
50 if ($_[0] =~ /uninitialized/) {
58 my $fmt = join('', map("%$_\$s%" . ((1 << 31)-$_) . '$s', 1..20));
59 my $result = sprintf $fmt, qw(a b c d);
60 is($result, "abcd", "only four valid values in $fmt");
61 is($warn, 36, "expected warnings");
62 is($bad, 0, "unexpected warnings");
66 foreach my $ord (0 .. 255) {
68 local $SIG{__WARN__} = sub {
69 if ($_[0] !~ /^Invalid conversion in sprintf/) {
74 my $r = eval {sprintf '%v' . chr $ord};
75 is ($bad, 0, "pattern '%v' . chr $ord");