line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Chai::Core::Assertions::Member; |
2
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
54
|
|
3
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
47
|
|
4
|
2
|
|
|
2
|
|
16
|
use utf8; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
11
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
53
|
use Exporter qw/import/; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
113
|
|
7
|
|
|
|
|
|
|
our @EXPORT_OK = qw/assert_member/; |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
11
|
use List::MoreUtils qw/any all/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
38
|
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
1013
|
use Test::Chai::Util::Flag qw/flag/; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
150
|
|
12
|
2
|
|
|
2
|
|
11
|
use Test::Chai::Util::Equal qw/eql/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
810
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub assert_member { |
15
|
18
|
|
|
18
|
0
|
34
|
my ($self, $subset, $msg) = @_; |
16
|
|
|
|
|
|
|
|
17
|
18
|
50
|
|
|
|
59
|
flag($self, 'message', $msg) if defined $msg; |
18
|
18
|
|
|
|
|
45
|
my $obj = flag($self, 'object'); |
19
|
|
|
|
|
|
|
|
20
|
18
|
|
|
|
|
69
|
ref($self)->new($obj)->to->be->an('ArrayRef'); |
21
|
18
|
|
|
|
|
107
|
ref($self)->new($subset)->to->be->an('ArrayRef'); |
22
|
|
|
|
|
|
|
|
23
|
18
|
100
|
|
4
|
|
94
|
my $cmp = flag($self, 'deep') ? sub { eql(@_) } : undef; |
|
4
|
|
|
|
|
15
|
|
24
|
|
|
|
|
|
|
|
25
|
18
|
100
|
|
|
|
53
|
if (flag($self, 'contains')) { |
26
|
4
|
|
|
|
|
16
|
return $self->assert( |
27
|
|
|
|
|
|
|
is_subset_of($subset, $obj, $cmp), |
28
|
|
|
|
|
|
|
'expected #{this} to be a superset of #{act}', |
29
|
|
|
|
|
|
|
'expected #{this} to not be a superset of #{act}', |
30
|
|
|
|
|
|
|
$obj, |
31
|
|
|
|
|
|
|
$subset |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
14
|
|
100
|
|
|
31
|
return $self->assert( |
36
|
|
|
|
|
|
|
is_subset_of($obj, $subset, $cmp) && is_subset_of($subset, $obj, $cmp), |
37
|
|
|
|
|
|
|
'expected #{this} to have the same members as #{act}', |
38
|
|
|
|
|
|
|
'expected #{this} to not have the same members as #{act}', |
39
|
|
|
|
|
|
|
$obj, |
40
|
|
|
|
|
|
|
$subset |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub is_subset_of { |
45
|
25
|
|
|
25
|
0
|
1164
|
my ($subset, $superset, $cmp) = @_; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
return all { |
48
|
42
|
|
|
42
|
|
62
|
my $elem = $_; |
49
|
|
|
|
|
|
|
return $cmp ? |
50
|
4
|
|
|
|
|
12
|
any { $cmp->($elem, $_) } @$superset : |
51
|
42
|
100
|
|
|
|
117
|
grep { $_ eq $elem } @$superset; |
|
82
|
|
|
|
|
260
|
|
52
|
25
|
|
|
|
|
170
|
} @$subset; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |