require './test.pl';
}
-plan tests => 1292;
+plan tests => 1368;
+
+use strict;
+use Config;
is(
sprintf("%.40g ",0.01),
}
}
+# test that %f doesn't panic with +Inf, -Inf, NaN [perl #45383]
+foreach my $n (2**1e100, -2**1e100, 2**1e100/2**1e100) { # +Inf, -Inf, NaN
+ eval { my $f = sprintf("%f", $n); };
+ is $@, "", "sprintf(\"%f\", $n)";
+}
+
+# test %ll formats with and without HAS_QUAD
+eval { my $q = pack "q", 0 };
+my $Q = $@ eq '';
+
+my @tests = (
+ [ '%lld' => [qw( 4294967296 -100000000000000 )] ],
+ [ '%lli' => [qw( 4294967296 -100000000000000 )] ],
+ [ '%llu' => [qw( 4294967296 100000000000000 )] ],
+ [ '%Ld' => [qw( 4294967296 -100000000000000 )] ],
+ [ '%Li' => [qw( 4294967296 -100000000000000 )] ],
+ [ '%Lu' => [qw( 4294967296 100000000000000 )] ],
+);
+
+for my $t (@tests) {
+ my($fmt, $nums) = @$t;
+ for my $num (@$nums) {
+ my $w; local $SIG{__WARN__} = sub { $w = shift };
+ is(sprintf($fmt, $num), $Q ? $num : $fmt, "quad: $fmt -> $num");
+ like($w, $Q ? '' : qr/Invalid conversion in sprintf: "$fmt"/, "warning: $fmt");
+ }
+}
+
+# Check unicode vs byte length
+for my $width (1,2,3,4,5,6,7) {
+ for my $precis (1,2,3,4,5,6,7) {
+ my $v = "\x{20ac}\x{20ac}";
+ my $format = "%" . $width . "." . $precis . "s";
+ my $chars = ($precis > 2 ? 2 : $precis);
+ my $space = ($width < 2 ? 0 : $width - $chars);
+ fresh_perl_is(
+ 'my $v = "\x{20ac}\x{20ac}"; my $x = sprintf "'.$format.'", $v; $x =~ /^(\s*)(\S*)$/; print "$_" for map {length} $1, $2',
+ "$space$chars",
+ {},
+ q(sprintf ").$format.q(", "\x{20ac}\x{20ac}"),
+ );
+ }
+}