Deep/HashKeysOnly.pm

filter: Statementstmt 96.4% 54 / 56 Branchbran 91.6% 11 / 12 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 86.6% 13 / 15 Podpod 0.0% 0 / 6 totaltotal 88.8% 88 / 99 CC 9 SCAR 12.8
CC
9
Cov
96%
descend
8.0
diagnostics
2.0
ignoreMissing
2.0
CRAP 3.6
« Deep/RegexpRef.pm ↑ Summary Deep/Regexp.pm »
1 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Test::Deep::HashKeysOnly 1.205;
5  
6 6 ▶use Test::Deep::Ref;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 sub init
9 21 ▶{
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
10 21 my $self = shift;
11  
12 21 my %keys;
13 21 @keys{@_} = ();
14 21 $self->{val} = \%keys;
15 21 $self->{keys} = [sort @_];
16 }
17  
18 sub descend
19 21 ▶{
Subroutine descend: called CC=8 SCAR=20.8
Pod undocumented
20 21 my $self = shift;
21 21 my $hash = shift;
22  
23 21 my $data = $self->data;
24 21 my $exp = $self->{val};
25 21 my %got;
26 21 @got{keys %$hash} = ();
27  
28 21 my @missing;
29 my @extra;
30  
31 21 ▶ while (my ($key, $value) = each %$exp)
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$exp) 25 21 46
32 {
33 25 ▶ if (exists $got{$key})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $got{$key}) { } 22 3 25
34 {
35 22 delete $got{$key};
36 }
37 else
38 {
39 3 push(@missing, $key);
40 }
41 }
42  
43 21 my @diags;
44 21 ▶ if (@missing and (not $self->ignoreMissing))
Branch: 1 branch
BranchTrueFalseTotal
if (@missing and not $self->ignoreMissing) 2 19 21
Condition100%3/3
@missing and not $self->ignoreMissing
!ll&&!rl&&r
1812
MC/DC100%2/2
@missing and not $self->ignoreMissing
@missing not $self->ignoreMissing
Truth table100%3/3
A and not(B)
A= @missingB= not $self->ignoreMissing
ABresult
0X0
100
111
45 {
46 2 push(@diags, "Missing: ".nice_list(\@missing));
47 }
48  
49 21 ▶ if (%got and (not $self->ignoreExtra))
Branch: 1 branch
BranchTrueFalseTotal
if (%got and not $self->ignoreExtra) 2 19 21
Condition100%3/3
%got and not $self->ignoreExtra
!ll&&!rl&&r
1812
MC/DC100%2/2
%got and not $self->ignoreExtra
%got not $self->ignoreExtra
Truth table100%3/3
A and not(B)
A= %gotB= not $self->ignoreExtra
ABresult
0X0
100
111
50 {
51 2 push(@diags, "Extra: ".nice_list([keys %got]));
52 }
53  
54 21 ▶ if (@diags)
Branch: 1 branch
BranchTrueFalseTotal
if (@diags) 3 18 21
55 {
56 3 $data->{diag} = join("\n", @diags);
57 3 return 0;
58 }
59  
60 18 return 1;
61 }
62  
63 sub diagnostics
64 3 ▶{
Subroutine diagnostics: called CC=2 SCAR=7.0
Pod undocumented
65 3 my $self = shift;
66 3 my ($where, $last) = @_;
67  
68 3 ▶ my $type = $self->{IgnoreDupes} ? "Set" : "Bag";
Branch: 1 branch
BranchTrueFalseTotal
$self->{'IgnoreDupes'} ? : 0 3 3
69  
70 3 my $error = $last->{diag};
71 3 my $diag = <<EOM;
72 Comparing hash keys of $where
73 $error
74 EOM
75  
76 3 return $diag;
77 }
78  
79 sub nice_list
80 4 ▶{
Subroutine nice_list: called CC=1 SCAR=0.0
Pod undocumented
81 4 my $list = shift;
82  
83 return join(", ",
84 4 (map {"'$_'"} sort @$list),
85 );
86 }
87  
88 sub ignoreMissing
89 2 ▶{
Subroutine ignoreMissing: called CC=1 SCAR=0.0
Pod undocumented
90 2 return 0;
91 }
92  
93 sub ignoreExtra
94 2 ▶{
Subroutine ignoreExtra: called CC=1 SCAR=0.0
Pod undocumented
95 2 return 0;
96 }
97  
98 package Test::Deep::SuperHashKeysOnly 1.205;
99  
100 6 ▶use base 'Test::Deep::HashKeysOnly';
Subroutine BEGIN: called CC=1 SCAR=0.0
101  
102 sub ignoreMissing
103 0 ▶{
Subroutine ignoreMissing: not called CC=1 SCAR=6.9
104 0 return 0;
105 }
106  
107 sub ignoreExtra
108 1 ▶{
Subroutine ignoreExtra: called CC=1 SCAR=0.0
109 1 return 1;
110 }
111  
112 package Test::Deep::SubHashKeysOnly 1.205;
113  
114 6 ▶use base 'Test::Deep::HashKeysOnly';
Subroutine BEGIN: called CC=1 SCAR=0.0
115  
116 sub ignoreMissing
117 1 ▶{
Subroutine ignoreMissing: called CC=1 SCAR=0.0
118 1 return 1;
119 }
120  
121 sub ignoreExtra
122 0 ▶{
Subroutine ignoreExtra: not called CC=1 SCAR=6.9
123 0 return 0;
124 }
125  
126 6 1;
127  
128 __END__
« Deep/RegexpRef.pm ↑ Summary Deep/Regexp.pm »