line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Chai::Core::Assertions::Include; |
2
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
54
|
|
3
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
53
|
|
4
|
2
|
|
|
2
|
|
11
|
use utf8; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
15
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
49
|
use Exporter qw/import/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
114
|
|
7
|
|
|
|
|
|
|
our @EXPORT_OK = qw/ |
8
|
|
|
|
|
|
|
assert_include |
9
|
|
|
|
|
|
|
assert_include_chaining_behavior |
10
|
|
|
|
|
|
|
/; |
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
822
|
use List::MoreUtils qw/any/; |
|
2
|
|
|
|
|
11256
|
|
|
2
|
|
|
|
|
16
|
|
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
1219
|
use Test::Chai::Util::Flag qw/flag/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
115
|
|
15
|
2
|
|
|
2
|
|
437
|
use Test::Chai::Util::Equal qw/eql/; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
114
|
|
16
|
2
|
|
|
2
|
|
11
|
use Test::Chai::Util::Type qw/is_type/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
99
|
|
17
|
2
|
|
|
2
|
|
12
|
use Test::Chai::Util::Inspect qw/inspect/; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
1591
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub assert_include { |
20
|
26
|
|
|
26
|
0
|
52
|
my ($self, $val, $msg) = @_; |
21
|
|
|
|
|
|
|
|
22
|
26
|
|
|
|
|
59
|
my $obj = flag($self, 'object'); |
23
|
26
|
|
|
|
|
104
|
expect_types($self, $obj, [ qw/ArrayRef HashRef Value/ ]); |
24
|
|
|
|
|
|
|
|
25
|
26
|
100
|
|
|
|
2649
|
flag($self, 'message', $msg) if defined $msg; |
26
|
26
|
|
|
|
|
48
|
my $expected = 0; |
27
|
|
|
|
|
|
|
|
28
|
26
|
100
|
100
|
|
|
181
|
if (ref $obj eq 'ARRAY' && ref $val eq 'HASH') { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
29
|
4
|
|
|
|
|
17
|
for (my $i = 0; $i < @$obj; ++$i) { |
30
|
5
|
100
|
|
|
|
676
|
if (eql($obj->[$i], $val)) { |
31
|
3
|
|
|
|
|
2905
|
$expected = 1; |
32
|
3
|
|
|
|
|
7
|
last; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
elsif (ref $val eq 'HASH') { |
38
|
6
|
100
|
|
|
|
20
|
if (!flag($self, 'negate')) { |
39
|
3
|
|
|
|
|
12
|
for my $k (keys %$val) { |
40
|
4
|
|
|
|
|
20
|
ref($self)->new($obj)->property($k, $val->{$k}); |
41
|
|
|
|
|
|
|
} |
42
|
3
|
|
|
|
|
13
|
return; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
3
|
|
|
|
|
9
|
my $subset = {}; |
46
|
3
|
|
|
|
|
12
|
for my $k (keys $val) { |
47
|
4
|
|
|
|
|
14
|
$subset->{$k} = $obj->{$k}; |
48
|
|
|
|
|
|
|
} |
49
|
3
|
|
|
|
|
15
|
$expected = eql($subset, $val); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
elsif (ref $obj eq 'ARRAY') { |
53
|
8
|
|
|
|
|
16
|
$expected = grep { $_ eq $val } @$obj; |
|
15
|
|
|
|
|
44
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
elsif (ref $obj eq 'HASH') { |
57
|
2
|
|
|
|
|
8
|
$expected = grep { $_ eq $val } values %$obj; |
|
4
|
|
|
|
|
16
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
else { |
61
|
6
|
|
100
|
|
|
32
|
$expected = defined $obj && index($obj, $val) > -1; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
23
|
|
|
|
|
4258
|
return $self->assert( |
65
|
|
|
|
|
|
|
$expected, |
66
|
|
|
|
|
|
|
'expected #{this} to include ' . inspect($val), |
67
|
|
|
|
|
|
|
'expected #{this} to not include ' . inspect($val) |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub assert_include_chaining_behavior { |
72
|
56
|
|
|
56
|
0
|
174
|
flag(shift, 'contains', 1); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub expect_types { |
76
|
26
|
|
|
26
|
0
|
53
|
my ($self, $obj, $types) = @_; |
77
|
|
|
|
|
|
|
|
78
|
26
|
|
|
|
|
54
|
for my $expected (@$types) { |
79
|
46
|
100
|
|
|
|
134
|
return if is_type($obj, $expected); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
2
|
|
|
|
|
5
|
$types = [ sort map { lc $_ } @$types ]; |
|
6
|
|
|
|
|
20
|
|
83
|
|
|
|
|
|
|
|
84
|
2
|
|
|
|
|
4
|
my @strs; |
85
|
2
|
|
|
|
|
7
|
for (my $index = 0; $index < @$types; ++$index) { |
86
|
6
|
|
|
|
|
12
|
my $t = $types->[$index]; |
87
|
|
|
|
|
|
|
|
88
|
6
|
100
|
|
|
|
10
|
my $art = (grep { $_ eq substr($t, 0, 1) } qw/a e i o u/) ? 'an' : 'a'; |
|
30
|
|
|
|
|
62
|
|
89
|
6
|
100
|
66
|
|
|
31
|
my $or = @$types > 1 && $index == @$types - 1 ? 'or ' : ''; |
90
|
|
|
|
|
|
|
|
91
|
6
|
|
|
|
|
23
|
push @strs, $or . $art . ' ' . $t; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
2
|
|
|
|
|
6
|
my $str = join(', ', @strs); |
95
|
2
|
|
|
|
|
8
|
$self->_fail('object tested must be ' . $str . ', but ' . inspect($obj) . ' given'); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |