1# copied over from JSON::PC and modified to use Cpanel::JSON::XS
2
3use Test::More;
4use strict;
5BEGIN { plan tests => 8 };
6use Cpanel::JSON::XS;
7use utf8;
8
9#########################
10my ($js,$obj);
11my $pc = new Cpanel::JSON::XS;
12
13$js  = '{"foo":0}';
14$obj = $pc->decode($js);
15is($obj->{foo}, 0, "normal 0");
16
17$js  = '{"foo":0.1}';
18$obj = $pc->decode($js);
19is($obj->{foo}, 0.1, "normal 0.1");
20
21
22$js  = '{"foo":10}';
23$obj = $pc->decode($js);
24is($obj->{foo}, 10, "normal 10");
25
26$js  = '{"foo":-10}';
27$obj = $pc->decode($js);
28is($obj->{foo}, -10, "normal -10");
29
30
31$js  = '{"foo":0, "bar":0.1}';
32$obj = $pc->decode($js);
33is($obj->{foo},0,  "normal 0");
34is($obj->{bar},0.1,"normal 0.1");
35
36# GH 154
37$obj = $pc->decode(q([0.3]));
38TODO: {
39  local $TODO = "strtold vs json_atof_scan1, GH #154" if $] < 5.021004;
40  is($obj->[0] - 0.3, 0.0, "normal 0.3");
41}
42ok(abs($obj->[0] - 0.3) < 1e-16, "numeric epsilon <1E-16");
43
44