1# copied over from JSON::XS and modified to use Cpanel::JSON::XS 2 3use Test::More; 4use strict; 5BEGIN { plan tests => 8 }; 6use Cpanel::JSON::XS; 7use Config (); 8 9######################### 10my ($js,$obj); 11my $pc = new Cpanel::JSON::XS; 12 13$js = q|[-12.34]|; 14$obj = $pc->decode($js); 15is($obj->[0], -12.34, 'digit -12.34'); 16$js = $pc->encode($obj); 17is($js,'[-12.34]', 'digit -12.34'); 18 19$js = q|[-1.234e5]|; 20$obj = $pc->decode($js); 21is($obj->[0], -123400, 'digit -1.234e5'); 22$js = $pc->encode($obj); 23is($js,'[-123400.0]', 'digit -1.234e5'); 24 25$js = q|[1.23E-4]|; 26$obj = $pc->decode($js); 27is($obj->[0], 0.000123, 'digit 1.23E-4'); 28$js = $pc->encode($obj); 29if ($] < 5.007 and $Config::Config{d_Gconvert} =~ /^g/ and $js ne '[0.000123]') { 30 is($js,'[1.23e-04]', 'digit 1.23e-4 v5.6'); 31} else { 32 is($js,'[0.000123]', 'digit 1.23E-4'); 33} 34 35$js = q|[1.01e+30]|; 36$obj = $pc->decode($js); 37is($obj->[0], 1.01e+30, 'digit 1.01e+30'); 38$js = $pc->encode($obj); 39if ($Config::Config{usequadmath}) { 40 is($js,'[1010000000000000000000000000000.0]', 'digit 1010000000000000000000000000000.0 (quadmath)'); 41} elsif ($Config::Config{uselongdouble} && $Config::Config{ptrsize} > 4) { 42 like($js, qr/^\[(1010000000000000000000000000000\.0|1.01[Ee]\+0?30)\]/, 43 'digit (64bit ld)'); # esp. non-intel 44} else { 45 like($js,qr/\[1.01[Ee]\+0?30\]/, 'digit 1.01e+30'); 46} 47