File: is_bool.pm

package info (click to toggle)
libjson-maybexs-perl 1.004000-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 164 kB
  • sloc: perl: 267; makefile: 2
file content (48 lines) | stat: -rw-r--r-- 1,044 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use strict;
use warnings;

use Test::More;
use JSON::MaybeXS;

my $data = JSON::MaybeXS->new->decode('{"foo": true, "bar": false, "baz": 1}');
diag 'true is: ', explain $data->{foo};
diag 'false is: ', explain $data->{bar};

ok(
    JSON::MaybeXS::is_bool($data->{foo}),
    JSON() . ': true decodes to a bool',
);
ok(
    JSON::MaybeXS::is_bool($data->{bar}),
    JSON() . ': false decodes to a bool',
);
ok(
    !JSON::MaybeXS::is_bool($data->{baz}),
    JSON() . ': int does not decode to a bool',
);

is(
    JSON::MaybeXS::encode_json([JSON::MaybeXS::true]),
    '[true]',
    JSON() . ': true sub encodes as correct boolean',
);

is(
    JSON::MaybeXS::encode_json([JSON::MaybeXS->true]),
    '[true]',
    JSON() . ': true method encodes as correct boolean',
);

is(
    JSON::MaybeXS::encode_json([JSON::MaybeXS::false]),
    '[false]',
    JSON() . ': false sub encodes as correct boolean',
);

is(
    JSON::MaybeXS::encode_json([JSON::MaybeXS->false]),
    '[false]',
    JSON() . ': false method encodes as correct boolean',
);

1;