1
2use strict;
3use Test::More;
4BEGIN { plan tests => 6 };
5
6BEGIN { $ENV{PERL_JSON_BACKEND} = 0; }
7
8use JSON::PP;
9
10eval q| require Math::BigInt |;
11
12SKIP: {
13    skip "Can't load Math::BigInt.", 6 if ($@);
14
15    my $v = Math::BigInt->VERSION;
16    $v =~ s/_.+$// if $v;
17
18my $fix =  !$v       ? '+'
19          : $v < 1.6 ? '+'
20          : '';
21
22
23my $json = new JSON::PP;
24
25$json->allow_nonref->allow_bignum(1);
26$json->convert_blessed->allow_blessed;
27
28my $num  = $json->decode(q|100000000000000000000000000000000000000|);
29
30isa_ok($num, 'Math::BigInt');
31is("$num", $fix . '100000000000000000000000000000000000000');
32is($json->encode($num), $fix . '100000000000000000000000000000000000000');
33
34$num  = $json->decode(q|2.0000000000000000001|);
35
36isa_ok($num, 'Math::BigFloat');
37is("$num", '2.0000000000000000001');
38is($json->encode($num), '2.0000000000000000001');
39
40
41}
42