Debian Codegraph @

t/e02_bool.t

raw
1 use strict;
2
3 use Test::More;
4 use strict;
5
6 BEGIN { plan tests => 8 };
7
8 BEGIN { $ENV{PERL_JSON_BACKEND} ||= "JSON::backportPP"; }
9
10 use JSON;
11
12 my $json = new JSON;
13
14 diag $json->backend->isa('JSON::PP');
15 my $not_not_a_number_is_a_number = (
16 $json->backend->isa('Cpanel::JSON::XS') ||
17 ($json->backend->isa('JSON::PP') && ($JSON::PP::Boolean::VERSION || $JSON::backportPP::Boolean::VERSION))
18 ) ? 1 : 0;
19
20 my $core_bool_support = JSON->backend->can("CORE_BOOL") && JSON->backend->CORE_BOOL ? 1 : 0;
21
22 is($json->encode([!1]), $core_bool_support ? '[false]' : '[""]');
23 if ($not_not_a_number_is_a_number) {
24 is($json->encode([!!2]), $core_bool_support ? '[true]' : '[1]');
25 } else {
26 is($json->encode([!!2]), '["1"]');
27 }
28
29 is($json->encode([ 'a' eq 'b' ]), $core_bool_support ? '[false]' : '[""]');
30 if ($not_not_a_number_is_a_number) {
31 is($json->encode([ 'a' eq 'a' ]), $core_bool_support ? '[true]' : '[1]');
32 } else {
33 is($json->encode([ 'a' eq 'a' ]), '["1"]');
34 }
35
36 is($json->encode([ ('a' eq 'b') + 1 ]), '[1]');
37 is($json->encode([ ('a' eq 'a') + 1 ]), '[2]');
38
39 # discard overload hack for JSON::XS 3.0 boolean class
40 #ok(JSON::true eq 'true');
41 #ok(JSON::true eq '1');
42 ok(JSON::true == 1);
43 isa_ok(JSON::true, 'JSON::PP::Boolean');
44 #isa_ok(JSON::true, 'JSON::Boolean');
45
46
47