line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::XML::Loy; |
2
|
1
|
|
|
1
|
|
1233
|
use Mojo::Base -base; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
3
|
1
|
|
|
1
|
|
155
|
use Mojo::Util 'encode'; |
|
1
|
|
|
|
|
15
|
|
|
1
|
|
|
|
|
45
|
|
4
|
1
|
|
|
1
|
|
25
|
use XML::Loy; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
5
|
1
|
|
|
1
|
|
5
|
use Test::More; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has [qw!loy success!]; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# Constructor |
10
|
|
|
|
|
|
|
sub new { |
11
|
3
|
|
|
3
|
1
|
711
|
my $self = shift->SUPER::new; |
12
|
3
|
|
|
|
|
24
|
$self->loy(XML::Loy->new(shift)); |
13
|
3
|
|
|
|
|
42
|
return $self |
14
|
|
|
|
|
|
|
}; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Check for exact attribute match |
18
|
|
|
|
|
|
|
sub attr_is { |
19
|
5
|
|
|
5
|
1
|
1158
|
my ($self, $selector, $attr, $value, $desc) = @_; |
20
|
5
|
|
|
|
|
16
|
$desc = _desc( |
21
|
|
|
|
|
|
|
$desc, |
22
|
|
|
|
|
|
|
qq{exact match for attribute "$attr" at selector "$selector"} |
23
|
|
|
|
|
|
|
); |
24
|
5
|
|
|
|
|
228
|
return $self->_test( |
25
|
|
|
|
|
|
|
'is', $self->_attr($selector, $attr), $value, $desc |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
}; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# Check for attribute mismatch |
31
|
|
|
|
|
|
|
sub attr_isnt { |
32
|
1
|
|
|
1
|
1
|
590
|
my ($self, $selector, $attr, $value, $desc) = @_; |
33
|
1
|
|
|
|
|
5
|
$desc = _desc( |
34
|
|
|
|
|
|
|
$desc, |
35
|
|
|
|
|
|
|
qq{no match for attribute "$attr" at selector "$selector"} |
36
|
|
|
|
|
|
|
); |
37
|
1
|
|
|
|
|
12
|
return $self->_test( |
38
|
|
|
|
|
|
|
'isnt', $self->_attr($selector, $attr), $value, $desc |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Check for attribute similarity |
44
|
|
|
|
|
|
|
sub attr_like { |
45
|
1
|
|
|
1
|
1
|
558
|
my ($self, $selector, $attr, $regex, $desc) = @_; |
46
|
1
|
|
|
|
|
5
|
$desc = _desc( |
47
|
|
|
|
|
|
|
$desc, |
48
|
|
|
|
|
|
|
qq{similar match for attribute "$attr" at selector "$selector"} |
49
|
|
|
|
|
|
|
); |
50
|
1
|
|
|
|
|
11
|
return $self->_test( |
51
|
|
|
|
|
|
|
'like', $self->_attr($selector, $attr), $regex, $desc |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
}; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Check for attribute dissimilarity |
57
|
|
|
|
|
|
|
sub attr_unlike { |
58
|
1
|
|
|
1
|
1
|
610
|
my ($self, $selector, $attr, $regex, $desc) = @_; |
59
|
1
|
|
|
|
|
5
|
$desc = _desc( |
60
|
|
|
|
|
|
|
$desc, |
61
|
|
|
|
|
|
|
qq{no similar match for attribute "$attr" at selector "$selector"} |
62
|
|
|
|
|
|
|
); |
63
|
1
|
|
|
|
|
16
|
return $self->_test( |
64
|
|
|
|
|
|
|
'unlike', |
65
|
|
|
|
|
|
|
$self->_attr($selector, $attr), $regex, $desc |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
}; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# Check for plain text match |
71
|
|
|
|
|
|
|
sub content_is { |
72
|
1
|
|
|
1
|
1
|
573
|
my ($self, $value, $desc) = @_; |
73
|
1
|
|
|
|
|
4
|
return $self->_test( |
74
|
|
|
|
|
|
|
'is', |
75
|
|
|
|
|
|
|
$self->_loy_text, |
76
|
|
|
|
|
|
|
$value, |
77
|
|
|
|
|
|
|
_desc($desc, 'exact match for content') |
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
}; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# Check for plain text mismatch |
83
|
|
|
|
|
|
|
sub content_isnt { |
84
|
1
|
|
|
1
|
1
|
536
|
my ($self, $value, $desc) = @_; |
85
|
1
|
|
|
|
|
4
|
return $self->_test( |
86
|
|
|
|
|
|
|
'isnt', |
87
|
|
|
|
|
|
|
$self->_loy_text, |
88
|
|
|
|
|
|
|
$value, |
89
|
|
|
|
|
|
|
_desc($desc, 'no match for content') |
90
|
|
|
|
|
|
|
); |
91
|
|
|
|
|
|
|
}; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# Check for plain text similarity |
95
|
|
|
|
|
|
|
sub content_like { |
96
|
1
|
|
|
1
|
1
|
556
|
my ($self, $regex, $desc) = @_; |
97
|
1
|
|
|
|
|
2
|
return $self->_test( |
98
|
|
|
|
|
|
|
'like', |
99
|
|
|
|
|
|
|
$self->_loy_text, |
100
|
|
|
|
|
|
|
$regex, |
101
|
|
|
|
|
|
|
_desc($desc, 'content is similar') |
102
|
|
|
|
|
|
|
); |
103
|
|
|
|
|
|
|
}; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# Check for plain text dissimilarity |
107
|
|
|
|
|
|
|
sub content_unlike { |
108
|
1
|
|
|
1
|
1
|
547
|
my ($self, $regex, $desc) = @_; |
109
|
1
|
|
|
|
|
4
|
return $self->_test( |
110
|
|
|
|
|
|
|
'unlike', |
111
|
|
|
|
|
|
|
$self->_loy_text, |
112
|
|
|
|
|
|
|
$regex, |
113
|
|
|
|
|
|
|
_desc($desc, 'content is not similar') |
114
|
|
|
|
|
|
|
); |
115
|
|
|
|
|
|
|
}; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# Test for element occurrences |
119
|
|
|
|
|
|
|
sub element_count_is { |
120
|
2
|
|
|
2
|
1
|
1095
|
my ($self, $selector, $count, $desc) = @_; |
121
|
2
|
|
|
|
|
6
|
my $size = $self->loy->find($selector)->size; |
122
|
2
|
|
|
|
|
83
|
return $self->_test( |
123
|
|
|
|
|
|
|
'is', |
124
|
|
|
|
|
|
|
$size, |
125
|
|
|
|
|
|
|
$count, |
126
|
|
|
|
|
|
|
_desc($desc, qq{element count for selector "$selector"}) |
127
|
|
|
|
|
|
|
); |
128
|
|
|
|
|
|
|
}; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# Test for element existence |
132
|
|
|
|
|
|
|
sub element_exists { |
133
|
1
|
|
|
1
|
1
|
544
|
my ($self, $selector, $desc) = @_; |
134
|
1
|
|
|
|
|
5
|
$desc = _desc( |
135
|
|
|
|
|
|
|
$desc, |
136
|
|
|
|
|
|
|
qq{element for selector "$selector" exists} |
137
|
|
|
|
|
|
|
); |
138
|
1
|
|
|
|
|
11
|
return $self->_test( |
139
|
|
|
|
|
|
|
'ok', |
140
|
|
|
|
|
|
|
$self->loy->at($selector), |
141
|
|
|
|
|
|
|
$desc |
142
|
|
|
|
|
|
|
); |
143
|
|
|
|
|
|
|
}; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
# Test for missing element |
147
|
|
|
|
|
|
|
sub element_exists_not { |
148
|
1
|
|
|
1
|
1
|
305
|
my ($self, $selector, $desc) = @_; |
149
|
1
|
|
|
|
|
5
|
$desc = _desc( |
150
|
|
|
|
|
|
|
$desc, |
151
|
|
|
|
|
|
|
qq{no element for selector "$selector"} |
152
|
|
|
|
|
|
|
); |
153
|
1
|
|
|
|
|
24
|
return $self->_test( |
154
|
|
|
|
|
|
|
'ok', |
155
|
|
|
|
|
|
|
!$self->loy->at($selector), |
156
|
|
|
|
|
|
|
$desc |
157
|
|
|
|
|
|
|
); |
158
|
|
|
|
|
|
|
}; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
# Test for exact pcdata match |
162
|
|
|
|
|
|
|
sub text_is { |
163
|
5
|
|
|
5
|
1
|
2678
|
my ($self, $selector, $value, $desc) = @_; |
164
|
5
|
|
|
|
|
12
|
return $self->_test( |
165
|
|
|
|
|
|
|
'is', |
166
|
|
|
|
|
|
|
$self->_text($selector), |
167
|
|
|
|
|
|
|
$value, |
168
|
|
|
|
|
|
|
_desc($desc, qq{exact match for selector "$selector"}) |
169
|
|
|
|
|
|
|
); |
170
|
|
|
|
|
|
|
}; |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# Test for pcdata mismatch |
174
|
|
|
|
|
|
|
sub text_isnt { |
175
|
3
|
|
|
3
|
1
|
1596
|
my ($self, $selector, $value, $desc) = @_; |
176
|
3
|
|
|
|
|
9
|
return $self->_test( |
177
|
|
|
|
|
|
|
'isnt', |
178
|
|
|
|
|
|
|
$self->_text($selector), |
179
|
|
|
|
|
|
|
$value, |
180
|
|
|
|
|
|
|
_desc($desc, qq{no match for selector "$selector"}) |
181
|
|
|
|
|
|
|
); |
182
|
|
|
|
|
|
|
}; |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
# Test for pcdata similarity |
186
|
|
|
|
|
|
|
sub text_like { |
187
|
3
|
|
|
3
|
1
|
1566
|
my ($self, $selector, $regex, $desc) = @_; |
188
|
3
|
|
|
|
|
9
|
return $self->_test( |
189
|
|
|
|
|
|
|
'like', |
190
|
|
|
|
|
|
|
$self->_text($selector), |
191
|
|
|
|
|
|
|
$regex, |
192
|
|
|
|
|
|
|
_desc($desc, qq{similar match for selector "$selector"}) |
193
|
|
|
|
|
|
|
); |
194
|
|
|
|
|
|
|
}; |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
# Test for pcdata dissimilarity |
198
|
|
|
|
|
|
|
sub text_unlike { |
199
|
3
|
|
|
3
|
1
|
1602
|
my ($self, $selector, $regex, $desc) = @_; |
200
|
3
|
|
|
|
|
9
|
return $self->_test( |
201
|
|
|
|
|
|
|
'unlike', |
202
|
|
|
|
|
|
|
$self->_text($selector), |
203
|
|
|
|
|
|
|
$regex, |
204
|
|
|
|
|
|
|
_desc($desc, qq{no similar match for selector "$selector"}) |
205
|
|
|
|
|
|
|
); |
206
|
|
|
|
|
|
|
}; |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
sub _desc { |
210
|
30
|
|
33
|
30
|
|
608
|
encode 'UTF-8', shift || shift; |
211
|
|
|
|
|
|
|
}; |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
sub _attr { |
215
|
8
|
|
|
8
|
|
17
|
my ($self, $selector, $attr) = @_; |
216
|
8
|
50
|
|
|
|
17
|
return '' unless my $e = $self->loy->at($selector); |
217
|
8
|
|
50
|
|
|
230
|
return $e->attr($attr) || ''; |
218
|
|
|
|
|
|
|
}; |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
sub _test { |
222
|
30
|
|
|
30
|
|
733
|
my ($self, $name, @args) = @_; |
223
|
30
|
|
|
|
|
60
|
local $Test::Builder::Level = $Test::Builder::Level + 2; |
224
|
30
|
|
|
|
|
188
|
return $self->success(!!Test::More->can($name)->(@args)); |
225
|
|
|
|
|
|
|
}; |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
sub _text { |
229
|
14
|
50
|
|
14
|
|
34
|
return '' unless my $e = shift->loy->at(shift); |
230
|
14
|
|
|
|
|
666
|
return $e->text; |
231
|
|
|
|
|
|
|
}; |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
sub _loy_text { |
235
|
4
|
|
|
4
|
|
7
|
my $self = shift; |
236
|
4
|
100
|
|
|
|
19
|
return $self->{_data} if $self->{_data}; |
237
|
1
|
|
|
|
|
3
|
$self->{_data} = $self->loy->to_pretty_xml; |
238
|
1
|
|
|
|
|
3
|
return $self->{_data}; |
239
|
|
|
|
|
|
|
}; |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
1; |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
__END__ |