| 1 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | package Test::Deep::Set 1.205; | ||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Test::Deep::Cmp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | sub init | ||||||||||||||||||||||||||||||||||||||||||
| 9 | 82 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 82 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 82 | $self->{IgnoreDupes} = shift; | |||||||||||||||||||||||||||||||||||||||||
| 13 | 82 | $self->{SubSup} = shift; | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 82 | $self->{val} = []; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 82 | $self->add(@_); | |||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | sub descend | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 90 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
descend: called CC=18 SCAR=28.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 90 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 90 | my $d1 = shift; | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 90 | my $d2 = $self->{val}; | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 90 | my $IgnoreDupes = $self->{IgnoreDupes}; | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 90 | my $data = $self->data; | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 90 | my $SubSup = $self->{SubSup}; | |||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 90 | ▶ | my $type = $IgnoreDupes ? "Set" : "Bag"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 90 | my $diag; | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 90 | ▶ | if (ref $d1 ne 'ARRAY') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | { | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 25 | my $got = Test::Deep::render_val($d1); | |||||||||||||||||||||||||||||||||||||||||
| 40 | 25 | $diag = <<EOM; | |||||||||||||||||||||||||||||||||||||||||
| 41 | got : $got | ||||||||||||||||||||||||||||||||||||||||||
| 42 | expect : An array to use as a $type | ||||||||||||||||||||||||||||||||||||||||||
| 43 | EOM | ||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 90 | ▶ | if (not $diag) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | { | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 65 | my @got = @$d1; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 65 | my @found; | |||||||||||||||||||||||||||||||||||||||||
| 50 | my @missing; | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 65 | foreach my $expect (@$d2) | |||||||||||||||||||||||||||||||||||||||||
| 52 | { | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 178 | my $found = 0; | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 178 | ▶ | for (my $i = $#got; $i >= 0; $i--) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | { | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 400 | ▶ | if (Test::Deep::eq_deeply_cache($got[$i], $expect)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 144 | $found = 1; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 144 | push(@found, $expect); | |||||||||||||||||||||||||||||||||||||||||
| 61 | 144 | splice(@got, $i, 1); | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 144 | ▶ | last unless $IgnoreDupes; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 178 | ▶ | push(@missing, $expect) unless $found; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 65 | my @diags; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 65 | ▶ | if (@missing and $SubSup ne "sub" && $SubSup ne "none") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
@missing and ($SubSup ne "sub" and $SubSup ne "none")
$SubSup ne "sub" and $SubSup ne "none"
MC/DC100%3/3
@missing and ($SubSup ne "sub" and $SubSup ne "none")
@missing
$SubSup ne "sub"
$SubSup ne "none"
Truth table100%4/4
A and B and C
A= @missingB= $SubSup ne "sub"C= $SubSup ne "none"
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 20 | push(@diags, "Missing: ".nice_list(\@missing)); | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 65 | ▶ | if (@got and $SubSup ne "sup" && $SubSup ne "none") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
@got and ($SubSup ne "sup" and $SubSup ne "none")
$SubSup ne "sup" and $SubSup ne "none"
MC/DC100%3/3
@got and ($SubSup ne "sup" and $SubSup ne "none")
@got
$SubSup ne "sup"
$SubSup ne "none"
Truth table100%4/4
A and B and C
A= @gotB= $SubSup ne "sup"C= $SubSup ne "none"
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | { | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 24 | my $got = __PACKAGE__->new($IgnoreDupes, "", @got); | |||||||||||||||||||||||||||||||||||||||||
| 79 | 24 | push(@diags, "Extra: ".nice_list($got->{val})); | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 65 | ▶ | if (@found and $SubSup eq "none") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@found and $SubSup eq "none"
MC/DC100%2/2
@found and $SubSup eq "none"
@found
$SubSup eq "none"
Truth table100%3/3
A and B
A= @foundB= $SubSup eq "none"
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | { | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 2 | my $found = __PACKAGE__->new($IgnoreDupes, "", @found); | |||||||||||||||||||||||||||||||||||||||||
| 85 | 2 | push(@diags, "Extra: ".nice_list($found->{val})); | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 65 | $diag = join("\n", @diags); | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 90 | ▶ | if ($diag) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | { | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 56 | $data->{diag} = $diag; | |||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 56 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | else | ||||||||||||||||||||||||||||||||||||||||||
| 98 | { | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 34 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | sub diagnostics | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 23 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
diagnostics: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 23 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 23 | my ($where, $last) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 23 | ▶ | my $type = $self->{IgnoreDupes} ? "Set" : "Bag"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 23 | ▶ | $type = "Sub$type" if $self->{SubSup} eq "sub"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 23 | ▶ | $type = "Super$type" if $self->{SubSup} eq "sup"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 23 | ▶ | $type = "NoneOf" if $self->{SubSup} eq "none"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 23 | my $error = $last->{diag}; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 23 | my $diag = <<EOM; | |||||||||||||||||||||||||||||||||||||||||
| 115 | Comparing $where as a $type | ||||||||||||||||||||||||||||||||||||||||||
| 116 | $error | ||||||||||||||||||||||||||||||||||||||||||
| 117 | EOM | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 23 | return $diag; | |||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | sub add | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 88 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | # this takes an array. | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | # For each element A of the array, it looks for an element, B, already in | ||||||||||||||||||||||||||||||||||||||||||
| 127 | # the set which are deeply equal to A. If no matching B is found then A is | ||||||||||||||||||||||||||||||||||||||||||
| 128 | # added to the set. If a B is found and IgnoreDupes is true, then A will | ||||||||||||||||||||||||||||||||||||||||||
| 129 | # be discarded, if IgnoreDupes is false, then B will be added to the set | ||||||||||||||||||||||||||||||||||||||||||
| 130 | # again. | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 88 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 88 | my @array = @_; | |||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 88 | my $IgnoreDupes = $self->{IgnoreDupes}; | |||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 88 | my $already = $self->{val}; | |||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 88 | local $Test::Deep::Expects = 1; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 88 | foreach my $new_elem (@array) | |||||||||||||||||||||||||||||||||||||||||
| 142 | { | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 223 | my $want_push = 1; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 223 | my $push_this = $new_elem; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 223 | foreach my $old_elem (@$already) | |||||||||||||||||||||||||||||||||||||||||
| 146 | { | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 225 | ▶ | if (Test::Deep::eq_deeply($new_elem, $old_elem)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | { | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 53 | $push_this = $old_elem; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 53 | $want_push = ! $IgnoreDupes; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 53 | last; | |||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 223 | ▶ | push(@$already, $push_this) if $want_push; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | # so we can compare 2 Test::Deep::Set objects using array comparison | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | 88 | ▶ | @$already = sort {(defined $a ? $a : "") cmp (defined $b ? $b : "")} @$already; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | sub nice_list | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 46 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nice_list: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 46 | my $list = shift; | |||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 46 | my @scalars = grep ! ref $_, @$list; | |||||||||||||||||||||||||||||||||||||||||
| 167 | 46 | my $refs = grep ref $_, @$list; | |||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 46 | ▶ | my @ref_string = "$refs reference" if $refs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 46 | ▶ | $ref_string[0] .= "s" if $refs > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | # sort them so we can predict the diagnostic output | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | return join(", ", | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 46 | ▶ | (map {Test::Deep::render_val($_)} sort {(defined $a ? $a : "") cmp (defined $b ? $b : "")} @scalars), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | @ref_string | ||||||||||||||||||||||||||||||||||||||||||
| 177 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | sub compare | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 14 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compare: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 14 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 14 | my $other = shift; | |||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 14 | ▶ | return 0 if $self->{IgnoreDupes} != $other->{IgnoreDupes}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | # this works (kind of) because the arrays are sorted | ||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | 14 | return Test::Deep::descend($self->{val}, $other->{val}); | |||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | __END__ | ||||||||||||||||||||||||||||||||||||||||||