Debian Codegraph @

t/unit/Test2/Harness/Util/JSON.t

raw
1 use Test2::Bundle::Extended -target => 'Test2::Harness::Util::JSON';
2 # HARNESS-DURATION-SHORT
3
4 use ok $CLASS;
5
6 imported_ok(qw{
7 JSON
8 encode_json decode_json
9 encode_pretty_json encode_canon_json
10 });
11
12 ok(JSON(), "Have JSON constant");
13
14 can_ok(JSON(), ['new'], "JSON returns a class (" . JSON() . ")");
15
16 my $struct = { a => 1, b => 2 };
17 for my $encode_name (qw/encode_json encode_pretty_json encode_canon_json/) {
18 is(
19 decode_json(__PACKAGE__->can($encode_name)->($struct)),
20 $struct,
21 "Round Trip $encode_name+decode"
22 );
23
24 is(
25 decode_json(__PACKAGE__->can($encode_name)->(undef)),
26 undef,
27 "undef/null round-trip $encode_name+decode"
28 );
29 }
30
31 done_testing;