diff options
author | Tels <nospam-abuse@bloodgate.com> | 2007-06-16 16:33:47 +0200 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2007-06-17 13:28:00 +0000 |
commit | d1a15766ff5cdfaf84d91442a68bc2a05880bf12 (patch) | |
tree | 050d2d413b2850d26d0aee67b05c542490fad92a /lib/bignum | |
parent | 3006a4e1991c29fe722177d0ddb5a525c7ce8822 (diff) | |
download | perl-d1a15766ff5cdfaf84d91442a68bc2a05880bf12.tar.gz |
bignum 0.22 take 4 (hex()/oct() overloading)
Message-Id: <200706161433.47489@bloodgate.com>
p4raw-id: //depot/perl@31403
Diffstat (limited to 'lib/bignum')
-rwxr-xr-x | lib/bignum/t/bigint.t | 27 | ||||
-rwxr-xr-x | lib/bignum/t/bignum.t | 27 | ||||
-rwxr-xr-x | lib/bignum/t/bigrat.t | 27 | ||||
-rw-r--r-- | lib/bignum/t/in_effect.t | 2 | ||||
-rw-r--r-- | lib/bignum/t/scope_f.t | 15 | ||||
-rw-r--r-- | lib/bignum/t/scope_i.t | 16 | ||||
-rw-r--r-- | lib/bignum/t/scope_r.t | 15 |
7 files changed, 116 insertions, 13 deletions
diff --git a/lib/bignum/t/bigint.t b/lib/bignum/t/bigint.t index 03fb11bebe..baf76a3005 100755 --- a/lib/bignum/t/bigint.t +++ b/lib/bignum/t/bigint.t @@ -10,10 +10,10 @@ BEGIN $| = 1; chdir 't' if -d 't'; unshift @INC, '../lib'; - plan tests => 36; + plan tests => 51; } -use bigint; +use bigint qw/hex oct/; ############################################################################### # _constant tests @@ -88,6 +88,29 @@ ok (bigint->round_mode('odd'),'odd'); ok (bigint->round_mode(),'odd'); ############################################################################### +# hex() and oct() + +my $c = 'Math::BigInt'; + +ok (ref(hex(1)), $c); +ok (ref(hex(0x1)), $c); +ok (ref(hex("af")), $c); +ok (hex("af"), Math::BigInt->new(0xaf)); +ok (ref(hex("0x1")), $c); + +ok (ref(oct("0x1")), $c); +ok (ref(oct("01")), $c); +ok (ref(oct("0b01")), $c); +ok (ref(oct("1")), $c); +ok (ref(oct(" 1")), $c); +ok (ref(oct(" 0x1")), $c); + +ok (ref(oct(0x1)), $c); +ok (ref(oct(01)), $c); +ok (ref(oct(0b01)), $c); +ok (ref(oct(1)), $c); + +############################################################################### ############################################################################### # Perl 5.005 does not like ok ($x,undef) diff --git a/lib/bignum/t/bignum.t b/lib/bignum/t/bignum.t index ee5b8d4375..fe299a2e24 100755 --- a/lib/bignum/t/bignum.t +++ b/lib/bignum/t/bignum.t @@ -10,10 +10,10 @@ BEGIN $| = 1; chdir 't' if -d 't'; unshift @INC, '../lib'; - plan tests => 20; + plan tests => 35; } -use bignum; +use bignum qw/oct hex/; ############################################################################### # general tests @@ -59,6 +59,29 @@ ok (bignum->round_mode('odd'),'odd'); ok (bignum->round_mode(),'odd'); ############################################################################### +# hex() and oct() + +my $c = 'Math::BigInt'; + +ok (ref(hex(1)), $c); +ok (ref(hex(0x1)), $c); +ok (ref(hex("af")), $c); +ok (hex("af"), Math::BigInt->new(0xaf)); +ok (ref(hex("0x1")), $c); + +ok (ref(oct("0x1")), $c); +ok (ref(oct("01")), $c); +ok (ref(oct("0b01")), $c); +ok (ref(oct("1")), $c); +ok (ref(oct(" 1")), $c); +ok (ref(oct(" 0x1")), $c); + +ok (ref(oct(0x1)), $c); +ok (ref(oct(01)), $c); +ok (ref(oct(0b01)), $c); +ok (ref(oct(1)), $c); + +############################################################################### ############################################################################### # Perl 5.005 does not like ok ($x,undef) diff --git a/lib/bignum/t/bigrat.t b/lib/bignum/t/bigrat.t index c8162fc719..972b83cde2 100755 --- a/lib/bignum/t/bigrat.t +++ b/lib/bignum/t/bigrat.t @@ -10,10 +10,10 @@ BEGIN $| = 1; chdir 't' if -d 't'; unshift @INC, '../lib'; - plan tests => 25; + plan tests => 40; } -use bigrat; +use bigrat qw/oct hex/; ############################################################################### # general tests @@ -63,6 +63,29 @@ ok (bigrat->round_mode('odd'),'odd'); ok (bigrat->round_mode(),'odd'); ############################################################################### +# hex() and oct() + +my $c = 'Math::BigInt'; + +ok (ref(hex(1)), $c); +ok (ref(hex(0x1)), $c); +ok (ref(hex("af")), $c); +ok (hex("af"), Math::BigInt->new(0xaf)); +ok (ref(hex("0x1")), $c); + +ok (ref(oct("0x1")), $c); +ok (ref(oct("01")), $c); +ok (ref(oct("0b01")), $c); +ok (ref(oct("1")), $c); +ok (ref(oct(" 1")), $c); +ok (ref(oct(" 0x1")), $c); + +ok (ref(oct(0x1)), $c); +ok (ref(oct(01)), $c); +ok (ref(oct(0b01)), $c); +ok (ref(oct(1)), $c); + +############################################################################### ############################################################################### # Perl 5.005 does not like ok ($x,undef) diff --git a/lib/bignum/t/in_effect.t b/lib/bignum/t/in_effect.t index d2545e48cf..b163f12b8f 100644 --- a/lib/bignum/t/in_effect.t +++ b/lib/bignum/t/in_effect.t @@ -23,7 +23,7 @@ can_ok ('bignum', qw/in_effect/); can_ok ('bigrat', qw/in_effect/); SKIP: { - skip ('Need at least Perl v5.9.4', 3) unless $] > 5.009004; + skip ('Need at least Perl v5.9.4', 3) if $] < "5.009005"; is (bigint::in_effect(), 1, 'bigint in effect'); is (bignum::in_effect(), 1, 'bignum in effect'); diff --git a/lib/bignum/t/scope_f.t b/lib/bignum/t/scope_f.t index e2d4417484..dd748e11c8 100644 --- a/lib/bignum/t/scope_f.t +++ b/lib/bignum/t/scope_f.t @@ -1,7 +1,7 @@ #!/usr/bin/perl -w ############################################################################### -# Test no bignum; +# Test "no bignum;" and overloading of hex()/oct() for newer Perls use Test::More; use strict; @@ -11,20 +11,31 @@ BEGIN $| = 1; chdir 't' if -d 't'; unshift @INC, '../lib'; - plan tests => 6; + plan tests => 10; } +# no :hex and :oct means these do not get overloaded for older Perls: use bignum; isnt (ref(1), '', 'is in effect'); isnt (ref(2.0), '', 'is in effect'); isnt (ref(0x20), '', 'is in effect'); +SKIP: { + skip ('Need at least Perl v5.9.4', 2) if $] < 5.009004; + + is (ref(hex(9)), 'Math::BigInt', 'hex is overloaded'); + is (ref(oct(07)), 'Math::BigInt', 'oct is overloaded'); + } + { no bignum; is (ref(1), '', 'is not in effect'); is (ref(2.0), '', 'is not in effect'); is (ref(0x20), '', 'is not in effect'); + + isnt (ref(hex(9)), 'Math::BigInt', 'hex is not overloaded'); + isnt (ref(oct(07)), 'Math::BigInt', 'oct is not overloaded'); } diff --git a/lib/bignum/t/scope_i.t b/lib/bignum/t/scope_i.t index d663401659..4e2f1e6e7f 100644 --- a/lib/bignum/t/scope_i.t +++ b/lib/bignum/t/scope_i.t @@ -1,7 +1,7 @@ #!/usr/bin/perl -w ############################################################################### -# Test no bigint; +# Test "no bigint;" and overloading of hex()/oct() for newer Perls use Test::More; use strict; @@ -11,20 +11,32 @@ BEGIN $| = 1; chdir 't' if -d 't'; unshift @INC, '../lib'; - plan tests => 6; + plan tests => 10; } +# no :hex and :oct means these do not get overloaded for older Perls: use bigint; isnt (ref(1), '', 'is in effect'); isnt (ref(2.0), '', 'is in effect'); isnt (ref(0x20), '', 'is in effect'); +SKIP: { + skip ('Need at least Perl v5.9.4', 2) if $] < "5.009004"; # quote due to "use bigint;" + + is (ref(hex(9)), 'Math::BigInt', 'hex is overloaded'); + is (ref(oct(07)), 'Math::BigInt', 'oct is overloaded'); + } + { no bigint; is (ref(1), '', 'is not in effect'); is (ref(2.0), '', 'is not in effect'); is (ref(0x20), '', 'is not in effect'); + + isnt (ref(hex(9)), 'Math::BigInt', 'hex is not overloaded'); + isnt (ref(oct(07)), 'Math::BigInt', 'oct is not overloaded'); + } diff --git a/lib/bignum/t/scope_r.t b/lib/bignum/t/scope_r.t index 888398867e..784fe0e6b0 100644 --- a/lib/bignum/t/scope_r.t +++ b/lib/bignum/t/scope_r.t @@ -1,7 +1,7 @@ #!/usr/bin/perl -w ############################################################################### -# Test no bigint; +# Test "no bigrat;" and overloading of hex()/oct() for newer Perls use Test::More; use strict; @@ -11,20 +11,31 @@ BEGIN $| = 1; chdir 't' if -d 't'; unshift @INC, '../lib'; - plan tests => 6; + plan tests => 10; } +# no :hex and :oct means these do not get overloaded for older Perls: use bigrat; isnt (ref(1), '', 'is in effect'); isnt (ref(2.0), '', 'is in effect'); isnt (ref(0x20), '', 'is in effect'); +SKIP: { + skip ('Need at least Perl v5.9.4', 2) if $] < 5.009004; + + is (ref(hex(9)), 'Math::BigInt', 'hex is overloaded'); + is (ref(oct(07)), 'Math::BigInt', 'oct is overloaded'); + } + { no bigrat; is (ref(1), '', 'is not in effect'); is (ref(2.0), '', 'is not in effect'); is (ref(0x20), '', 'is not in effect'); + + isnt (ref(hex(9)), 'Math::BigInt', 'hex is not overloaded'); + isnt (ref(oct(07)), 'Math::BigInt', 'oct is not overloaded'); } |