line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Chai::Core::Assertions::Property; |
2
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
54
|
|
3
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
49
|
|
4
|
2
|
|
|
2
|
|
10
|
use utf8; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
10
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
48
|
use Exporter qw/import/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
111
|
|
7
|
|
|
|
|
|
|
our @EXPORT_OK = qw/assert_property/; |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
11
|
use Test::Chai::Util::Flag qw/flag/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
108
|
|
10
|
2
|
|
|
2
|
|
10
|
use Test::Chai::Util::Equal qw/equal/; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
94
|
|
11
|
2
|
|
|
2
|
|
10
|
use Test::Chai::Util::Inspect qw/inspect/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
112
|
|
12
|
2
|
|
|
2
|
|
388
|
use Test::Chai::Util::PathInfo qw/get_path_info/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
120
|
|
13
|
2
|
|
|
2
|
|
10
|
use Test::Chai::Util::Property qw/has_property/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
882
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub assert_property { |
16
|
47
|
|
|
47
|
0
|
89
|
my ($self, $name, $val, $msg) = @_; |
17
|
|
|
|
|
|
|
|
18
|
47
|
100
|
|
|
|
135
|
flag($self, 'message', $msg) if defined $msg; |
19
|
|
|
|
|
|
|
|
20
|
47
|
100
|
|
|
|
123
|
my $is_deep = flag($self, 'deep') ? 1 : 0; |
21
|
47
|
100
|
|
|
|
117
|
my $descriptor = $is_deep ? 'deep property ' : 'property '; |
22
|
47
|
|
|
|
|
108
|
my $negate = flag($self, 'negate'); |
23
|
47
|
|
|
|
|
110
|
my $obj = flag($self, 'object'); |
24
|
47
|
100
|
|
|
|
149
|
my $path_info = $is_deep ? get_path_info($name, $obj) : undef; |
25
|
47
|
100
|
|
|
|
168
|
my $has_property = $is_deep ? $path_info->{exists} : has_property($name, $obj); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $value = |
28
|
|
|
|
|
|
|
$is_deep ? $path_info->{value} : |
29
|
47
|
50
|
|
|
|
178
|
ref $obj ? $obj->{$name} : |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
30
|
|
|
|
|
|
|
defined $obj ? length $obj : |
31
|
|
|
|
|
|
|
undef; |
32
|
|
|
|
|
|
|
|
33
|
47
|
100
|
100
|
|
|
166
|
if ($negate && @_ - 1 > 1) { |
34
|
4
|
100
|
|
|
|
12
|
unless (defined $value) { |
35
|
1
|
50
|
|
|
|
5
|
$msg = defined $msg ? "$msg: " : ''; |
36
|
1
|
|
|
|
|
5
|
$self->_fail($msg . inspect($obj) . ' has no ' . $descriptor . inspect($name)); |
37
|
1
|
|
|
|
|
1228
|
return; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
else { |
42
|
43
|
|
|
|
|
184
|
$self->assert( |
43
|
|
|
|
|
|
|
$has_property, |
44
|
|
|
|
|
|
|
'expected #{this} to have a ' . $descriptor . inspect($name), |
45
|
|
|
|
|
|
|
'expected #{this} to not have ' . $descriptor . inspect($name) |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
46
|
100
|
|
|
|
40048
|
if (@_ - 1 > 1) { |
50
|
20
|
|
|
|
|
86
|
$self->assert( |
51
|
|
|
|
|
|
|
equal($val, $value), |
52
|
|
|
|
|
|
|
'expected #{this} to have a ' . $descriptor . inspect($name) . ' of #{exp}, but got #{act}', |
53
|
|
|
|
|
|
|
'expected #{this} to not have a ' . $descriptor . inspect($name) . ' of #{act}', |
54
|
|
|
|
|
|
|
$val, |
55
|
|
|
|
|
|
|
$value |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
46
|
|
|
|
|
24843
|
flag($self, 'object', $value); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |