This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
upgrade cpan/JSON-PP from 4.00 to 4.02
[perl5.git] / cpan / JSON-PP / t / 011_pc_expo.t
CommitLineData
dec273dc
CBW
1# copied over from JSON::PC and modified to use JSON::PP
2# copied over from JSON::XS and modified to use JSON::PP
d5424315
DG
3
4use Test::More;
5use strict;
5eabe055 6BEGIN { plan tests => 8 + 2 };
d5424315
DG
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');
dec273dc 24{ #SKIP_IF_CPANEL
d5424315
DG
25$js = $pc->encode($obj);
26is($js,'[-123400]', 'digit -1.234e5');
dec273dc 27}
d5424315
DG
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);
5eabe055 33is($js,'[0.000123]', 'digit 1.23E-4');
d5424315 34
d5424315 35
5eabe055
N
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);
929e53be 40like($js,qr/\[(?:1.01[Ee]\+0?30|1010000000000000000000000000000)]/, 'digit 1.01e+30'); # RT-128589 (-Duselongdouble or -Dquadmath)
d5424315 41
28c20d1f
JH
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}