blib/lib/Test/Regexp.pm

filter: Statementstmt 98.5% 270 / 274 Branchbran 91.0% 102 / 112 Conditioncond 86.3% 63 / 73 MC/DCmcdc 71.7% 28 / 39 Subroutinesub 100% 27 / 27 Podpod 57.1% 4 / 7 totaltotal 92.8% 494 / 532 CC 93 SCAR 34.8
CC
93
Cov
95%
match
59.0
todo
15.2
import
7.1
CRAP 32.6
↑ Summary
1 package Test::Regexp;
2  
3 19 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 19 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
6 19 binmode STDOUT, ":utf8";
7 }
8  
9 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 19 ▶use charnames ":full";
Subroutine BEGIN: called CC=1 SCAR=0.0
12 19 ▶no warnings 'syntax';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 19 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 19 ▶use Test::Builder;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 19 our @EXPORT = qw [match no_match];
18 19 our @ISA = qw [Exporter Test::More];
19  
20 19 our $VERSION = '2017040101';
21  
22  
23 19 my $Test = Test::Builder -> new;
24  
25 19 my $ESCAPE_NONE = 0;
26 19 my $ESCAPE_WHITE_SPACE = 1;
27 19 my $ESCAPE_NAMES = 2;
28 19 my $ESCAPE_CODES = 3;
29 19 my $ESCAPE_NON_PRINTABLE = 4;
30 19 ▶my $ESCAPE_DEFAULT = ${^UNICODE} ? $ESCAPE_NON_PRINTABLE
Branch: 1 branch
BranchTrueFalseTotal
${^UNICODE} ? : 0 19 19
31 : $ESCAPE_CODES;
32  
33 18 ▶sub import {
Subroutine import: called CC=7 SCAR=19.7
34 18 my $self = shift;
35 18 my $pkg = caller;
36  
37 18 my %arg = @_;
38  
39 18 $Test -> exported_to ($pkg);
40  
41 18 ▶ $arg {import} //= [qw [match no_match]];
Condition100%2/2
$arg{"import"} //= ["match", "no_match"]
l!l
711
MC/DC100%1/1
$arg{"import"} //= ["match", "no_match"]
$arg{"import"}
Truth table100%2/2
A
A= $arg{"import"}
Aresult
11
00
42  
43 18 ▶ while (my ($key, $value) = each %arg) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %arg) 19 18 37
44 19 ▶ if ($key eq "tests") {
Branch: 2 branches
BranchTrueFalseTotal
if ($key eq 'tests') { } 1 18 19
elsif ($key eq 'import') { } 18 0 18
45 1 $Test -> plan ($value);
46 }
47 elsif ($key eq "import") {
48 18 ▶ $self -> export_to_level (1, $self, $_) for @{$value || []};
Condition50%1/2
$value || []
l!l
180
MC/DC0%0/1
$value || []
$value
Truth table50%1/2
A
A= $value
Aresult
11
00
49 }
50 else {
51 0 die "Unknown option '$key'\n";
52 }
53 }
54 }
55  
56  
57 19 my $__ = " ";
58  
59 619 ▶sub escape {
Subroutine escape: called CC=7 SCAR=19.7
Pod documented
60 619 my ($str, $escape) = @_;
61 619 ▶ $escape //= $ESCAPE_DEFAULT;
Condition66%2/3
$escape //= $ESCAPE_DEFAULT
l!l&&r!l&&!r
2323870
MC/DC0%0/2
$escape //= $ESCAPE_DEFAULT
$escape $ESCAPE_DEFAULT
Truth table66%2/3
A //= B
A= $escapeB= $ESCAPE_DEFAULT
ABresult
1X1
011
000
62 619 ▶ return $str if $escape == $ESCAPE_NONE;
Branch: 1 branch
BranchTrueFalseTotal
if $escape == $ESCAPE_NONE 0 619 619
63 619 $str =~ s/\n/\\n/g;
64 619 $str =~ s/\t/\\t/g;
65 619 $str =~ s/\r/\\r/g;
66 619 ▶ if ($escape == $ESCAPE_NAMES) {
Branch: 3 branches
BranchTrueFalseTotal
if ($escape == $ESCAPE_NAMES) { } 58 561 619
elsif ($escape == $ESCAPE_CODES) { } 445 116 561
elsif ($escape == $ESCAPE_NON_PRINTABLE) { } 58 58 116
67 58 $str =~ s{([^\x20-\x7E])}
68 38 {my $name = charnames::viacode (ord $1);
69 38 ▶ $name ? sprintf "\\N{%s}" => $name
Branch: 1 branch
BranchTrueFalseTotal
$name ? : 38 0 38
70 : sprintf "\\x{%02X}" => ord $1}eg;
71 }
72 elsif ($escape == $ESCAPE_CODES) {
73 445 $str =~ s{([^\x20-\x7E])}
74 38 {sprintf "\\x{%02X}" => ord $1}eg;
75 }
76 elsif ($escape == $ESCAPE_NON_PRINTABLE) {
77 58 $str =~ s{([\x00-\x1F\xFF])}
78 0 {sprintf "\\x{%02X}" => ord $1}eg;
79 }
80 619 $str;
81 }
82  
83 421 ▶sub pretty {
Subroutine pretty: called CC=3 SCAR=11.0
Pod undocumented
84 421 my $str = shift;
85 421 my %arg = @_;
86 421 ▶ substr ($str, 50, -5, "...") if length $str > 55 && !$arg {full_text};
Branch: 1 branch
BranchTrueFalseTotal
if length $str > 55 and not $arg{"full_text"} 1 420 421
Condition100%3/3
length $str > 55 and not $arg{"full_text"}
!ll&&!rl&&r
41911
MC/DC100%2/2
length $str > 55 and not $arg{"full_text"}
length $str > 55 not $arg{"full_text"}
Truth table100%3/3
A and not(B)
A= length $str > 55B= not $arg{"full_text"}
ABresult
0X0
100
111
87 421 $str = escape $str, $arg {escape};
88 421 $str;
89 }
90  
91  
92 223 ▶sub mess {
Subroutine mess: called CC=5 SCAR=17.1
Pod undocumented
93 223 my $val = shift;
94 0 ▶ unless (defined $val) {return 'undefined'}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $val) 0 223 223
95 223 my %arg = @_;
96 my $pretty = pretty $val, full_text => $arg {full_text},
97 223 escape => $arg {escape};
98 223 ▶ if ($pretty eq $val && $val !~ /'/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($pretty eq $val and not $val =~ /'/) { } 183 40 223
elsif (not $pretty =~ /"/) { } 40 0 40
Condition66%2/3
$pretty eq $val and not $val =~ /'/
!ll&&!rl&&r
400183
MC/DC50%1/2
$pretty eq $val and not $val =~ /'/
$pretty eq $val not $val =~ /'/
Truth table66%2/3
A and not(B)
A= $pretty eq $valB= not $val =~ /'/
ABresult
0X0
100
111
99 183 return "eq '$val'";
100 }
101 elsif ($pretty !~ /"/) {
102 40 return 'eq "' . $pretty . '"';
103 }
104 else {
105 0 return "eq qq {$pretty}";
106 }
107 }
108  
109  
110 198 ▶sub todo {
Subroutine todo: called CC=15 SCAR=27.2
Pod documented
111 198 my %arg = @_;
112 198 my $subject = $arg {subject};
113 198 my $comment = $arg {comment};
114 198 my $upgrade = $arg {upgrade};
115 198 my $downgrade = $arg {downgrade};
116 198 ▶ my $neg = $arg {match} ? "" : "not ";
Branch: 1 branch
BranchTrueFalseTotal
$arg{'match'} ? : 164 34 198
117 198 my $full_text = $arg {full_text};
118 198 my $escape = $arg {escape};
119  
120 198 my $line = "";
121  
122 198 ▶ if ($arg {show_line}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg{"show_line"}) 24 174 198
123 19 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
124 24 ▶ my ($file, $l_nr) = (caller ($Test::Builder::deepness // 1)) [1, 2];
Condition50%1/2
$Test::Builder::deepness // 1
l!l
024
MC/DC0%0/1
$Test::Builder::deepness // 1
$Test::Builder::deepness
Truth table50%1/2
A
A= $Test::Builder::deepness
Aresult
11
00
125 24 $line = " [$file:$l_nr]";
126 }
127  
128 198 my $subject_pretty = pretty $subject, full_text => $full_text,
129 escape => $escape;
130 198 my $Comment = qq {qq {$subject_pretty}};
131 198 $Comment .= qq { ${neg}matched by "$comment"};
132  
133 198 my @todo = [$subject, $Comment, $line];
134  
135 #
136 # If the subject isn't already UTF-8, and there are characters in
137 # the range "\x{80}" .. "\x{FF}", we do the test a second time,
138 # with the subject upgraded to UTF-8.
139 #
140 # Otherwise, if the subject is in UTF-8 format, and there are *no*
141 # characters with code point > 0xFF, but with characters in the
142 # range 0x80 .. 0xFF, we downgrade and test again.
143 #
144 198 ▶ if ($upgrade && ($upgrade == 2 || !utf8::is_utf8 ($subject)
Branch: 2 branches
BranchTrueFalseTotal
if ($upgrade and $upgrade == 2 || !utf8::is_utf8($subject) && $subject =~ /[\x80-\xFF]/) { } 24 174 198
elsif ($downgrade and $downgrade == 2 || utf8::is_utf8($subject) && $subject =~ /[\x80-\xFF]/ && !($subject =~ /[^\x00-\xFF]/)) { } 24 300 324
Condition88%8/9
$upgrade and $upgrade == 2 || !utf8::is_utf8($subject) && $subject =~ /[\x80-\xFF]/
!ll&&!rl&&r
2415024
$upgrade == 2 or not utf8::is_utf8($subject) and $subject =~ /[\x80-\xFF]/
l!l&&r!l&&!r
024150
not utf8::is_utf8($subject) and $subject =~ /[\x80-\xFF]/
!ll&&!rl&&r
2412624
MC/DC75%3/4
$upgrade and $upgrade == 2 || !utf8::is_utf8($subject) && $subject =~ /[\x80-\xFF]/
$upgrade $upgrade == 2 not utf8::is_utf8($subject) $subject =~ /[\x80-\xFF]/
Truth table80%4/5
A and B or not(C) and D
A= $upgradeB= $upgrade == 2C= not utf8::is_utf8($subject)D= $subject =~ /[\x80-\xFF]/
ABCDresult
0XXX0
100X0
10100
11XX1
10111
145 && $subject =~ /[\x80-\xFF]/)) {
146 24 my $subject_utf8 = $subject;
147 24 ▶ if (utf8::upgrade ($subject_utf8)) {
Branch: 1 branch
BranchTrueFalseTotal
if (utf8::upgrade($subject_utf8)) 24 0 24
148 24 my $Comment_utf8 = qq {qq {$subject_pretty}};
149 24 $Comment_utf8 .= qq { [UTF-8]};
150 24 $Comment_utf8 .= qq { ${neg}matched by "$comment"};
151  
152 24 push @todo => [$subject_utf8, $Comment_utf8, $line];
153 }
154 }
155 ▶ elsif ($downgrade && ($downgrade == 2 || utf8::is_utf8 ($subject)
Condition75%9/12
$downgrade and $downgrade == 2 || utf8::is_utf8($subject) && $subject =~ /[\x80-\xFF]/ && !($subject =~ /[^\x00-\xFF]/)
!ll&&!rl&&r
1213824
$downgrade == 2 or utf8::is_utf8($subject) and $subject =~ /[\x80-\xFF]/ and not $subject =~ /[^\x00-\xFF]/
l!l&&r!l&&!r
024138
utf8::is_utf8($subject) and $subject =~ /[\x80-\xFF]/ and not $subject =~ /[^\x00-\xFF]/
!ll&&!rl&&r
138024
utf8::is_utf8($subject) and $subject =~ /[\x80-\xFF]/
!ll&&!rl&&r
138024
MC/DC40%2/5
$downgrade and $downgrade == 2 || utf8::is_utf8($subject) && $subject =~ /[\x80-\xFF]/ && !($subject =~ /[^\x00-\xFF]/)
$downgrade $downgrade == 2 utf8::is_utf8($subject) $subject =~ /[\x80-\xFF]/ not $subject =~ /[^\x00-\xFF]/
Truth table50%3/6
A and B or C and D and not(E)
A= $downgradeB= $downgrade == 2C= utf8::is_utf8($subject)D= $subject =~ /[\x80-\xFF]/E= not $subject =~ /[^\x00-\xFF]/
ABCDEresult
0XXXX0
100XX0
1010X0
101100
11XXX1
101111
156 && $subject =~ /[\x80-\xFF]/
157 && $subject !~ /[^\x00-\xFF]/)) {
158 24 my $subject_non_utf8 = $subject;
159 24 ▶ if (utf8::downgrade ($subject_non_utf8)) {
Branch: 1 branch
BranchTrueFalseTotal
if (utf8::downgrade($subject_non_utf8)) 24 0 24
160 24 my $Comment_non_utf8 = qq {qq {$subject_pretty}};
161 24 $Comment_non_utf8 .= qq { [non-UTF-8]};
162 24 $Comment_non_utf8 .= qq { ${neg}matched by "$comment"};
163  
164 24 push @todo => [$subject_non_utf8, $Comment_non_utf8, $line];
165 }
166 }
167  
168 198 @todo;
169 }
170
171  
172  
173 #
174 # Arguments:
175 # name: 'Name' of the pattern.
176 # pattern: Pattern to be tested, without captures.
177 # keep_pattern: Pattern to be tested, with captures.
178 # subject: String to match.
179 # captures: Array of captures; elements are either strings
180 # (match for the corresponding numbered capture),
181 # or an array, where the first element is the name
182 # of the capture and the second its value.
183 # comment: Comment to use, defaults to name or "".
184 # utf8_upgrade: If set, upgrade the string if applicable. Defaults to 1.
185 # utf8_downgrade If set, downgrade the string if applicable. Defaults to 1.
186 # match If true, pattern(s) should match, otherwise, should fail
187 # to match. Defaults to 1.
188 # reason The reason a match should fail.
189 # test What is tested.
190 # todo This test is a todo test; argument is the reason.
191 # show_line Show file name/line number of call to 'match'.
192 # full_text Don't shorten long messages.
193 #
194  
195 198 ▶sub match {
Subroutine match: called CC=59 SCAR=40.8
Pod documented
196 198 my %arg = @_;
197  
198 198 my $name = $arg {name};
199 198 my $pattern = $arg {pattern};
200 198 my $keep_pattern = $arg {keep_pattern};
201 198 my $subject = $arg {subject};
202 198 ▶ my $captures = $arg {captures} // [];
Condition100%2/2
$arg{"captures"} // []
l!l
10692
MC/DC100%1/1
$arg{"captures"} // []
$arg{"captures"}
Truth table100%2/2
A
A= $arg{"captures"}
Aresult
11
00
203 198 ▶ my $comment = escape $arg {comment} // $name // "";
Condition100%5/5
($arg{"comment"} // $name) // ""
l!l
78120
$arg{"comment"} // $name
l!l&&r!l&&!r
870120
MC/DC100%2/2
($arg{"comment"} // $name) // ""
$arg{"comment"} $name
Truth table100%3/3
A // B
A= $arg{"comment"}B= $name
ABresult
1X1
011
000
204 198 ▶ my $upgrade = $arg {utf8_upgrade} // 1;
Condition100%2/2
$arg{"utf8_upgrade"} // 1
l!l
24174
MC/DC100%1/1
$arg{"utf8_upgrade"} // 1
$arg{"utf8_upgrade"}
Truth table100%2/2
A
A= $arg{"utf8_upgrade"}
Aresult
11
00
205 198 ▶ my $downgrade = $arg {utf8_downgrade} // 1;
Condition100%2/2
$arg{"utf8_downgrade"} // 1
l!l
24174
MC/DC100%1/1
$arg{"utf8_downgrade"} // 1
$arg{"utf8_downgrade"}
Truth table100%2/2
A
A= $arg{"utf8_downgrade"}
Aresult
11
00
206 198 ▶ my $match = $arg {match} // 1;
Condition100%2/2
$arg{"match"} // 1
l!l
15840
MC/DC100%1/1
$arg{"match"} // 1
$arg{"match"}
Truth table100%2/2
A
A= $arg{"match"}
Aresult
11
00
207 my $reason = defined $arg {reason}
208 198 ▶ ? " [Reason: " . $arg {reason} . "]"
Branch: 1 branch
BranchTrueFalseTotal
defined $arg{'reason'} ? : 39 159 198
209 : "";
210 my $test = defined $arg {test}
211 198 ▶ ? " [Test: " . $arg {test} . "]"
Branch: 1 branch
BranchTrueFalseTotal
defined $arg{'test'} ? : 36 162 198
212 : "";
213 198 my $show_line = $arg {show_line};
214 198 my $full_text = $arg {full_text};
215 198 my $escape = $arg {escape};
216 198 my $todo = $arg {todo};
217 198 ▶ my $keep_message = $arg {no_keep_message} ? "" : " (with -Keep)";
Branch: 1 branch
BranchTrueFalseTotal
$arg{'no_keep_message'} ? : 1 197 198
218  
219 198 my $numbered_captures;
220 my $named_captures;
221  
222 198 my $pass = 1;
223  
224 #
225 # First split the captures into a hash (for named captures) and
226 # an array (for numbered captures) so we can check $1 and friends, and %-.
227 #
228 198 foreach my $capture (@$captures) {
229 117 ▶ if (ref $capture eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $capture eq 'ARRAY') { } 70 47 117
230 70 my ($name, $match) = @$capture;
231 70 push @$numbered_captures => $match;
232 70 push @{$$named_captures {$name}} => $match;
233 }
234 else {
235 47 push @$numbered_captures => $capture;
236 }
237 }
238
239 198 ▶ $numbered_captures ||= [];
Condition100%2/2
$numbered_captures ||= []
l!l
55143
MC/DC100%1/1
$numbered_captures ||= []
$numbered_captures
Truth table100%2/2
A
A= $numbered_captures
Aresult
11
00
240 198 ▶ $named_captures ||= {};
Condition100%2/2
$named_captures ||= {}
l!l
35163
MC/DC100%1/1
$named_captures ||= {}
$named_captures
Truth table100%2/2
A
A= $named_captures
Aresult
11
00
241  
242 198 my @todo = todo subject => $subject,
243 comment => $comment,
244 upgrade => $upgrade,
245 downgrade => $downgrade,
246 match => $match,
247 show_line => $show_line,
248 full_text => $full_text,
249 escape => $escape;
250  
251 198 ▶ $Test -> todo_start ($todo) if defined $todo;
Branch: 1 branch
BranchTrueFalseTotal
if defined $todo 4 194 198
252  
253 #
254 # Now we will do the tests.
255 #
256 198 foreach my $todo (@todo) {
257 246 my $subject = $$todo [0];
258 246 my $comment = $$todo [1];
259 246 my $line = $$todo [2];
260  
261 246 ▶ if ($match && defined $pattern) {
Branch: 1 branch
BranchTrueFalseTotal
if ($match and defined $pattern) 134 112 246
Condition100%3/3
$match and defined $pattern
!ll&&!rl&&r
3478134
MC/DC100%2/2
$match and defined $pattern
$match defined $pattern
Truth table100%3/3
A and B
A= $matchB= defined $pattern
ABresult
0X0
100
111
262 134 my $comment = $comment;
263 134 ▶ my $pat = ref $pattern ? $pattern
Branch: 1 branch
BranchTrueFalseTotal
ref $pattern ? : 116 18 134
264 : qr /$pattern/;
265 134 $comment =~ s{""$}{/$pat/};
266 134 $comment .= "$line$test";
267 #
268 # Test match; match should also be complete, and not
269 # have any captures.
270 #
271 SKIP: {
272 134 my $result = $subject =~ /^$pattern/;
273 134 ▶ unless ($Test -> ok ($result, $comment)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Test->ok($result, $comment)) 3 131 134
274 3 $Test -> skip ("Match failed") for 1 .. 3;
275 3 $pass = 0;
276 3 last SKIP;
277 }
278  
279 #
280 # %- contains an entry for *each* named group, regardless
281 # whether it's a capture or not.
282 #
283 131 my $named_matches = 0;
284 131 $named_matches += @$_ for values %-;
285  
286 131 ▶ unless ($Test -> is_eq ($&, $subject,
Branch: 1 branch
BranchTrueFalseTotal
unless ($Test->is_eq($&, $subject, "${__}match is complete")) 22 109 131
287 "${__}match is complete")) {
288 22 $Test -> skip ("Match failed") for 2 .. 3;
289 22 $pass = 0;
290 22 last SKIP;
291 }
292
293 109 ▶ $pass = 0 unless
Branch: 1 branch
BranchTrueFalseTotal
unless $Test->is_eq(scalar @+, 1, "${__}no numbered captures") 4 105 109
294 $Test -> is_eq (scalar @+, 1,
295 "${__}no numbered captures");
296 109 ▶ $pass = 0 unless
Branch: 1 branch
BranchTrueFalseTotal
unless $Test->is_eq($named_matches, 0, "${__}no named captures") 2 107 109
297 $Test -> is_eq ($named_matches, 0,
298 "${__}no named captures");
299 }
300 }
301  
302  
303 246 ▶ if ($match && defined $keep_pattern) {
Branch: 1 branch
BranchTrueFalseTotal
if ($match and defined $keep_pattern) 82 164 246
Condition100%3/3
$match and defined $keep_pattern
!ll&&!rl&&r
3413082
MC/DC100%2/2
$match and defined $keep_pattern
$match defined $keep_pattern
Truth table100%3/3
A and B
A= $matchB= defined $keep_pattern
ABresult
0X0
100
111
304 82 my $comment = $comment;
305 82 ▶ my $pat = ref $keep_pattern ? $keep_pattern
Branch: 1 branch
BranchTrueFalseTotal
ref $keep_pattern ? : 68 14 82
306 : qr /$keep_pattern/;
307 82 $comment =~ s{""$}{/$pat/};
308 82 $comment .= $keep_message;
309 82 $comment .= "$line$test";
310 #
311 # Test keep. Should match, and the parts as well.
312 #
313 # Total number of tests:
314 # - 1 for match.
315 # - 1 for match complete.
316 # - 1 for each named capture.
317 # - 1 for each capture name.
318 # - 1 for number of different capture names.
319 # - 1 for each capture.
320 # - 1 for number of captures.
321 # So, if you only have named captures, and all the names
322 # are different, you have 4 + 3 * N tests.
323 # If you only have numbered captures, you have 4 + N tests.
324 #
325 SKIP: {
326 82 my $nr_of_tests = 0;
327 82 $nr_of_tests += 1; # For match.
328 82 $nr_of_tests += 1; # For match complete.
329 82 $nr_of_tests += @{$_} for values %$named_captures;
330 # Number of named captures.
331 82 $nr_of_tests += scalar keys %$named_captures;
332 # Number of different named captures.
333 82 $nr_of_tests += 1; # Right number of named captures.
334 82 $nr_of_tests += @$numbered_captures;
335 # Number of numbered captures.
336 82 $nr_of_tests += 1; # Right number of numbered captures.
337  
338 82 my ($amp, @numbered_matches, %minus);
339  
340 82 my $result = $subject =~ /^$keep_pattern/;
341 82 ▶ unless ($Test -> ok ($result, $comment)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Test->ok($result, $comment)) 2 80 82
342 2 $Test -> skip ("Match failed") for 2 .. $nr_of_tests;
343 2 $pass = 0;
344 2 last SKIP;
345 }
346  
347  
348 #
349 # Copy $&, $N and %- before doing anything that
350 # migh override them.
351 #
352  
353 80 $amp = $&;
354  
355 #
356 # Grab numbered captures.
357 #
358 80 ▶ for (my $i = 1; $i < @+; $i ++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @+) 139 80 219
359 19 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
360 139 push @numbered_matches => $$i;
361 }
362  
363 #
364 # Copy %-;
365 #
366 80 ▶ while (my ($key, $value) = each %-) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %-) 98 80 178
367 98 $minus {$key} = [@$value];
368 }
369  
370 #
371 # Test to see if match is complete.
372 #
373 80 ▶ unless ($Test -> is_eq ($amp, $subject,
Branch: 1 branch
BranchTrueFalseTotal
unless ($Test->is_eq($amp, $subject, "${__}match is complete")) 6 74 80
374 "${__}match is complete")) {
375 6 $Test -> skip ("Match incomplete") for 3 .. $nr_of_tests;
376 6 $pass = 0;
377 6 last SKIP;
378 }
379  
380 #
381 # Test named captures.
382 #
383 74 ▶ while (my ($key, $value) = each %$named_captures) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$named_captures) 93 74 167
384 93 ▶ for (my $i = 0; $i < @$value; $i ++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$value) 97 93 190
385 $pass = 0 unless
386 $Test -> is_eq (
387 97 ▶ $minus {$key} ? $minus {$key} [$i] : undef,
Branch: 2 branches
BranchTrueFalseTotal
unless $Test->is_eq($minus{$key} ? $minus{$key}[$i] : undef, $value->[$i], "$__\$- {$key} [$i] " . mess($value->[$i], "full_text", $full_text, "escape", $escape)) 7 90 97
$minus{$key} ? : 95 2 97
388 $$value [$i],
389 "${__}\$- {$key} [$i] " .
390 mess ($$value [$i], full_text => $full_text,
391 escape => $escape));
392 }
393 $pass = 0 unless
394 93 ▶ $Test -> is_num (scalar @{$minus {$key} || []},
Branch: 2 branches
BranchTrueFalseTotal
unless $Test->is_num(scalar @{$minus{$key} or [];}, scalar @$value, "$__${__}capture '${key}' has " . (@$value == 1 ? "1 match" : @$value . ' matches')) 4 89 93
@$value == 1 ? : 90 3 93
Condition100%2/2
$minus{$key} || []
l!l
912
MC/DC100%1/1
$minus{$key} || []
$minus{$key}
Truth table100%2/2
A
A= $minus{$key}
Aresult
11
00
395 scalar @$value, "$__${__}capture '$key' has " .
396 (@$value == 1 ? "1 match" :
397 @$value . " matches"));
398 }
399 #
400 # Test for the right number of captures.
401 #
402 74 ▶ $pass = 0 unless
Branch: 1 branch
BranchTrueFalseTotal
unless $Test->is_num(scalar keys %minus, scalar keys %$named_captures, $__ . scalar(keys %$named_captures) . ' named capture groups') 2 72 74
403 $Test -> is_num (scalar keys %minus,
404 scalar keys %$named_captures,
405 $__ . scalar (keys %$named_captures)
406 . " named capture groups"
407 );
408  
409  
410 #
411 # Test numbered captures.
412 #
413 74 ▶ for (my $i = 0; $i < @$numbered_captures; $i ++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$numbered_captures) 126 74 200
414 126 ▶ $pass = 0 unless
Branch: 1 branch
BranchTrueFalseTotal
unless $Test->is_eq($numbered_matches[$i], $numbered_captures->[$i], "$__\$" . ($i + 1) . ' ' . mess($numbered_captures->[$i], "full_text", $full_text, "escape", $escape)) 8 118 126
415 $Test -> is_eq ($numbered_matches [$i],
416 $$numbered_captures [$i],
417 "${__}\$" . ($i + 1) . " " .
418 mess ($$numbered_captures [$i],
419 full_text => $full_text,
420 escape => $escape));
421 }
422 74 ▶ $pass = 0 unless
Branch: 2 branches
BranchTrueFalseTotal
unless $Test->is_num(scalar @numbered_matches, scalar @$numbered_captures, $__ . (@$numbered_captures == 1 ? "1 numbered capture group" : @$numbered_captures . ' numbered capture groups')) 5 69 74
@$numbered_captures == 1 ? : 4 70 74
423 $Test -> is_num (scalar @numbered_matches,
424 scalar @$numbered_captures,
425 $__ .
426 (@$numbered_captures == 1 ?
427 "1 numbered capture group" :
428 @$numbered_captures .
429 " numbered capture groups"));
430 }
431 }
432  
433 246 ▶ if (!$match && defined $pattern) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $match and defined $pattern) 33 213 246
Condition100%3/3
not $match and defined $pattern
!ll&&!rl&&r
212133
MC/DC100%2/2
not $match and defined $pattern
not $match defined $pattern
Truth table100%3/3
not(A) and B
A= not $matchB= defined $pattern
ABresult
0X0
100
111
434 33 my $comment = $comment;
435 33 ▶ my $pat = ref $pattern ? $pattern
Branch: 1 branch
BranchTrueFalseTotal
ref $pattern ? : 26 7 33
436 : qr /$pattern/;
437 33 $comment =~ s{""$}{/$pat/};
438 33 $comment .= "$line$reason";
439 33 my $r = $subject =~ /^$pattern/;
440 33 ▶ $pass = 0 unless
Branch: 1 branch
BranchTrueFalseTotal
unless $Test->ok(!$r || $subject ne $&, $comment) 3 30 33
Condition100%3/3
!$r || $subject ne $&
l!l&&r!l&&!r
2913
MC/DC100%2/2
!$r || $subject ne $&
!$r $subject ne $&
Truth table100%3/3
not(A) || B
A= !$rB= $subject ne $&
ABresult
1X1
011
000
441 $Test -> ok (!$r || $subject ne $&, $comment);
442 }
443 246 ▶ if (!$match && defined $keep_pattern) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $match and defined $keep_pattern) 1 245 246
Condition100%3/3
not $match and defined $keep_pattern
!ll&&!rl&&r
212331
MC/DC100%2/2
not $match and defined $keep_pattern
not $match defined $keep_pattern
Truth table100%3/3
not(A) and B
A= not $matchB= defined $keep_pattern
ABresult
0X0
100
111
444 1 my $comment = $comment;
445 1 ▶ my $pat = ref $keep_pattern ? $keep_pattern
Branch: 1 branch
BranchTrueFalseTotal
ref $keep_pattern ? : 1 0 1
446 : qr /$keep_pattern/;
447 1 $comment =~ s{""$}{/$pat/};
448 1 $comment .= $keep_message;
449 1 $comment .= "$line$reason";
450 1 my $r = $subject =~ /^$keep_pattern/;
451 1 ▶ $pass = 0 unless
Branch: 1 branch
BranchTrueFalseTotal
unless $Test->ok(!$r || $subject ne $&, $comment) 0 1 1
Condition33%1/3
!$r || $subject ne $&
l!l&&r!l&&!r
100
MC/DC0%0/2
!$r || $subject ne $&
!$r $subject ne $&
Truth table33%1/3
not(A) || B
A= !$rB= $subject ne $&
ABresult
1X1
011
000
452 $Test -> ok (!$r || $subject ne $&, $comment);
453 }
454 }
455  
456 198 ▶ $Test -> todo_end if defined $todo;
Branch: 1 branch
BranchTrueFalseTotal
if defined $todo 4 194 198
457  
458 198 $pass;
459 }
460  
461 6 ▶sub no_match {
Subroutine no_match: called CC=1 SCAR=0.0
Pod documented
462 6 push @_ => match => 0;
463 6 goto &match;
464 }
465  
466 19 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
467 19 "Test::Regexp::Object" -> new
468 }
469  
470 package Test::Regexp::Object;
471  
472 21 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
473 21 bless \do {my $var} => shift;
474 }
475  
476 19 ▶use Hash::Util::FieldHash qw [fieldhash];
Subroutine BEGIN: called CC=1 SCAR=0.0
477  
478 19 fieldhash my %pattern;
479 19 fieldhash my %keep_pattern;
480 19 fieldhash my %name;
481 19 fieldhash my %comment;
482 19 fieldhash my %utf8_upgrade;
483 19 fieldhash my %utf8_downgrade;
484 19 fieldhash my %match;
485 19 fieldhash my %reason;
486 19 fieldhash my %test;
487 19 fieldhash my %show_line;
488 19 fieldhash my %full_text;
489 19 fieldhash my %escape;
490 19 fieldhash my %todo;
491 19 fieldhash my %tags;
492 19 fieldhash my %no_keep_message;
493  
494 19 ▶sub init {
Subroutine init: called CC=2 SCAR=6.9
495 19 my $self = shift;
496 19 my %arg = @_;
497  
498 19 $pattern {$self} = $arg {pattern};
499 19 $keep_pattern {$self} = $arg {keep_pattern};
500 19 $name {$self} = $arg {name};
501 19 $comment {$self} = $arg {comment};
502 19 $utf8_upgrade {$self} = $arg {utf8_upgrade};
503 19 $utf8_downgrade {$self} = $arg {utf8_downgrade};
504 19 $match {$self} = $arg {match};
505 19 $reason {$self} = $arg {reason};
506 19 $test {$self} = $arg {test};
507 19 $show_line {$self} = $arg {show_line};
508 19 $full_text {$self} = $arg {full_text};
509 19 $escape {$self} = $arg {escape};
510 19 $todo {$self} = $arg {todo};
511 19 ▶ $tags {$self} = $arg {tags} if exists $arg {tags};
Branch: 1 branch
BranchTrueFalseTotal
if exists $arg{"tags"} 2 17 19
512 19 $no_keep_message {$self} = $arg {no_keep_message};
513  
514 19 $self;
515 }
516  
517 28 ▶sub args {
Subroutine args: called CC=1 SCAR=0.0
518 28 my $self = shift;
519 (
520 pattern => $pattern {$self},
521 keep_pattern => $keep_pattern {$self},
522 name => $name {$self},
523 comment => $comment {$self},
524 utf8_upgrade => $utf8_upgrade {$self},
525 utf8_downgrade => $utf8_downgrade {$self},
526 match => $match {$self},
527 reason => $reason {$self},
528 test => $test {$self},
529 show_line => $show_line {$self},
530 full_text => $full_text {$self},
531 escape => $escape {$self},
532 todo => $todo {$self},
533 28 no_keep_message => $no_keep_message {$self},
534 )
535 }
536  
537 22 ▶sub match {
Subroutine match: called CC=2 SCAR=6.9
538 22 my $self = shift;
539 22 my $subject = shift;
540 22 ▶ my $captures = @_ % 2 ? shift : undef;
Branch: 1 branch
BranchTrueFalseTotal
@_ % 2 ? : 15 7 22
541  
542 22 Test::Regexp::match subject => $subject,
543 captures => $captures,
544 $self -> args,
545 @_;
546 }
547  
548 6 ▶sub no_match {
Subroutine no_match: called CC=1 SCAR=0.0
549 6 my $self = shift;
550 6 my $subject = shift;
551  
552 6 Test::Regexp::no_match subject => $subject,
553 $self -> args,
554 @_;
555 }
556  
557 9 ▶sub name {$name {+shift}}
Subroutine name: called CC=1 SCAR=0.0
558  
559 2 ▶sub set_tag {
Subroutine set_tag: called CC=1 SCAR=0.0
560 2 my $self = shift;
561 2 $tags {$self} {$_ [0]} = $_ [1];
562 }
563 11 ▶sub tag {
Subroutine tag: called CC=1 SCAR=0.0
564 11 my $self = shift;
565 11 $tags {$self} {$_ [0]};
566 }
567  
568  
569  
570 19 1;
571  
572 __END__
↑ Summary