blib/lib/Test2/Compare/OrderedSubset.pm

filter: Statementstmt 100% 60 / 60 Branchbran 95.0% 19 / 20 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 11 / 11 Podpod 80.0% 4 / 5 totaltotal 97.9% 97 / 99 CC 13 SCAR 12.8
CC
13
Cov
99%
init
5.0
verify
5.0
deltas
5.0
CRAP 3.6
« blib/lib/Test2/API/Stack.pm ↑ Summary blib/lib/Test2/Util/ExternalMeta.pm »
1 package Test2::Compare::OrderedSubset;
2 176 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 176 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 176 ▶use base 'Test2::Compare::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 176 our $VERSION = '1.302226';
8  
9 176 ▶use Test2::Util::HashBase qw/inref items/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 176 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 176 ▶use Scalar::Util qw/reftype/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 38 ▶sub init {
Subroutine init: called CC=5 SCAR=16.1
Pod undocumented
15 38 my $self = shift;
16  
17 38 ▶ if(my $ref = $self->{+INREF}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ref = $self->{"inref"}) 3 35 38
18 3 ▶ croak "Cannot specify both 'inref' and 'items'" if $self->{+ITEMS};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"items"} 0 3 3
19 3 ▶ croak "'inref' must be an array reference, got '$ref'" unless reftype($ref) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::reftype($ref) eq "ARRAY" 1 2 3
20 2 $self->{+ITEMS} = [@{$self->{+INREF}}];
21 }
22  
23 37 ▶ $self->{+ITEMS} ||= [];
Condition100%2/2
$self->{"items"} ||= []
l!l
334
MC/DC100%1/1
$self->{"items"} ||= []
$self->{"items"}
Truth table100%2/2
A
A= $self->{"items"}
Aresult
11
00
24  
25 37 $self->SUPER::init();
26 }
27  
28 1 ▶sub name { '<ORDERED SUBSET>' }
Subroutine name: called CC=1 SCAR=0.0
Pod documented
29  
30 38 ▶sub verify {
Subroutine verify: called CC=5 SCAR=16.1
Pod documented
31 38 my $self = shift;
32 38 my %params = @_;
33  
34 38 ▶ return 0 unless $params{exists};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"exists"} 1 37 38
35 37 ▶ defined( my $got = $params{got} ) || return 0;
Branch: 1 branch
BranchTrueFalseTotal
defined(my $got = $params{"got"}) or return 0 36 1 37
36 36 ▶ return 0 unless ref($got);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $got 3 33 36
37 33 ▶ return 0 unless reftype($got) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::reftype($got) eq "ARRAY" 1 32 33
38 32 return 1;
39 }
40  
41 53 ▶sub add_item {
Subroutine add_item: called CC=1 SCAR=0.0
Pod documented
42 53 my $self = shift;
43 53 my $check = pop;
44  
45 53 push @{$self->{+ITEMS}} => $check;
46 }
47  
48 35 ▶sub deltas {
Subroutine deltas: called CC=5 SCAR=16.1
Pod documented
49 35 my $self = shift;
50 35 my %params = @_;
51 35 my ($got, $convert, $seen) = @params{qw/got convert seen/};
52  
53 35 my @deltas;
54 35 my $state = 0;
55 35 my $items = $self->{+ITEMS};
56  
57 35 my $idx = 0;
58  
59 35 for my $item (@$items) {
60 56 my $check = $convert->($item);
61  
62 56 my $i = $idx;
63 56 my $found;
64 56 ▶ while($i < @$got) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$got) 57 2 59
65 57 my $val = $got->[$i++];
66 57 ▶ next if $check->run(
Branch: 1 branch
BranchTrueFalseTotal
if $check->run("id", ["ARRAY", $i], "convert", $convert, "seen", $seen, "exists", 1, "got", $val) 3 54 57
67 id => [ARRAY => $i],
68 convert => $convert,
69 seen => $seen,
70 exists => 1,
71 got => $val,
72 );
73  
74 54 $idx = $i;
75 54 $found++;
76 54 last;
77 }
78  
79 56 ▶ next if $found;
Branch: 1 branch
BranchTrueFalseTotal
if $found 54 2 56
80  
81 2 push @deltas => Test2::Compare::Delta->new(
82 verified => 0,
83 id => ['ARRAY', '?'],
84 check => $check,
85 dne => 'got',
86 );
87 }
88  
89 35 return @deltas;
90 }
91  
92 176 1;
93  
94 __END__
« blib/lib/Test2/API/Stack.pm ↑ Summary blib/lib/Test2/Util/ExternalMeta.pm »