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