Commit | Line | Data |
1ca3b561 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use JSON::MaybeXS; |
6 | |
7 | my $data = JSON::MaybeXS->new->decode('{"foo": true, "bar": false, "baz": 1}'); |
0b694b31 |
8 | diag 'true is: ', explain $data->{foo}; |
9 | diag 'false is: ', explain $data->{bar}; |
10 | |
1ca3b561 |
11 | ok( |
12 | JSON::MaybeXS::is_bool($data->{foo}), |
13 | JSON() . ': true decodes to a bool', |
14 | ); |
15 | ok( |
16 | JSON::MaybeXS::is_bool($data->{bar}), |
17 | JSON() . ': false decodes to a bool', |
18 | ); |
19 | ok( |
20 | !JSON::MaybeXS::is_bool($data->{baz}), |
21 | JSON() . ': int does not decode to a bool', |
22 | ); |
23 | |
048d1726 |
24 | is( |
25 | JSON::MaybeXS::encode_json([JSON::MaybeXS::true]), |
26 | '[true]', |
27 | JSON() . ': true sub encodes as correct boolean', |
28 | ); |
29 | |
30 | is( |
31 | JSON::MaybeXS::encode_json([JSON::MaybeXS->true]), |
32 | '[true]', |
33 | JSON() . ': true method encodes as correct boolean', |
34 | ); |
35 | |
36 | is( |
37 | JSON::MaybeXS::encode_json([JSON::MaybeXS::false]), |
38 | '[false]', |
39 | JSON() . ': false sub encodes as correct boolean', |
40 | ); |
41 | |
42 | is( |
43 | JSON::MaybeXS::encode_json([JSON::MaybeXS->false]), |
44 | '[false]', |
45 | JSON() . ': false method encodes as correct boolean', |
46 | ); |
47 | |
1ca3b561 |
48 | 1; |