1#!perl
2
3# test calling conventions, and :constant overloading
4
5use strict;
6use warnings;
7
8use Test::More tests => 156;
9
10##############################################################################
11
12package Math::BigInt::Test;
13
14use Math::BigInt;
15our @ISA = qw/Math::BigInt/;            # subclass of MBI
16use overload;
17
18##############################################################################
19
20package Math::BigFloat::Test;
21
22use Math::BigFloat;
23our @ISA = qw/Math::BigFloat/;          # subclass of MBI
24use overload;
25
26##############################################################################
27
28package main;
29
30use Math::BigInt try => 'Calc';
31use Math::BigFloat;
32
33my ($x, $y, $z, $u);
34
35###############################################################################
36# check whether op's accept normal strings, even when inherited by subclasses
37
38# do one positive and one negative test to avoid false positives by "accident"
39
40my ($method, $expected);
41while (<DATA>) {
42    s/#.*$//;                   # remove comments
43    s/\s+$//;                   # remove trailing whitespace
44    next unless length;         # skip empty lines
45
46    if (s/^&//) {
47        $method = $_;
48        next;
49    }
50
51    my @args = split /:/, $_, 99;
52    $expected = pop @args;
53    foreach my $class (qw/
54                             Math::BigInt Math::BigFloat
55                             Math::BigInt::Test Math::BigFloat::Test
56                         /)
57    {
58        my $arg = $args[0] =~ /"/ || $args[0] eq "" ? $args[0]
59                                                    : qq|"$args[0]"|;
60        my $try = "$class -> new($arg) -> $method();";
61        my $got = eval $try;
62        is($got, $expected, $try);
63    }
64}
65
66__END__
67&is_zero
681:0
690:1
70&is_one
711:1
720:0
73&is_positive
741:1
75-1:0
76&is_negative
771:0
78-1:1
79&is_non_positive
801:0
81-1:1
82&is_non_negative
831:1
84-1:0
85&is_nan
86abc:1
871:0
88&is_inf
89inf:1
900:0
91&bstr
925:5
9310:10
94-10:-10
95abc:NaN
96"+inf":inf
97"-inf":-inf
98&bsstr
991:1e+0
1000:0e+0
1012:2e+0
102200:2e+2
103-5:-5e+0
104-100:-1e+2
105abc:NaN
106"+inf":inf
107&babs
108-1:1
1091:1
110&bnot
111-2:1
1121:-2
113&bzero
114:0
115&bnan
116:NaN
117abc:NaN
118&bone
119:1
120#"+":1
121#"-":-1
122&binf
123:inf
124#"+":inf
125#"-":-inf
126