3 # Test behaviour of hex and oct overrides in detail, and also how the three
6 use Test::More tests => 35;
8 # For testing that existing CORE::GLOBAL overrides are not clobbered
14 *CORE::GLOBAL::hex = sub(_) { ++$hex_called; CORE::hex(@_?$_[0]:$_) };
15 *CORE::GLOBAL::oct = sub(_) { ++$oct_called; CORE::oct(@_?$_[0]:$_) };
19 *CORE::GLOBAL::hex = sub(;$) { ++$hex_called; CORE::hex(@_?$_[0]:$_) };
20 *CORE::GLOBAL::oct = sub(;$) { ++$oct_called; CORE::oct(@_?$_[0]:$_) };
27 is hex, "32", 'bigint hex override without arguments infers $_';
28 is oct, "16", 'bigint oct override without arguments infers $_';
30 is hex(@_), "32", 'bigint hex override provides scalar context';
31 is oct(@_), "16", 'bigint oct override provides scalar context';
32 is ref hex(1), 'Math::BigInt',
33 'bigint hex() works when bignum and bigrat are loaded';
34 is ref oct(1), 'Math::BigInt',
35 'bigint oct() works when bignum and bigrat are loaded';
40 is hex, "32", 'bignum hex override without arguments infers $_';
41 is oct, "16", 'bignum oct override without arguments infers $_';
43 is hex(@_), "32", 'bignum hex override provides scalar context';
44 is oct(@_), "16", 'bignum oct override provides scalar context';
45 is ref hex(1), 'Math::BigInt',
46 'bignum hex() works when bigint and bigrat are loaded';
47 is ref oct(1), 'Math::BigInt',
48 'bignum oct() works when bigint and bigrat are loaded';
53 is hex, "32", 'bigrat hex override without arguments infers $_';
54 is oct, "16", 'bigrat oct override without arguments infers $_';
56 is hex(@_), "32", 'bigrat hex override provides scalar context';
57 is oct(@_), "16", 'bigrat oct override provides scalar context';
58 is ref hex(1), 'Math::BigInt',
59 'bigrat hex() works when bignum and bigint are loaded';
60 is ref oct(1), 'Math::BigInt',
61 'bigrat oct() works when bignum and bigint are loaded';
66 is $hex_called, 1, 'existing hex overrides are called';
69 is $oct_called, 1, 'existing oct overrides are called';
74 use bigint 'hex', 'oct';
75 ::is \&hex, \&bigint::hex, 'exported hex function';
76 ::is \&oct, \&bigint::oct, 'exported oct function';
78 ::ok ref hex(), 'exported hex function returns ref outside pragma scope';
79 ::ok ref oct(), 'exported oct function returns ref outside pragma scope';
80 ::is oct("20"), "16", 'exported oct function works with "decimal"';
81 # (used to return 20 because it thought it was decimal)
85 use bignum 'hex', 'oct';
86 ::is \&hex, \&bignum::hex, 'bignum exports hex';
87 ::is \&oct, \&bignum::oct, 'bignum exports oct';
88 ::is \&hex, \&bigint::hex, 'bignum exports same hex as bigint';
89 ::is \&oct, \&bigint::oct, 'bignum exports same oct as bigint';
93 use bigrat 'hex', 'oct';
94 ::is \&hex, \&bigrat::hex, 'bigrat exports hex';
95 ::is \&oct, \&bigrat::oct, 'bigrat exports oct';
96 ::is \&hex, \&bigint::hex, 'bigrat exports same hex as bigint';
97 ::is \&oct, \&bigint::oct, 'bigrat exports same oct as bigint';
99 is ref hex 0, "", 'hex export is not global';
100 is ref oct 0, "", 'oct export is not global';