1# copied over from JSON::PC and modified to use JSON::PP
2# copied over from JSON::XS and modified to use JSON::PP
3
4use Test::More;
5use strict;
6BEGIN { plan tests => 8 + 2 };
7BEGIN { $ENV{PERL_JSON_BACKEND} = 0; }
8
9use JSON::PP;
10
11#########################
12my ($js,$obj);
13my $pc = new JSON::PP;
14
15$js  = q|[-12.34]|;
16$obj = $pc->decode($js);
17is($obj->[0], -12.34, 'digit -12.34');
18$js = $pc->encode($obj);
19is($js,'[-12.34]', 'digit -12.34');
20
21$js  = q|[-1.234e5]|;
22$obj = $pc->decode($js);
23is($obj->[0], -123400, 'digit -1.234e5');
24{ #SKIP_IF_CPANEL
25$js = $pc->encode($obj);
26is($js,'[-123400]', 'digit -1.234e5');
27}
28
29$js  = q|[1.23E-4]|;
30$obj = $pc->decode($js);
31is($obj->[0], 0.000123, 'digit 1.23E-4');
32$js = $pc->encode($obj);
33is($js,'[0.000123]', 'digit 1.23E-4');
34
35
36$js  = q|[1.01e+30]|;
37$obj = $pc->decode($js);
38is($obj->[0], 1.01e+30, 'digit 1.01e+30');
39$js = $pc->encode($obj);
40like($js,qr/\[(?:1.01[Ee]\+0?30|1010000000000000000000000000000)]/, 'digit 1.01e+30'); # RT-128589 (-Duselongdouble or -Dquadmath)
41
42my $vax_float = (pack("d",1) =~ /^[\x80\x10]\x40/);
43
44if ($vax_float) {
45    # VAX has smaller float range.
46    $js  = q|[1.01e+37]|;
47    $obj = $pc->decode($js);
48    is($obj->[0], eval '1.01e+37', 'digit 1.01e+37');
49    $js = $pc->encode($obj);
50    like($js,qr/\[1.01[Ee]\+0?37\]/, 'digit 1.01e+37');
51} else {
52    $js  = q|[1.01e+67]|; # 30 -> 67 ... patched by H.Merijn Brand
53    $obj = $pc->decode($js);
54    is($obj->[0], eval '1.01e+67', 'digit 1.01e+67');
55    $js = $pc->encode($obj);
56    like($js,qr/\[1.01[Ee]\+0?67\]/, 'digit 1.01e+67');
57}
58