File Coverage

File:t/05-o2h.t
Coverage:100.0%

linestmtbrancondsubpodtimecode
1
1
1
1
4243
3
36
use strict;
2
1
1
1
5
2
55
use warnings;
3
4
1
1
1
481
112181
9
use Test::More q//;
5
1
1
1
735
3600
6
use Test::Exception q//;
6
1
1
1
816
2
96
use Util::H2O::More qw/h2o o2h/;
7
8# for included module required for testing
9
1
1
1
390
1440
146
use FindBin qw/$Bin/;
10
1
1
1
370
829
7
use lib qq{$Bin/lib};
11
1
1
1
421
3
2016
use Foo;
12
13
1
95266
my $origin_ref = {
14    somewhere => q{over},
15    the       => { rainbow => { way => { out => q{there} } } },
16};
17
18
1
3
my $ref = {
19    somewhere => q{over},
20    the       => { rainbow => { way => { out => q{there} } } },
21};
22
23
1
3
h2o $ref;
24
25
1
139
is_deeply o2h($ref), $origin_ref, q{'o2h' does inverse of h2o};
26
1
1423
is ref o2h($ref), q{HASH}, q{making sure test ref really is just a 'HASH'};
27
28
1
331
my $ref2 = o2h $ref;
29
30
1
5
h2o -recurse, $ref2;
31
1
445
is_deeply o2h($ref2), $origin_ref, q{'o2h' does inverse of 'h2o --recurse'};
32
33
1
1243
my $ref3 = o2h $ref2;
34
35# composing h2o/o2h in one line
36
1
2
is_deeply o2h(h2o $ref3), $origin_ref, q{'o2h' does inverse of 'h2o --recurse'};
37
38
1
1182
my $foo = Foo->new(a => 1);
39
1
3
is ref o2h($foo), q{HASH}, q{'o2h' works on baptised module-based object};
40
41
1
326
my $_foo = {
42    somewhere => q{over},
43    the       => { rainbow => { way => { out => q{there} } } },
44};
45
46
1
5
my $foo2 = o2h(Foo->new(%$_foo));
47
48
1
9
is_deeply $foo2, $_foo, q{'o2h' does invere of a package built with 'baptise -recurse'};
49
50# Util::H2O::o2h returns non-H2O references unchanged. The wrapper in
51# Util::H2O::More intentionally requires the top-level result to be a HASH.
52
1
1
1269
35
dies_ok { o2h [] } q{'o2h' rejects a top-level reference that cannot be converted to a HASH};
53
54
1
303
done_testing;