This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
bignum overrides.t: Skip some tests under 5.8
[perl5.git] / dist / bignum / t / overrides.t
CommitLineData
9663a7f5
FC
1#!perl -w
2
3# Test behaviour of hex and oct overrides in detail, and also how the three
4# modules interact.
5
6use Test::More tests => 35;
7
8# For testing that existing CORE::GLOBAL overrides are not clobbered
9BEGIN
10 {
11 if ($] > 5.009004)
12 {
13 no warnings 'syntax';
14 *CORE::GLOBAL::hex = sub(_) { ++$hex_called; CORE::hex(@_?$_[0]:$_) };
15 *CORE::GLOBAL::oct = sub(_) { ++$oct_called; CORE::oct(@_?$_[0]:$_) };
16 }
17 else
18 {
19 *CORE::GLOBAL::hex = sub(;$) { ++$hex_called; CORE::hex(@_?$_[0]:$_) };
20 *CORE::GLOBAL::oct = sub(;$) { ++$oct_called; CORE::oct(@_?$_[0]:$_) };
21 }
22 }
23
24{
25 use bigint;
26 $_ = "20";
27 is hex, "32", 'bigint hex override without arguments infers $_';
28 is oct, "16", 'bigint oct override without arguments infers $_';
29 @_ = 1..20;
30 is hex(@_), "32", 'bigint hex override provides scalar context';
31 is oct(@_), "16", 'bigint oct override provides scalar context';
2666a4be
FC
32 SKIP:
33 {
34 skip "no lexical hex/oct", 2 unless $] > 5.009004;
35 is ref hex(1), 'Math::BigInt',
36 'bigint hex() works when bignum and bigrat are loaded';
37 is ref oct(1), 'Math::BigInt',
38 'bigint oct() works when bignum and bigrat are loaded';
39 }
9663a7f5
FC
40}
41{
42 use bignum;
43 $_ = "20";
44 is hex, "32", 'bignum hex override without arguments infers $_';
45 is oct, "16", 'bignum oct override without arguments infers $_';
46 @_ = 1..20;
47 is hex(@_), "32", 'bignum hex override provides scalar context';
48 is oct(@_), "16", 'bignum oct override provides scalar context';
2666a4be
FC
49 SKIP:
50 {
51 skip "no lexical hex/oct", 2 unless $] > 5.009004;
52 is ref hex(1), 'Math::BigInt',
53 'bignum hex() works when bigint and bigrat are loaded';
54 is ref oct(1), 'Math::BigInt',
55 'bignum oct() works when bigint and bigrat are loaded';
56 }
9663a7f5
FC
57}
58{
59 use bigrat;
60 $_ = "20";
61 is hex, "32", 'bigrat hex override without arguments infers $_';
62 is oct, "16", 'bigrat oct override without arguments infers $_';
63 @_ = 1..20;
64 is hex(@_), "32", 'bigrat hex override provides scalar context';
65 is oct(@_), "16", 'bigrat oct override provides scalar context';
2666a4be
FC
66 SKIP:
67 {
68 skip "no lexical hex/oct", 2 unless $] > 5.009004;
69 is ref hex(1), 'Math::BigInt',
70 'bigrat hex() works when bignum and bigint are loaded';
71 is ref oct(1), 'Math::BigInt',
72 'bigrat oct() works when bignum and bigint are loaded';
73 }
9663a7f5
FC
74}
75
76$hex_called = 0;
77() = hex 0;
78is $hex_called, 1, 'existing hex overrides are called';
79$oct_called = 0;
80() = oct 0;
81is $oct_called, 1, 'existing oct overrides are called';
82
83{
84 package _importer;
85 {
86 use bigint 'hex', 'oct';
87 ::is \&hex, \&bigint::hex, 'exported hex function';
88 ::is \&oct, \&bigint::oct, 'exported oct function';
89 }
90 ::ok ref hex(), 'exported hex function returns ref outside pragma scope';
91 ::ok ref oct(), 'exported oct function returns ref outside pragma scope';
92 ::is oct("20"), "16", 'exported oct function works with "decimal"';
93 # (used to return 20 because it thought it was decimal)
94}
95{
96 package _importer2;
97 use bignum 'hex', 'oct';
98 ::is \&hex, \&bignum::hex, 'bignum exports hex';
99 ::is \&oct, \&bignum::oct, 'bignum exports oct';
100 ::is \&hex, \&bigint::hex, 'bignum exports same hex as bigint';
101 ::is \&oct, \&bigint::oct, 'bignum exports same oct as bigint';
102}
103{
104 package _importer3;
105 use bigrat 'hex', 'oct';
106 ::is \&hex, \&bigrat::hex, 'bigrat exports hex';
107 ::is \&oct, \&bigrat::oct, 'bigrat exports oct';
108 ::is \&hex, \&bigint::hex, 'bigrat exports same hex as bigint';
109 ::is \&oct, \&bigint::oct, 'bigrat exports same oct as bigint';
110}
111is ref hex 0, "", 'hex export is not global';
112is ref oct 0, "", 'oct export is not global';