Debian Codegraph @

t/117_numbers.t

raw
1 use Test::More;
2 use strict;
3 use warnings;
4 BEGIN { $ENV{PERL_JSON_BACKEND} ||= "JSON::backportPP"; }
5 BEGIN { $ENV{PERL_JSON_PP_USE_B} = 0 }
6 use JSON;
7
8 BEGIN { plan skip_all => "requires $JSON::BackendModule 2.90 or newer" if JSON->backend->is_pp and eval $JSON::BackendModule->VERSION < 2.90 }
9 BEGIN { plan skip_all => "not for $JSON::BackendModule" if $JSON::BackendModule eq 'JSON::XS' }
10
11 BEGIN { plan tests => 3 }
12
13 # TODO ("inf"/"nan" representations are not portable)
14 # is encode_json([9**9**9]), '["inf"]';
15 # is encode_json([-sin(9**9**9)]), '["nan"]';
16
17 my $num = 3;
18 my $str = "$num";
19 is encode_json({test => [$num, $str]}), '{"test":[3,"3"]}';
20 $num = 3.21;
21 $str = "$num";
22 is encode_json({test => [$num, $str]}), '{"test":[3.21,"3.21"]}';
23 $str = '0 but true';
24 $num = 1 + $str;
25 is encode_json({test => [$num, $str]}), '{"test":[1,"0 but true"]}';