"Fossies" - the Fresh Open Source Software Archive

Member "perl-5.32.1/cpan/JSON-PP/t/011_pc_expo.t" (18 Dec 2020, 1562 Bytes) of package /linux/misc/perl-5.32.1.tar.xz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    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 
    4 use Test::More;
    5 use strict;
    6 BEGIN { plan tests => 8 + 2 };
    7 BEGIN { $ENV{PERL_JSON_BACKEND} = 0; }
    8 
    9 use JSON::PP;
   10 
   11 #########################
   12 my ($js,$obj);
   13 my $pc = new JSON::PP;
   14 
   15 $js  = q|[-12.34]|;
   16 $obj = $pc->decode($js);
   17 is($obj->[0], -12.34, 'digit -12.34');
   18 $js = $pc->encode($obj);
   19 is($js,'[-12.34]', 'digit -12.34');
   20 
   21 $js  = q|[-1.234e5]|;
   22 $obj = $pc->decode($js);
   23 is($obj->[0], -123400, 'digit -1.234e5');
   24 { #SKIP_IF_CPANEL
   25 $js = $pc->encode($obj);
   26 is($js,'[-123400]', 'digit -1.234e5');
   27 }
   28 
   29 $js  = q|[1.23E-4]|;
   30 $obj = $pc->decode($js);
   31 is($obj->[0], 0.000123, 'digit 1.23E-4');
   32 $js = $pc->encode($obj);
   33 is($js,'[0.000123]', 'digit 1.23E-4');
   34 
   35 
   36 $js  = q|[1.01e+30]|;
   37 $obj = $pc->decode($js);
   38 is($obj->[0], 1.01e+30, 'digit 1.01e+30');
   39 $js = $pc->encode($obj);
   40 like($js,qr/\[(?:1.01[Ee]\+0?30|1010000000000000000000000000000)]/, 'digit 1.01e+30'); # RT-128589 (-Duselongdouble or -Dquadmath) 
   41 
   42 my $vax_float = (pack("d",1) =~ /^[\x80\x10]\x40/);
   43 
   44 if ($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 }