1#!perl
2
3# test calling conventions, and :constant overloading
4
5use strict;
6use warnings;
7
8use Test::More tests => 140;
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_nan
80abc:1
811:0
82&is_inf
83inf:1
840:0
85&bstr
865:5
8710:10
88-10:-10
89abc:NaN
90"+inf":inf
91"-inf":-inf
92&bsstr
931:1e+0
940:0e+0
952:2e+0
96200:2e+2
97-5:-5e+0
98-100:-1e+2
99abc:NaN
100"+inf":inf
101&babs
102-1:1
1031:1
104&bnot
105-2:1
1061:-2
107&bzero
108:0
109&bnan
110:NaN
111abc:NaN
112&bone
113:1
114#"+":1
115#"-":-1
116&binf
117:inf
118#"+":inf
119#"-":-inf
120