From 333f87f24de2f15740185612410ef911ccfed6a3 Mon Sep 17 00:00:00 2001 From: Bo Lindbergh Date: Mon, 5 Jul 2010 00:04:46 +0200 Subject: [PATCH] Tests for allowing uppercase X/B in hexadecimal/binary numbers (#76296). Signed-off-by: David Golden --- t/base/num.t | 15 ++++++++++++++- t/op/oct.t | 15 ++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/t/base/num.t b/t/base/num.t index 06eea52..fbeddc94 100644 --- a/t/base/num.t +++ b/t/base/num.t @@ -1,6 +1,6 @@ #!./perl -print "1..50\n"; +print "1..53\n"; # First test whether the number stringification works okay. # (Testing with == would exercize the IV/NV part, not the PV.) @@ -50,6 +50,8 @@ print $a eq "256" ? "ok 14\n" : "not ok 14 # $a\n"; $a = 1000; "$a"; print $a eq "1000" ? "ok 15\n" : "not ok 15 # $a\n"; +# more hex and binary tests below starting at 51 + # Okay, now test the numerics. # We may be assuming too much, given the painfully well-known floating # point sloppiness, but the following are still quite reasonable @@ -196,3 +198,14 @@ print $a == 10.0 ? "ok 49\n" : "not ok 49\n"; $a = 57.295779513082320876798154814169; print ok($a*10,572.95779513082320876798154814169,1e-10) ? "ok 50\n" : "not ok 50 # $a\n"; + +# Allow uppercase base markers (#76296) + +$a = 0Xabcdef; "$a"; +print $a eq "11259375" ? "ok 51\n" : "not ok 51 # $a\n"; + +$a = 0XFEDCBA; "$a"; +print $a eq "16702650" ? "ok 52\n" : "not ok 52 # $a\n"; + +$a = 0B1101; "$a"; +print $a eq "13" ? "ok 53\n" : "not ok 53 # $a\n"; diff --git a/t/op/oct.t b/t/op/oct.t index f996b48..dcd2256 100644 --- a/t/op/oct.t +++ b/t/op/oct.t @@ -2,7 +2,7 @@ # tests 51 onwards aren't all warnings clean. (intentionally) -print "1..71\n"; +print "1..77\n"; my $test = 1; @@ -25,10 +25,10 @@ sub test ($$$) { print "ok $test # $act $string\n"; } else { my ($valstr, $resstr); - if ($act eq 'hex' or $string =~ /x/) { + if ($act eq 'hex' or $string =~ /x/i) { $valstr = sprintf "0x%X", $value; $resstr = sprintf "0x%X", $result; - } elsif ($string =~ /b/) { + } elsif ($string =~ /b/i) { $valstr = sprintf "0b%b", $value; $resstr = sprintf "0b%b", $result; } else { @@ -150,3 +150,12 @@ print $@ =~ /Wide character/ ? "ok $test\n" : "not ok $test\n"; $test++; eval '$a = hex "ab\x{100}"'; print $@ =~ /Wide character/ ? "ok $test\n" : "not ok $test\n"; $test++; + +# Allow uppercase base markers (#76296) + +test ('hex', "0XCAFE", 0xCAFE); +test ('hex', "XCAFE", 0xCAFE); +test ('oct', "0XCAFE", 0xCAFE); +test ('oct', "XCAFE", 0xCAFE); +test ('oct', "0B101001", 0b101001); +test ('oct', "B101001", 0b101001); -- 2.7.4