Commit | Line | Data |
---|---|---|
8d063cd8 | 1 | #!./perl |
8d37f932 DD |
2 | # |
3 | # This is a home for regular expression tests that don't fit into | |
4 | # the format supported by op/regexp.t. If you want to add a test | |
5 | # that does fit that format, add it to op/re_tests, not here. | |
8d063cd8 | 6 | |
fd291da9 | 7 | print "1..245\n"; |
8d37f932 | 8 | |
e4d48cc9 GS |
9 | BEGIN { |
10 | chdir 't' if -d 't'; | |
20822f61 | 11 | @INC = '../lib'; |
e4d48cc9 | 12 | } |
8d37f932 | 13 | eval 'use Config'; # Defaults assumed if this fails |
8d063cd8 | 14 | |
9c63abab GS |
15 | # XXX known to leak scalars |
16 | $ENV{PERL_DESTRUCT_LEVEL} = 0 unless $ENV{PERL_DESTRUCT_LEVEL} > 3; | |
eec2d3df | 17 | |
8d063cd8 LW |
18 | $x = "abc\ndef\n"; |
19 | ||
20 | if ($x =~ /^abc/) {print "ok 1\n";} else {print "not ok 1\n";} | |
21 | if ($x !~ /^def/) {print "ok 2\n";} else {print "not ok 2\n";} | |
22 | ||
23 | $* = 1; | |
24 | if ($x =~ /^def/) {print "ok 3\n";} else {print "not ok 3\n";} | |
25 | $* = 0; | |
26 | ||
27 | $_ = '123'; | |
28 | if (/^([0-9][0-9]*)/) {print "ok 4\n";} else {print "not ok 4\n";} | |
29 | ||
30 | if ($x =~ /^xxx/) {print "not ok 5\n";} else {print "ok 5\n";} | |
31 | if ($x !~ /^abc/) {print "not ok 6\n";} else {print "ok 6\n";} | |
32 | ||
33 | if ($x =~ /def/) {print "ok 7\n";} else {print "not ok 7\n";} | |
34 | if ($x !~ /def/) {print "not ok 8\n";} else {print "ok 8\n";} | |
35 | ||
36 | if ($x !~ /.def/) {print "ok 9\n";} else {print "not ok 9\n";} | |
37 | if ($x =~ /.def/) {print "not ok 10\n";} else {print "ok 10\n";} | |
38 | ||
39 | if ($x =~ /\ndef/) {print "ok 11\n";} else {print "not ok 11\n";} | |
40 | if ($x !~ /\ndef/) {print "not ok 12\n";} else {print "ok 12\n";} | |
41 | ||
42 | $_ = 'aaabbbccc'; | |
43 | if (/(a*b*)(c*)/ && $1 eq 'aaabbb' && $2 eq 'ccc') { | |
44 | print "ok 13\n"; | |
45 | } else { | |
46 | print "not ok 13\n"; | |
47 | } | |
48 | if (/(a+b+c+)/ && $1 eq 'aaabbbccc') { | |
49 | print "ok 14\n"; | |
50 | } else { | |
51 | print "not ok 14\n"; | |
52 | } | |
53 | ||
54 | if (/a+b?c+/) {print "not ok 15\n";} else {print "ok 15\n";} | |
55 | ||
56 | $_ = 'aaabccc'; | |
57 | if (/a+b?c+/) {print "ok 16\n";} else {print "not ok 16\n";} | |
58 | if (/a*b+c*/) {print "ok 17\n";} else {print "not ok 17\n";} | |
59 | ||
60 | $_ = 'aaaccc'; | |
61 | if (/a*b?c*/) {print "ok 18\n";} else {print "not ok 18\n";} | |
62 | if (/a*b+c*/) {print "not ok 19\n";} else {print "ok 19\n";} | |
63 | ||
64 | $_ = 'abcdef'; | |
65 | if (/bcd|xyz/) {print "ok 20\n";} else {print "not ok 20\n";} | |
66 | if (/xyz|bcd/) {print "ok 21\n";} else {print "not ok 21\n";} | |
67 | ||
68 | if (m|bc/*d|) {print "ok 22\n";} else {print "not ok 22\n";} | |
378cc40b LW |
69 | |
70 | if (/^$_$/) {print "ok 23\n";} else {print "not ok 23\n";} | |
71 | ||
72 | $* = 1; # test 3 only tested the optimized version--this one is for real | |
73 | if ("ab\ncd\n" =~ /^cd/) {print "ok 24\n";} else {print "not ok 24\n";} | |
74 | $* = 0; | |
75 | ||
f8b27a63 JH |
76 | #$XXX{123} = 123; |
77 | #$XXX{234} = 234; | |
78 | #$XXX{345} = 345; | |
79 | # | |
80 | #@XXX = ('ok 25','not ok 25', 'ok 26','not ok 26','not ok 27'); | |
81 | #while ($_ = shift(@XXX)) { | |
82 | # ?(.*)? && (print $1,"\n"); | |
922205fa | 83 | # /not/ && reset; |
f8b27a63 JH |
84 | # /not ok 26/ && reset 'X'; |
85 | #} | |
86 | # | |
87 | #while (($key,$val) = each(%XXX)) { | |
88 | # print "not ok 27\n"; | |
89 | # exit; | |
90 | #} | |
91 | # | |
92 | #print "ok 27\n"; | |
922205fa | 93 | for (25..27) { print "ok $_\n" } |
378cc40b | 94 | |
378cc40b LW |
95 | 'cde' =~ /[^ab]*/; |
96 | 'xyz' =~ //; | |
97 | if ($& eq 'xyz') {print "ok 28\n";} else {print "not ok 28\n";} | |
98 | ||
99 | $foo = '[^ab]*'; | |
100 | 'cde' =~ /$foo/; | |
101 | 'xyz' =~ //; | |
102 | if ($& eq 'xyz') {print "ok 29\n";} else {print "not ok 29\n";} | |
103 | ||
104 | $foo = '[^ab]*'; | |
105 | 'cde' =~ /$foo/; | |
106 | 'xyz' =~ /$null/; | |
107 | if ($& eq 'xyz') {print "ok 30\n";} else {print "not ok 30\n";} | |
a687059c LW |
108 | |
109 | $_ = 'abcdefghi'; | |
110 | /def/; # optimized up to cmd | |
111 | if ("$`:$&:$'" eq 'abc:def:ghi') {print "ok 31\n";} else {print "not ok 31\n";} | |
112 | ||
113 | /cde/ + 0; # optimized only to spat | |
114 | if ("$`:$&:$'" eq 'ab:cde:fghi') {print "ok 32\n";} else {print "not ok 32\n";} | |
115 | ||
116 | /[d][e][f]/; # not optimized | |
117 | if ("$`:$&:$'" eq 'abc:def:ghi') {print "ok 33\n";} else {print "not ok 33\n";} | |
118 | ||
119 | $_ = 'now is the {time for all} good men to come to.'; | |
120 | / {([^}]*)}/; | |
121 | if ($1 eq 'time for all') {print "ok 34\n";} else {print "not ok 34 $1\n";} | |
122 | ||
123 | $_ = 'xxx {3,4} yyy zzz'; | |
124 | print /( {3,4})/ ? "ok 35\n" : "not ok 35\n"; | |
125 | print $1 eq ' ' ? "ok 36\n" : "not ok 36\n"; | |
126 | print /( {4,})/ ? "not ok 37\n" : "ok 37\n"; | |
127 | print /( {2,3}.)/ ? "ok 38\n" : "not ok 38\n"; | |
128 | print $1 eq ' y' ? "ok 39\n" : "not ok 39\n"; | |
129 | print /(y{2,3}.)/ ? "ok 40\n" : "not ok 40\n"; | |
130 | print $1 eq 'yyy ' ? "ok 41\n" : "not ok 41\n"; | |
131 | print /x {3,4}/ ? "not ok 42\n" : "ok 42\n"; | |
132 | print /^xxx {3,4}/ ? "not ok 43\n" : "ok 43\n"; | |
352d5a3a LW |
133 | |
134 | $_ = "now is the time for all good men to come to."; | |
135 | @words = /(\w+)/g; | |
136 | print join(':',@words) eq "now:is:the:time:for:all:good:men:to:come:to" | |
137 | ? "ok 44\n" | |
138 | : "not ok 44\n"; | |
139 | ||
140 | @words = (); | |
141 | while (/\w+/g) { | |
142 | push(@words, $&); | |
143 | } | |
144 | print join(':',@words) eq "now:is:the:time:for:all:good:men:to:come:to" | |
145 | ? "ok 45\n" | |
146 | : "not ok 45\n"; | |
147 | ||
148 | @words = (); | |
71be2cbc | 149 | pos = 0; |
352d5a3a LW |
150 | while (/to/g) { |
151 | push(@words, $&); | |
152 | } | |
153 | print join(':',@words) eq "to:to" | |
154 | ? "ok 46\n" | |
71be2cbc | 155 | : "not ok 46 `@words'\n"; |
352d5a3a | 156 | |
71be2cbc | 157 | pos $_ = 0; |
352d5a3a LW |
158 | @words = /to/g; |
159 | print join(':',@words) eq "to:to" | |
160 | ? "ok 47\n" | |
71be2cbc | 161 | : "not ok 47 `@words'\n"; |
352d5a3a LW |
162 | |
163 | $_ = "abcdefghi"; | |
164 | ||
165 | $pat1 = 'def'; | |
166 | $pat2 = '^def'; | |
167 | $pat3 = '.def.'; | |
168 | $pat4 = 'abc'; | |
169 | $pat5 = '^abc'; | |
170 | $pat6 = 'abc$'; | |
171 | $pat7 = 'ghi'; | |
172 | $pat8 = '\w*ghi'; | |
173 | $pat9 = 'ghi$'; | |
174 | ||
175 | $t1=$t2=$t3=$t4=$t5=$t6=$t7=$t8=$t9=0; | |
176 | ||
177 | for $iter (1..5) { | |
178 | $t1++ if /$pat1/o; | |
179 | $t2++ if /$pat2/o; | |
180 | $t3++ if /$pat3/o; | |
181 | $t4++ if /$pat4/o; | |
182 | $t5++ if /$pat5/o; | |
183 | $t6++ if /$pat6/o; | |
184 | $t7++ if /$pat7/o; | |
185 | $t8++ if /$pat8/o; | |
186 | $t9++ if /$pat9/o; | |
187 | } | |
188 | ||
189 | $x = "$t1$t2$t3$t4$t5$t6$t7$t8$t9"; | |
190 | print $x eq '505550555' ? "ok 48\n" : "not ok 48 $x\n"; | |
1462b684 LW |
191 | |
192 | $xyz = 'xyz'; | |
193 | print "abc" =~ /^abc$|$xyz/ ? "ok 49\n" : "not ok 49\n"; | |
194 | ||
195 | # perl 4.009 says "unmatched ()" | |
196 | eval '"abc" =~ /a(bc$)|$xyz/; $result = "$&:$1"'; | |
197 | print $@ eq "" ? "ok 50\n" : "not ok 50\n"; | |
198 | print $result eq "abc:bc" ? "ok 51\n" : "not ok 51\n"; | |
a0d0e21e LW |
199 | |
200 | ||
201 | $_="abcfooabcbar"; | |
202 | $x=/abc/g; | |
203 | print $` eq "" ? "ok 52\n" : "not ok 52\n" if $x; | |
204 | $x=/abc/g; | |
205 | print $` eq "abcfoo" ? "ok 53\n" : "not ok 53\n" if $x; | |
206 | $x=/abc/g; | |
207 | print $x == 0 ? "ok 54\n" : "not ok 54\n"; | |
71be2cbc | 208 | pos = 0; |
a0d0e21e LW |
209 | $x=/ABC/gi; |
210 | print $` eq "" ? "ok 55\n" : "not ok 55\n" if $x; | |
211 | $x=/ABC/gi; | |
212 | print $` eq "abcfoo" ? "ok 56\n" : "not ok 56\n" if $x; | |
213 | $x=/ABC/gi; | |
214 | print $x == 0 ? "ok 57\n" : "not ok 57\n"; | |
71be2cbc | 215 | pos = 0; |
a0d0e21e LW |
216 | $x=/abc/g; |
217 | print $' eq "fooabcbar" ? "ok 58\n" : "not ok 58\n" if $x; | |
218 | $x=/abc/g; | |
219 | print $' eq "bar" ? "ok 59\n" : "not ok 59\n" if $x; | |
220 | $_ .= ''; | |
221 | @x=/abc/g; | |
222 | print scalar @x == 2 ? "ok 60\n" : "not ok 60\n"; | |
71be2cbc | 223 | |
224 | $_ = "abdc"; | |
225 | pos $_ = 2; | |
c90c0ff4 | 226 | /\Gc/gc; |
71be2cbc | 227 | print "not " if (pos $_) != 2; |
228 | print "ok 61\n"; | |
c90c0ff4 | 229 | /\Gc/g; |
230 | print "not " if defined pos $_; | |
231 | print "ok 62\n"; | |
c277df42 IZ |
232 | |
233 | $out = 1; | |
234 | 'abc' =~ m'a(?{ $out = 2 })b'; | |
235 | print "not " if $out != 2; | |
236 | print "ok 63\n"; | |
237 | ||
238 | $out = 1; | |
239 | 'abc' =~ m'a(?{ $out = 3 })c'; | |
240 | print "not " if $out != 1; | |
241 | print "ok 64\n"; | |
242 | ||
243 | $_ = 'foobar1 bar2 foobar3 barfoobar5 foobar6'; | |
244 | @out = /(?<!foo)bar./g; | |
245 | print "not " if "@out" ne 'bar2 barf'; | |
246 | print "ok 65\n"; | |
247 | ||
8d37f932 DD |
248 | # Tests which depend on REG_INFTY |
249 | $reg_infty = defined $Config{reg_infty} ? $Config{reg_infty} : 32767; | |
250 | $reg_infty_m = $reg_infty - 1; $reg_infty_p = $reg_infty + 1; | |
251 | ||
252 | # As well as failing if the pattern matches do unexpected things, the | |
253 | # next three tests will fail if you should have picked up a lower-than- | |
254 | # default value for $reg_infty from Config.pm, but have not. | |
255 | ||
256 | undef $@; | |
257 | print "not " if eval q(('aaa' =~ /(a{1,$reg_infty_m})/)[0] ne 'aaa') || $@; | |
258 | print "ok 66\n"; | |
259 | ||
260 | undef $@; | |
261 | print "not " if eval q(('a' x $reg_infty_m) !~ /a{$reg_infty_m}/) || $@; | |
262 | print "ok 67\n"; | |
263 | ||
264 | undef $@; | |
265 | print "not " if eval q(('a' x ($reg_infty_m - 1)) =~ /a{$reg_infty_m}/) || $@; | |
266 | print "ok 68\n"; | |
267 | ||
268 | undef $@; | |
269 | eval "'aaa' =~ /a{1,$reg_infty}/"; | |
9baa0206 | 270 | print "not " if $@ !~ m%^\QQuantifier in {,} bigger than%; |
8d37f932 DD |
271 | print "ok 69\n"; |
272 | ||
273 | eval "'aaa' =~ /a{1,$reg_infty_p}/"; | |
274 | print "not " | |
9baa0206 | 275 | if $@ !~ m%^\QQuantifier in {,} bigger than%; |
8d37f932 DD |
276 | print "ok 70\n"; |
277 | undef $@; | |
278 | ||
279 | # Poke a couple more parse failures | |
280 | ||
281 | $context = 'x' x 256; | |
282 | eval qq("${context}y" =~ /(?<=$context)y/); | |
9baa0206 | 283 | print "not " if $@ !~ m%^\QLookbehind longer than 255 not%; |
8d37f932 DD |
284 | print "ok 71\n"; |
285 | ||
b8c5462f | 286 | # removed test |
8d37f932 DD |
287 | print "ok 72\n"; |
288 | ||
c277df42 | 289 | # Long Monsters |
8d37f932 | 290 | $test = 73; |
c277df42 IZ |
291 | for $l (125, 140, 250, 270, 300000, 30) { # Ordered to free memory |
292 | $a = 'a' x $l; | |
293 | print "# length=$l\nnot " unless "ba$a=" =~ /a$a=/; | |
294 | print "ok $test\n"; | |
295 | $test++; | |
296 | ||
297 | print "not " if "b$a=" =~ /a$a=/; | |
298 | print "ok $test\n"; | |
299 | $test++; | |
300 | } | |
301 | ||
302 | # 20000 nodes, each taking 3 words per string, and 1 per branch | |
303 | $long_constant_len = join '|', 12120 .. 32645; | |
304 | $long_var_len = join '|', 8120 .. 28645; | |
305 | %ans = ( 'ax13876y25677lbc' => 1, | |
306 | 'ax13876y25677mcb' => 0, # not b. | |
307 | 'ax13876y35677nbc' => 0, # Num too big | |
308 | 'ax13876y25677y21378obc' => 1, | |
309 | 'ax13876y25677y21378zbc' => 0, # Not followed by [k-o] | |
310 | 'ax13876y25677y21378y21378kbc' => 1, | |
311 | 'ax13876y25677y21378y21378kcb' => 0, # Not b. | |
312 | 'ax13876y25677y21378y21378y21378kbc' => 0, # 5 runs | |
313 | ); | |
314 | ||
315 | for ( keys %ans ) { | |
316 | print "# const-len `$_' not => $ans{$_}\nnot " | |
317 | if $ans{$_} xor /a(?=([yx]($long_constant_len)){2,4}[k-o]).*b./o; | |
318 | print "ok $test\n"; | |
319 | $test++; | |
320 | print "# var-len `$_' not => $ans{$_}\nnot " | |
321 | if $ans{$_} xor /a(?=([yx]($long_var_len)){2,4}[k-o]).*b./o; | |
322 | print "ok $test\n"; | |
323 | $test++; | |
324 | } | |
325 | ||
326 | $_ = " a (bla()) and x(y b((l)u((e))) and b(l(e)e)e"; | |
327 | $expect = "(bla()) ((l)u((e))) (l(e)e)"; | |
328 | ||
329 | sub matchit { | |
cc6b7395 | 330 | m/ |
c277df42 IZ |
331 | ( |
332 | \( | |
333 | (?{ $c = 1 }) # Initialize | |
334 | (?: | |
335 | (?(?{ $c == 0 }) # PREVIOUS iteration was OK, stop the loop | |
336 | (?! | |
337 | ) # Fail: will unwind one iteration back | |
338 | ) | |
339 | (?: | |
340 | [^()]+ # Match a big chunk | |
341 | (?= | |
342 | [()] | |
343 | ) # Do not try to match subchunks | |
344 | | | |
345 | \( | |
346 | (?{ ++$c }) | |
347 | | | |
348 | \) | |
349 | (?{ --$c }) | |
350 | ) | |
351 | )+ # This may not match with different subblocks | |
352 | ) | |
353 | (?(?{ $c != 0 }) | |
354 | (?! | |
355 | ) # Fail | |
356 | ) # Otherwise the chunk 1 may succeed with $c>0 | |
cc6b7395 | 357 | /xg; |
c277df42 IZ |
358 | } |
359 | ||
0f5d15d6 | 360 | @ans = (); |
c277df42 IZ |
361 | push @ans, $res while $res = matchit; |
362 | ||
363 | print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne "1 1 1"; | |
364 | print "ok $test\n"; | |
365 | $test++; | |
366 | ||
367 | @ans = matchit; | |
368 | ||
369 | print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne $expect; | |
370 | print "ok $test\n"; | |
371 | $test++; | |
372 | ||
96776eda GS |
373 | print "not " unless "abc" =~ /^(??{"a"})b/; |
374 | print "ok $test\n"; | |
375 | $test++; | |
376 | ||
0f5d15d6 | 377 | my $matched; |
14455d6c | 378 | $matched = qr/\((?:(?>[^()]+)|(??{$matched}))*\)/; |
0f5d15d6 IZ |
379 | |
380 | @ans = @ans1 = (); | |
381 | push(@ans, $res), push(@ans1, $&) while $res = m/$matched/g; | |
382 | ||
383 | print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne "1 1 1"; | |
384 | print "ok $test\n"; | |
385 | $test++; | |
386 | ||
387 | print "# ans1='@ans1'\n# expect='$expect'\nnot " if "@ans1" ne $expect; | |
388 | print "ok $test\n"; | |
389 | $test++; | |
390 | ||
391 | @ans = m/$matched/g; | |
392 | ||
393 | print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne $expect; | |
394 | print "ok $test\n"; | |
395 | $test++; | |
396 | ||
c277df42 IZ |
397 | @ans = ('a/b' =~ m%(.*/)?(.*)%); # Stack may be bad |
398 | print "not " if "@ans" ne 'a/ b'; | |
399 | print "ok $test\n"; | |
400 | $test++; | |
401 | ||
cc6b7395 | 402 | $code = '{$blah = 45}'; |
c277df42 | 403 | $blah = 12; |
2cd61cdb IZ |
404 | eval { /(?$code)/ }; |
405 | print "not " unless $@ and $@ =~ /not allowed at runtime/ and $blah == 12; | |
e4d48cc9 GS |
406 | print "ok $test\n"; |
407 | $test++; | |
408 | ||
2cd61cdb IZ |
409 | for $code ('{$blah = 45}','=xx') { |
410 | $blah = 12; | |
411 | $res = eval { "xx" =~ /(?$code)/o }; | |
412 | if ($code eq '=xx') { | |
413 | print "#'$@','$res','$blah'\nnot " unless not $@ and $res; | |
414 | } else { | |
415 | print "#'$@','$res','$blah'\nnot " unless $@ and $@ =~ /not allowed at runtime/ and $blah == 12; | |
416 | } | |
417 | print "ok $test\n"; | |
418 | $test++; | |
419 | } | |
420 | ||
e4d48cc9 GS |
421 | $code = '{$blah = 45}'; |
422 | $blah = 12; | |
423 | eval "/(?$code)/"; | |
cc6b7395 IZ |
424 | print "not " if $blah != 45; |
425 | print "ok $test\n"; | |
426 | $test++; | |
427 | ||
428 | $blah = 12; | |
429 | /(?{$blah = 45})/; | |
c277df42 IZ |
430 | print "not " if $blah != 45; |
431 | print "ok $test\n"; | |
432 | $test++; | |
433 | ||
74d6a13a MB |
434 | $x = 'banana'; |
435 | $x =~ /.a/g; | |
436 | print "not " unless pos($x) == 2; | |
437 | print "ok $test\n"; | |
438 | $test++; | |
439 | ||
440 | $x =~ /.z/gc; | |
441 | print "not " unless pos($x) == 2; | |
442 | print "ok $test\n"; | |
443 | $test++; | |
444 | ||
445 | sub f { | |
446 | my $p = $_[0]; | |
447 | return $p; | |
448 | } | |
449 | ||
450 | $x =~ /.a/g; | |
451 | print "not " unless f(pos($x)) == 4; | |
452 | print "ok $test\n"; | |
453 | $test++; | |
4599a1de | 454 | |
ce862d02 IZ |
455 | $x = $^R = 67; |
456 | 'foot' =~ /foo(?{$x = 12; 75})[t]/; | |
457 | print "not " unless $^R eq '75'; | |
458 | print "ok $test\n"; | |
459 | $test++; | |
460 | ||
461 | $x = $^R = 67; | |
462 | 'foot' =~ /foo(?{$x = 12; 75})[xy]/; | |
463 | print "not " unless $^R eq '67' and $x eq '12'; | |
464 | print "ok $test\n"; | |
465 | $test++; | |
466 | ||
467 | $x = $^R = 67; | |
468 | 'foot' =~ /foo(?{ $^R + 12 })((?{ $x = 12; $^R + 17 })[xy])?/; | |
469 | print "not " unless $^R eq '79' and $x eq '12'; | |
470 | print "ok $test\n"; | |
471 | $test++; | |
472 | ||
8782bef2 GB |
473 | print "not " unless qr/\b\v$/i eq '(?i-xsm:\bv$)'; |
474 | print "ok $test\n"; | |
475 | $test++; | |
476 | ||
477 | print "not " unless qr/\b\v$/s eq '(?s-xim:\bv$)'; | |
478 | print "ok $test\n"; | |
479 | $test++; | |
480 | ||
481 | print "not " unless qr/\b\v$/m eq '(?m-xis:\bv$)'; | |
482 | print "ok $test\n"; | |
483 | $test++; | |
484 | ||
485 | print "not " unless qr/\b\v$/x eq '(?x-ism:\bv$)'; | |
486 | print "ok $test\n"; | |
487 | $test++; | |
488 | ||
489 | print "not " unless qr/\b\v$/xism eq '(?msix:\bv$)'; | |
490 | print "ok $test\n"; | |
491 | $test++; | |
492 | ||
493 | print "not " unless qr/\b\v$/ eq '(?-xism:\bv$)'; | |
97197631 IZ |
494 | print "ok $test\n"; |
495 | $test++; | |
496 | ||
7e5428c5 IZ |
497 | $_ = 'xabcx'; |
498 | foreach $ans ('', 'c') { | |
499 | /(?<=(?=a)..)((?=c)|.)/g; | |
02db2b7b | 500 | print "# \$1 ='$1'\n# \$ans='$ans'\nnot " unless $1 eq $ans; |
7e5428c5 IZ |
501 | print "ok $test\n"; |
502 | $test++; | |
503 | } | |
504 | ||
505 | $_ = 'a'; | |
506 | foreach $ans ('', 'a', '') { | |
507 | /^|a|$/g; | |
02db2b7b | 508 | print "# \$& ='$&'\n# \$ans='$ans'\nnot " unless $& eq $ans; |
7e5428c5 IZ |
509 | print "ok $test\n"; |
510 | $test++; | |
511 | } | |
512 | ||
09f25ae4 IZ |
513 | sub prefixify { |
514 | my($v,$a,$b,$res) = @_; | |
515 | $v =~ s/\Q$a\E/$b/; | |
516 | print "not " unless $res eq $v; | |
517 | print "ok $test\n"; | |
518 | $test++; | |
519 | } | |
520 | prefixify('/a/b/lib/arch', "/a/b/lib", 'X/lib', 'X/lib/arch'); | |
521 | prefixify('/a/b/man/arch', "/a/b/man", 'X/man', 'X/man/arch'); | |
522 | ||
523 | $_ = 'var="foo"'; | |
524 | /(\")/; | |
525 | print "not " unless $1 and /$1/; | |
526 | print "ok $test\n"; | |
527 | $test++; | |
528 | ||
8782bef2 | 529 | $a=qr/(?{++$b})/; |
2cd61cdb IZ |
530 | $b = 7; |
531 | /$a$a/; | |
532 | print "not " unless $b eq '9'; | |
533 | print "ok $test\n"; | |
534 | $test++; | |
535 | ||
536 | $c="$a"; | |
537 | /$a$a/; | |
538 | print "not " unless $b eq '11'; | |
539 | print "ok $test\n"; | |
540 | $test++; | |
541 | ||
542 | { | |
543 | use re "eval"; | |
544 | /$a$c$a/; | |
545 | print "not " unless $b eq '14'; | |
546 | print "ok $test\n"; | |
547 | $test++; | |
548 | ||
160cb429 JH |
549 | local $lex_a = 2; |
550 | my $lex_a = 43; | |
551 | my $lex_b = 17; | |
552 | my $lex_c = 27; | |
553 | my $lex_res = ($lex_b =~ qr/$lex_b(?{ $lex_c = $lex_a++ })/); | |
554 | print "not " unless $lex_res eq '1'; | |
555 | print "ok $test\n"; | |
556 | $test++; | |
557 | print "not " unless $lex_a eq '44'; | |
558 | print "ok $test\n"; | |
559 | $test++; | |
560 | print "not " unless $lex_c eq '43'; | |
561 | print "ok $test\n"; | |
562 | $test++; | |
563 | ||
564 | ||
2cd61cdb IZ |
565 | no re "eval"; |
566 | $match = eval { /$a$c$a/ }; | |
567 | print "not " | |
568 | unless $b eq '14' and $@ =~ /Eval-group not allowed/ and not $match; | |
569 | print "ok $test\n"; | |
570 | $test++; | |
571 | } | |
cbce877f IZ |
572 | |
573 | { | |
160cb429 JH |
574 | local $lex_a = 2; |
575 | my $lex_a = 43; | |
576 | my $lex_b = 17; | |
577 | my $lex_c = 27; | |
578 | my $lex_res = ($lex_b =~ qr/17(?{ $lex_c = $lex_a++ })/); | |
579 | print "not " unless $lex_res eq '1'; | |
580 | print "ok $test\n"; | |
581 | $test++; | |
582 | print "not " unless $lex_a eq '44'; | |
583 | print "ok $test\n"; | |
584 | $test++; | |
585 | print "not " unless $lex_c eq '43'; | |
586 | print "ok $test\n"; | |
587 | $test++; | |
588 | } | |
589 | ||
590 | { | |
cbce877f IZ |
591 | package aa; |
592 | $c = 2; | |
593 | $::c = 3; | |
594 | '' =~ /(?{ $c = 4 })/; | |
595 | print "not " unless $c == 4; | |
596 | } | |
597 | print "ok $test\n"; | |
598 | $test++; | |
599 | print "not " unless $c == 3; | |
600 | print "ok $test\n"; | |
601 | $test++; | |
2cd61cdb | 602 | |
4599a1de JH |
603 | sub must_warn_pat { |
604 | my $warn_pat = shift; | |
605 | return sub { print "not " unless $_[0] =~ /$warn_pat/ } | |
606 | } | |
607 | ||
608 | sub must_warn { | |
609 | my ($warn_pat, $code) = @_; | |
9f1b1f2d GS |
610 | local %SIG; |
611 | eval 'BEGIN { use warnings; $SIG{__WARN__} = $warn_pat };' . $code; | |
4599a1de JH |
612 | print "ok $test\n"; |
613 | $test++; | |
614 | } | |
615 | ||
616 | ||
617 | sub make_must_warn { | |
618 | my $warn_pat = shift; | |
619 | return sub { must_warn(must_warn_pat($warn_pat)) } | |
620 | } | |
621 | ||
622 | my $for_future = make_must_warn('reserved for future extensions'); | |
623 | ||
624 | &$for_future('q(a:[b]:) =~ /[x[:foo:]]/'); | |
9baa0206 HS |
625 | |
626 | #&$for_future('q(a=[b]=) =~ /[x[=foo=]]/'); | |
627 | print "ok $test\n"; $test++; # now a fatal croak | |
628 | ||
629 | #&$for_future('q(a.[b].) =~ /[x[.foo.]]/'); | |
630 | print "ok $test\n"; $test++; # now a fatal croak | |
f7e33566 GS |
631 | |
632 | # test if failure of patterns returns empty list | |
633 | $_ = 'aaa'; | |
634 | @_ = /bbb/; | |
635 | print "not " if @_; | |
636 | print "ok $test\n"; | |
637 | $test++; | |
638 | ||
639 | @_ = /bbb/g; | |
640 | print "not " if @_; | |
641 | print "ok $test\n"; | |
642 | $test++; | |
643 | ||
644 | @_ = /(bbb)/; | |
645 | print "not " if @_; | |
646 | print "ok $test\n"; | |
647 | $test++; | |
648 | ||
649 | @_ = /(bbb)/g; | |
650 | print "not " if @_; | |
651 | print "ok $test\n"; | |
652 | $test++; | |
653 | ||
6cef1e77 IZ |
654 | /a(?=.$)/; |
655 | print "not " if $#+ != 0 or $#- != 0; | |
656 | print "ok $test\n"; | |
657 | $test++; | |
658 | ||
659 | print "not " if $+[0] != 2 or $-[0] != 1; | |
660 | print "ok $test\n"; | |
661 | $test++; | |
662 | ||
663 | print "not " | |
664 | if defined $+[1] or defined $-[1] or defined $+[2] or defined $-[2]; | |
665 | print "ok $test\n"; | |
666 | $test++; | |
667 | ||
668 | /a(a)(a)/; | |
669 | print "not " if $#+ != 2 or $#- != 2; | |
670 | print "ok $test\n"; | |
671 | $test++; | |
672 | ||
673 | print "not " if $+[0] != 3 or $-[0] != 0; | |
674 | print "ok $test\n"; | |
675 | $test++; | |
676 | ||
677 | print "not " if $+[1] != 2 or $-[1] != 1; | |
678 | print "ok $test\n"; | |
679 | $test++; | |
680 | ||
681 | print "not " if $+[2] != 3 or $-[2] != 2; | |
682 | print "ok $test\n"; | |
683 | $test++; | |
684 | ||
685 | print "not " | |
686 | if defined $+[3] or defined $-[3] or defined $+[4] or defined $-[4]; | |
687 | print "ok $test\n"; | |
688 | $test++; | |
689 | ||
690 | /.(a)(b)?(a)/; | |
691 | print "not " if $#+ != 3 or $#- != 3; | |
692 | print "ok $test\n"; | |
693 | $test++; | |
694 | ||
695 | print "not " if $+[0] != 3 or $-[0] != 0; | |
696 | print "ok $test\n"; | |
697 | $test++; | |
698 | ||
699 | print "not " if $+[1] != 2 or $-[1] != 1; | |
700 | print "ok $test\n"; | |
701 | $test++; | |
702 | ||
703 | print "not " if $+[3] != 3 or $-[3] != 2; | |
704 | print "ok $test\n"; | |
705 | $test++; | |
706 | ||
707 | print "not " | |
708 | if defined $+[2] or defined $-[2] or defined $+[4] or defined $-[4]; | |
709 | print "ok $test\n"; | |
710 | $test++; | |
711 | ||
712 | /.(a)/; | |
713 | print "not " if $#+ != 1 or $#- != 1; | |
714 | print "ok $test\n"; | |
715 | $test++; | |
716 | ||
717 | print "not " if $+[0] != 2 or $-[0] != 0; | |
718 | print "ok $test\n"; | |
719 | $test++; | |
720 | ||
721 | print "not " if $+[1] != 2 or $-[1] != 1; | |
722 | print "ok $test\n"; | |
723 | $test++; | |
724 | ||
725 | print "not " | |
726 | if defined $+[2] or defined $-[2] or defined $+[3] or defined $-[3]; | |
727 | print "ok $test\n"; | |
728 | $test++; | |
729 | ||
03a27ae7 MG |
730 | eval { $+[0] = 13; }; |
731 | print "not " | |
732 | if $@ !~ /^Modification of a read-only value attempted/; | |
733 | print "ok $test\n"; | |
734 | $test++; | |
735 | ||
736 | eval { $-[0] = 13; }; | |
737 | print "not " | |
738 | if $@ !~ /^Modification of a read-only value attempted/; | |
739 | print "ok $test\n"; | |
740 | $test++; | |
741 | ||
742 | eval { @+ = (7, 6, 5); }; | |
743 | print "not " | |
744 | if $@ !~ /^Modification of a read-only value attempted/; | |
745 | print "ok $test\n"; | |
746 | $test++; | |
747 | ||
748 | eval { @- = qw(foo bar); }; | |
749 | print "not " | |
750 | if $@ !~ /^Modification of a read-only value attempted/; | |
751 | print "ok $test\n"; | |
752 | $test++; | |
753 | ||
8f580fb8 IZ |
754 | /.(a)(ba*)?/; |
755 | print "#$#-..$#+\nnot " if $#+ != 2 or $#- != 1; | |
756 | print "ok $test\n"; | |
757 | $test++; | |
758 | ||
ad94a511 IZ |
759 | $_ = 'aaa'; |
760 | pos = 1; | |
761 | @a = /\Ga/g; | |
762 | print "not " unless "@a" eq "a a"; | |
763 | print "ok $test\n"; | |
764 | $test++; | |
765 | ||
22e551b9 IZ |
766 | $str = 'abcde'; |
767 | pos $str = 2; | |
768 | ||
769 | print "not " if $str =~ /^\G/; | |
770 | print "ok $test\n"; | |
771 | $test++; | |
772 | ||
773 | print "not " if $str =~ /^.\G/; | |
774 | print "ok $test\n"; | |
775 | $test++; | |
776 | ||
777 | print "not " unless $str =~ /^..\G/; | |
778 | print "ok $test\n"; | |
779 | $test++; | |
780 | ||
781 | print "not " if $str =~ /^...\G/; | |
782 | print "ok $test\n"; | |
783 | $test++; | |
784 | ||
785 | print "not " unless $str =~ /.\G./ and $& eq 'bc'; | |
786 | print "ok $test\n"; | |
787 | $test++; | |
788 | ||
789 | print "not " unless $str =~ /\G../ and $& eq 'cd'; | |
790 | print "ok $test\n"; | |
791 | $test++; | |
792 | ||
9661b544 IZ |
793 | undef $foo; undef $bar; |
794 | print "#'$str','$foo','$bar'\nnot " | |
795 | unless $str =~ /b(?{$foo = $_; $bar = pos})c/ | |
796 | and $foo eq 'abcde' and $bar eq 2; | |
797 | print "ok $test\n"; | |
798 | $test++; | |
799 | ||
800 | undef $foo; undef $bar; | |
801 | pos $str = undef; | |
802 | print "#'$str','$foo','$bar'\nnot " | |
803 | unless $str =~ /b(?{$foo = $_; $bar = pos})c/g | |
804 | and $foo eq 'abcde' and $bar eq 2 and pos $str eq 3; | |
805 | print "ok $test\n"; | |
806 | $test++; | |
807 | ||
808 | $_ = $str; | |
809 | ||
810 | undef $foo; undef $bar; | |
811 | print "#'$str','$foo','$bar'\nnot " | |
812 | unless /b(?{$foo = $_; $bar = pos})c/ | |
813 | and $foo eq 'abcde' and $bar eq 2; | |
814 | print "ok $test\n"; | |
815 | $test++; | |
816 | ||
817 | undef $foo; undef $bar; | |
818 | print "#'$str','$foo','$bar'\nnot " | |
819 | unless /b(?{$foo = $_; $bar = pos})c/g | |
820 | and $foo eq 'abcde' and $bar eq 2 and pos eq 3; | |
821 | print "ok $test\n"; | |
822 | $test++; | |
823 | ||
824 | undef $foo; undef $bar; | |
825 | pos = undef; | |
826 | 1 while /b(?{$foo = $_; $bar = pos})c/g; | |
827 | print "#'$str','$foo','$bar'\nnot " | |
828 | unless $foo eq 'abcde' and $bar eq 2 and not defined pos; | |
829 | print "ok $test\n"; | |
830 | $test++; | |
831 | ||
832 | undef $foo; undef $bar; | |
833 | $_ = 'abcde|abcde'; | |
834 | print "#'$str','$foo','$bar','$_'\nnot " | |
835 | unless s/b(?{$foo = $_; $bar = pos})c/x/g and $foo eq 'abcde|abcde' | |
836 | and $bar eq 8 and $_ eq 'axde|axde'; | |
837 | print "ok $test\n"; | |
838 | $test++; | |
839 | ||
5c5e4c24 IZ |
840 | @res = (); |
841 | # List context: | |
842 | $_ = 'abcde|abcde'; | |
843 | @dummy = /([ace]).(?{push @res, $1,$2})([ce])(?{push @res, $1,$2})/g; | |
844 | @res = map {defined $_ ? "'$_'" : 'undef'} @res; | |
845 | $res = "@res"; | |
846 | print "#'@res' '$_'\nnot " | |
847 | unless "@res" eq "'a' undef 'a' 'c' 'e' undef 'a' undef 'a' 'c'"; | |
848 | print "ok $test\n"; | |
849 | $test++; | |
850 | ||
851 | @res = (); | |
852 | @dummy = /([ace]).(?{push @res, $`,$&,$'})([ce])(?{push @res, $`,$&,$'})/g; | |
853 | @res = map {defined $_ ? "'$_'" : 'undef'} @res; | |
854 | $res = "@res"; | |
855 | print "#'@res' '$_'\nnot " | |
856 | unless "@res" eq | |
857 | "'' 'ab' 'cde|abcde' " . | |
858 | "'' 'abc' 'de|abcde' " . | |
859 | "'abcd' 'e|' 'abcde' " . | |
860 | "'abcde|' 'ab' 'cde' " . | |
861 | "'abcde|' 'abc' 'de'" ; | |
862 | print "ok $test\n"; | |
863 | $test++; | |
864 | ||
b7a35066 IZ |
865 | #Some more \G anchor checks |
866 | $foo='aabbccddeeffgg'; | |
867 | ||
868 | pos($foo)=1; | |
869 | ||
870 | $foo=~/.\G(..)/g; | |
871 | print "not " unless($1 eq 'ab'); | |
872 | print "ok $test\n"; | |
873 | $test++; | |
874 | ||
875 | pos($foo) += 1; | |
876 | $foo=~/.\G(..)/g; | |
877 | print "not " unless($1 eq 'cc'); | |
878 | print "ok $test\n"; | |
879 | $test++; | |
880 | ||
881 | pos($foo) += 1; | |
882 | $foo=~/.\G(..)/g; | |
883 | print "not " unless($1 eq 'de'); | |
884 | print "ok $test\n"; | |
885 | $test++; | |
886 | ||
0ef3e39e HS |
887 | print "not " unless $foo =~ /\Gef/g; |
888 | print "ok $test\n"; | |
889 | $test++; | |
890 | ||
b7a35066 IZ |
891 | undef pos $foo; |
892 | ||
893 | $foo=~/\G(..)/g; | |
894 | print "not " unless($1 eq 'aa'); | |
895 | print "ok $test\n"; | |
896 | $test++; | |
897 | ||
898 | $foo=~/\G(..)/g; | |
899 | print "not " unless($1 eq 'bb'); | |
900 | print "ok $test\n"; | |
901 | $test++; | |
902 | ||
903 | pos($foo)=5; | |
904 | $foo=~/\G(..)/g; | |
905 | print "not " unless($1 eq 'cd'); | |
906 | print "ok $test\n"; | |
907 | $test++; | |
908 | ||
e60df1fa IZ |
909 | $_='123x123'; |
910 | @res = /(\d*|x)/g; | |
911 | print "not " unless('123||x|123|' eq join '|', @res); | |
912 | print "ok $test\n"; | |
913 | $test++; | |
914 | ||
9d080a66 GS |
915 | # see if matching against temporaries (created via pp_helem()) is safe |
916 | { foo => "ok $test\n".$^X }->{foo} =~ /^(.*)\n/g; | |
917 | print "$1\n"; | |
918 | $test++; | |
919 | ||
cf93c79d IZ |
920 | # See if $i work inside (?{}) in the presense of saved substrings and |
921 | # changing $_ | |
922 | @a = qw(foo bar); | |
923 | @b = (); | |
924 | s/(\w)(?{push @b, $1})/,$1,/g for @a; | |
925 | ||
926 | print "# \@b='@b', expect 'f o o b a r'\nnot " unless("@b" eq "f o o b a r"); | |
927 | print "ok $test\n"; | |
928 | $test++; | |
929 | ||
930 | print "not " unless("@a" eq ",f,,o,,o, ,b,,a,,r,"); | |
931 | print "ok $test\n"; | |
932 | $test++; | |
933 | ||
2c914db6 | 934 | $brackets = qr{ |
14455d6c | 935 | { (?> [^{}]+ | (??{ $brackets }) )* } |
2c914db6 IZ |
936 | }x; |
937 | ||
938 | "{{}" =~ $brackets; | |
939 | print "ok $test\n"; # Did we survive? | |
940 | $test++; | |
941 | ||
942 | "something { long { and } hairy" =~ $brackets; | |
943 | print "ok $test\n"; # Did we survive? | |
944 | $test++; | |
945 | ||
14455d6c | 946 | "something { long { and } hairy" =~ m/((??{ $brackets }))/; |
2c914db6 IZ |
947 | print "not " unless $1 eq "{ and }"; |
948 | print "ok $test\n"; | |
949 | $test++; | |
950 | ||
30944b6d IZ |
951 | $_ = "a-a\nxbb"; |
952 | pos=1; | |
953 | m/^-.*bb/mg and print "not "; | |
954 | print "ok $test\n"; | |
955 | $test++; | |
30382c73 IZ |
956 | |
957 | $text = "aaXbXcc"; | |
958 | pos($text)=0; | |
959 | $text =~ /\GXb*X/g and print 'not '; | |
960 | print "ok $test\n"; | |
961 | $test++; | |
3cf5c195 IZ |
962 | |
963 | $text = "xA\n" x 500; | |
964 | $text =~ /^\s*A/m and print 'not '; | |
965 | print "ok $test\n"; | |
966 | $test++; | |
d506a20d IZ |
967 | |
968 | $text = "abc dbf"; | |
969 | @res = ($text =~ /.*?(b).*?\b/g); | |
970 | "@res" eq 'b b' or print 'not '; | |
971 | print "ok $test\n"; | |
972 | $test++; | |
973 | ||
9442cb0e | 974 | @a = map chr,0..255; |
aeaf5620 GS |
975 | |
976 | @b = grep(/\S/,@a); | |
977 | @c = grep(/[^\s]/,@a); | |
978 | print "not " if "@b" ne "@c"; | |
9442cb0e GS |
979 | print "ok $test\n"; |
980 | $test++; | |
981 | ||
aeaf5620 GS |
982 | @b = grep(/\S/,@a); |
983 | @c = grep(/[\S]/,@a); | |
984 | print "not " if "@b" ne "@c"; | |
9442cb0e GS |
985 | print "ok $test\n"; |
986 | $test++; | |
987 | ||
aeaf5620 GS |
988 | @b = grep(/\s/,@a); |
989 | @c = grep(/[^\S]/,@a); | |
990 | print "not " if "@b" ne "@c"; | |
9442cb0e GS |
991 | print "ok $test\n"; |
992 | $test++; | |
993 | ||
aeaf5620 GS |
994 | @b = grep(/\s/,@a); |
995 | @c = grep(/[\s]/,@a); | |
996 | print "not " if "@b" ne "@c"; | |
9442cb0e GS |
997 | print "ok $test\n"; |
998 | $test++; | |
999 | ||
aeaf5620 GS |
1000 | @b = grep(/\D/,@a); |
1001 | @c = grep(/[^\d]/,@a); | |
1002 | print "not " if "@b" ne "@c"; | |
9442cb0e GS |
1003 | print "ok $test\n"; |
1004 | $test++; | |
1005 | ||
aeaf5620 GS |
1006 | @b = grep(/\D/,@a); |
1007 | @c = grep(/[\D]/,@a); | |
1008 | print "not " if "@b" ne "@c"; | |
9442cb0e GS |
1009 | print "ok $test\n"; |
1010 | $test++; | |
1011 | ||
aeaf5620 GS |
1012 | @b = grep(/\d/,@a); |
1013 | @c = grep(/[^\D]/,@a); | |
1014 | print "not " if "@b" ne "@c"; | |
9442cb0e GS |
1015 | print "ok $test\n"; |
1016 | $test++; | |
1017 | ||
aeaf5620 GS |
1018 | @b = grep(/\d/,@a); |
1019 | @c = grep(/[\d]/,@a); | |
1020 | print "not " if "@b" ne "@c"; | |
9442cb0e GS |
1021 | print "ok $test\n"; |
1022 | $test++; | |
1023 | ||
aeaf5620 GS |
1024 | @b = grep(/\W/,@a); |
1025 | @c = grep(/[^\w]/,@a); | |
1026 | print "not " if "@b" ne "@c"; | |
9442cb0e GS |
1027 | print "ok $test\n"; |
1028 | $test++; | |
1029 | ||
aeaf5620 GS |
1030 | @b = grep(/\W/,@a); |
1031 | @c = grep(/[\W]/,@a); | |
1032 | print "not " if "@b" ne "@c"; | |
9442cb0e GS |
1033 | print "ok $test\n"; |
1034 | $test++; | |
1035 | ||
aeaf5620 GS |
1036 | @b = grep(/\w/,@a); |
1037 | @c = grep(/[^\W]/,@a); | |
1038 | print "not " if "@b" ne "@c"; | |
9442cb0e GS |
1039 | print "ok $test\n"; |
1040 | $test++; | |
1041 | ||
aeaf5620 GS |
1042 | @b = grep(/\w/,@a); |
1043 | @c = grep(/[\w]/,@a); | |
1044 | print "not " if "@b" ne "@c"; | |
9442cb0e GS |
1045 | print "ok $test\n"; |
1046 | $test++; | |
1aeab75a GS |
1047 | |
1048 | # see if backtracking optimization works correctly | |
1049 | "\n\n" =~ /\n $ \n/x or print "not "; | |
1050 | print "ok $test\n"; | |
1051 | $test++; | |
1052 | ||
1053 | "\n\n" =~ /\n* $ \n/x or print "not "; | |
1054 | print "ok $test\n"; | |
1055 | $test++; | |
1056 | ||
1057 | "\n\n" =~ /\n+ $ \n/x or print "not "; | |
1058 | print "ok $test\n"; | |
1059 | $test++; | |
05b4157f GS |
1060 | |
1061 | [] =~ /^ARRAY/ or print "# [] \nnot "; | |
1062 | print "ok $test\n"; | |
1063 | $test++; | |
1064 | ||
1065 | eval << 'EOE'; | |
1066 | { | |
1067 | package S; | |
1068 | use overload '""' => sub { 'Object S' }; | |
1069 | sub new { bless [] } | |
1070 | } | |
1071 | $a = 'S'->new; | |
1072 | EOE | |
1073 | ||
1074 | $a and $a =~ /^Object\sS/ or print "# '$a' \nnot "; | |
1075 | print "ok $test\n"; | |
1076 | $test++; | |
815d35b9 MG |
1077 | |
1078 | # test result of match used as match (!) | |
1079 | 'a1b' =~ ('xyz' =~ /y/) and $` eq 'a' or print "not "; | |
1080 | print "ok $test\n"; | |
1081 | $test++; | |
1082 | ||
1083 | 'a1b' =~ ('xyz' =~ /t/) and $` eq 'a' or print "not "; | |
1084 | print "ok $test\n"; | |
1085 | $test++; | |
5e39e1e5 HS |
1086 | |
1087 | $w = 0; | |
1088 | { | |
1089 | local $SIG{__WARN__} = sub { $w = 1 }; | |
1090 | local $^W = 1; | |
1091 | $w = 1 if ("1\n" x 102) =~ /^\s*\n/m; | |
1092 | } | |
1093 | print $w ? "not " : "", "ok $test\n"; | |
1094 | $test++; | |
aaa51d5e JF |
1095 | |
1096 | my %space = ( spc => " ", | |
1097 | tab => "\t", | |
1098 | cr => "\r", | |
1099 | lf => "\n", | |
1100 | ff => "\f", | |
75369ccb JH |
1101 | # There's no \v but the vertical tabulator seems miraculously |
1102 | # be 11 both in ASCII and EBCDIC. | |
aaa51d5e JF |
1103 | vt => chr(11), |
1104 | false => "space" ); | |
1105 | ||
1106 | my @space0 = sort grep { $space{$_} =~ /\s/ } keys %space; | |
1107 | my @space1 = sort grep { $space{$_} =~ /[[:space:]]/ } keys %space; | |
1108 | my @space2 = sort grep { $space{$_} =~ /[[:blank:]]/ } keys %space; | |
1109 | ||
1110 | print "not " unless "@space0" eq "cr ff lf spc tab"; | |
3bec3564 | 1111 | print "ok $test # @space0\n"; |
aaa51d5e JF |
1112 | $test++; |
1113 | ||
1114 | print "not " unless "@space1" eq "cr ff lf spc tab vt"; | |
3bec3564 | 1115 | print "ok $test # @space1\n"; |
aaa51d5e JF |
1116 | $test++; |
1117 | ||
1118 | print "not " unless "@space2" eq "spc tab"; | |
3bec3564 | 1119 | print "ok $test # @space2\n"; |
aaa51d5e JF |
1120 | $test++; |
1121 | ||
a1933d95 HS |
1122 | # bugid 20001021.005 - this caused a SEGV |
1123 | print "not " unless undef =~ /^([^\/]*)(.*)$/; | |
1124 | print "ok $test\n"; | |
1125 | $test++; | |
b91bb191 JH |
1126 | |
1127 | # bugid 20000731.001 | |
1128 | ||
1129 | print "not " unless "A \x{263a} B z C" =~ /A . B (??{ "z" }) C/; | |
1130 | print "ok $test\n"; | |
1131 | $test++; | |
1132 | ||
3baa4c62 JH |
1133 | $_ = "a\x{100}b"; |
1134 | if (/(.)(\C)(\C)(.)/) { | |
1135 | print "ok 232\n"; | |
1136 | if ($1 eq "a") { | |
1137 | print "ok 233\n"; | |
1138 | } else { | |
1139 | print "not ok 233\n"; | |
1140 | } | |
1141 | if ($2 eq "\xC4") { | |
1142 | print "ok 234\n"; | |
1143 | } else { | |
1144 | print "not ok 234\n"; | |
1145 | } | |
1146 | if ($3 eq "\x80") { | |
1147 | print "ok 235\n"; | |
1148 | } else { | |
1149 | print "not ok 235\n"; | |
1150 | } | |
1151 | if ($4 eq "b") { | |
1152 | print "ok 236\n"; | |
1153 | } else { | |
1154 | print "not ok 236\n"; | |
1155 | } | |
1156 | } else { | |
1157 | for (232..236) { | |
1158 | print "not ok $_\n"; | |
1159 | } | |
1160 | } | |
1161 | $_ = "\x{100}"; | |
1162 | if (/(\C)/g) { | |
1163 | print "ok 237\n"; | |
1164 | if ($1 eq "\xC4") { | |
1165 | print "ok 238\n"; | |
1166 | } else { | |
1167 | print "not ok 238\n"; | |
1168 | } | |
1169 | } else { | |
1170 | for (237..238) { | |
1171 | print "not ok $_\n"; | |
1172 | } | |
1173 | } | |
1174 | if (/(\C)/g) { | |
1175 | print "ok 239\n"; | |
1176 | if ($1 eq "\x80") { | |
1177 | print "ok 240\n"; | |
1178 | } else { | |
1179 | print "not ok 240\n"; | |
1180 | } | |
1181 | } else { | |
1182 | for (239..240) { | |
1183 | print "not ok $_\n"; | |
1184 | } | |
1185 | } | |
b485d051 | 1186 | |
db615365 JP |
1187 | { |
1188 | # japhy -- added 03/03/2001 | |
1189 | () = (my $str = "abc") =~ /(...)/; | |
1190 | $str = "def"; | |
1191 | print "not " if $1 ne "abc"; | |
fd291da9 JH |
1192 | print "ok 241\n"; |
1193 | } | |
1194 | ||
1195 | # The 242 and 243 go with the 244 and 245. | |
1196 | # The trick is that in EBCDIC the explicit numeric range should match | |
1197 | # (as also in non-EBCDIC) but the explicit alphabetic range should not match. | |
1198 | ||
1199 | if ("\x8e" =~ /[\x89-\x91]/) { | |
1200 | print "ok 242\n"; | |
1201 | } else { | |
1202 | print "not ok 242\n"; | |
1203 | } | |
1204 | ||
1205 | if ("\xce" =~ /[\xc9-\xd1]/) { | |
db615365 | 1206 | print "ok 243\n"; |
fd291da9 JH |
1207 | } else { |
1208 | print "not ok 243\n"; | |
1209 | } | |
1210 | ||
1211 | # In most places these tests would succeed since \x8e does not | |
1212 | # in most character sets match 'i' or 'j' nor would \xce match | |
1213 | # 'I' or 'J', but strictly speaking these tests are here for | |
1214 | # the good of EBCDIC, so let's test these only there. | |
1215 | if (ord('i') == 0x89 && ord('J') == 0xd1) { # EBCDIC | |
1216 | if ("\x8e" !~ /[i-j]/) { | |
1217 | print "ok 244\n"; | |
1218 | } else { | |
1219 | print "not ok 244\n"; | |
1220 | } | |
1221 | if ("\xce" !~ /[I-J]/) { | |
1222 | print "ok 245\n"; | |
1223 | } else { | |
1224 | print "not ok 245\n"; | |
1225 | } | |
1226 | } else { | |
1227 | for (244..245) { | |
1228 | print "ok $_ # Skip: not EBCDIC\n"; | |
1229 | } | |
db615365 | 1230 | } |