1#!perl
2
3# test calling conventions, and :constant overloading
4
5use strict;
6use warnings;
7use lib 't';
8
9my $VERSION = '1.999816';       # adjust manually to match latest release
10
11use Test::More tests => 5;
12
13##############################################################################
14
15package Math::BigInt::Test;
16
17use Math::BigInt;
18our @ISA = qw/Math::BigInt/;            # subclass of MBI
19use overload;
20
21##############################################################################
22
23package Math::BigFloat::Test;
24
25use Math::BigFloat;
26our @ISA = qw/Math::BigFloat/;          # subclass of MBF
27use overload;
28
29##############################################################################
30
31package main;
32
33use Math::BigInt try => 'Calc';
34use Math::BigFloat;
35
36my ($x, $expected, $try);
37
38my $class = 'Math::BigInt';
39
40# test whether use Math::BigInt qw/VERSION/ works
41$try = "use $class (" . ($VERSION . '1') .");";
42$try .= ' $x = $class->new(123); $x = "$x";';
43eval $try;
44like($@, qr/ ^ Math::BigInt \s+ ( version \s+ )? \S+ \s+ required--this \s+
45             is \s+ only \s+ version \s+ \S+ /x,
46     $try);
47
48# test whether fallback to calc works
49$try = qq|use $class ($VERSION, "try", "foo, bar, ");|
50     . qq| $class\->config('lib');|;
51$expected = eval $try;
52like($expected, qr/^Math::BigInt::(Fast)?Calc\z/, $try);
53
54# test whether constant works or not, also test for qw($VERSION)
55# bgcd() is present in subclass, too
56$try = qq|use $class ($VERSION, "bgcd", ":constant");|
57     . q| $x = 2**150; bgcd($x); $x = "$x";|;
58$expected = eval $try;
59is($expected, "1427247692705959881058285969449495136382746624", $try);
60
61# test whether Math::BigInt::Scalar via use works (w/ dff. spellings of calc)
62$try = qq|use $class ($VERSION, "lib", "Scalar");|
63     . q| $x = 2**10; $x = "$x";|;
64$expected = eval $try;
65is($expected, "1024", $try);
66
67$try = qq|use $class ($VERSION, "lib", "$class\::Scalar");|
68     . q| $x = 2**10; $x = "$x";|;
69$expected = eval $try;
70is($expected, "1024", $try);
71