15759b3d2Safresh1# copied over from JSON::PC and modified to use JSON::PP 25759b3d2Safresh1# copied over from JSON::XS and modified to use JSON::PP 3898184e3Ssthen 4898184e3Ssthenuse Test::More; 5898184e3Ssthenuse strict; 6*256a93a4Safresh1use warnings; 7f3efcd01Safresh1BEGIN { plan tests => 8 + 2 }; 8898184e3SsthenBEGIN { $ENV{PERL_JSON_BACKEND} = 0; } 9898184e3Ssthen 10898184e3Ssthenuse JSON::PP; 11898184e3Ssthen 12898184e3Ssthen######################### 13898184e3Ssthenmy ($js,$obj); 14*256a93a4Safresh1my $pc = JSON::PP->new; 15898184e3Ssthen 16898184e3Ssthen$js = q|[-12.34]|; 17898184e3Ssthen$obj = $pc->decode($js); 18898184e3Ssthenis($obj->[0], -12.34, 'digit -12.34'); 19898184e3Ssthen$js = $pc->encode($obj); 20898184e3Ssthenis($js,'[-12.34]', 'digit -12.34'); 21898184e3Ssthen 22898184e3Ssthen$js = q|[-1.234e5]|; 23898184e3Ssthen$obj = $pc->decode($js); 24898184e3Ssthenis($obj->[0], -123400, 'digit -1.234e5'); 255759b3d2Safresh1{ #SKIP_IF_CPANEL 26898184e3Ssthen$js = $pc->encode($obj); 27898184e3Ssthenis($js,'[-123400]', 'digit -1.234e5'); 285759b3d2Safresh1} 29898184e3Ssthen 30898184e3Ssthen$js = q|[1.23E-4]|; 31898184e3Ssthen$obj = $pc->decode($js); 32898184e3Ssthenis($obj->[0], 0.000123, 'digit 1.23E-4'); 33898184e3Ssthen$js = $pc->encode($obj); 34898184e3Ssthenis($js,'[0.000123]', 'digit 1.23E-4'); 35898184e3Ssthen 36898184e3Ssthen 37f3efcd01Safresh1$js = q|[1.01e+30]|; 38f3efcd01Safresh1$obj = $pc->decode($js); 39f3efcd01Safresh1is($obj->[0], 1.01e+30, 'digit 1.01e+30'); 40f3efcd01Safresh1$js = $pc->encode($obj); 41f3efcd01Safresh1like($js,qr/\[(?:1.01[Ee]\+0?30|1010000000000000000000000000000)]/, 'digit 1.01e+30'); # RT-128589 (-Duselongdouble or -Dquadmath) 42f3efcd01Safresh1 435759b3d2Safresh1my $vax_float = (pack("d",1) =~ /^[\x80\x10]\x40/); 44898184e3Ssthen 455759b3d2Safresh1if ($vax_float) { 465759b3d2Safresh1 # VAX has smaller float range. 475759b3d2Safresh1 $js = q|[1.01e+37]|; 485759b3d2Safresh1 $obj = $pc->decode($js); 495759b3d2Safresh1 is($obj->[0], eval '1.01e+37', 'digit 1.01e+37'); 505759b3d2Safresh1 $js = $pc->encode($obj); 515759b3d2Safresh1 like($js,qr/\[1.01[Ee]\+0?37\]/, 'digit 1.01e+37'); 525759b3d2Safresh1} else { 53898184e3Ssthen $js = q|[1.01e+67]|; # 30 -> 67 ... patched by H.Merijn Brand 54898184e3Ssthen $obj = $pc->decode($js); 555759b3d2Safresh1 is($obj->[0], eval '1.01e+67', 'digit 1.01e+67'); 56898184e3Ssthen $js = $pc->encode($obj); 57898184e3Ssthen like($js,qr/\[1.01[Ee]\+0?67\]/, 'digit 1.01e+67'); 585759b3d2Safresh1} 59