line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Tools::DOM::Check; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
21
|
use v5.20; |
|
2
|
|
|
|
|
10
|
|
4
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
55
|
|
5
|
2
|
|
|
2
|
|
9
|
use experimental 'signatures'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
8
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
174
|
use Test2::Util (); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
27
|
|
8
|
2
|
|
|
2
|
|
499
|
use Mojo::DOM58; |
|
2
|
|
|
|
|
37368
|
|
|
2
|
|
|
|
|
102
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.003'; |
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
708
|
use parent 'Test2::Compare::Base'; |
|
2
|
|
|
|
|
470
|
|
|
2
|
|
|
|
|
9
|
|
13
|
|
|
|
|
|
|
|
14
|
3
|
|
|
3
|
1
|
13
|
sub name { '' } |
15
|
|
|
|
|
|
|
|
16
|
34
|
|
|
34
|
1
|
9293
|
sub verify ( $self, %params ) { !!$params{exists} } |
|
34
|
|
|
|
|
54
|
|
|
34
|
|
|
|
|
64
|
|
|
34
|
|
|
|
|
35
|
|
|
34
|
|
|
|
|
88
|
|
17
|
|
|
|
|
|
|
|
18
|
33
|
|
|
33
|
0
|
610
|
sub init ( $self ) { $self->{calls} = [] } |
|
33
|
|
|
|
|
45
|
|
|
33
|
|
|
|
|
37
|
|
|
33
|
|
|
|
|
97
|
|
19
|
|
|
|
|
|
|
|
20
|
49
|
|
|
49
|
0
|
881
|
sub add_call ( $self, $method, $check, $args ) { |
|
49
|
|
|
|
|
58
|
|
|
49
|
|
|
|
|
50
|
|
|
49
|
|
|
|
|
51
|
|
|
49
|
|
|
|
|
50
|
|
|
49
|
|
|
|
|
50
|
|
21
|
49
|
|
|
|
|
50
|
push @{ $self->{calls} } => [ $method, $check, $args ]; |
|
49
|
|
|
|
|
151
|
|
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
34
|
|
|
34
|
1
|
153
|
sub deltas ( $self, %params ) { |
|
34
|
|
|
|
|
43
|
|
|
34
|
|
|
|
|
60
|
|
|
34
|
|
|
|
|
39
|
|
25
|
34
|
|
|
|
|
38
|
my @deltas; |
26
|
34
|
|
|
|
|
66
|
my ( $got, $convert, $seen ) = @params{qw( got convert seen )}; |
27
|
|
|
|
|
|
|
|
28
|
34
|
100
|
|
|
|
99
|
$self->{dom} = ref $got eq 'Mojo::DOM58' ? $got : Mojo::DOM58->new($got); |
29
|
|
|
|
|
|
|
|
30
|
34
|
100
|
|
|
|
6442
|
if ( $self->{dom}->type eq 'root' ) { |
31
|
|
|
|
|
|
|
# Keep root in scope. |
32
|
|
|
|
|
|
|
# See https://github.com/mojolicious/mojo/issues/1924 |
33
|
17
|
|
|
|
|
179
|
$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
|
|
|
|
34
|
if ( my $top = $self->{dom}->children->first ) { |
39
|
17
|
|
|
|
|
1256
|
$self->{dom} = $top; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
34
|
|
|
|
|
240
|
my $dom = $self->{dom}; |
44
|
|
|
|
|
|
|
|
45
|
34
|
|
50
|
|
|
41
|
for my $call (@{ $self->{calls} // [] }) { |
|
34
|
|
|
|
|
84
|
|
46
|
50
|
|
|
|
|
690
|
my ( $name, $args, $check ) = @$call; |
47
|
|
|
|
|
|
|
|
48
|
50
|
|
|
|
|
93
|
$check = $convert->($check); |
49
|
|
|
|
|
|
|
|
50
|
50
|
50
|
|
|
|
3697
|
my $method = $dom->can($name) |
51
|
|
|
|
|
|
|
or Carp::croak "Cannot call $name on an object of type " . ref $dom; |
52
|
|
|
|
|
|
|
|
53
|
50
|
|
|
|
|
78
|
my $value; |
54
|
50
|
|
|
50
|
|
204
|
my ( $ok, $err ) = Test2::Util::try { $value = $dom->$method(@$args) }; |
|
50
|
|
|
|
|
473
|
|
55
|
|
|
|
|
|
|
|
56
|
50
|
50
|
|
|
|
4872
|
if ($ok) { |
57
|
50
|
|
|
|
|
180
|
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
|
|
|
176
|
if ( @$args && $name eq 'attr' ) { |
|
|
100
|
|
|
|
|
|
67
|
14
|
|
|
|
|
27
|
my $exists = exists $dom->attr->{ $args->[0] }; |
68
|
14
|
100
|
|
|
|
171
|
$args{got} = $exists if $check->name =~ /^(?:TRUE|FALSE)$/; |
69
|
14
|
100
|
|
|
|
91
|
$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
|
|
|
|
27
|
$args{exists} = defined $value if $check->name =~ /EXIST/; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
50
|
|
|
|
|
262
|
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
|
|
|
|
|
1937
|
return @deltas; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |