line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Tools::DOM::Check; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
22
|
use v5.20; |
|
2
|
|
|
|
|
14
|
|
4
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
50
|
|
5
|
2
|
|
|
2
|
|
8
|
use experimental 'signatures'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
17
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
185
|
use Test2::Util (); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
30
|
|
8
|
2
|
|
|
2
|
|
526
|
use Mojo::DOM58; |
|
2
|
|
|
|
|
39891
|
|
|
2
|
|
|
|
|
140
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.002'; |
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
861
|
use parent 'Test2::Compare::Base'; |
|
2
|
|
|
|
|
538
|
|
|
2
|
|
|
|
|
10
|
|
13
|
|
|
|
|
|
|
|
14
|
3
|
|
|
3
|
1
|
15
|
sub name { '' } |
15
|
|
|
|
|
|
|
|
16
|
34
|
|
|
34
|
1
|
10174
|
sub verify ( $self, %params ) { !!$params{exists} } |
|
34
|
|
|
|
|
55
|
|
|
34
|
|
|
|
|
74
|
|
|
34
|
|
|
|
|
39
|
|
|
34
|
|
|
|
|
94
|
|
17
|
|
|
|
|
|
|
|
18
|
33
|
|
|
33
|
0
|
714
|
sub init ( $self ) { $self->{calls} = [] } |
|
33
|
|
|
|
|
56
|
|
|
33
|
|
|
|
|
44
|
|
|
33
|
|
|
|
|
74
|
|
19
|
|
|
|
|
|
|
|
20
|
49
|
|
|
49
|
0
|
1061
|
sub add_call ( $self, $method, $check, $args ) { |
|
49
|
|
|
|
|
62
|
|
|
49
|
|
|
|
|
64
|
|
|
49
|
|
|
|
|
53
|
|
|
49
|
|
|
|
|
51
|
|
|
49
|
|
|
|
|
52
|
|
21
|
49
|
|
|
|
|
57
|
push @{ $self->{calls} } => [ $method, $check, $args ]; |
|
49
|
|
|
|
|
218
|
|
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
34
|
|
|
34
|
1
|
179
|
sub deltas ( $self, %params ) { |
|
34
|
|
|
|
|
46
|
|
|
34
|
|
|
|
|
69
|
|
|
34
|
|
|
|
|
38
|
|
25
|
34
|
|
|
|
|
43
|
my @deltas; |
26
|
34
|
|
|
|
|
78
|
my ( $got, $convert, $seen ) = @params{qw( got convert seen )}; |
27
|
|
|
|
|
|
|
|
28
|
34
|
100
|
|
|
|
144
|
$self->{dom} = ref $got eq 'Mojo::DOM58' ? $got : Mojo::DOM58->new($got); |
29
|
|
|
|
|
|
|
|
30
|
34
|
100
|
|
|
|
7079
|
if ( $self->{dom}->type eq 'root' ) { |
31
|
|
|
|
|
|
|
# Keep root in scope. |
32
|
|
|
|
|
|
|
# See https://github.com/mojolicious/mojo/issues/1924 |
33
|
17
|
|
|
|
|
221
|
$self->{root} = $self->{dom}; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# For usability's sake, if we received the root of the DOM, we move |
36
|
|
|
|
|
|
|
# to its first child (if one exists). In the contexts where this |
37
|
|
|
|
|
|
|
# module will be used, this will in most cases be what people expect. |
38
|
17
|
50
|
|
|
|
54
|
if ( my $top = $self->{dom}->children->first ) { |
39
|
17
|
|
|
|
|
1507
|
$self->{dom} = $top; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
34
|
|
|
|
|
242
|
my $dom = $self->{dom}; |
44
|
|
|
|
|
|
|
|
45
|
34
|
|
50
|
|
|
56
|
for my $call (@{ $self->{calls} // [] }) { |
|
34
|
|
|
|
|
94
|
|
46
|
50
|
|
|
|
|
784
|
my ( $name, $args, $check ) = @$call; |
47
|
|
|
|
|
|
|
|
48
|
50
|
|
|
|
|
143
|
$check = $convert->($check); |
49
|
|
|
|
|
|
|
|
50
|
50
|
50
|
|
|
|
4037
|
my $method = $dom->can($name) |
51
|
|
|
|
|
|
|
or Carp::croak "Cannot call $name on an object of type " . ref $dom; |
52
|
|
|
|
|
|
|
|
53
|
50
|
|
|
|
|
68
|
my $value; |
54
|
50
|
|
|
50
|
|
259
|
my ( $ok, $err ) = Test2::Util::try { $value = $dom->$method(@$args) }; |
|
50
|
|
|
|
|
509
|
|
55
|
|
|
|
|
|
|
|
56
|
50
|
50
|
|
|
|
5382
|
if ($ok) { |
57
|
50
|
|
|
|
|
199
|
my %args = ( |
58
|
|
|
|
|
|
|
id => [ METHOD => $name ], |
59
|
|
|
|
|
|
|
seen => $seen, |
60
|
|
|
|
|
|
|
convert => $convert, |
61
|
|
|
|
|
|
|
got => $value, |
62
|
|
|
|
|
|
|
exists => $method, |
63
|
|
|
|
|
|
|
); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Support HTML/XML logic for element attributes |
66
|
50
|
100
|
100
|
|
|
183
|
if ( @$args && $name eq 'attr' ) { |
|
|
100
|
|
|
|
|
|
67
|
14
|
|
|
|
|
31
|
my $exists = exists $dom->attr->{ $args->[0] }; |
68
|
14
|
100
|
|
|
|
178
|
$args{got} = $exists if $check->name =~ /^(?:TRUE|FALSE)$/; |
69
|
14
|
100
|
|
|
|
97
|
$args{exists} = $exists if $check->name =~ /EXIST/; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
# If the element is not found, it does not exist |
72
|
|
|
|
|
|
|
elsif ( $name eq 'at' ) { |
73
|
10
|
100
|
|
|
|
29
|
$args{exists} = defined $value if $check->name =~ /EXIST/; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
50
|
|
|
|
|
327
|
push @deltas => $check->run(%args); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
else { |
79
|
0
|
|
|
|
|
0
|
push @deltas => $check->delta_class->new( |
80
|
|
|
|
|
|
|
id => [ METHOD => $name ], |
81
|
|
|
|
|
|
|
check => $check, |
82
|
|
|
|
|
|
|
exception => $err, |
83
|
|
|
|
|
|
|
got => undef, |
84
|
|
|
|
|
|
|
verified => undef, |
85
|
|
|
|
|
|
|
); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
34
|
|
|
|
|
2068
|
return @deltas; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |