This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #18209] bug in regex s/\s$word\s/ /gi; and $&
[perl5.git] / t / op / pat.t
CommitLineData
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
9133bbab 7$| = 1;
3568d838 8
fc8cd66c 9# Test counter output is generated by a BEGIN block at bottom of file
8d37f932 10
e4d48cc9
GS
11BEGIN {
12 chdir 't' if -d 't';
20822f61 13 @INC = '../lib';
e4d48cc9 14}
f0852a51 15our $Message = "Line";
ffbc6a93 16
8d37f932 17eval 'use Config'; # Defaults assumed if this fails
8d063cd8
LW
18
19$x = "abc\ndef\n";
20
21if ($x =~ /^abc/) {print "ok 1\n";} else {print "not ok 1\n";}
22if ($x !~ /^def/) {print "ok 2\n";} else {print "not ok 2\n";}
23
f02c194e
RGS
24# used to be a test for $*
25if ($x =~ /^def/m) {print "ok 3\n";} else {print "not ok 3\n";}
8d063cd8
LW
26
27$_ = '123';
28if (/^([0-9][0-9]*)/) {print "ok 4\n";} else {print "not ok 4\n";}
29
30if ($x =~ /^xxx/) {print "not ok 5\n";} else {print "ok 5\n";}
31if ($x !~ /^abc/) {print "not ok 6\n";} else {print "ok 6\n";}
32
33if ($x =~ /def/) {print "ok 7\n";} else {print "not ok 7\n";}
34if ($x !~ /def/) {print "not ok 8\n";} else {print "ok 8\n";}
35
36if ($x !~ /.def/) {print "ok 9\n";} else {print "not ok 9\n";}
37if ($x =~ /.def/) {print "not ok 10\n";} else {print "ok 10\n";}
38
39if ($x =~ /\ndef/) {print "ok 11\n";} else {print "not ok 11\n";}
40if ($x !~ /\ndef/) {print "not ok 12\n";} else {print "ok 12\n";}
41
42$_ = 'aaabbbccc';
43if (/(a*b*)(c*)/ && $1 eq 'aaabbb' && $2 eq 'ccc') {
44 print "ok 13\n";
45} else {
46 print "not ok 13\n";
47}
48if (/(a+b+c+)/ && $1 eq 'aaabbbccc') {
49 print "ok 14\n";
50} else {
51 print "not ok 14\n";
52}
53
54if (/a+b?c+/) {print "not ok 15\n";} else {print "ok 15\n";}
55
56$_ = 'aaabccc';
57if (/a+b?c+/) {print "ok 16\n";} else {print "not ok 16\n";}
58if (/a*b+c*/) {print "ok 17\n";} else {print "not ok 17\n";}
59
60$_ = 'aaaccc';
61if (/a*b?c*/) {print "ok 18\n";} else {print "not ok 18\n";}
62if (/a*b+c*/) {print "not ok 19\n";} else {print "ok 19\n";}
63
64$_ = 'abcdef';
65if (/bcd|xyz/) {print "ok 20\n";} else {print "not ok 20\n";}
66if (/xyz|bcd/) {print "ok 21\n";} else {print "not ok 21\n";}
67
68if (m|bc/*d|) {print "ok 22\n";} else {print "not ok 22\n";}
378cc40b
LW
69
70if (/^$_$/) {print "ok 23\n";} else {print "not ok 23\n";}
71
f02c194e
RGS
72# used to be a test for $*
73if ("ab\ncd\n" =~ /^cd/m) {print "ok 24\n";} else {print "not ok 24\n";}
378cc40b 74
cb55de95
JH
75$XXX{123} = 123;
76$XXX{234} = 234;
77$XXX{345} = 345;
78
79@XXX = ('ok 25','not ok 25', 'ok 26','not ok 26','not ok 27');
80while ($_ = shift(@XXX)) {
81 ?(.*)? && (print $1,"\n");
82 /not/ && reset;
1606b0c7
JM
83 if (/not ok 26/) {
84 if ($^O eq 'VMS') {
85 $_ = shift(@XXX);
86 }
87 else {
88 reset 'X';
89 }
90 }
cb55de95
JH
91}
92
1606b0c7
JM
93if ($^O ne 'VMS') {
94 while (($key,$val) = each(%XXX)) {
cb55de95
JH
95 print "not ok 27\n";
96 exit;
1606b0c7 97 }
cb55de95
JH
98}
99
100print "ok 27\n";
378cc40b 101
378cc40b
LW
102'cde' =~ /[^ab]*/;
103'xyz' =~ //;
104if ($& eq 'xyz') {print "ok 28\n";} else {print "not ok 28\n";}
105
106$foo = '[^ab]*';
107'cde' =~ /$foo/;
108'xyz' =~ //;
109if ($& eq 'xyz') {print "ok 29\n";} else {print "not ok 29\n";}
110
111$foo = '[^ab]*';
112'cde' =~ /$foo/;
113'xyz' =~ /$null/;
114if ($& eq 'xyz') {print "ok 30\n";} else {print "not ok 30\n";}
a687059c
LW
115
116$_ = 'abcdefghi';
117/def/; # optimized up to cmd
118if ("$`:$&:$'" eq 'abc:def:ghi') {print "ok 31\n";} else {print "not ok 31\n";}
119
120/cde/ + 0; # optimized only to spat
121if ("$`:$&:$'" eq 'ab:cde:fghi') {print "ok 32\n";} else {print "not ok 32\n";}
122
123/[d][e][f]/; # not optimized
124if ("$`:$&:$'" eq 'abc:def:ghi') {print "ok 33\n";} else {print "not ok 33\n";}
125
126$_ = 'now is the {time for all} good men to come to.';
127/ {([^}]*)}/;
128if ($1 eq 'time for all') {print "ok 34\n";} else {print "not ok 34 $1\n";}
129
130$_ = 'xxx {3,4} yyy zzz';
131print /( {3,4})/ ? "ok 35\n" : "not ok 35\n";
132print $1 eq ' ' ? "ok 36\n" : "not ok 36\n";
133print /( {4,})/ ? "not ok 37\n" : "ok 37\n";
134print /( {2,3}.)/ ? "ok 38\n" : "not ok 38\n";
135print $1 eq ' y' ? "ok 39\n" : "not ok 39\n";
136print /(y{2,3}.)/ ? "ok 40\n" : "not ok 40\n";
137print $1 eq 'yyy ' ? "ok 41\n" : "not ok 41\n";
138print /x {3,4}/ ? "not ok 42\n" : "ok 42\n";
139print /^xxx {3,4}/ ? "not ok 43\n" : "ok 43\n";
352d5a3a
LW
140
141$_ = "now is the time for all good men to come to.";
142@words = /(\w+)/g;
143print join(':',@words) eq "now:is:the:time:for:all:good:men:to:come:to"
144 ? "ok 44\n"
145 : "not ok 44\n";
146
147@words = ();
148while (/\w+/g) {
149 push(@words, $&);
150}
151print join(':',@words) eq "now:is:the:time:for:all:good:men:to:come:to"
152 ? "ok 45\n"
153 : "not ok 45\n";
154
155@words = ();
71be2cbc 156pos = 0;
352d5a3a
LW
157while (/to/g) {
158 push(@words, $&);
159}
160print join(':',@words) eq "to:to"
161 ? "ok 46\n"
71be2cbc 162 : "not ok 46 `@words'\n";
352d5a3a 163
71be2cbc 164pos $_ = 0;
352d5a3a
LW
165@words = /to/g;
166print join(':',@words) eq "to:to"
167 ? "ok 47\n"
71be2cbc 168 : "not ok 47 `@words'\n";
352d5a3a
LW
169
170$_ = "abcdefghi";
171
172$pat1 = 'def';
173$pat2 = '^def';
174$pat3 = '.def.';
175$pat4 = 'abc';
176$pat5 = '^abc';
177$pat6 = 'abc$';
178$pat7 = 'ghi';
179$pat8 = '\w*ghi';
180$pat9 = 'ghi$';
181
182$t1=$t2=$t3=$t4=$t5=$t6=$t7=$t8=$t9=0;
183
184for $iter (1..5) {
185 $t1++ if /$pat1/o;
186 $t2++ if /$pat2/o;
187 $t3++ if /$pat3/o;
188 $t4++ if /$pat4/o;
189 $t5++ if /$pat5/o;
190 $t6++ if /$pat6/o;
191 $t7++ if /$pat7/o;
192 $t8++ if /$pat8/o;
193 $t9++ if /$pat9/o;
194}
195
196$x = "$t1$t2$t3$t4$t5$t6$t7$t8$t9";
197print $x eq '505550555' ? "ok 48\n" : "not ok 48 $x\n";
1462b684
LW
198
199$xyz = 'xyz';
200print "abc" =~ /^abc$|$xyz/ ? "ok 49\n" : "not ok 49\n";
201
202# perl 4.009 says "unmatched ()"
203eval '"abc" =~ /a(bc$)|$xyz/; $result = "$&:$1"';
204print $@ eq "" ? "ok 50\n" : "not ok 50\n";
205print $result eq "abc:bc" ? "ok 51\n" : "not ok 51\n";
a0d0e21e
LW
206
207
208$_="abcfooabcbar";
209$x=/abc/g;
210print $` eq "" ? "ok 52\n" : "not ok 52\n" if $x;
211$x=/abc/g;
212print $` eq "abcfoo" ? "ok 53\n" : "not ok 53\n" if $x;
213$x=/abc/g;
214print $x == 0 ? "ok 54\n" : "not ok 54\n";
71be2cbc 215pos = 0;
a0d0e21e
LW
216$x=/ABC/gi;
217print $` eq "" ? "ok 55\n" : "not ok 55\n" if $x;
218$x=/ABC/gi;
219print $` eq "abcfoo" ? "ok 56\n" : "not ok 56\n" if $x;
220$x=/ABC/gi;
221print $x == 0 ? "ok 57\n" : "not ok 57\n";
71be2cbc 222pos = 0;
a0d0e21e
LW
223$x=/abc/g;
224print $' eq "fooabcbar" ? "ok 58\n" : "not ok 58\n" if $x;
225$x=/abc/g;
226print $' eq "bar" ? "ok 59\n" : "not ok 59\n" if $x;
227$_ .= '';
228@x=/abc/g;
229print scalar @x == 2 ? "ok 60\n" : "not ok 60\n";
71be2cbc
PP
230
231$_ = "abdc";
232pos $_ = 2;
c90c0ff4 233/\Gc/gc;
71be2cbc
PP
234print "not " if (pos $_) != 2;
235print "ok 61\n";
c90c0ff4
PP
236/\Gc/g;
237print "not " if defined pos $_;
238print "ok 62\n";
c277df42
IZ
239
240$out = 1;
241'abc' =~ m'a(?{ $out = 2 })b';
242print "not " if $out != 2;
243print "ok 63\n";
244
245$out = 1;
246'abc' =~ m'a(?{ $out = 3 })c';
247print "not " if $out != 1;
459f542a 248print "ok 64\n";
c277df42
IZ
249
250$_ = 'foobar1 bar2 foobar3 barfoobar5 foobar6';
251@out = /(?<!foo)bar./g;
252print "not " if "@out" ne 'bar2 barf';
253print "ok 65\n";
254
8d37f932
DD
255# Tests which depend on REG_INFTY
256$reg_infty = defined $Config{reg_infty} ? $Config{reg_infty} : 32767;
257$reg_infty_m = $reg_infty - 1; $reg_infty_p = $reg_infty + 1;
258
259# As well as failing if the pattern matches do unexpected things, the
260# next three tests will fail if you should have picked up a lower-than-
261# default value for $reg_infty from Config.pm, but have not.
262
263undef $@;
264print "not " if eval q(('aaa' =~ /(a{1,$reg_infty_m})/)[0] ne 'aaa') || $@;
265print "ok 66\n";
266
267undef $@;
268print "not " if eval q(('a' x $reg_infty_m) !~ /a{$reg_infty_m}/) || $@;
269print "ok 67\n";
270
271undef $@;
272print "not " if eval q(('a' x ($reg_infty_m - 1)) =~ /a{$reg_infty_m}/) || $@;
273print "ok 68\n";
274
275undef $@;
276eval "'aaa' =~ /a{1,$reg_infty}/";
9baa0206 277print "not " if $@ !~ m%^\QQuantifier in {,} bigger than%;
8d37f932
DD
278print "ok 69\n";
279
280eval "'aaa' =~ /a{1,$reg_infty_p}/";
281print "not "
9baa0206 282 if $@ !~ m%^\QQuantifier in {,} bigger than%;
8d37f932
DD
283print "ok 70\n";
284undef $@;
285
286# Poke a couple more parse failures
287
288$context = 'x' x 256;
289eval qq("${context}y" =~ /(?<=$context)y/);
9baa0206 290print "not " if $@ !~ m%^\QLookbehind longer than 255 not%;
8d37f932
DD
291print "ok 71\n";
292
b8c5462f 293# removed test
8d37f932
DD
294print "ok 72\n";
295
c277df42 296# Long Monsters
8d37f932 297$test = 73;
c277df42
IZ
298for $l (125, 140, 250, 270, 300000, 30) { # Ordered to free memory
299 $a = 'a' x $l;
300 print "# length=$l\nnot " unless "ba$a=" =~ /a$a=/;
301 print "ok $test\n";
302 $test++;
73d6d589 303
c277df42
IZ
304 print "not " if "b$a=" =~ /a$a=/;
305 print "ok $test\n";
306 $test++;
307}
308
309# 20000 nodes, each taking 3 words per string, and 1 per branch
310$long_constant_len = join '|', 12120 .. 32645;
311$long_var_len = join '|', 8120 .. 28645;
312%ans = ( 'ax13876y25677lbc' => 1,
313 'ax13876y25677mcb' => 0, # not b.
314 'ax13876y35677nbc' => 0, # Num too big
315 'ax13876y25677y21378obc' => 1,
316 'ax13876y25677y21378zbc' => 0, # Not followed by [k-o]
317 'ax13876y25677y21378y21378kbc' => 1,
318 'ax13876y25677y21378y21378kcb' => 0, # Not b.
319 'ax13876y25677y21378y21378y21378kbc' => 0, # 5 runs
320 );
321
322for ( keys %ans ) {
73d6d589 323 print "# const-len `$_' not => $ans{$_}\nnot "
c277df42
IZ
324 if $ans{$_} xor /a(?=([yx]($long_constant_len)){2,4}[k-o]).*b./o;
325 print "ok $test\n";
326 $test++;
73d6d589 327 print "# var-len `$_' not => $ans{$_}\nnot "
c277df42
IZ
328 if $ans{$_} xor /a(?=([yx]($long_var_len)){2,4}[k-o]).*b./o;
329 print "ok $test\n";
330 $test++;
331}
332
333$_ = " a (bla()) and x(y b((l)u((e))) and b(l(e)e)e";
334$expect = "(bla()) ((l)u((e))) (l(e)e)";
335
73d6d589 336sub matchit {
cc6b7395 337 m/
c277df42 338 (
73d6d589 339 \(
c277df42
IZ
340 (?{ $c = 1 }) # Initialize
341 (?:
342 (?(?{ $c == 0 }) # PREVIOUS iteration was OK, stop the loop
343 (?!
344 ) # Fail: will unwind one iteration back
73d6d589 345 )
c277df42
IZ
346 (?:
347 [^()]+ # Match a big chunk
348 (?=
349 [()]
350 ) # Do not try to match subchunks
351 |
73d6d589 352 \(
c277df42
IZ
353 (?{ ++$c })
354 |
73d6d589 355 \)
c277df42
IZ
356 (?{ --$c })
357 )
358 )+ # This may not match with different subblocks
359 )
360 (?(?{ $c != 0 })
361 (?!
362 ) # Fail
363 ) # Otherwise the chunk 1 may succeed with $c>0
cc6b7395 364 /xg;
c277df42
IZ
365}
366
0f5d15d6 367@ans = ();
c277df42
IZ
368push @ans, $res while $res = matchit;
369
370print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne "1 1 1";
371print "ok $test\n";
372$test++;
373
374@ans = matchit;
375
376print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne $expect;
377print "ok $test\n";
378$test++;
379
96776eda
GS
380print "not " unless "abc" =~ /^(??{"a"})b/;
381print "ok $test\n";
382$test++;
383
0f5d15d6 384my $matched;
14455d6c 385$matched = qr/\((?:(?>[^()]+)|(??{$matched}))*\)/;
0f5d15d6
IZ
386
387@ans = @ans1 = ();
388push(@ans, $res), push(@ans1, $&) while $res = m/$matched/g;
389
390print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne "1 1 1";
391print "ok $test\n";
392$test++;
393
394print "# ans1='@ans1'\n# expect='$expect'\nnot " if "@ans1" ne $expect;
395print "ok $test\n";
396$test++;
397
398@ans = m/$matched/g;
399
400print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne $expect;
401print "ok $test\n";
402$test++;
403
c277df42
IZ
404@ans = ('a/b' =~ m%(.*/)?(.*)%); # Stack may be bad
405print "not " if "@ans" ne 'a/ b';
406print "ok $test\n";
407$test++;
408
cc6b7395 409$code = '{$blah = 45}';
c277df42 410$blah = 12;
2cd61cdb
IZ
411eval { /(?$code)/ };
412print "not " unless $@ and $@ =~ /not allowed at runtime/ and $blah == 12;
e4d48cc9
GS
413print "ok $test\n";
414$test++;
415
2cd61cdb
IZ
416for $code ('{$blah = 45}','=xx') {
417 $blah = 12;
418 $res = eval { "xx" =~ /(?$code)/o };
419 if ($code eq '=xx') {
420 print "#'$@','$res','$blah'\nnot " unless not $@ and $res;
421 } else {
73d6d589 422 print "#'$@','$res','$blah'\nnot " unless $@ and $@ =~ /not allowed at runtime/ and $blah == 12;
2cd61cdb
IZ
423 }
424 print "ok $test\n";
425 $test++;
426}
427
e4d48cc9
GS
428$code = '{$blah = 45}';
429$blah = 12;
430eval "/(?$code)/";
cc6b7395
IZ
431print "not " if $blah != 45;
432print "ok $test\n";
433$test++;
434
435$blah = 12;
436/(?{$blah = 45})/;
c277df42
IZ
437print "not " if $blah != 45;
438print "ok $test\n";
439$test++;
440
74d6a13a
MB
441$x = 'banana';
442$x =~ /.a/g;
443print "not " unless pos($x) == 2;
444print "ok $test\n";
445$test++;
446
447$x =~ /.z/gc;
448print "not " unless pos($x) == 2;
449print "ok $test\n";
450$test++;
451
452sub f {
453 my $p = $_[0];
454 return $p;
455}
456
457$x =~ /.a/g;
458print "not " unless f(pos($x)) == 4;
459print "ok $test\n";
460$test++;
4599a1de 461
ce862d02
IZ
462$x = $^R = 67;
463'foot' =~ /foo(?{$x = 12; 75})[t]/;
464print "not " unless $^R eq '75';
465print "ok $test\n";
466$test++;
467
468$x = $^R = 67;
469'foot' =~ /foo(?{$x = 12; 75})[xy]/;
470print "not " unless $^R eq '67' and $x eq '12';
471print "ok $test\n";
472$test++;
473
474$x = $^R = 67;
475'foot' =~ /foo(?{ $^R + 12 })((?{ $x = 12; $^R + 17 })[xy])?/;
476print "not " unless $^R eq '79' and $x eq '12';
477print "ok $test\n";
478$test++;
479
cc74c5bd 480print "not " unless qr/\b\v$/i eq '(?i-xsm:\b\v$)';
8782bef2
GB
481print "ok $test\n";
482$test++;
483
cc74c5bd 484print "not " unless qr/\b\v$/s eq '(?s-xim:\b\v$)';
8782bef2
GB
485print "ok $test\n";
486$test++;
487
cc74c5bd 488print "not " unless qr/\b\v$/m eq '(?m-xis:\b\v$)';
8782bef2
GB
489print "ok $test\n";
490$test++;
491
cc74c5bd 492print "not " unless qr/\b\v$/x eq '(?x-ism:\b\v$)';
8782bef2
GB
493print "ok $test\n";
494$test++;
495
cc74c5bd 496print "not " unless qr/\b\v$/xism eq '(?msix:\b\v$)';
8782bef2
GB
497print "ok $test\n";
498$test++;
499
cc74c5bd 500print "not " unless qr/\b\v$/ eq '(?-xism:\b\v$)';
97197631
IZ
501print "ok $test\n";
502$test++;
503
7e5428c5
IZ
504$_ = 'xabcx';
505foreach $ans ('', 'c') {
506 /(?<=(?=a)..)((?=c)|.)/g;
02db2b7b 507 print "# \$1 ='$1'\n# \$ans='$ans'\nnot " unless $1 eq $ans;
7e5428c5
IZ
508 print "ok $test\n";
509 $test++;
510}
511
512$_ = 'a';
513foreach $ans ('', 'a', '') {
514 /^|a|$/g;
02db2b7b 515 print "# \$& ='$&'\n# \$ans='$ans'\nnot " unless $& eq $ans;
7e5428c5
IZ
516 print "ok $test\n";
517 $test++;
518}
519
09f25ae4 520sub prefixify {
73d6d589
NIS
521 my($v,$a,$b,$res) = @_;
522 $v =~ s/\Q$a\E/$b/;
523 print "not " unless $res eq $v;
09f25ae4
IZ
524 print "ok $test\n";
525 $test++;
526}
527prefixify('/a/b/lib/arch', "/a/b/lib", 'X/lib', 'X/lib/arch');
528prefixify('/a/b/man/arch', "/a/b/man", 'X/man', 'X/man/arch');
529
530$_ = 'var="foo"';
531/(\")/;
532print "not " unless $1 and /$1/;
533print "ok $test\n";
534$test++;
535
73d6d589 536$a=qr/(?{++$b})/;
2cd61cdb 537$b = 7;
73d6d589
NIS
538/$a$a/;
539print "not " unless $b eq '9';
2cd61cdb
IZ
540print "ok $test\n";
541$test++;
542
73d6d589
NIS
543$c="$a";
544/$a$a/;
545print "not " unless $b eq '11';
2cd61cdb
IZ
546print "ok $test\n";
547$test++;
548
549{
73d6d589
NIS
550 use re "eval";
551 /$a$c$a/;
552 print "not " unless $b eq '14';
2cd61cdb
IZ
553 print "ok $test\n";
554 $test++;
555
160cb429
JH
556 local $lex_a = 2;
557 my $lex_a = 43;
558 my $lex_b = 17;
559 my $lex_c = 27;
560 my $lex_res = ($lex_b =~ qr/$lex_b(?{ $lex_c = $lex_a++ })/);
561 print "not " unless $lex_res eq '1';
562 print "ok $test\n";
563 $test++;
564 print "not " unless $lex_a eq '44';
565 print "ok $test\n";
566 $test++;
567 print "not " unless $lex_c eq '43';
568 print "ok $test\n";
569 $test++;
570
571
73d6d589 572 no re "eval";
2cd61cdb 573 $match = eval { /$a$c$a/ };
73d6d589 574 print "not "
2cd61cdb
IZ
575 unless $b eq '14' and $@ =~ /Eval-group not allowed/ and not $match;
576 print "ok $test\n";
577 $test++;
578}
cbce877f
IZ
579
580{
160cb429
JH
581 local $lex_a = 2;
582 my $lex_a = 43;
583 my $lex_b = 17;
584 my $lex_c = 27;
585 my $lex_res = ($lex_b =~ qr/17(?{ $lex_c = $lex_a++ })/);
586 print "not " unless $lex_res eq '1';
587 print "ok $test\n";
588 $test++;
589 print "not " unless $lex_a eq '44';
590 print "ok $test\n";
591 $test++;
592 print "not " unless $lex_c eq '43';
593 print "ok $test\n";
594 $test++;
595}
596
597{
cbce877f
IZ
598 package aa;
599 $c = 2;
600 $::c = 3;
601 '' =~ /(?{ $c = 4 })/;
602 print "not " unless $c == 4;
603}
604print "ok $test\n";
605$test++;
606print "not " unless $c == 3;
607print "ok $test\n";
73d6d589
NIS
608$test++;
609
4599a1de
JH
610sub must_warn_pat {
611 my $warn_pat = shift;
612 return sub { print "not " unless $_[0] =~ /$warn_pat/ }
613}
614
615sub must_warn {
616 my ($warn_pat, $code) = @_;
9f1b1f2d
GS
617 local %SIG;
618 eval 'BEGIN { use warnings; $SIG{__WARN__} = $warn_pat };' . $code;
4599a1de
JH
619 print "ok $test\n";
620 $test++;
621}
622
623
624sub make_must_warn {
625 my $warn_pat = shift;
626 return sub { must_warn(must_warn_pat($warn_pat)) }
627}
628
629my $for_future = make_must_warn('reserved for future extensions');
630
631&$for_future('q(a:[b]:) =~ /[x[:foo:]]/');
9baa0206
HS
632
633#&$for_future('q(a=[b]=) =~ /[x[=foo=]]/');
634print "ok $test\n"; $test++; # now a fatal croak
635
636#&$for_future('q(a.[b].) =~ /[x[.foo.]]/');
637print "ok $test\n"; $test++; # now a fatal croak
f7e33566
GS
638
639# test if failure of patterns returns empty list
640$_ = 'aaa';
641@_ = /bbb/;
642print "not " if @_;
643print "ok $test\n";
644$test++;
645
646@_ = /bbb/g;
647print "not " if @_;
648print "ok $test\n";
649$test++;
650
651@_ = /(bbb)/;
652print "not " if @_;
653print "ok $test\n";
654$test++;
655
656@_ = /(bbb)/g;
657print "not " if @_;
658print "ok $test\n";
659$test++;
660
6cef1e77
IZ
661/a(?=.$)/;
662print "not " if $#+ != 0 or $#- != 0;
663print "ok $test\n";
664$test++;
665
666print "not " if $+[0] != 2 or $-[0] != 1;
667print "ok $test\n";
668$test++;
669
73d6d589 670print "not "
6cef1e77
IZ
671 if defined $+[1] or defined $-[1] or defined $+[2] or defined $-[2];
672print "ok $test\n";
673$test++;
674
675/a(a)(a)/;
676print "not " if $#+ != 2 or $#- != 2;
677print "ok $test\n";
678$test++;
679
680print "not " if $+[0] != 3 or $-[0] != 0;
681print "ok $test\n";
682$test++;
683
684print "not " if $+[1] != 2 or $-[1] != 1;
685print "ok $test\n";
686$test++;
687
688print "not " if $+[2] != 3 or $-[2] != 2;
689print "ok $test\n";
690$test++;
691
73d6d589 692print "not "
6cef1e77
IZ
693 if defined $+[3] or defined $-[3] or defined $+[4] or defined $-[4];
694print "ok $test\n";
695$test++;
696
697/.(a)(b)?(a)/;
698print "not " if $#+ != 3 or $#- != 3;
699print "ok $test\n";
700$test++;
701
702print "not " if $+[0] != 3 or $-[0] != 0;
703print "ok $test\n";
704$test++;
705
706print "not " if $+[1] != 2 or $-[1] != 1;
707print "ok $test\n";
708$test++;
709
710print "not " if $+[3] != 3 or $-[3] != 2;
711print "ok $test\n";
712$test++;
713
73d6d589 714print "not "
6cef1e77
IZ
715 if defined $+[2] or defined $-[2] or defined $+[4] or defined $-[4];
716print "ok $test\n";
717$test++;
718
719/.(a)/;
720print "not " if $#+ != 1 or $#- != 1;
721print "ok $test\n";
722$test++;
723
724print "not " if $+[0] != 2 or $-[0] != 0;
725print "ok $test\n";
726$test++;
727
728print "not " if $+[1] != 2 or $-[1] != 1;
729print "ok $test\n";
730$test++;
731
73d6d589 732print "not "
6cef1e77
IZ
733 if defined $+[2] or defined $-[2] or defined $+[3] or defined $-[3];
734print "ok $test\n";
735$test++;
736
03a27ae7 737eval { $+[0] = 13; };
73d6d589 738print "not "
03a27ae7
MG
739 if $@ !~ /^Modification of a read-only value attempted/;
740print "ok $test\n";
741$test++;
742
743eval { $-[0] = 13; };
73d6d589 744print "not "
03a27ae7
MG
745 if $@ !~ /^Modification of a read-only value attempted/;
746print "ok $test\n";
747$test++;
748
749eval { @+ = (7, 6, 5); };
73d6d589 750print "not "
03a27ae7
MG
751 if $@ !~ /^Modification of a read-only value attempted/;
752print "ok $test\n";
753$test++;
754
755eval { @- = qw(foo bar); };
73d6d589 756print "not "
03a27ae7
MG
757 if $@ !~ /^Modification of a read-only value attempted/;
758print "ok $test\n";
759$test++;
760
8f580fb8
IZ
761/.(a)(ba*)?/;
762print "#$#-..$#+\nnot " if $#+ != 2 or $#- != 1;
763print "ok $test\n";
764$test++;
765
ad94a511
IZ
766$_ = 'aaa';
767pos = 1;
768@a = /\Ga/g;
769print "not " unless "@a" eq "a a";
770print "ok $test\n";
771$test++;
772
22e551b9
IZ
773$str = 'abcde';
774pos $str = 2;
775
776print "not " if $str =~ /^\G/;
777print "ok $test\n";
778$test++;
779
780print "not " if $str =~ /^.\G/;
781print "ok $test\n";
782$test++;
783
784print "not " unless $str =~ /^..\G/;
785print "ok $test\n";
786$test++;
787
788print "not " if $str =~ /^...\G/;
789print "ok $test\n";
790$test++;
791
792print "not " unless $str =~ /.\G./ and $& eq 'bc';
793print "ok $test\n";
794$test++;
795
796print "not " unless $str =~ /\G../ and $& eq 'cd';
797print "ok $test\n";
798$test++;
799
9661b544
IZ
800undef $foo; undef $bar;
801print "#'$str','$foo','$bar'\nnot "
73d6d589 802 unless $str =~ /b(?{$foo = $_; $bar = pos})c/
9661b544
IZ
803 and $foo eq 'abcde' and $bar eq 2;
804print "ok $test\n";
805$test++;
806
807undef $foo; undef $bar;
808pos $str = undef;
809print "#'$str','$foo','$bar'\nnot "
73d6d589 810 unless $str =~ /b(?{$foo = $_; $bar = pos})c/g
9661b544
IZ
811 and $foo eq 'abcde' and $bar eq 2 and pos $str eq 3;
812print "ok $test\n";
813$test++;
814
815$_ = $str;
816
817undef $foo; undef $bar;
818print "#'$str','$foo','$bar'\nnot "
73d6d589 819 unless /b(?{$foo = $_; $bar = pos})c/
9661b544
IZ
820 and $foo eq 'abcde' and $bar eq 2;
821print "ok $test\n";
822$test++;
823
824undef $foo; undef $bar;
825print "#'$str','$foo','$bar'\nnot "
73d6d589 826 unless /b(?{$foo = $_; $bar = pos})c/g
9661b544
IZ
827 and $foo eq 'abcde' and $bar eq 2 and pos eq 3;
828print "ok $test\n";
829$test++;
830
831undef $foo; undef $bar;
832pos = undef;
8331 while /b(?{$foo = $_; $bar = pos})c/g;
834print "#'$str','$foo','$bar'\nnot "
835 unless $foo eq 'abcde' and $bar eq 2 and not defined pos;
836print "ok $test\n";
837$test++;
838
839undef $foo; undef $bar;
840$_ = 'abcde|abcde';
841print "#'$str','$foo','$bar','$_'\nnot "
73d6d589 842 unless s/b(?{$foo = $_; $bar = pos})c/x/g and $foo eq 'abcde|abcde'
9661b544
IZ
843 and $bar eq 8 and $_ eq 'axde|axde';
844print "ok $test\n";
845$test++;
846
5c5e4c24
IZ
847@res = ();
848# List context:
849$_ = 'abcde|abcde';
850@dummy = /([ace]).(?{push @res, $1,$2})([ce])(?{push @res, $1,$2})/g;
851@res = map {defined $_ ? "'$_'" : 'undef'} @res;
852$res = "@res";
853print "#'@res' '$_'\nnot "
854 unless "@res" eq "'a' undef 'a' 'c' 'e' undef 'a' undef 'a' 'c'";
855print "ok $test\n";
856$test++;
857
858@res = ();
859@dummy = /([ace]).(?{push @res, $`,$&,$'})([ce])(?{push @res, $`,$&,$'})/g;
860@res = map {defined $_ ? "'$_'" : 'undef'} @res;
861$res = "@res";
862print "#'@res' '$_'\nnot "
863 unless "@res" eq
864 "'' 'ab' 'cde|abcde' " .
865 "'' 'abc' 'de|abcde' " .
866 "'abcd' 'e|' 'abcde' " .
867 "'abcde|' 'ab' 'cde' " .
868 "'abcde|' 'abc' 'de'" ;
869print "ok $test\n";
870$test++;
871
b7a35066
IZ
872#Some more \G anchor checks
873$foo='aabbccddeeffgg';
874
875pos($foo)=1;
876
877$foo=~/.\G(..)/g;
878print "not " unless($1 eq 'ab');
879print "ok $test\n";
880$test++;
881
882pos($foo) += 1;
883$foo=~/.\G(..)/g;
884print "not " unless($1 eq 'cc');
885print "ok $test\n";
886$test++;
887
888pos($foo) += 1;
889$foo=~/.\G(..)/g;
890print "not " unless($1 eq 'de');
891print "ok $test\n";
892$test++;
893
0ef3e39e
HS
894print "not " unless $foo =~ /\Gef/g;
895print "ok $test\n";
896$test++;
897
b7a35066
IZ
898undef pos $foo;
899
900$foo=~/\G(..)/g;
901print "not " unless($1 eq 'aa');
902print "ok $test\n";
903$test++;
904
905$foo=~/\G(..)/g;
906print "not " unless($1 eq 'bb');
907print "ok $test\n";
908$test++;
909
910pos($foo)=5;
911$foo=~/\G(..)/g;
912print "not " unless($1 eq 'cd');
913print "ok $test\n";
914$test++;
915
73d6d589 916$_='123x123';
e60df1fa
IZ
917@res = /(\d*|x)/g;
918print "not " unless('123||x|123|' eq join '|', @res);
919print "ok $test\n";
920$test++;
921
9d080a66
GS
922# see if matching against temporaries (created via pp_helem()) is safe
923{ foo => "ok $test\n".$^X }->{foo} =~ /^(.*)\n/g;
924print "$1\n";
925$test++;
926
cf93c79d
IZ
927# See if $i work inside (?{}) in the presense of saved substrings and
928# changing $_
929@a = qw(foo bar);
930@b = ();
931s/(\w)(?{push @b, $1})/,$1,/g for @a;
932
933print "# \@b='@b', expect 'f o o b a r'\nnot " unless("@b" eq "f o o b a r");
934print "ok $test\n";
935$test++;
936
937print "not " unless("@a" eq ",f,,o,,o, ,b,,a,,r,");
938print "ok $test\n";
939$test++;
940
2c914db6 941$brackets = qr{
14455d6c 942 { (?> [^{}]+ | (??{ $brackets }) )* }
2c914db6
IZ
943 }x;
944
945"{{}" =~ $brackets;
946print "ok $test\n"; # Did we survive?
947$test++;
948
949"something { long { and } hairy" =~ $brackets;
950print "ok $test\n"; # Did we survive?
951$test++;
952
14455d6c 953"something { long { and } hairy" =~ m/((??{ $brackets }))/;
2c914db6
IZ
954print "not " unless $1 eq "{ and }";
955print "ok $test\n";
956$test++;
957
30944b6d
IZ
958$_ = "a-a\nxbb";
959pos=1;
960m/^-.*bb/mg and print "not ";
961print "ok $test\n";
962$test++;
30382c73
IZ
963
964$text = "aaXbXcc";
965pos($text)=0;
966$text =~ /\GXb*X/g and print 'not ';
967print "ok $test\n";
968$test++;
3cf5c195
IZ
969
970$text = "xA\n" x 500;
971$text =~ /^\s*A/m and print 'not ';
972print "ok $test\n";
973$test++;
d506a20d
IZ
974
975$text = "abc dbf";
976@res = ($text =~ /.*?(b).*?\b/g);
977"@res" eq 'b b' or print 'not ';
978print "ok $test\n";
979$test++;
980
9442cb0e 981@a = map chr,0..255;
aeaf5620
GS
982
983@b = grep(/\S/,@a);
984@c = grep(/[^\s]/,@a);
985print "not " if "@b" ne "@c";
9442cb0e
GS
986print "ok $test\n";
987$test++;
988
aeaf5620
GS
989@b = grep(/\S/,@a);
990@c = grep(/[\S]/,@a);
991print "not " if "@b" ne "@c";
9442cb0e
GS
992print "ok $test\n";
993$test++;
994
aeaf5620
GS
995@b = grep(/\s/,@a);
996@c = grep(/[^\S]/,@a);
997print "not " if "@b" ne "@c";
9442cb0e
GS
998print "ok $test\n";
999$test++;
1000
aeaf5620
GS
1001@b = grep(/\s/,@a);
1002@c = grep(/[\s]/,@a);
1003print "not " if "@b" ne "@c";
9442cb0e
GS
1004print "ok $test\n";
1005$test++;
1006
aeaf5620
GS
1007@b = grep(/\D/,@a);
1008@c = grep(/[^\d]/,@a);
1009print "not " if "@b" ne "@c";
9442cb0e
GS
1010print "ok $test\n";
1011$test++;
1012
aeaf5620
GS
1013@b = grep(/\D/,@a);
1014@c = grep(/[\D]/,@a);
1015print "not " if "@b" ne "@c";
9442cb0e
GS
1016print "ok $test\n";
1017$test++;
1018
aeaf5620
GS
1019@b = grep(/\d/,@a);
1020@c = grep(/[^\D]/,@a);
1021print "not " if "@b" ne "@c";
9442cb0e
GS
1022print "ok $test\n";
1023$test++;
1024
aeaf5620
GS
1025@b = grep(/\d/,@a);
1026@c = grep(/[\d]/,@a);
1027print "not " if "@b" ne "@c";
9442cb0e
GS
1028print "ok $test\n";
1029$test++;
1030
aeaf5620
GS
1031@b = grep(/\W/,@a);
1032@c = grep(/[^\w]/,@a);
1033print "not " if "@b" ne "@c";
9442cb0e
GS
1034print "ok $test\n";
1035$test++;
1036
aeaf5620
GS
1037@b = grep(/\W/,@a);
1038@c = grep(/[\W]/,@a);
1039print "not " if "@b" ne "@c";
9442cb0e
GS
1040print "ok $test\n";
1041$test++;
1042
aeaf5620
GS
1043@b = grep(/\w/,@a);
1044@c = grep(/[^\W]/,@a);
1045print "not " if "@b" ne "@c";
9442cb0e
GS
1046print "ok $test\n";
1047$test++;
1048
aeaf5620
GS
1049@b = grep(/\w/,@a);
1050@c = grep(/[\w]/,@a);
1051print "not " if "@b" ne "@c";
9442cb0e
GS
1052print "ok $test\n";
1053$test++;
1aeab75a
GS
1054
1055# see if backtracking optimization works correctly
1056"\n\n" =~ /\n $ \n/x or print "not ";
1057print "ok $test\n";
1058$test++;
1059
1060"\n\n" =~ /\n* $ \n/x or print "not ";
1061print "ok $test\n";
1062$test++;
1063
1064"\n\n" =~ /\n+ $ \n/x or print "not ";
1065print "ok $test\n";
1066$test++;
05b4157f
GS
1067
1068[] =~ /^ARRAY/ or print "# [] \nnot ";
1069print "ok $test\n";
1070$test++;
1071
1072eval << 'EOE';
1073{
1074 package S;
1075 use overload '""' => sub { 'Object S' };
1076 sub new { bless [] }
1077}
1078$a = 'S'->new;
1079EOE
1080
1081$a and $a =~ /^Object\sS/ or print "# '$a' \nnot ";
1082print "ok $test\n";
1083$test++;
815d35b9
G
1084
1085# test result of match used as match (!)
1086'a1b' =~ ('xyz' =~ /y/) and $` eq 'a' or print "not ";
1087print "ok $test\n";
1088$test++;
1089
1090'a1b' =~ ('xyz' =~ /t/) and $` eq 'a' or print "not ";
1091print "ok $test\n";
1092$test++;
5e39e1e5
HS
1093
1094$w = 0;
1095{
1096 local $SIG{__WARN__} = sub { $w = 1 };
1097 local $^W = 1;
1098 $w = 1 if ("1\n" x 102) =~ /^\s*\n/m;
1099}
1100print $w ? "not " : "", "ok $test\n";
1101$test++;
aaa51d5e
JF
1102
1103my %space = ( spc => " ",
1104 tab => "\t",
1105 cr => "\r",
1106 lf => "\n",
1107 ff => "\f",
75369ccb
JH
1108# There's no \v but the vertical tabulator seems miraculously
1109# be 11 both in ASCII and EBCDIC.
aaa51d5e
JF
1110 vt => chr(11),
1111 false => "space" );
1112
1113my @space0 = sort grep { $space{$_} =~ /\s/ } keys %space;
1114my @space1 = sort grep { $space{$_} =~ /[[:space:]]/ } keys %space;
1115my @space2 = sort grep { $space{$_} =~ /[[:blank:]]/ } keys %space;
1116
1117print "not " unless "@space0" eq "cr ff lf spc tab";
3bec3564 1118print "ok $test # @space0\n";
aaa51d5e
JF
1119$test++;
1120
1121print "not " unless "@space1" eq "cr ff lf spc tab vt";
3bec3564 1122print "ok $test # @space1\n";
aaa51d5e
JF
1123$test++;
1124
1125print "not " unless "@space2" eq "spc tab";
3bec3564 1126print "ok $test # @space2\n";
aaa51d5e 1127$test++;
73d6d589 1128
a1933d95
HS
1129# bugid 20001021.005 - this caused a SEGV
1130print "not " unless undef =~ /^([^\/]*)(.*)$/;
1131print "ok $test\n";
1132$test++;
b91bb191
JH
1133
1134# bugid 20000731.001
1135
1136print "not " unless "A \x{263a} B z C" =~ /A . B (??{ "z" }) C/;
1137print "ok $test\n";
1138$test++;
1139
5ae032e5
JH
1140my $ordA = ord('A');
1141
3baa4c62
JH
1142$_ = "a\x{100}b";
1143if (/(.)(\C)(\C)(.)/) {
1144 print "ok 232\n";
1145 if ($1 eq "a") {
1146 print "ok 233\n";
1147 } else {
1148 print "not ok 233\n";
1149 }
5ae032e5
JH
1150 if ($ordA == 65) { # ASCII (or equivalent), should be UTF-8
1151 if ($2 eq "\xC4") {
1152 print "ok 234\n";
1153 } else {
1154 print "not ok 234\n";
1155 }
1156 if ($3 eq "\x80") {
1157 print "ok 235\n";
1158 } else {
1159 print "not ok 235\n";
1160 }
1161 } elsif ($ordA == 193) { # EBCDIC (or equivalent), should be UTF-EBCDIC
1162 if ($2 eq "\x8C") {
1163 print "ok 234\n";
1164 } else {
1165 print "not ok 234\n";
1166 }
1167 if ($3 eq "\x41") {
1168 print "ok 235\n";
1169 } else {
1170 print "not ok 235\n";
1171 }
3baa4c62 1172 } else {
5ae032e5
JH
1173 for (234..235) {
1174 print "not ok $_ # ord('A') == $ordA\n";
1175 }
3baa4c62
JH
1176 }
1177 if ($4 eq "b") {
1178 print "ok 236\n";
1179 } else {
1180 print "not ok 236\n";
1181 }
1182} else {
1183 for (232..236) {
1184 print "not ok $_\n";
1185 }
1186}
1187$_ = "\x{100}";
1188if (/(\C)/g) {
1189 print "ok 237\n";
73d6d589 1190 # currently \C are still tagged as UTF-8
5ae032e5
JH
1191 if ($ordA == 65) {
1192 if ($1 eq "\xC4") {
1193 print "ok 238\n";
1194 } else {
1195 print "not ok 238\n";
1196 }
1197 } elsif ($ordA == 193) {
1198 if ($1 eq "\x8C") {
1199 print "ok 238\n";
1200 } else {
1201 print "not ok 238\n";
1202 }
3baa4c62 1203 } else {
5ae032e5 1204 print "not ok 238 # ord('A') == $ordA\n";
3baa4c62
JH
1205 }
1206} else {
1207 for (237..238) {
1208 print "not ok $_\n";
1209 }
1210}
1211if (/(\C)/g) {
1212 print "ok 239\n";
73d6d589 1213 # currently \C are still tagged as UTF-8
5ae032e5
JH
1214 if ($ordA == 65) {
1215 if ($1 eq "\x80") {
1216 print "ok 240\n";
1217 } else {
1218 print "not ok 240\n";
1219 }
1220 } elsif ($ordA == 193) {
1221 if ($1 eq "\x41") {
1222 print "ok 240\n";
1223 } else {
1224 print "not ok 240\n";
1225 }
3baa4c62 1226 } else {
5ae032e5 1227 print "not ok 240 # ord('A') == $ordA\n";
3baa4c62
JH
1228 }
1229} else {
1230 for (239..240) {
1231 print "not ok $_\n";
1232 }
1233}
b485d051 1234
db615365
JP
1235{
1236 # japhy -- added 03/03/2001
1237 () = (my $str = "abc") =~ /(...)/;
1238 $str = "def";
1239 print "not " if $1 ne "abc";
fd291da9
JH
1240 print "ok 241\n";
1241}
1242
1243# The 242 and 243 go with the 244 and 245.
1244# The trick is that in EBCDIC the explicit numeric range should match
1245# (as also in non-EBCDIC) but the explicit alphabetic range should not match.
1246
1247if ("\x8e" =~ /[\x89-\x91]/) {
1248 print "ok 242\n";
1249} else {
1250 print "not ok 242\n";
1251}
1252
1253if ("\xce" =~ /[\xc9-\xd1]/) {
db615365 1254 print "ok 243\n";
fd291da9
JH
1255} else {
1256 print "not ok 243\n";
1257}
1258
1259# In most places these tests would succeed since \x8e does not
1260# in most character sets match 'i' or 'j' nor would \xce match
1261# 'I' or 'J', but strictly speaking these tests are here for
1262# the good of EBCDIC, so let's test these only there.
1263if (ord('i') == 0x89 && ord('J') == 0xd1) { # EBCDIC
1264 if ("\x8e" !~ /[i-j]/) {
1265 print "ok 244\n";
1266 } else {
1267 print "not ok 244\n";
1268 }
1269 if ("\xce" !~ /[I-J]/) {
1270 print "ok 245\n";
1271 } else {
1272 print "not ok 245\n";
1273 }
1274} else {
1275 for (244..245) {
60425c38 1276 print "ok $_ # Skip: only in EBCDIC\n";
fd291da9 1277 }
db615365 1278}
4765795a
JH
1279
1280print "not " unless "\x{ab}" =~ /\x{ab}/;
1281print "ok 246\n";
1282
1283print "not " unless "\x{abcd}" =~ /\x{abcd}/;
1284print "ok 247\n";
1285
1286{
f9969324
JH
1287 # bug id 20001008.001
1288
fc8cd66c 1289 $test = 248;
f9969324
JH
1290 my @x = ("stra\337e 138","stra\337e 138");
1291 for (@x) {
1292 s/(\d+)\s*([\w\-]+)/$1 . uc $2/e;
1293 my($latin) = /^(.+)(?:\s+\d)/;
1294 print $latin eq "stra\337e" ? "ok $test\n" : # 248,249
1295 "#latin[$latin]\nnot ok $test\n";
1296 $test++;
1297 $latin =~ s/stra\337e/straße/; # \303\237 after the 2nd a
1298 use utf8; # needed for the raw UTF-8
1299 $latin =~ s!(s)tr(?:aß|s+e)!$1tr.!; # \303\237 after the a
4765795a
JH
1300 }
1301}
1302
1303{
1304 print "not " unless "ba\xd4c" =~ /([a\xd4]+)/ && $1 eq "a\xd4";
1305 print "ok 250\n";
1306
1307 print "not " unless "ba\xd4c" =~ /([a\xd4]+)/ && $1 eq "a\x{d4}";
1308 print "ok 251\n";
1309
1310 print "not " unless "ba\x{d4}c" =~ /([a\xd4]+)/ && $1 eq "a\x{d4}";
1311 print "ok 252\n";
1312
1313 print "not " unless "ba\x{d4}c" =~ /([a\xd4]+)/ && $1 eq "a\xd4";
1314 print "ok 253\n";
1315
1316 print "not " unless "ba\xd4c" =~ /([a\x{d4}]+)/ && $1 eq "a\xd4";
1317 print "ok 254\n";
1318
1319 print "not " unless "ba\xd4c" =~ /([a\x{d4}]+)/ && $1 eq "a\x{d4}";
1320 print "ok 255\n";
1321
1322 print "not " unless "ba\x{d4}c" =~ /([a\x{d4}]+)/ && $1 eq "a\x{d4}";
1323 print "ok 256\n";
1324
1325 print "not " unless "ba\x{d4}c" =~ /([a\x{d4}]+)/ && $1 eq "a\xd4";
1326 print "ok 257\n";
1327}
1328
1329{
1330 # the first half of 20001028.003
1331
1332 my $X = chr(1448);
1333 my ($Y) = $X =~ /(.*)/;
1334 print "not " unless $Y eq v1448 && length($Y) == 1;
1335 print "ok 258\n";
1336}
1337
1338{
1339 # 20001108.001
1340
1341 my $X = "Szab\x{f3},Bal\x{e1}zs";
1342 my $Y = $X;
1343 $Y =~ s/(B)/$1/ for 0..3;
1344 print "not " unless $Y eq $X && $X eq "Szab\x{f3},Bal\x{e1}zs";
1345 print "ok 259\n";
1346}
1347
1348{
1349 # the second half of 20001028.003
1350
3568d838 1351 my $X = '';
4765795a
JH
1352 $X =~ s/^/chr(1488)/e;
1353 print "not " unless length $X == 1 && ord($X) == 1488;
1354 print "ok 260\n";
1355}
1356
1357{
1358 # 20000517.001
1359
1360 my $x = "\x{100}A";
1361
1362 $x =~ s/A/B/;
1363
1364 print "not " unless $x eq "\x{100}B" && length($x) == 2;
1365 print "ok 261\n";
1366}
1367
1368{
1369 # bug id 20001230.002
1370
1371 print "not " unless "École" =~ /^\C\C(.)/ && $1 eq 'c';
1372 print "ok 262\n";
1373
1374 print "not " unless "École" =~ /^\C\C(c)/;
1375 print "ok 263\n";
1376}
1377
8dcad4ad 1378SKIP: {
fc8cd66c 1379 $test = 264; # till 575
4765795a 1380
bb99e5f1 1381 use charnames ":full";
4765795a
JH
1382
1383 # This is far from complete testing, there are dozens of character
1384 # classes in Unicode. The mixing of literals and \N{...} is
1385 # intentional so that in non-Latin-1 places we test the native
1386 # characters, not the Unicode code points.
1387
1388 my %s = (
1389 "a" => 'Ll',
1390 "\N{CYRILLIC SMALL LETTER A}" => 'Ll',
1391 "A" => 'Lu',
1392 "\N{GREEK CAPITAL LETTER ALPHA}" => 'Lu',
1393 "\N{HIRAGANA LETTER SMALL A}" => 'Lo',
1394 "\N{COMBINING GRAVE ACCENT}" => 'Mn',
1395 "0" => 'Nd',
1396 "\N{ARABIC-INDIC DIGIT ZERO}" => 'Nd',
1397 "_" => 'N',
1398 "!" => 'P',
1399 " " => 'Zs',
1400 "\0" => 'Cc',
1401 );
73d6d589 1402
3568d838
JH
1403 for my $char (map { s/^\S+ //; $_ }
1404 sort map { sprintf("%06x", ord($_))." $_" } keys %s) {
4765795a 1405 my $class = $s{$char};
3568d838
JH
1406 my $code = sprintf("%06x", ord($char));
1407 printf "#\n# 0x$code\n#\n";
4765795a
JH
1408 print "# IsAlpha\n";
1409 if ($class =~ /^[LM]/) {
1410 print "not " unless $char =~ /\p{IsAlpha}/;
1411 print "ok $test\n"; $test++;
1412 print "not " if $char =~ /\P{IsAlpha}/;
1413 print "ok $test\n"; $test++;
1414 } else {
1415 print "not " if $char =~ /\p{IsAlpha}/;
1416 print "ok $test\n"; $test++;
1417 print "not " unless $char =~ /\P{IsAlpha}/;
1418 print "ok $test\n"; $test++;
1419 }
1420 print "# IsAlnum\n";
1421 if ($class =~ /^[LMN]/ && $char ne "_") {
1422 print "not " unless $char =~ /\p{IsAlnum}/;
1423 print "ok $test\n"; $test++;
1424 print "not " if $char =~ /\P{IsAlnum}/;
1425 print "ok $test\n"; $test++;
1426 } else {
1427 print "not " if $char =~ /\p{IsAlnum}/;
1428 print "ok $test\n"; $test++;
1429 print "not " unless $char =~ /\P{IsAlnum}/;
1430 print "ok $test\n"; $test++;
1431 }
1432 print "# IsASCII\n";
24817587
JH
1433 if (ord("A") == 193) {
1434 print "ok $test # Skip: in EBCDIC\n"; $test++;
1435 print "ok $test # Skip: in EBCDIC\n"; $test++;
4765795a 1436 } else {
24817587
JH
1437 if ($code le '00007f') {
1438 print "not " unless $char =~ /\p{IsASCII}/;
1439 print "ok $test\n"; $test++;
1440 print "not " if $char =~ /\P{IsASCII}/;
1441 print "ok $test\n"; $test++;
1442 } else {
1443 print "not " if $char =~ /\p{IsASCII}/;
1444 print "ok $test\n"; $test++;
1445 print "not " unless $char =~ /\P{IsASCII}/;
1446 print "ok $test\n"; $test++;
1447 }
4765795a
JH
1448 }
1449 print "# IsCntrl\n";
1450 if ($class =~ /^C/) {
1451 print "not " unless $char =~ /\p{IsCntrl}/;
1452 print "ok $test\n"; $test++;
1453 print "not " if $char =~ /\P{IsCntrl}/;
1454 print "ok $test\n"; $test++;
1455 } else {
1456 print "not " if $char =~ /\p{IsCntrl}/;
1457 print "ok $test\n"; $test++;
1458 print "not " unless $char =~ /\P{IsCntrl}/;
1459 print "ok $test\n"; $test++;
1460 }
1461 print "# IsBlank\n";
1462 if ($class =~ /^Z[lp]/ || $char eq " ") {
1463 print "not " unless $char =~ /\p{IsBlank}/;
1464 print "ok $test\n"; $test++;
1465 print "not " if $char =~ /\P{IsBlank}/;
1466 print "ok $test\n"; $test++;
1467 } else {
1468 print "not " if $char =~ /\p{IsBlank}/;
1469 print "ok $test\n"; $test++;
1470 print "not " unless $char =~ /\P{IsBlank}/;
1471 print "ok $test\n"; $test++;
1472 }
1473 print "# IsDigit\n";
1474 if ($class =~ /^Nd$/) {
1475 print "not " unless $char =~ /\p{IsDigit}/;
1476 print "ok $test\n"; $test++;
1477 print "not " if $char =~ /\P{IsDigit}/;
1478 print "ok $test\n"; $test++;
1479 } else {
1480 print "not " if $char =~ /\p{IsDigit}/;
1481 print "ok $test\n"; $test++;
1482 print "not " unless $char =~ /\P{IsDigit}/;
1483 print "ok $test\n"; $test++;
1484 }
1485 print "# IsGraph\n";
1486 if ($class =~ /^([LMNPS])|Co/) {
1487 print "not " unless $char =~ /\p{IsGraph}/;
1488 print "ok $test\n"; $test++;
1489 print "not " if $char =~ /\P{IsGraph}/;
1490 print "ok $test\n"; $test++;
1491 } else {
1492 print "not " if $char =~ /\p{IsGraph}/;
1493 print "ok $test\n"; $test++;
1494 print "not " unless $char =~ /\P{IsGraph}/;
1495 print "ok $test\n"; $test++;
1496 }
1497 print "# IsLower\n";
1498 if ($class =~ /^Ll$/) {
1499 print "not " unless $char =~ /\p{IsLower}/;
1500 print "ok $test\n"; $test++;
1501 print "not " if $char =~ /\P{IsLower}/;
1502 print "ok $test\n"; $test++;
1503 } else {
1504 print "not " if $char =~ /\p{IsLower}/;
1505 print "ok $test\n"; $test++;
1506 print "not " unless $char =~ /\P{IsLower}/;
1507 print "ok $test\n"; $test++;
1508 }
1509 print "# IsPrint\n";
1510 if ($class =~ /^([LMNPS])|Co|Zs/) {
1511 print "not " unless $char =~ /\p{IsPrint}/;
1512 print "ok $test\n"; $test++;
1513 print "not " if $char =~ /\P{IsPrint}/;
1514 print "ok $test\n"; $test++;
1515 } else {
1516 print "not " if $char =~ /\p{IsPrint}/;
1517 print "ok $test\n"; $test++;
1518 print "not " unless $char =~ /\P{IsPrint}/;
1519 print "ok $test\n"; $test++;
1520 }
1521 print "# IsPunct\n";
1522 if ($class =~ /^P/ || $char eq "_") {
1523 print "not " unless $char =~ /\p{IsPunct}/;
1524 print "ok $test\n"; $test++;
1525 print "not " if $char =~ /\P{IsPunct}/;
1526 print "ok $test\n"; $test++;
1527 } else {
1528 print "not " if $char =~ /\p{IsPunct}/;
1529 print "ok $test\n"; $test++;
1530 print "not " unless $char =~ /\P{IsPunct}/;
1531 print "ok $test\n"; $test++;
1532 }
1533 print "# IsSpace\n";
1534 if ($class =~ /^Z/ || ($code =~ /^(0009|000A|000B|000C|000D)$/)) {
1535 print "not " unless $char =~ /\p{IsSpace}/;
1536 print "ok $test\n"; $test++;
1537 print "not " if $char =~ /\P{IsSpace}/;
1538 print "ok $test\n"; $test++;
1539 } else {
1540 print "not " if $char =~ /\p{IsSpace}/;
1541 print "ok $test\n"; $test++;
1542 print "not " unless $char =~ /\P{IsSpace}/;
1543 print "ok $test\n"; $test++;
1544 }
1545 print "# IsUpper\n";
1546 if ($class =~ /^L[ut]/) {
1547 print "not " unless $char =~ /\p{IsUpper}/;
1548 print "ok $test\n"; $test++;
1549 print "not " if $char =~ /\P{IsUpper}/;
1550 print "ok $test\n"; $test++;
1551 } else {
1552 print "not " if $char =~ /\p{IsUpper}/;
1553 print "ok $test\n"; $test++;
1554 print "not " unless $char =~ /\P{IsUpper}/;
1555 print "ok $test\n"; $test++;
1556 }
1557 print "# IsWord\n";
1558 if ($class =~ /^[LMN]/ || $char eq "_") {
1559 print "not " unless $char =~ /\p{IsWord}/;
1560 print "ok $test\n"; $test++;
1561 print "not " if $char =~ /\P{IsWord}/;
1562 print "ok $test\n"; $test++;
1563 } else {
1564 print "not " if $char =~ /\p{IsWord}/;
1565 print "ok $test\n"; $test++;
1566 print "not " unless $char =~ /\P{IsWord}/;
1567 print "ok $test\n"; $test++;
1568 }
1569 }
1570}
1571
1572{
1573 $_ = "abc\x{100}\x{200}\x{300}\x{380}\x{400}defg";
1574
1575 if (/(.\x{300})./) {
1576 print "ok 576\n";
1577
1578 print "not " unless $` eq "abc\x{100}" && length($`) == 4;
73d6d589 1579 print "ok 577\n";
4765795a
JH
1580
1581 print "not " unless $& eq "\x{200}\x{300}\x{380}" && length($&) == 3;
73d6d589 1582 print "ok 578\n";
4765795a
JH
1583
1584 print "not " unless $' eq "\x{400}defg" && length($') == 5;
73d6d589 1585 print "ok 579\n";
4765795a
JH
1586
1587 print "not " unless $1 eq "\x{200}\x{300}" && length($1) == 2;
73d6d589 1588 print "ok 580\n";
a8a2fe91
JH
1589 } else {
1590 for (576..580) { print "not ok $_\n" }
4765795a
JH
1591 }
1592}
8269fa76
JH
1593
1594{
1595 # bug id 20010306.008
1596
1597 $a = "a\x{1234}";
1598 # The original bug report had 'no utf8' here but that was irrelevant.
1599 $a =~ m/\w/; # used to core dump
1600
1601 print "ok 581\n";
1602}
b8ef571c
JH
1603
1604{
339e86bc
JH
1605 $test = 582;
1606
b8ef571c
JH
1607 # bugid 20010410.006
1608 for my $rx (
1609 '/(.*?)\{(.*?)\}/csg',
1610 '/(.*?)\{(.*?)\}/cg',
1611 '/(.*?)\{(.*?)\}/sg',
1612 '/(.*?)\{(.*?)\}/g',
1613 '/(.+?)\{(.+?)\}/csg',
1614 )
1615 {
1616 my($input, $i);
1617
1618 $i = 0;
1619 $input = "a{b}c{d}";
1620 eval <<EOT;
1621 while (eval \$input =~ $rx) {
1622 print "# \\\$1 = '\$1' \\\$2 = '\$2'\n";
1623 ++\$i;
1624 }
1625EOT
1626 print "not " unless $i == 2;
1627 print "ok " . $test++ . "\n";
1628 }
1629}
209a9bc1
JH
1630
1631{
1632 # from Robin Houston
1633
b851fbc1 1634 my $x = "\x{10FFFD}";
209a9bc1 1635 $x =~ s/(.)/$1/g;
b851fbc1 1636 print "not " unless ord($x) == 0x10FFFD && length($x) == 1;
209a9bc1
JH
1637 print "ok 587\n";
1638}
3568d838
JH
1639
1640{
1641 my $x = "\x7f";
1642
1643 print "not " if $x =~ /[\x80-\xff]/;
1644 print "ok 588\n";
1645
1646 print "not " if $x =~ /[\x80-\x{100}]/;
1647 print "ok 589\n";
1648
1649 print "not " if $x =~ /[\x{100}]/;
1650 print "ok 590\n";
1651
1652 print "not " if $x =~ /\p{InLatin1Supplement}/;
1653 print "ok 591\n";
1654
1655 print "not " unless $x =~ /\P{InLatin1Supplement}/;
1656 print "ok 592\n";
1657
1658 print "not " if $x =~ /\p{InLatinExtendedA}/;
1659 print "ok 593\n";
1660
1661 print "not " unless $x =~ /\P{InLatinExtendedA}/;
1662 print "ok 594\n";
1663}
1664
1665{
1666 my $x = "\x80";
1667
1668 print "not " unless $x =~ /[\x80-\xff]/;
1669 print "ok 595\n";
1670
1671 print "not " unless $x =~ /[\x80-\x{100}]/;
1672 print "ok 596\n";
1673
1674 print "not " if $x =~ /[\x{100}]/;
1675 print "ok 597\n";
1676
1677 print "not " unless $x =~ /\p{InLatin1Supplement}/;
1678 print "ok 598\n";
1679
1680 print "not " if $x =~ /\P{InLatin1Supplement}/;
1681 print "ok 599\n";
1682
1683 print "not " if $x =~ /\p{InLatinExtendedA}/;
1684 print "ok 600\n";
1685
1686 print "not " unless $x =~ /\P{InLatinExtendedA}/;
1687 print "ok 601\n";
1688}
1689
1690{
1691 my $x = "\xff";
1692
1693 print "not " unless $x =~ /[\x80-\xff]/;
1694 print "ok 602\n";
1695
1696 print "not " unless $x =~ /[\x80-\x{100}]/;
1697 print "ok 603\n";
1698
1699 print "not " if $x =~ /[\x{100}]/;
1700 print "ok 604\n";
1701
cc8040a1
DT
1702 # the next two tests must be ignored on EBCDIC
1703 print "not " unless $x =~ /\p{InLatin1Supplement}/ or ord("A") == 193;
3568d838
JH
1704 print "ok 605\n";
1705
cc8040a1 1706 print "not " if $x =~ /\P{InLatin1Supplement}/ and ord("A") != 193;
3568d838
JH
1707 print "ok 606\n";
1708
1709 print "not " if $x =~ /\p{InLatinExtendedA}/;
1710 print "ok 607\n";
1711
1712 print "not " unless $x =~ /\P{InLatinExtendedA}/;
1713 print "ok 608\n";
1714}
1715
1716{
1717 my $x = "\x{100}";
1718
1719 print "not " if $x =~ /[\x80-\xff]/;
1720 print "ok 609\n";
1721
1722 print "not " unless $x =~ /[\x80-\x{100}]/;
1723 print "ok 610\n";
1724
1725 print "not " unless $x =~ /[\x{100}]/;
1726 print "ok 611\n";
1727
1728 print "not " if $x =~ /\p{InLatin1Supplement}/;
1729 print "ok 612\n";
1730
1731 print "not " unless $x =~ /\P{InLatin1Supplement}/;
1732 print "ok 613\n";
1733
1734 print "not " unless $x =~ /\p{InLatinExtendedA}/;
1735 print "ok 614\n";
1736
1737 print "not " if $x =~ /\P{InLatinExtendedA}/;
1738 print "ok 615\n";
1739}
1740
9d1d55b5
JP
1741{
1742 # from japhy
1743 my $w;
1744 use warnings;
1745 local $SIG{__WARN__} = sub { $w .= shift };
1746
1747 $w = "";
1748 eval 'qr/(?c)/';
1749 print "not " if $w !~ /^Useless \(\?c\)/;
1750 print "ok 616\n";
1751
1752 $w = "";
1753 eval 'qr/(?-c)/';
1754 print "not " if $w !~ /^Useless \(\?-c\)/;
1755 print "ok 617\n";
1756
1757 $w = "";
1758 eval 'qr/(?g)/';
1759 print "not " if $w !~ /^Useless \(\?g\)/;
1760 print "ok 618\n";
1761
1762 $w = "";
1763 eval 'qr/(?-g)/';
1764 print "not " if $w !~ /^Useless \(\?-g\)/;
1765 print "ok 619\n";
1766
1767 $w = "";
1768 eval 'qr/(?o)/';
1769 print "not " if $w !~ /^Useless \(\?o\)/;
1770 print "ok 620\n";
1771
1772 $w = "";
1773 eval 'qr/(?-o)/';
1774 print "not " if $w !~ /^Useless \(\?-o\)/;
1775 print "ok 621\n";
1776
1777 # now test multi-error regexes
1778
1779 $w = "";
1780 eval 'qr/(?g-o)/';
1781 print "not " if $w !~ /^Useless \(\?g\).*\nUseless \(\?-o\)/;
1782 print "ok 622\n";
1783
1784 $w = "";
1785 eval 'qr/(?g-c)/';
1786 print "not " if $w !~ /^Useless \(\?g\).*\nUseless \(\?-c\)/;
1787 print "ok 623\n";
1788
1789 $w = "";
1790 eval 'qr/(?o-cg)/'; # (?c) means (?g) error won't be thrown
1791 print "not " if $w !~ /^Useless \(\?o\).*\nUseless \(\?-c\)/;
1792 print "ok 624\n";
1793
1794 $w = "";
1795 eval 'qr/(?ogc)/';
1796 print "not " if $w !~ /^Useless \(\?o\).*\nUseless \(\?g\).*\nUseless \(\?c\)/;
1797 print "ok 625\n";
1798}
a72deede
JH
1799
1800# More Unicode "class" tests
1801
1802{
1803 use charnames ':full';
1804
1805 print "not " unless "\N{LATIN CAPITAL LETTER A}" =~ /\p{InBasicLatin}/;
1806 print "ok 626\n";
1807
1808 print "not " unless "\N{LATIN CAPITAL LETTER A WITH GRAVE}" =~ /\p{InLatin1Supplement}/;
1809 print "ok 627\n";
1810
1811 print "not " unless "\N{LATIN CAPITAL LETTER A WITH MACRON}" =~ /\p{InLatinExtendedA}/;
1812 print "ok 628\n";
1813
1814 print "not " unless "\N{LATIN SMALL LETTER B WITH STROKE}" =~ /\p{InLatinExtendedB}/;
1815 print "ok 629\n";
1816
1817 print "not " unless "\N{KATAKANA LETTER SMALL A}" =~ /\p{InKatakana}/;
1818 print "ok 630\n";
1819}
1820
6002328a
JH
1821$_ = "foo";
1822
1823eval <<"EOT"; die if $@;
1824 /f
1825 o\r
1826 o
1827 \$
1828 /x && print "ok 631\n";
1829EOT
1830
1831eval <<"EOT"; die if $@;
1832 /f
1833 o
1834 o
1835 \$\r
1836 /x && print "ok 632\n";
1837EOT
1838
569b5e07
AB
1839#test /o feature
1840sub test_o { $_[0] =~/$_[1]/o; return $1}
1841if(test_o('abc','(.)..') eq 'a') {
395ddfe6 1842 print "ok 633\n";
569b5e07 1843} else {
395ddfe6 1844 print "not ok 633\n";
569b5e07
AB
1845}
1846if(test_o('abc','..(.)') eq 'a') {
395ddfe6 1847 print "ok 634\n";
569b5e07 1848} else {
395ddfe6 1849 print "not ok 634\n";
569b5e07
AB
1850}
1851
f79b3095
JH
1852# 635..639: ID 20010619.003 (only the space character is
1853# supposed to be [:print:], not the whole isprint()).
1854
1855print "not " if "\n" =~ /[[:print:]]/;
1856print "ok 635\n";
1857
1858print "not " if "\t" =~ /[[:print:]]/;
1859print "ok 636\n";
1860
e857312d 1861# Amazingly vertical tabulator is the same in ASCII and EBCDIC.
f79b3095
JH
1862print "not " if "\014" =~ /[[:print:]]/;
1863print "ok 637\n";
1864
1865print "not " if "\r" =~ /[[:print:]]/;
1866print "ok 638\n";
1867
1868print "not " unless " " =~ /[[:print:]]/;
1869print "ok 639\n";
1870
a01268b5
JH
1871##
1872## Test basic $^N usage outside of a regex
1873##
1874$x = "abcdef";
1875$T="ok 640\n";if ($x =~ /cde/ and not defined $^N) {print $T} else {print "not $T"};
1876$T="ok 641\n";if ($x =~ /(cde)/ and $^N eq "cde") {print $T} else {print "not $T"};
1877$T="ok 642\n";if ($x =~ /(c)(d)(e)/ and $^N eq "e") {print $T} else {print "not $T"};
1878$T="ok 643\n";if ($x =~ /(c(d)e)/ and $^N eq "cde") {print $T} else {print "not $T"};
1879$T="ok 644\n";if ($x =~ /(foo)|(c(d)e)/ and $^N eq "cde") {print $T} else {print "not $T"};
1880$T="ok 645\n";if ($x =~ /(c(d)e)|(foo)/ and $^N eq "cde") {print $T} else {print "not $T"};
1881$T="ok 646\n";if ($x =~ /(c(d)e)|(abc)/ and $^N eq "abc") {print $T} else {print "not $T"};
1882$T="ok 647\n";if ($x =~ /(c(d)e)|(abc)x/ and $^N eq "cde") {print $T} else {print "not $T"};
1883$T="ok 648\n";if ($x =~ /(c(d)e)(abc)?/ and $^N eq "cde") {print $T} else {print "not $T"};
1884$T="ok 649\n";if ($x =~ /(?:c(d)e)/ and $^N eq "d" ) {print $T} else {print "not $T"};
1885$T="ok 650\n";if ($x =~ /(?:c(d)e)(?:f)/ and $^N eq "d" ) {print $T} else {print "not $T"};
1886$T="ok 651\n";if ($x =~ /(?:([abc])|([def]))*/ and $^N eq "f" ){print $T} else {print "not $T"};
1887$T="ok 652\n";if ($x =~ /(?:([ace])|([bdf]))*/ and $^N eq "f" ){print $T} else {print "not $T"};
1888$T="ok 653\n";if ($x =~ /(([ace])|([bd]))*/ and $^N eq "e" ){print $T} else {print "not $T"};
1889{
1890 $T="ok 654\n";if($x =~ /(([ace])|([bdf]))*/ and $^N eq "f" ){print $T} else {print "not $T"};
1891}
1892## test to see if $^N is automatically localized -- it should now
1893## have the value set in test 653
1894$T="ok 655\n";if ($^N eq "e" ){print $T} else {print "not $T"};
1895
1896##
1897## Now test inside (?{...})
1898##
1899$T="ok 656\n";if ($x =~ /a([abc])(?{$y=$^N})c/ and $y eq "b" ){print $T} else {print "not $T"};
1900$T="ok 657\n";if ($x =~ /a([abc]+)(?{$y=$^N})d/ and $y eq "bc"){print $T} else {print "not $T"};
1901$T="ok 658\n";if ($x =~ /a([abcdefg]+)(?{$y=$^N})d/ and $y eq "bc"){print $T} else {print "not $T"};
1902$T="ok 659\n";if ($x =~ /(a([abcdefg]+)(?{$y=$^N})d)(?{$z=$^N})e/ and $y eq "bc" and $z eq "abcd")
1903 {print $T} else {print "not $T"};
1904$T="ok 660\n";if ($x =~ /(a([abcdefg]+)(?{$y=$^N})de)(?{$z=$^N})/ and $y eq "bc" and $z eq "abcde")
1905 {print $T} else {print "not $T"};
2796c109
JH
1906
1907# Test the Unicode script classes
1908
cf25bb62 1909print "not " unless chr(0x100) =~ /\p{IsLatin}/; # outside Latin-1
2796c109
JH
1910print "ok 661\n";
1911
cf25bb62 1912print "not " unless chr(0x212b) =~ /\p{IsLatin}/; # Angstrom sign, very outside
2796c109
JH
1913print "ok 662\n";
1914
cf25bb62 1915print "not " unless chr(0x5d0) =~ /\p{IsHebrew}/; # inside InHebrew
2796c109
JH
1916print "ok 663\n";
1917
cf25bb62 1918print "not " unless chr(0xfb4f) =~ /\p{IsHebrew}/; # outside InHebrew
2796c109
JH
1919print "ok 664\n";
1920
7be0dac3
NC
1921# # singleton (not in a range, this test must be ignored on EBCDIC)
1922# print "not " unless chr(0xb5) =~ /\p{IsGreek}/ or ord("A") == 193;
1923# print "ok 665\n";
1924print "ok 665 # 0xb5 moved from Greek to Common with Unicode 4.0.1\n";
5f9563ea 1925
cf25bb62 1926print "not " unless chr(0x37a) =~ /\p{IsGreek}/; # singleton
5f9563ea
JH
1927print "ok 666\n";
1928
cf25bb62 1929print "not " unless chr(0x386) =~ /\p{IsGreek}/; # singleton
5f9563ea
JH
1930print "ok 667\n";
1931
cf25bb62 1932print "not " unless chr(0x387) =~ /\P{IsGreek}/; # not there
5f9563ea
JH
1933print "ok 668\n";
1934
cf25bb62 1935print "not " unless chr(0x388) =~ /\p{IsGreek}/; # range
5f9563ea
JH
1936print "ok 669\n";
1937
cf25bb62 1938print "not " unless chr(0x38a) =~ /\p{IsGreek}/; # range
5f9563ea
JH
1939print "ok 670\n";
1940
cf25bb62 1941print "not " unless chr(0x38b) =~ /\P{IsGreek}/; # not there
5f9563ea
JH
1942print "ok 671\n";
1943
cf25bb62 1944print "not " unless chr(0x38c) =~ /\p{IsGreek}/; # singleton
5f9563ea
JH
1945print "ok 672\n";
1946
550cec39 1947if (ord("A") == 65) {
7be5a6cf
JF
1948##
1949## Test [:cntrl:]...
1950##
1951## Should probably put in tests for all the POSIX stuff, but not sure how to
1952## guarantee a specific locale......
1953##
550cec39
JH
1954 $AllBytes = join('', map { chr($_) } 0..255);
1955 ($x = $AllBytes) =~ s/[[:cntrl:]]//g;
1956 if ($x ne join('', map { chr($_) } 0x20..0x7E, 0x80..0xFF)) {
1957 print "not ";
1958 }
1959 print "ok 673\n";
1960
1961 ($x = $AllBytes) =~ s/[^[:cntrl:]]//g;
1962 if ($x ne join('', map { chr($_) } 0..0x1F, 0x7F)) { print "not " }
1963 print "ok 674\n";
1964} else {
1965 print "ok $_ # Skip: EBCDIC\n" for 673..674;
1966}
f33976b4
DB
1967
1968# With /s modifier UTF8 chars were interpreted as bytes
1969{
1970 my $a = "Hello \x{263A} World";
1971
1972 my @a = ($a =~ /./gs);
1973
1974 print "not " unless $#a == 12;
1975 print "ok 675\n";
1976}
cce850e4
JH
1977
1978@a = ("foo\nbar" =~ /./g);
1979print "ok 676\n" if @a == 6 && "@a" eq "f o o b a r";
1980
1981@a = ("foo\nbar" =~ /./gs);
1982print "ok 677\n" if @a == 7 && "@a" eq "f o o \n b a r";
1983
1984@a = ("foo\nbar" =~ /\C/g);
1985print "ok 678\n" if @a == 7 && "@a" eq "f o o \n b a r";
1986
1987@a = ("foo\nbar" =~ /\C/gs);
1988print "ok 679\n" if @a == 7 && "@a" eq "f o o \n b a r";
1989
1990@a = ("foo\n\x{100}bar" =~ /./g);
1991print "ok 680\n" if @a == 7 && "@a" eq "f o o \x{100} b a r";
1992
1993@a = ("foo\n\x{100}bar" =~ /./gs);
1994print "ok 681\n" if @a == 8 && "@a" eq "f o o \n \x{100} b a r";
1995
1996($a, $b) = map { chr } ord('A') == 65 ? (0xc4, 0x80) : (0x8c, 0x41);
1997
1998@a = ("foo\n\x{100}bar" =~ /\C/g);
1999print "ok 682\n" if @a == 9 && "@a" eq "f o o \n $a $b b a r";
2000
2001@a = ("foo\n\x{100}bar" =~ /\C/gs);
2002print "ok 683\n" if @a == 9 && "@a" eq "f o o \n $a $b b a r";
2003
0af80b60
HS
2004{
2005 # [ID 20010814.004] pos() doesn't work when using =~m// in list context
2006 $_ = "ababacadaea";
2007 $a = join ":", /b./gc;
2008 $b = join ":", /a./gc;
2009 $c = pos;
2010 print "$a $b $c" eq 'ba:ba ad:ae 10' ? "ok 684\n" : "not ok 684\t# $a $b $c\n";
2011}
d9f424b2
JH
2012
2013{
75685a94
JH
2014 # [ID 20010407.006] matching utf8 return values from functions does not work
2015
d9f424b2
JH
2016 package ID_20010407_006;
2017
2018 sub x {
2019 "a\x{1234}";
2020 }
2021
2022 my $x = x;
2023 my $y;
2024
2025 $x =~ /(..)/; $y = $1;
2026 print "not " unless length($y) == 2 && $y eq $x;
75685a94 2027 print "ok 685\n";
d9f424b2
JH
2028
2029 x =~ /(..)/; $y = $1;
2030 print "not " unless length($y) == 2 && $y eq $x;
2031 print "ok 686\n";
2032}
a4c04bdc 2033
e2d8ce26 2034
fc8cd66c 2035$test = 687;
a4c04bdc
NC
2036
2037# Force scalar context on the patern match
fc8cd66c 2038sub ok ($;$) {
a4c04bdc
NC
2039 my($ok, $name) = @_;
2040
f0852a51
YO
2041 printf "%sok %d - %s\n", ($ok ? "" : "not "), $test,
2042 $name||"$Message:".((caller)[2]);
a4c04bdc
NC
2043
2044 printf "# Failed test at line %d\n", (caller)[2] unless $ok;
2045
2046 $test++;
2047 return $ok;
2048}
2049
2050{
2051 # Check that \x## works. 5.6.1 and 5.005_03 fail some of these.
2052 $x = "\x4e" . "E";
2053 ok ($x =~ /^\x4EE$/, "Check only 2 bytes of hex are matched.");
2054
2055 $x = "\x4e" . "i";
2056 ok ($x =~ /^\x4Ei$/, "Check that invalid hex digit stops it (2)");
2057
2058 $x = "\x4" . "j";
2059 ok ($x =~ /^\x4j$/, "Check that invalid hex digit stops it (1)");
2060
2061 $x = "\x0" . "k";
2062 ok ($x =~ /^\xk$/, "Check that invalid hex digit stops it (0)");
2063
2064 $x = "\x0" . "x";
2065 ok ($x =~ /^\xx$/, "\\xx isn't to be treated as \\0");
2066
2067 $x = "\x0" . "xa";
2068 ok ($x =~ /^\xxa$/, "\\xxa isn't to be treated as \\xa");
2069
2070 $x = "\x9" . "_b";
2071 ok ($x =~ /^\x9_b$/, "\\x9_b isn't to be treated as \\x9b");
2072
2073 print "# and now again in [] ranges\n";
2074
2075 $x = "\x4e" . "E";
2076 ok ($x =~ /^[\x4EE]{2}$/, "Check only 2 bytes of hex are matched.");
2077
2078 $x = "\x4e" . "i";
2079 ok ($x =~ /^[\x4Ei]{2}$/, "Check that invalid hex digit stops it (2)");
2080
2081 $x = "\x4" . "j";
2082 ok ($x =~ /^[\x4j]{2}$/, "Check that invalid hex digit stops it (1)");
2083
2084 $x = "\x0" . "k";
2085 ok ($x =~ /^[\xk]{2}$/, "Check that invalid hex digit stops it (0)");
2086
2087 $x = "\x0" . "x";
2088 ok ($x =~ /^[\xx]{2}$/, "\\xx isn't to be treated as \\0");
2089
2090 $x = "\x0" . "xa";
2091 ok ($x =~ /^[\xxa]{3}$/, "\\xxa isn't to be treated as \\xa");
2092
2093 $x = "\x9" . "_b";
2094 ok ($x =~ /^[\x9_b]{3}$/, "\\x9_b isn't to be treated as \\x9b");
2095
2096}
2097
2098{
2099 # Check that \x{##} works. 5.6.1 fails quite a few of these.
2100
2101 $x = "\x9b";
2102 ok ($x =~ /^\x{9_b}$/, "\\x{9_b} is to be treated as \\x9b");
2103
2104 $x = "\x9b" . "y";
2105 ok ($x =~ /^\x{9_b}y$/, "\\x{9_b} is to be treated as \\x9b (again)");
2106
2107 $x = "\x9b" . "y";
2108 ok ($x =~ /^\x{9b_}y$/, "\\x{9b_} is to be treated as \\x9b");
2109
2110 $x = "\x9b" . "y";
2111 ok ($x =~ /^\x{9_bq}y$/, "\\x{9_bc} is to be treated as \\x9b");
2112
2113 $x = "\x0" . "y";
2114 ok ($x =~ /^\x{x9b}y$/, "\\x{x9b} is to be treated as \\x0");
2115
2116 $x = "\x0" . "y";
2117 ok ($x =~ /^\x{0x9b}y$/, "\\x{0x9b} is to be treated as \\x0");
2118
2119 $x = "\x9b" . "y";
2120 ok ($x =~ /^\x{09b}y$/, "\\x{09b} is to be treated as \\x9b");
2121
2122 print "# and now again in [] ranges\n";
2123
2124 $x = "\x9b";
2125 ok ($x =~ /^[\x{9_b}]$/, "\\x{9_b} is to be treated as \\x9b");
2126
2127 $x = "\x9b" . "y";
2128 ok ($x =~ /^[\x{9_b}y]{2}$/, "\\x{9_b} is to be treated as \\x9b (again)");
2129
2130 $x = "\x9b" . "y";
2131 ok ($x =~ /^[\x{9b_}y]{2}$/, "\\x{9b_} is to be treated as \\x9b");
2132
2133 $x = "\x9b" . "y";
2134 ok ($x =~ /^[\x{9_bq}y]{2}$/, "\\x{9_bc} is to be treated as \\x9b");
2135
2136 $x = "\x0" . "y";
2137 ok ($x =~ /^[\x{x9b}y]{2}$/, "\\x{x9b} is to be treated as \\x0");
2138
2139 $x = "\x0" . "y";
2140 ok ($x =~ /^[\x{0x9b}y]{2}$/, "\\x{0x9b} is to be treated as \\x0");
2141
2142 $x = "\x9b" . "y";
2143 ok ($x =~ /^[\x{09b}y]{2}$/, "\\x{09b} is to be treated as \\x9b");
2144}
e2d8ce26
JP
2145
2146{
d9efae67
JH
2147 # high bit bug -- japhy
2148 my $x = "ab\200d";
2149 $x =~ /.*?\200/ or print "not ";
2150 print "ok 715\n";
e2d8ce26
JP
2151}
2152
4193bef7
JH
2153print "# some Unicode properties\n";
2154
d9efae67 2155{
4193bef7 2156 # Dashes, underbars, case.
d9efae67
JH
2157 print "not " unless "\x80" =~ /\p{in-latin1_SUPPLEMENT}/;
2158 print "ok 716\n";
ab13f0c7 2159
4193bef7 2160 # Complement, leading and trailing whitespace.
ab13f0c7
JH
2161 print "not " unless "\x80" =~ /\P{ ^ In Latin 1 Supplement }/;
2162 print "ok 717\n";
4193bef7 2163
f173cd49
JH
2164 # No ^In, dashes, case, dash, any intervening (word-break) whitespace.
2165 # (well, newlines don't work...)
2166 print "not " unless "\x80" =~ /\p{latin-1 supplement}/;
4193bef7
JH
2167 print "ok 718\n";
2168}
2169
2170{
2171 print "not " unless "a" =~ /\pL/;
2172 print "ok 719\n";
4193bef7 2173
4193bef7
JH
2174 print "not " unless "a" =~ /\p{IsLl}/;
2175 print "ok 720\n";
4193bef7 2176
c87b7cc2 2177 print "not " if "a" =~ /\p{IsLu}/;
4193bef7 2178 print "ok 721\n";
4193bef7 2179
61247495 2180 print "not " unless "a" =~ /\p{Ll}/;
4193bef7 2181 print "ok 722\n";
c87b7cc2 2182
61247495 2183 print "not " if "a" =~ /\p{Lu}/;
c87b7cc2
JH
2184 print "ok 723\n";
2185
61247495 2186 print "not " unless "A" =~ /\pL/;
c87b7cc2
JH
2187 print "ok 724\n";
2188
61247495 2189 print "not " unless "A" =~ /\p{IsLu}/;
c87b7cc2
JH
2190 print "ok 725\n";
2191
61247495 2192 print "not " if "A" =~ /\p{IsLl}/;
c87b7cc2
JH
2193 print "ok 726\n";
2194
61247495 2195 print "not " unless "A" =~ /\p{Lu}/;
c87b7cc2
JH
2196 print "ok 727\n";
2197
61247495 2198 print "not " if "A" =~ /\p{Ll}/;
c87b7cc2
JH
2199 print "ok 728\n";
2200
61247495 2201 print "not " if "a" =~ /\PL/;
c87b7cc2
JH
2202 print "ok 729\n";
2203
61247495 2204 print "not " if "a" =~ /\P{IsLl}/;
c87b7cc2 2205 print "ok 730\n";
61247495
JH
2206
2207 print "not " unless "a" =~ /\P{IsLu}/;
2208 print "ok 731\n";
2209
2210 print "not " if "a" =~ /\P{Ll}/;
2211 print "ok 732\n";
2212
2213 print "not " unless "a" =~ /\P{Lu}/;
2214 print "ok 733\n";
2215
2216 print "not " if "A" =~ /\PL/;
2217 print "ok 734\n";
2218
2219 print "not " if "A" =~ /\P{IsLu}/;
2220 print "ok 735\n";
2221
2222 print "not " unless "A" =~ /\P{IsLl}/;
2223 print "ok 736\n";
2224
2225 print "not " if "A" =~ /\P{Lu}/;
2226 print "ok 737\n";
2227
2228 print "not " unless "A" =~ /\P{Ll}/;
2229 print "ok 738\n";
2230
4193bef7 2231}
9b4e380a
JH
2232
2233{
2234 print "not " if "a" =~ /\p{Common}/;
2235 print "ok 739\n";
2236
2237 print "not " unless "1" =~ /\p{Common}/;
2238 print "ok 740\n";
2239}
2240
2241{
2242 print "not " if "a" =~ /\p{Inherited}/;
2243 print "ok 741\n";
2244
2245 print "not " unless "\x{300}" =~ /\p{Inherited}/;
2246 print "ok 742\n";
2247}
2248
2249{
12ac2576
JP
2250 # L& and LC are the same
2251 print "not " unless "a" =~ /\p{LC}/ and "a" =~ /\p{L&}/;
9b4e380a
JH
2252 print "ok 743\n";
2253
12ac2576 2254 print "not " if "1" =~ /\p{LC}/ or "1" =~ /\p{L&}/;
9b4e380a
JH
2255 print "ok 744\n";
2256}
d73e5302
JH
2257
2258{
904bc114 2259 print "not " unless "a" =~ /\p{Lowercase Letter}/;
d73e5302
JH
2260 print "ok 745\n";
2261
904bc114 2262 print "not " if "A" =~ /\p{lowercaseletter}/;
d73e5302
JH
2263 print "ok 746\n";
2264}
2265
2266{
cf25bb62 2267 print "not " unless "\x{AC00}" =~ /\p{HangulSyllables}/;
d73e5302
JH
2268 print "ok 747\n";
2269}
71d929cb
JH
2270
2271{
701a277b
JH
2272 # Script=, Block=, Category=
2273
71d929cb
JH
2274 print "not " unless "\x{0100}" =~ /\p{Script=Latin}/;
2275 print "ok 748\n";
2276
2277 print "not " unless "\x{0100}" =~ /\p{Block=LatinExtendedA}/;
2278 print "ok 749\n";
2279
2280 print "not " unless "\x{0100}" =~ /\p{Category=UppercaseLetter}/;
2281 print "ok 750\n";
2282}
2283
ef54fa25 2284{
701a277b
JH
2285 print "# the basic character classes and Unicode \n";
2286
ef54fa25
JH
2287 # 0100;LATIN CAPITAL LETTER A WITH MACRON;Lu;0;L;0041 0304;;;;N;LATIN CAPITAL LETTER A MACRON;;;0101;
2288 print "not " unless "\x{0100}" =~ /\w/;
2289 print "ok 751\n";
2290
2291 # 0660;ARABIC-INDIC DIGIT ZERO;Nd;0;AN;;0;0;0;N;;;;;
2292 print "not " unless "\x{0660}" =~ /\d/;
2293 print "ok 752\n";
2294
2295 # 1680;OGHAM SPACE MARK;Zs;0;WS;;;;;N;;;;;
2296 print "not " unless "\x{1680}" =~ /\s/;
2297 print "ok 753\n";
2298}
701a277b
JH
2299
2300{
2301 print "# folding matches and Unicode\n";
2302
2303 print "not " unless "a\x{100}" =~ /A/i;
2304 print "ok 754\n";
2305
27e28630 2306 print "not " unless "A\x{100}" =~ /a/i;
701a277b
JH
2307 print "ok 755\n";
2308
2309 print "not " unless "a\x{100}" =~ /a/i;
2310 print "ok 756\n";
2311
2312 print "not " unless "A\x{100}" =~ /A/i;
2313 print "ok 757\n";
bc517b45
JH
2314
2315 print "not " unless "\x{101}a" =~ /\x{100}/i;
2316 print "ok 758\n";
2317
2318 print "not " unless "\x{100}a" =~ /\x{100}/i;
2319 print "ok 759\n";
2320
2321 print "not " unless "\x{101}a" =~ /\x{101}/i;
2322 print "ok 760\n";
2323
2324 print "not " unless "\x{100}a" =~ /\x{101}/i;
2325 print "ok 761\n";
2326
2327 print "not " unless "a\x{100}" =~ /A\x{100}/i;
2328 print "ok 762\n";
2329
27e28630 2330 print "not " unless "A\x{100}" =~ /a\x{100}/i;
bc517b45
JH
2331 print "ok 763\n";
2332
2333 print "not " unless "a\x{100}" =~ /a\x{100}/i;
2334 print "ok 764\n";
2335
2336 print "not " unless "A\x{100}" =~ /A\x{100}/i;
2337 print "ok 765\n";
2338
2339 print "not " unless "a\x{100}" =~ /[A]/i;
2340 print "ok 766\n";
2341
27e28630 2342 print "not " unless "A\x{100}" =~ /[a]/i;
bc517b45
JH
2343 print "ok 767\n";
2344
2345 print "not " unless "a\x{100}" =~ /[a]/i;
2346 print "ok 768\n";
2347
2348 print "not " unless "A\x{100}" =~ /[A]/i;
2349 print "ok 769\n";
2350
2351 print "not " unless "\x{101}a" =~ /[\x{100}]/i;
2352 print "ok 770\n";
2353
2354 print "not " unless "\x{100}a" =~ /[\x{100}]/i;
2355 print "ok 771\n";
2356
2357 print "not " unless "\x{101}a" =~ /[\x{101}]/i;
2358 print "ok 772\n";
2359
2360 print "not " unless "\x{100}a" =~ /[\x{101}]/i;
2361 print "ok 773\n";
2362
701a277b 2363}
a5961de5
JH
2364
2365{
2366 use charnames ':full';
2367
2368 print "# LATIN LETTER A WITH GRAVE\n";
2369 my $lower = "\N{LATIN SMALL LETTER A WITH GRAVE}";
2370 my $UPPER = "\N{LATIN CAPITAL LETTER A WITH GRAVE}";
2371
bc517b45
JH
2372 print $lower =~ m/$UPPER/i ? "ok 774\n" : "not ok 774\n";
2373 print $UPPER =~ m/$lower/i ? "ok 775\n" : "not ok 775\n";
2374 print $lower =~ m/[$UPPER]/i ? "ok 776\n" : "not ok 776\n";
2375 print $UPPER =~ m/[$lower]/i ? "ok 777\n" : "not ok 777\n";
a5961de5
JH
2376
2377 print "# GREEK LETTER ALPHA WITH VRACHY\n";
2378
2379 $lower = "\N{GREEK CAPITAL LETTER ALPHA WITH VRACHY}";
2380 $UPPER = "\N{GREEK SMALL LETTER ALPHA WITH VRACHY}";
2381
bc517b45
JH
2382 print $lower =~ m/$UPPER/i ? "ok 778\n" : "not ok 778\n";
2383 print $UPPER =~ m/$lower/i ? "ok 779\n" : "not ok 779\n";
2384 print $lower =~ m/[$UPPER]/i ? "ok 780\n" : "not ok 780\n";
2385 print $UPPER =~ m/[$lower]/i ? "ok 781\n" : "not ok 781\n";
a5961de5
JH
2386
2387 print "# LATIN LETTER Y WITH DIAERESIS\n";
2388
2389 $lower = "\N{LATIN CAPITAL LETTER Y WITH DIAERESIS}";
2390 $UPPER = "\N{LATIN SMALL LETTER Y WITH DIAERESIS}";
bc517b45
JH
2391 print $lower =~ m/$UPPER/i ? "ok 782\n" : "not ok 782\n";
2392 print $UPPER =~ m/$lower/i ? "ok 783\n" : "not ok 783\n";
2393 print $lower =~ m/[$UPPER]/i ? "ok 784\n" : "not ok 784\n";
2394 print $UPPER =~ m/[$lower]/i ? "ok 785\n" : "not ok 785\n";
a5961de5 2395}
55da9344
JH
2396
2397{
2398 use warnings;
2399 use charnames ':full';
2400
2401 print "# GREEK CAPITAL LETTER SIGMA vs COMBINING GREEK PERISPOMENI\n";
2402
2403 my $SIGMA = "\N{GREEK CAPITAL LETTER SIGMA}";
d07ddd77 2404 my $char = "\N{COMBINING GREEK PERISPOMENI}";
55da9344 2405
bc517b45
JH
2406 # Before #13843 this was failing by matching falsely.
2407 print "_:$char:_" =~ m/_:$SIGMA:_/i ? "not ok 786\n" : "ok 786\n";
55da9344 2408}
b7c83a7e
JH
2409
2410{
2411 print "# \\X\n";
2412
2413 use charnames ':full';
2414
eb08e2da
JH
2415 print "a!" =~ /^(\X)!/ && $1 eq "a" ?
2416 "ok 787\n" : "not ok 787 # $1\n";
2417 print "\xDF!" =~ /^(\X)!/ && $1 eq "\xDF" ?
2418 "ok 788\n" : "not ok 788 # $1\n";
2419 print "\x{100}!" =~ /^(\X)!/ && $1 eq "\x{100}" ?
2420 "ok 789\n" : "not ok 789 # $1\n";
2421 print "\x{100}\x{300}!" =~ /^(\X)!/ && $1 eq "\x{100}\x{300}" ?
2422 "ok 790\n" : "not ok 790 # $1\n";
2423 print "\N{LATIN CAPITAL LETTER E}!" =~ /^(\X)!/ &&
2424 $1 eq "\N{LATIN CAPITAL LETTER E}" ?
2425 "ok 791\n" : "not ok 791 # $1\n";
2426 print "\N{LATIN CAPITAL LETTER E}\N{COMBINING GRAVE ACCENT}!" =~
2427 /^(\X)!/ &&
2428 $1 eq "\N{LATIN CAPITAL LETTER E}\N{COMBINING GRAVE ACCENT}" ?
2429 "ok 792\n" : "not ok 792 # $1\n";
b7c83a7e 2430}
112bedeb
JH
2431
2432{
2433 print "#\\C and \\X\n";
2434
2435 print "!abc!" =~ /a\Cc/ ? "ok 793\n" : "not ok 793\n";
2436 print "!abc!" =~ /a\Xc/ ? "ok 794\n" : "not ok 794\n";
2437}
09091399
JH
2438
2439{
2440 print "# FINAL SIGMA\n";
2441
2442 my $SIGMA = "\x{03A3}"; # CAPITAL
2443 my $Sigma = "\x{03C2}"; # SMALL FINAL
2444 my $sigma = "\x{03C3}"; # SMALL
2445
2446 print $SIGMA =~ /$SIGMA/i ? "ok 795\n" : "not ok 795\n";
2447 print $SIGMA =~ /$Sigma/i ? "ok 796\n" : "not ok 796\n";
2448 print $SIGMA =~ /$sigma/i ? "ok 797\n" : "not ok 797\n";
2449
2450 print $Sigma =~ /$SIGMA/i ? "ok 798\n" : "not ok 798\n";
2451 print $Sigma =~ /$Sigma/i ? "ok 799\n" : "not ok 799\n";
2452 print $Sigma =~ /$sigma/i ? "ok 800\n" : "not ok 800\n";
2453
2454 print $sigma =~ /$SIGMA/i ? "ok 801\n" : "not ok 801\n";
2455 print $sigma =~ /$Sigma/i ? "ok 802\n" : "not ok 802\n";
2456 print $sigma =~ /$sigma/i ? "ok 803\n" : "not ok 803\n";
2457
2458 print $SIGMA =~ /[$SIGMA]/i ? "ok 804\n" : "not ok 804\n";
2459 print $SIGMA =~ /[$Sigma]/i ? "ok 805\n" : "not ok 805\n";
2460 print $SIGMA =~ /[$sigma]/i ? "ok 806\n" : "not ok 806\n";
2461
2462 print $Sigma =~ /[$SIGMA]/i ? "ok 807\n" : "not ok 807\n";
2463 print $Sigma =~ /[$Sigma]/i ? "ok 808\n" : "not ok 808\n";
2464 print $Sigma =~ /[$sigma]/i ? "ok 809\n" : "not ok 809\n";
2465
2466 print $sigma =~ /[$SIGMA]/i ? "ok 810\n" : "not ok 810\n";
2467 print $sigma =~ /[$Sigma]/i ? "ok 811\n" : "not ok 811\n";
2468 print $sigma =~ /[$sigma]/i ? "ok 812\n" : "not ok 812\n";
2469}
e036fef9
JF
2470
2471{
2472 print "# parlez-vous?\n";
2473
2474 use charnames ':full';
2475
2476 print "fran\N{LATIN SMALL LETTER C}ais" =~
2477 /fran.ais/ &&
2478 $& eq "francais" ?
2479 "ok 813\n" : "not ok 813\n";
2480
2481 print "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" =~
2482 /fran.ais/ &&
2483 $& eq "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" ?
2484 "ok 814\n" : "not ok 814\n";
2485
2486 print "fran\N{LATIN SMALL LETTER C}ais" =~
2487 /fran\Cais/ &&
2488 $& eq "francais" ?
2489 "ok 815\n" : "not ok 815\n";
2490
2491 print "franc\N{COMBINING CEDILLA}ais" =~
2492 /franc\C\Cais/ ? # COMBINING CEDILLA is two bytes when encoded
2493 "ok 816\n" : "not ok 816\n";
2494
2495 print "fran\N{LATIN SMALL LETTER C}ais" =~
2496 /fran\Xais/ &&
2497 $& eq "francais" ?
2498 "ok 817\n" : "not ok 817\n";
2499
2500 print "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" =~
2501 /fran\Xais/ &&
2502 $& eq "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" ?
2503 "ok 818\n" : "not ok 818\n";
2504
2505 print "franc\N{COMBINING CEDILLA}ais" =~
2506 /fran\Xais/ &&
2507 $& eq "franc\N{COMBINING CEDILLA}ais" ?
2508 "ok 819\n" : "not ok 819\n";
2509
2510 print "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" =~
2511 /fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais/ &&
2512 $& eq "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" ?
2513 "ok 820\n" : "not ok 820\n";
2514
2515 print "franc\N{COMBINING CEDILLA}ais" =~
2516 /franc\N{COMBINING CEDILLA}ais/ &&
2517 $& eq "franc\N{COMBINING CEDILLA}ais" ?
2518 "ok 821\n" : "not ok 821\n";
2519
2520 print "fran\N{LATIN SMALL LETTER C}ais" =~
2521 /fran(?:c\N{COMBINING CEDILLA}?|\N{LATIN SMALL LETTER C WITH CEDILLA})ais/ &&
2522 $& eq "francais" ?
2523 "ok 822\n" : "not ok 822\n";
2524
2525 print "fran\N{LATIN SMALL LETTER C}ais" =~
2526 /fran(?:c\N{COMBINING CEDILLA}?|\N{LATIN SMALL LETTER C WITH CEDILLA})ais/ &&
2527 $& eq "francais" ?
2528 "ok 823\n" : "not ok 823\n";
2529
2530 print "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" =~
2531 /fran(?:c\N{COMBINING CEDILLA}?|\N{LATIN SMALL LETTER C WITH CEDILLA})ais/ &&
2532 $& eq "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" ?
2533 "ok 824\n" : "not ok 824\n";
2534
2535 print "franc\N{COMBINING CEDILLA}ais" =~
2536 /fran(?:c\N{COMBINING CEDILLA}?|\N{LATIN SMALL LETTER C WITH CEDILLA})ais/ &&
2537 $& eq "franc\N{COMBINING CEDILLA}ais" ?
2538 "ok 825\n" : "not ok 825\n";
2539}
ffce6cc2
JH
2540
2541{
2542 print "# Does lingering (and useless) UTF8 flag mess up /i matching?\n";
2543
2544 {
2545 my $regex = "ABcde";
2546 my $string = "abcDE\x{100}";
2547 chop($string);
2548 if ($string =~ m/$regex/i) {
2549 print "ok 826\n";
2550 } else {
2551 print "not ok 826\n";
2552 }
2553 }
2554
2555 {
2556 my $regex = "ABcde\x{100}";
2557 my $string = "abcDE";
2558 chop($regex);
2559 if ($string =~ m/$regex/i) {
2560 print "ok 827\n";
2561 } else {
2562 print "not ok 827\n";
2563 }
2564 }
2565
2566 {
2567 my $regex = "ABcde\x{100}";
2568 my $string = "abcDE\x{100}";
2569 chop($regex);
2570 chop($string);
2571 if ($string =~ m/$regex/i) {
2572 print "ok 828\n";
2573 } else {
2574 print "not ok 828\n";
2575 }
2576 }
2577}
d07ddd77
JH
2578
2579{
2580 print "# more SIGMAs\n";
2581
2582 my $SIGMA = "\x{03A3}"; # CAPITAL
2583 my $Sigma = "\x{03C2}"; # SMALL FINAL
2584 my $sigma = "\x{03C3}"; # SMALL
2585
2586 my $S3 = "$SIGMA$Sigma$sigma";
2587
2588 print ":$S3:" =~ /:(($SIGMA)+):/i && $1 eq $S3 && $2 eq $sigma ?
2589 "ok 829\n" : "not ok 829\n";
2590 print ":$S3:" =~ /:(($Sigma)+):/i && $1 eq $S3 && $2 eq $sigma ?
2591 "ok 830\n" : "not ok 830\n";
2592 print ":$S3:" =~ /:(($sigma)+):/i && $1 eq $S3 && $2 eq $sigma ?
2593 "ok 831\n" : "not ok 831\n";
2594
2595 print ":$S3:" =~ /:(([$SIGMA])+):/i && $1 eq $S3 && $2 eq $sigma ?
2596 "ok 832\n" : "not ok 832\n";
2597 print ":$S3:" =~ /:(([$Sigma])+):/i && $1 eq $S3 && $2 eq $sigma ?
2598 "ok 833\n" : "not ok 833\n";
2599 print ":$S3:" =~ /:(([$sigma])+):/i && $1 eq $S3 && $2 eq $sigma ?
2600 "ok 834\n" : "not ok 834\n";
2601}
925f9e00
JH
2602
2603{
2604 print "# LATIN SMALL LETTER SHARP S\n";
2605
2606 use charnames ':full';
2607
fc8cd66c 2608 $test= 835;
925f9e00 2609
fc8cd66c
YO
2610 ok("\N{LATIN SMALL LETTER SHARP S}" =~ /\N{LATIN SMALL LETTER SHARP S}/);
2611 ok("\N{LATIN SMALL LETTER SHARP S}" =~ /\N{LATIN SMALL LETTER SHARP S}/i);
925f9e00 2612
fc8cd66c
YO
2613 ok("\N{LATIN SMALL LETTER SHARP S}" =~ /[\N{LATIN SMALL LETTER SHARP S}]/);
2614 ok("\N{LATIN SMALL LETTER SHARP S}" =~ /[\N{LATIN SMALL LETTER SHARP S}]/i);
925f9e00 2615
fc8cd66c
YO
2616 ok("ss" =~ /\N{LATIN SMALL LETTER SHARP S}/i);
2617 ok("SS" =~ /\N{LATIN SMALL LETTER SHARP S}/i);
2618 ok("ss" =~ /[\N{LATIN SMALL LETTER SHARP S}]/i);
2619 ok("SS" =~ /[\N{LATIN SMALL LETTER SHARP S}]/i);
925f9e00 2620
fc8cd66c
YO
2621 ok("\N{LATIN SMALL LETTER SHARP S}" =~ /ss/i);
2622 ok("\N{LATIN SMALL LETTER SHARP S}" =~ /SS/i);
925f9e00 2623}
d8f6a732
JH
2624
2625{
2626 print "# more whitespace: U+0085, U+2028, U+2029\n";
2627
2628 # U+0085 needs to be forced to be Unicode, the \x{100} does that.
250d67eb
JH
2629 if ($ordA == 193) {
2630 print "<\x{100}\x{0085}>" =~ /<\x{100}e>/ ? "ok 845\n" : "not ok 845\n";
2631 } else {
2632 print "<\x{100}\x{0085}>" =~ /<\x{100}\s>/ ? "ok 845\n" : "not ok 845\n";
2633 }
5486206c
JH
2634 print "<\x{2028}>" =~ /<\s>/ ? "ok 846\n" : "not ok 846\n";
2635 print "<\x{2029}>" =~ /<\s>/ ? "ok 847\n" : "not ok 847\n";
d8f6a732
JH
2636}
2637
def8e4ea 2638{
229196e5 2639 print "# . with /s should work on characters, as opposed to bytes\n";
def8e4ea
JH
2640
2641 my $s = "\x{e4}\x{100}";
2642
2643 # This is not expected to match: the point is that
2644 # neither should we get "Malformed UTF-8" warnings.
2645 print $s =~ /\G(.+?)\n/gcs ?
5486206c 2646 "not ok 848\n" : "ok 848\n";
def8e4ea
JH
2647
2648 my @c;
2649
2650 while ($s =~ /\G(.)/gs) {
2651 push @c, $1;
2652 }
2653
5486206c 2654 print join("", @c) eq $s ? "ok 849\n" : "not ok 849\n";
a0804c9e
A
2655
2656 my $t1 = "Q003\n\n\x{e4}\x{f6}\n\nQ004\n\n\x{e7}"; # test only chars < 256
2657 my $r1 = "";
2658 while ($t1 =~ / \G ( .+? ) \n\s+ ( .+? ) ( $ | \n\s+ ) /xgcs) {
2659 $r1 .= $1 . $2;
2660 }
2661
2662 my $t2 = $t1 . "\x{100}"; # repeat with a larger char
2663 my $r2 = "";
2664 while ($t2 =~ / \G ( .+? ) \n\s+ ( .+? ) ( $ | \n\s+ ) /xgcs) {
2665 $r2 .= $1 . $2;
2666 }
2667 $r2 =~ s/\x{100}//;
5486206c 2668 print $r1 eq $r2 ? "ok 850\n" : "not ok 850\n";
def8e4ea 2669}
e54858b0
JH
2670
2671{
2672 print "# Unicode lookbehind\n";
2673
5486206c
JH
2674 print "A\x{100}B" =~ /(?<=A.)B/ ? "ok 851\n" : "not ok 851\n";
2675 print "A\x{200}\x{300}B" =~ /(?<=A..)B/ ? "ok 852\n" : "not ok 852\n";
2676 print "\x{400}AB" =~ /(?<=\x{400}.)B/ ? "ok 853\n" : "not ok 853\n";
2677 print "\x{500\x{600}}B" =~ /(?<=\x{500}.)B/ ? "ok 854\n" : "not ok 854\n";
e54858b0 2678}
c46248c1
JH
2679
2680{
85fd1718
JH
2681 print "# UTF-8 hash keys and /\$/\n";
2682 # http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2002-01/msg01327.html
2683
2684 my $u = "a\x{100}";
2685 my $v = substr($u,0,1);
2686 my $w = substr($u,1,1);
2687 my %u = ( $u => $u, $v => $v, $w => $w );
8d21bda2 2688 my $i = 855;
85fd1718
JH
2689 for (keys %u) {
2690 my $m1 = /^\w*$/ ? 1 : 0;
2691 my $m2 = $u{$_}=~/^\w*$/ ? 1 : 0;
2692 print $m1 == $m2 ? "ok $i\n" : "not ok $i # $m1 $m2\n";
2693 $i++;
2694 }
2695}
8d21bda2
JH
2696
2697{
2698 print "# [ID 20020124.005]\n";
2699 # Fixed by #14795.
2700 my $i = 858;
2701 for my $char ("a", "\x{df}", "\x{100}"){
2702 $x = "$char b $char";
2703 $x =~ s{($char)}{
2704 "c" =~ /c/;
2705 "x";
2706 }ge;
2707 print substr($x,0,1) eq substr($x,-1,1) ?
2708 "ok $i\n" : "not ok $i # debug: $x\n";
2709 $i++;
2710 }
2711}
6e602e29
A
2712
2713{
2714 print "# SEGV in s/// and UTF-8\n";
2715 $s = "s#\x{100}" x 4;
2716 $s =~ s/[^\w]/ /g;
2717 print $s eq "s \x{100}" x 4 ? "ok 861\n" : "not ok 861\n";
2718}
f272994b
A
2719
2720{
2721 print "# UTF-8 bug (maybe alreayd known?)\n";
2722 my $u;
2723
2724 $u = "foo";
2725 $u =~ s/./\x{100}/g;
2726 print $u eq "\x{100}\x{100}\x{100}" ? "ok 862\n" : "not ok 862\n";
2727
2728 $u = "foobar";
2729 $u =~ s/[ao]/\x{100}/g;
2730 print $u eq "f\x{100}\x{100}b\x{100}r" ? "ok 863\n" : "not ok 863\n";
2731
2732 $u =~ s/\x{100}/e/g;
2733 print $u eq "feeber" ? "ok 864\n" : "not ok 864\n";
2734}
2735
33b8afdf
JH
2736{
2737 print "# UTF-8 bug with s///\n";
2738 # check utf8/non-utf8 mixtures
2739 # try to force all float/anchored check combinations
2740 my $c = "\x{100}";
fc8cd66c 2741 $test = 865;
33b8afdf
JH
2742 my $subst;
2743 for my $re (
2744 "xx.*$c", "x.*$c$c", "$c.*xx", "$c$c.*x", "xx.*(?=$c)", "(?=$c).*xx",
2745 ) {
2746 print "xxx" =~ /$re/ ? "not ok $test\n" : "ok $test\n";
2747 ++$test;
2748 print +($subst = "xxx") =~ s/$re// ? "not ok $test\n" : "ok $test\n";
2749 ++$test;
2750 }
2751 for my $re ("xx.*$c*", "$c*.*xx") {
2752 print "xxx" =~ /$re/ ? "ok $test\n" : "not ok $test\n";
2753 ++$test;
2754 ($subst = "xxx") =~ s/$re//;
2755 print $subst eq '' ? "ok $test\n" : "not ok $test\t# $subst\n";
2756 ++$test;
2757 }
2758 for my $re ("xxy*", "y*xx") {
2759 print "xx$c" =~ /$re/ ? "ok $test\n" : "not ok $test\n";
2760 ++$test;
2761 ($subst = "xx$c") =~ s/$re//;
2762 print $subst eq $c ? "ok $test\n" : "not ok $test\n";
2763 ++$test;
2764 print "xy$c" =~ /$re/ ? "not ok $test\n" : "ok $test\n";
2765 ++$test;
2766 print +($subst = "xy$c") =~ /$re/ ? "not ok $test\n" : "ok $test\n";
2767 ++$test;
2768 }
2769 for my $re ("xy$c*z", "x$c*yz") {
2770 print "xyz" =~ /$re/ ? "ok $test\n" : "not ok $test\n";
2771 ++$test;
2772 ($subst = "xyz") =~ s/$re//;
2773 print $subst eq '' ? "ok $test\n" : "not ok $test\n";
2774 ++$test;
2775 }
2776}
574c8022 2777
ff385a1b
JF
2778{
2779 print "# qr/.../x\n";
fc8cd66c 2780 $test = 893;
ff385a1b
JF
2781
2782 my $R = qr/ A B C # D E/x;
2783
2784 print eval {"ABCDE" =~ $R} ? "ok $test\n" : "not ok $test\n";
2785 $test++;
2786
2787 print eval {"ABCDE" =~ m/$R/} ? "ok $test\n" : "not ok $test\n";
2788 $test++;
2789
2790 print eval {"ABCDE" =~ m/($R)/} ? "ok $test\n" : "not ok $test\n";
2791 $test++;
2792}
bc45ce41
JH
2793
2794{
2795 print "# illegal Unicode properties\n";
fc8cd66c 2796 $test = 896;
bc45ce41
JH
2797
2798 print eval { "a" =~ /\pq / } ? "not ok $test\n" : "ok $test\n";
2799 $test++;
2800
2801 print eval { "a" =~ /\p{qrst} / } ? "not ok $test\n" : "ok $test\n";
2802 $test++;
2803}
d65afb4b
HS
2804
2805{
491fd90a 2806 print "# [ID 20020412.005] wrong pmop flags checked when empty pattern\n";
d65afb4b 2807 # requires reuse of last successful pattern
fc8cd66c 2808 $test = 898;
d65afb4b
HS
2809 $test =~ /\d/;
2810 for (0 .. 1) {
2811 my $match = ?? + 0;
2812 if ($match != $_) {
2813 print "ok $test\n";
2814 } else {
2815 printf "not ok %s\t# 'match once' %s on %s iteration\n", $test,
2816 $match ? 'succeeded' : 'failed', $_ ? 'second' : 'first';
2817 }
2818 ++$test;
2819 }
2820 $test =~ /(\d)/;
2821 my $result = join '', $test =~ //g;
2822 if ($result eq $test) {
2823 print "ok $test\n";
2824 } else {
2825 printf "not ok %s\t# expected '%s', got '%s'\n", $test, $test, $result;
2826 }
2827 ++$test;
2828}
491fd90a
JH
2829
2830print "# user-defined character properties\n";
2831
2832sub InKana1 {
2833 return <<'END';
28343040 309F
283530A0 30FF
2836END
2837}
2838
2839sub InKana2 {
2840 return <<'END';
2841+utf8::InHiragana
2842+utf8::InKatakana
2843END
2844}
2845
2846sub InKana3 {
2847 return <<'END';
2848+utf8::InHiragana
2849+utf8::InKatakana
2850-utf8::IsCn
2851END
2852}
2853
2854sub InNotKana {
2855 return <<'END';
2856!utf8::InHiragana
2857-utf8::InKatakana
2858+utf8::IsCn
2859END
2860}
2861
2862$test = 901;
2863
2864print "\x{3040}" =~ /\p{InKana1}/ ? "ok $test\n" : "not ok $test\n"; $test++;
2865print "\x{303F}" =~ /\P{InKana1}/ ? "ok $test\n" : "not ok $test\n"; $test++;
2866
2867print "\x{3040}" =~ /\p{InKana2}/ ? "ok $test\n" : "not ok $test\n"; $test++;
2868print "\x{303F}" =~ /\P{InKana2}/ ? "ok $test\n" : "not ok $test\n"; $test++;
2869
2870print "\x{3041}" =~ /\p{InKana3}/ ? "ok $test\n" : "not ok $test\n"; $test++;
2871print "\x{3040}" =~ /\P{InKana3}/ ? "ok $test\n" : "not ok $test\n"; $test++;
2872
2873print "\x{3040}" =~ /\p{InNotKana}/ ? "ok $test\n" : "not ok $test\n"; $test++;
2874print "\x{3041}" =~ /\P{InNotKana}/ ? "ok $test\n" : "not ok $test\n"; $test++;
2875
11ef8fdd
JH
2876sub InConsonant { # Not EBCDIC-aware.
2877 return <<EOF;
28780061 007f
2879-0061
2880-0065
2881-0069
2882-006f
2883-0075
2884EOF
2885}
2886
2887print "d" =~ /\p{InConsonant}/ ? "ok $test\n" : "not ok $test\n"; $test++;
2888print "e" =~ /\P{InConsonant}/ ? "ok $test\n" : "not ok $test\n"; $test++;
2889
faf11cac
HS
2890{
2891 print "# [ID 20020630.002] utf8 regex only matches 32k\n";
2892 $test = 911;
2893 for ([ 'byte', "\x{ff}" ], [ 'utf8', "\x{1ff}" ]) {
2894 my($type, $char) = @$_;
2895 for my $len (32000, 32768, 33000) {
2896 my $s = $char . "f" x $len;
2897 my $r = $s =~ /$char([f]*)/gc;
2898 print $r ? "ok $test\n" : "not ok $test\t# <$type x $len> fail\n";
2899 ++$test;
2900 print +(!$r or pos($s) == $len + 1) ? "ok $test\n"
2901 : "not ok $test\t# <$type x $len> pos @{[ pos($s) ]}\n";
2902 ++$test;
2903 }
2904 }
2905}
2906
2907$test = 923;
f3b1e556
YST
2908
2909$a = bless qr/foo/, 'Foo';
2910print(('goodfood' =~ $a ? '' : 'not '),
2911 "ok $test\t# reblessed qr// matches\n");
2912++$test;
2913
2914print(($a eq '(?-xism:foo)' ? '' : 'not '),
2915 "ok $test\t# reblessed qr// stringizes\n");
2916++$test;
446eaa42
YST
2917
2918$x = "\x{3fe}";
cb50f42d
YST
2919$z=$y = "\317\276"; # $y is byte representation of $x
2920
446eaa42
YST
2921$a = qr/$x/;
2922print(($x =~ $a ? '' : 'not '), "ok $test - utf8 interpolation in qr//\n");
2923++$test;
2924
2925print(("a$a" =~ $x ? '' : 'not '),
cb50f42d
YST
2926 "ok $test - stringifed qr// preserves utf8\n");
2927++$test;
2928
2929print(("a$x" =~ /^a$a\z/ ? '' : 'not '),
2930 "ok $test - interpolated qr// preserves utf8\n");
2931++$test;
2932
2933print(("a$x" =~ /^a(??{$a})\z/ ? '' : 'not '),
2934 "ok $test - postponed interpolation of qr// preserves utf8\n");
2935++$test;
2936
ab01544f
RGS
2937print((length(qr/##/x) == 12 ? '' : 'not '),
2938 "ok $test - ## in qr// doesn't corrupt memory [perl #17776]\n");
2939++$test;
2940
cb50f42d
YST
2941{ use re 'eval';
2942
2943print(("$x$x" =~ /^$x(??{$x})\z/ ? '' : 'not '),
2944 "ok $test - postponed utf8 string in utf8 re matches utf8\n");
2945++$test;
2946
2947print(("$y$x" =~ /^$y(??{$x})\z/ ? '' : 'not '),
2948 "ok $test - postponed utf8 string in non-utf8 re matches utf8\n");
446eaa42
YST
2949++$test;
2950
cb50f42d
YST
2951print(("$y$x" !~ /^$y(??{$y})\z/ ? '' : 'not '),
2952 "ok $test - postponed non-utf8 string in non-utf8 re doesn't match utf8\n");
446eaa42
YST
2953++$test;
2954
cb50f42d
YST
2955print(("$x$x" !~ /^$x(??{$y})\z/ ? '' : 'not '),
2956 "ok $test - postponed non-utf8 string in utf8 re doesn't match utf8\n");
446eaa42
YST
2957++$test;
2958
cb50f42d
YST
2959print(("$y$y" =~ /^$y(??{$y})\z/ ? '' : 'not '),
2960 "ok $test - postponed non-utf8 string in non-utf8 re matches non-utf8\n");
2961++$test;
2962
2963print(("$x$y" =~ /^$x(??{$y})\z/ ? '' : 'not '),
2964 "ok $test - postponed non-utf8 string in utf8 re matches non-utf8\n");
2965++$test;
2966$y = $z; # reset $y after upgrade
2967
2968print(("$x$y" !~ /^$x(??{$x})\z/ ? '' : 'not '),
2969 "ok $test - postponed utf8 string in utf8 re doesn't match non-utf8\n");
2970++$test;
2971$y = $z; # reset $y after upgrade
2972
2973print(("$y$y" !~ /^$y(??{$x})\z/ ? '' : 'not '),
2974 "ok $test - postponed utf8 string in non-utf8 re doesn't match non-utf8\n");
2975++$test;
2976
2977} # no re 'eval'
2978
2d92f8a0
JH
2979print "# more user-defined character properties\n";
2980
2981sub IsSyriac1 {
2982 return <<'END';
29830712 072C
29840730 074A
2985END
2986}
2987
711a919c
ST
2988ok("\x{0712}" =~ /\p{IsSyriac1}/, '\x{0712}, \p{IsSyriac1}');
2989ok("\x{072F}" =~ /\P{IsSyriac1}/, '\x{072F}, \P{IsSyriac1}');
2d92f8a0
JH
2990
2991sub Syriac1 {
2992 return <<'END';
29930712 072C
29940730 074A
2995END
2996}
2997
711a919c
ST
2998ok("\x{0712}" =~ /\p{Syriac1}/, '\x{0712}, \p{Syriac1}');
2999ok("\x{072F}" =~ /\P{Syriac1}/, '\x{072F}, \p{Syriac1}');
2d92f8a0 3000
4a818d86
ST
3001print "# user-defined character properties may lack \\n at the end\n";
3002sub InGreekSmall { return "03B1\t03C9" }
3003sub InGreekCapital { return "0391\t03A9\n-03A2" }
3004
3005ok("\x{03C0}" =~ /\p{InGreekSmall}/, "Small pi");
3006ok("\x{03C2}" =~ /\p{InGreekSmall}/, "Final sigma");
3007ok("\x{03A0}" =~ /\p{InGreekCapital}/, "Capital PI");
3008ok("\x{03A2}" =~ /\P{InGreekCapital}/, "Reserved");
3009
711a919c
ST
3010sub AsciiHexAndDash {
3011 return <<'END';
3012+utf8::ASCII_Hex_Digit
3013+utf8::Dash
3014END
3015}
3016
3017ok("-" =~ /\p{Dash}/, "'-' is Dash");
3018ok("A" =~ /\p{ASCII_Hex_Digit}/, "'A' is ASCII_Hex_Digit");
3019ok("-" =~ /\p{AsciiHexAndDash}/, "'-' is AsciiHexAndDash");
3020ok("A" =~ /\p{AsciiHexAndDash}/, "'A' is AsciiHexAndDash");
3021
0e933229 3022{
3a2263fe
RGS
3023 print "# Change #18179\n";
3024 # previously failed with "panic: end_shift
0e933229
IH
3025 my $s = "\x{100}" x 5;
3026 my $ok = $s =~ /(\x{100}{4})/;
3027 my($ord, $len) = (ord $1, length $1);
3028 print +($ok && $ord == 0x100 && $len == 4)
fc8cd66c 3029 ? "ok $test\n" : "not ok $test\t# [#18179] $ok/$ord/$len\n";
0e933229
IH
3030 ++$test;
3031}
3032
f14c76ed
RGS
3033{
3034 print "# [perl #15763]\n";
3035
3036 $a = "x\x{100}";
3037 chop $a; # but leaves the UTF-8 flag
3038 $a .= "y"; # 1 byte before "y"
3039
3040 ok($a =~ /^\C/, 'match one \C on 1-byte UTF-8');
3041 ok($a =~ /^\C{1}/, 'match \C{1}');
3042
3043 ok($a =~ /^\Cy/, 'match \Cy');
3044 ok($a =~ /^\C{1}y/, 'match \C{1}y');
3045
3046 $a = "\x{100}y"; # 2 bytes before "y"
3047
3048 ok($a =~ /^\C/, 'match one \C on 2-byte UTF-8');
3049 ok($a =~ /^\C{1}/, 'match \C{1}');
3050 ok($a =~ /^\C\C/, 'match two \C');
3051 ok($a =~ /^\C{2}/, 'match \C{2}');
3052
3053 ok($a =~ /^\C\C\C/, 'match three \C on 2-byte UTF-8 and a byte');
3054 ok($a =~ /^\C{3}/, 'match \C{3}');
3055
3056 ok($a =~ /^\C\Cy/, 'match two \C');
3057 ok($a =~ /^\C{2}y/, 'match \C{2}');
3058
836995da
RGS
3059 ok($a !~ /^\C\C\Cy/, q{don't match three \Cy});
3060 ok($a !~ /^\C{2}\Cy/, q{don't match \C{3}y});
f14c76ed
RGS
3061
3062 $a = "\x{1000}y"; # 3 bytes before "y"
3063
3064 ok($a =~ /^\C/, 'match one \C on three-byte UTF-8');
3065 ok($a =~ /^\C{1}/, 'match \C{1}');
3066 ok($a =~ /^\C\C/, 'match two \C');
3067 ok($a =~ /^\C{2}/, 'match \C{2}');
3068 ok($a =~ /^\C\C\C/, 'match three \C');
3069 ok($a =~ /^\C{3}/, 'match \C{3}');
3070
3071 ok($a =~ /^\C\C\C\C/, 'match four \C on three-byte UTF-8 and a byte');
3072 ok($a =~ /^\C{4}/, 'match \C{4}');
3073
3074 ok($a =~ /^\C\C\Cy/, 'match three \Cy');
3075 ok($a =~ /^\C{3}y/, 'match \C{3}y');
3076
836995da
RGS
3077 ok($a !~ /^\C\C\C\C\y/, q{don't match four \Cy});
3078 ok($a !~ /^\C{4}y/, q{don't match \C{4}y});
f14c76ed
RGS
3079}
3080
5dec093f
AE
3081$_ = 'aaaaaaaaaa';
3082utf8::upgrade($_); chop $_; $\="\n";
3083ok(/[^\s]+/, "m/[^\s]/ utf8");
3084ok(/[^\d]+/, "m/[^\d]/ utf8");
3085ok(($a = $_, $_ =~ s/[^\s]+/./g), "s/[^\s]/ utf8");
3086ok(($a = $_, $a =~ s/[^\d]+/./g), "s/[^\s]/ utf8");
f14c76ed 3087
ce97f9d6
JH
3088ok("\x{100}" =~ /\x{100}/, "[perl #15397]");
3089ok("\x{100}" =~ /(\x{100})/, "[perl #15397]");
3090ok("\x{100}" =~ /(\x{100}){1}/, "[perl #15397]");
3091ok("\x{100}\x{100}" =~ /(\x{100}){2}/, "[perl #15397]");
3092ok("\x{100}\x{100}" =~ /(\x{100})(\x{100})/, "[perl #15397]");
3093
fbeb8e69
JH
3094$x = "CD";
3095$x =~ /(AB)*?CD/;
3096ok(!defined $1, "[perl #7471]");
ce97f9d6 3097
fbeb8e69
JH
3098$x = "CD";
3099$x =~ /(AB)*CD/;
3100ok(!defined $1, "[perl #7471]");
3101
ec391688
JH
3102$pattern = "^(b+?|a){1,2}c";
3103ok("bac" =~ /$pattern/ && $1 eq 'a', "[perl #3547]");
3104ok("bbac" =~ /$pattern/ && $1 eq 'a', "[perl #3547]");
3105ok("bbbac" =~ /$pattern/ && $1 eq 'a', "[perl #3547]");
3106ok("bbbbac" =~ /$pattern/ && $1 eq 'a', "[perl #3547]");
3107
a30b2f1f
RGS
3108{
3109 # [perl #18232]
3110 "\x{100}" =~ /(.)/;
3111 ok( $1 eq "\x{100}", '$1 is utf-8 [perl #18232]' );
3112 { 'a' =~ /./; }
3113 ok( $1 eq "\x{100}", '$1 is still utf-8' );
3114 ok( $1 ne "\xC4\x80", '$1 is not non-utf-8' );
3115}
3116
f119b0fb
JH
3117{
3118 use utf8;
3119 my $attr = 'Name-1' ;
3120
3121 my $NormalChar = qr/[\p{IsDigit}\p{IsLower}\p{IsUpper}]/;
3122 my $NormalWord = qr/${NormalChar}+?/;
3123 my $PredNameHyphen = qr/^${NormalWord}(\-${NormalWord})*?$/;
3124
3125 $attr =~ /^$/;
3126 ok( $attr =~ $PredNameHyphen, "[perl #19767] original test" );
3127}
3128
3129{
3130 use utf8;
3131 "a" =~ m/[b]/;
3132 ok ( "0" =~ /\p{N}+\z/, "[perl #19767] variant test" );
3133}
3134
faf82a0b
AE
3135{
3136
3137 $p = 1;
3138 foreach (1,2,3,4) {
3139 $p++ if /(??{ $p })/
3140 }
3141 ok ($p == 5, "[perl #20683] (??{ }) returns stale values");
3142 { package P; $a=1; sub TIESCALAR { bless[] } sub FETCH { $a++ } }
3143 tie $p, P;
3144 foreach (1,2,3,4) {
3145 /(??{ $p })/
3146 }
3147 ok ( $p == 5, "(??{ }) returns stale values");
3148}
3149
351208f1
JH
3150{
3151 # Subject: Odd regexp behavior
3152 # From: Markus Kuhn <Markus.Kuhn@cl.cam.ac.uk>
3153 # Date: Wed, 26 Feb 2003 16:53:12 +0000
3154 # Message-Id: <E18o4nw-0008Ly-00@wisbech.cl.cam.ac.uk>
3155 # To: perl-unicode@perl.org
3156
3157 $x = "\x{2019}\nk"; $x =~ s/(\S)\n(\S)/$1 $2/sg;
3158 ok($x eq "\x{2019} k", "Markus Kuhn 2003-02-26");
3159
3160 $x = "b\nk"; $x =~ s/(\S)\n(\S)/$1 $2/sg;
3161 ok($x eq "b k", "Markus Kuhn 2003-02-26");
3162
3163 ok("\x{2019}" =~ /\S/, "Markus Kuhn 2003-02-26");
3164}
3165
91e09a61
AE
3166{
3167 my $i;
3168 ok('-1-3-5-' eq join('', split /((??{$i++}))/, '-1-3-5-'),
080c2dec
AE
3169 "[perl #21411] (??{ .. }) corrupts split's stack");
3170 split /(?{'WOW'})/, 'abc';
3171 ok('a|b|c' eq join ('|', @_),
3172 "[perl #21411] (?{ .. }) version of the above");
3173}
3174
3175{
36daacbf
DM
3176 # XXX DAPM 13-Apr-06. Recursive split is still broken. It's only luck it
3177 # hasn't been crashing. Disable this test until it is fixed properly.
3178 # XXX also check what it returns rather than just doing ok(1,...)
3179 # split /(?{ split "" })/, "abc";
080c2dec 3180 ok(1,'cache_re & "(?{": it dumps core in 5.6.1 & 5.8.0');
91e09a61
AE
3181}
3182
c517dc2b
JH
3183{
3184 ok("\x{100}\n" =~ /\x{100}\n$/, "UTF8 length cache and fbm_compile");
3185}
ec391688 3186
16e1b944
JH
3187{
3188 package Str;
3189 use overload q/""/ => sub { ${$_[0]}; };
3190 sub new { my ($c, $v) = @_; bless \$v, $c; }
3191
3192 package main;
3193 $_ = Str->new("a\x{100}/\x{100}b");
3194 ok(join(":", /\b(.)\x{100}/g) eq "a:/", "re_intuit_start and PL_bostr");
3195}
3196
7ef91622
IH
3197{
3198 $_ = "code: 'x' { '...' }\n"; study;
3199 my @x; push @x, $& while m/'[^\']*'/gx;
3200 ok(join(":", @x) eq "'x':'...'",
3201 "[perl #17757] Parse::RecDescent triggers infinite loop");
3202}
3203
14ebb1a2
JH
3204{
3205 my $re = qq/^([^X]*)X/;
3206 utf8::upgrade($re);
3207 ok("\x{100}X" =~ /$re/, "S_cl_and ANYOF_UNICODE & ANYOF_INVERTED");
3208}
3209
f02c194e
RGS
3210# bug #22354
3211sub func ($) {
3212 ok( "a\nb" !~ /^b/, $_[0] );
3213 ok( "a\nb" =~ /^b/m, "$_[0] - with /m" );
3214}
3215func "standalone";
3216$_ = "x"; s/x/func "in subst"/e;
3217$_ = "x"; s/x/func "in multiline subst"/em;
3218#$_ = "x"; /x(?{func "in regexp"})/;
3219#$_ = "x"; /x(?{func "in multiline regexp"})/m;
3220
c74340f9 3221# bug RT#19049
5aca4364
AG
3222$_="abcdef\n";
3223@x = m/./g;
c74340f9 3224ok("abcde" eq "$`", 'RT#19049 - global match not setting $`');
5aca4364 3225
6b43b216
DM
3226ok("123\x{100}" =~ /^.*1.*23\x{100}$/, 'uft8 + multiple floating substr');
3227
89d0f8e1 3228# LATIN SMALL/CAPITAL LETTER A WITH MACRON
c1e0e3d2
NIS
3229ok(" \x{101}" =~ qr/\x{100}/i,
3230 "<20030808193656.5109.1@llama.ni-s.u-net.com>");
3231
89d0f8e1 3232# LATIN SMALL/CAPITAL LETTER A WITH RING BELOW
5dab1207
NIS
3233ok(" \x{1E01}" =~ qr/\x{1E00}/i,
3234 "<20030808193656.5109.1@llama.ni-s.u-net.com>");
3235
89d0f8e1
JH
3236# DESERET SMALL/CAPITAL LETTER LONG I
3237ok(" \x{10428}" =~ qr/\x{10400}/i,
3238 "<20030808193656.5109.1@llama.ni-s.u-net.com>");
3239
3240# LATIN SMALL/CAPITAL LETTER A WITH RING BELOW + 'X'
3241ok(" \x{1E01}x" =~ qr/\x{1E00}X/i,
3242 "<20030808193656.5109.1@llama.ni-s.u-net.com>");
3243
a7913593
JH
3244{
3245 # [perl #23769] Unicode regex broken on simple example
3246 # regrepeat() didn't handle UTF-8 EXACT case right.
3247
3248 my $s = "\x{a0}\x{a0}\x{a0}\x{100}"; chop $s;
3249
3250 ok($s =~ /\x{a0}/, "[perl #23769]");
3251 ok($s =~ /\x{a0}+/, "[perl #23769]");
3252 ok($s =~ /\x{a0}\x{a0}/, "[perl #23769]");
090f7165
JH
3253
3254 ok("aaa\x{100}" =~ /(a+)/, "[perl #23769] easy invariant");
3255 ok($1 eq "aaa", "[perl #23769]");
3256
3257 ok("\xa0\xa0\xa0\x{100}" =~ /(\xa0+)/, "[perl #23769] regrepeat invariant");
3258 ok($1 eq "\xa0\xa0\xa0", "[perl #23769]");
3259
3260 ok("ababab\x{100} " =~ /((?:ab)+)/, "[perl #23769] hard invariant");
3261 ok($1 eq "ababab", "[perl #23769]");
3262
3263 ok("\xa0\xa1\xa0\xa1\xa0\xa1\x{100}" =~ /((?:\xa0\xa1)+)/, "[perl #23769] hard variant");
3264 ok($1 eq "\xa0\xa1\xa0\xa1\xa0\xa1", "[perl #23769]");
3265
3266 ok("aaa\x{100} " =~ /(a+?)/, "[perl #23769] easy invariant");
3267 ok($1 eq "a", "[perl #23769]");
3268
3269 ok("\xa0\xa0\xa0\x{100} " =~ /(\xa0+?)/, "[perl #23769] regrepeat variant");
3270 ok($1 eq "\xa0", "[perl #23769]");
3271
3272 ok("ababab\x{100} " =~ /((?:ab)+?)/, "[perl #23769] hard invariant");
3273 ok($1 eq "ab", "[perl #23769]");
3274
3275 ok("\xa0\xa1\xa0\xa1\xa0\xa1\x{100}" =~ /((?:\xa0\xa1)+?)/, "[perl #23769] hard variant");
3276 ok($1 eq "\xa0\xa1", "[perl #23769]");
3277
3278 ok("\xc4\xc4\xc4" !~ /(\x{100}+)/, "[perl #23769] don't match first byte of utf8 representation");
3279 ok("\xc4\xc4\xc4" !~ /(\x{100}+?)/, "[perl #23769] don't match first byte of utf8 representation");
a7913593
JH
3280}
3281
4be7a33f
HS
3282for (120 .. 130) {
3283 my $head = 'x' x $_;
3284 for my $tail ('\x{0061}', '\x{1234}') {
3285 ok(
3286 eval qq{ "$head$tail" =~ /$head$tail/ },
3287 '\x{...} misparsed in regexp near 127 char EXACT limit'
3288 );
3289 }
3290}
3291
289555fe
HS
3292# perl #25269: panic: pp_match start/end pointers
3293ok("a-bc" eq eval {
3294 my($x, $y) = "bca" =~ /^(?=.*(a)).*(bc)/;
3295 "$x-$y";
3296}, 'captures can move backwards in string');
3297
b6d5fef8
RGS
3298# perl #27940: \cA not recognized in character classes
3299ok("a\cAb" =~ /\cA/, '\cA in pattern');
3300ok("a\cAb" =~ /[\cA]/, '\cA in character class');
3301ok("a\cAb" =~ /[\cA-\cB]/, '\cA in character class range');
3302ok("abc" =~ /[^\cA-\cB]/, '\cA in negated character class range');
3303ok("a\cBb" =~ /[\cA-\cC]/, '\cB in character class range');
3304ok("a\cCbc" =~ /[^\cA-\cB]/, '\cC in negated character class range');
3305ok("a\cAb" =~ /(??{"\cA"})/, '\cA in ??{} pattern');
25f684f7 3306ok("ab" !~ /a\cIb/x, '\cI in pattern');
5dab1207 3307
0e788c72
HS
3308# perl #28532: optional zero-width match at end of string is ignored
3309ok(("abc" =~ /^abc(\z)?/) && defined($1),
3310 'optional zero-width match at end of string');
3311ok(("abc" =~ /^abc(\z)??/) && !defined($1),
3312 'optional zero-width match at end of string');
3313
a3621e74
YO
3314
3315
3316{ # TRIE related
3317 my @got=();
3318 "words"=~/(word|word|word)(?{push @got,$1})s$/;
3319 ok(@got==1,"TRIE optimation is working") or warn "# @got";
3320 @got=();
3321 "words"=~/(word|word|word)(?{push @got,$1})s$/i;
3322 ok(@got==1,"TRIEF optimisation is working") or warn "# @got";
3323
3324 my @nums=map {int rand 1000} 1..100;
3325 my $re="(".(join "|",@nums).")";
3326 $re=qr/\b$re\b/;
3327
3328 foreach (@nums) {
3329 ok($_=~/$re/,"Trie nums");
3330 }
3331 $_=join " ", @nums;
3332 @got=();
3333 push @got,$1 while /$re/g;
3334
3335 my %count;
3336 $count{$_}++ for @got;
3337 my $ok=1;
3338 for (@nums) {
3339 $ok=0 if --$count{$_}<0;
3340 }
3341 ok($ok,"Trie min count matches");
3342}
3343
3344
3345# TRIE related
3346# LATIN SMALL/CAPITAL LETTER A WITH MACRON
3347ok(("foba \x{101}foo" =~ qr/(foo|\x{100}foo|bar)/i) && $1 eq "\x{101}foo",
3348 "TRIEF + LATIN SMALL/CAPITAL LETTER A WITH MACRON");
3349
3350# LATIN SMALL/CAPITAL LETTER A WITH RING BELOW
3351ok(("foba \x{1E01}foo" =~ qr/(foo|\x{1E00}foo|bar)/i) && $1 eq "\x{1E01}foo",
3352 "TRIEF + LATIN SMALL/CAPITAL LETTER A WITH RING BELOW");
3353
3354# DESERET SMALL/CAPITAL LETTER LONG I
3355ok(("foba \x{10428}foo" =~ qr/(foo|\x{10400}foo|bar)/i) && $1 eq "\x{10428}foo",
3356 "TRIEF + DESERET SMALL/CAPITAL LETTER LONG I");
3357
3358# LATIN SMALL/CAPITAL LETTER A WITH RING BELOW + 'X'
3359ok(("foba \x{1E01}xfoo" =~ qr/(foo|\x{1E00}Xfoo|bar)/i) && $1 eq "\x{1E01}xfoo",
3360 "TRIEF + LATIN SMALL/CAPITAL LETTER A WITH RING BELOW + 'X'");
3361
3362{# TRIE related
3363
3364use charnames ':full';
3365
3366$s="\N{LATIN SMALL LETTER SHARP S}";
3367ok(("foba ba$s" =~ qr/(foo|Ba$s|bar)/i)
3368 && $1 eq "ba$s",
3369 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss");
3370ok(("foba ba$s" =~ qr/(Ba$s|foo|bar)/i)
3371 && $1 eq "ba$s",
3372 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss");
3373ok(("foba ba$s" =~ qr/(foo|bar|Ba$s)/i)
3374 && $1 eq "ba$s",
3375 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss");
3376
3377ok(("foba ba$s" =~ qr/(foo|Bass|bar)/i)
3378 && $1 eq "ba$s",
3379 "TRIEF + LATIN SMALL LETTER SHARP S =~ ss");
3380
3381ok(("foba ba$s" =~ qr/(foo|BaSS|bar)/i)
3382 && $1 eq "ba$s",
3383 "TRIEF + LATIN SMALL LETTER SHARP S =~ SS");
786e8c11
YO
3384
3385ok(("foba ba${s}pxySS$s$s" =~ qr/(b(?:a${s}t|a${s}f|a${s}p)[xy]+$s*)/i)
3386 && $1 eq "ba${s}pxySS$s$s",
3387 "COMMON PREFIX TRIEF + LATIN SMALL LETTER SHARP S");
3388
3389
a3621e74
YO
3390}
3391
3392
3393
fc8cd66c 3394if (!$ENV{PERL_SKIP_PSYCHO_TEST}){
a3621e74
YO
3395 my @normal=qw(these are some normal words);
3396 my $psycho=join "|",@normal,map chr $_,255..20000;
3397 ok(('these'=~/($psycho)/) && $1 eq 'these','Pyscho');
fc8cd66c
YO
3398} else {
3399 ok(1,'Skipped Psycho');
a3621e74 3400}
809e8e66
DM
3401
3402# [perl #36207] mixed utf8 / latin-1 and case folding
3403
3404{
108bb1ad
YO
3405 my $utf8 = "\xe9\x{100}"; chop $utf8;
3406 my $latin1 = "\xe9";
3407
3408 ok($utf8 =~ /\xe9/i, "utf8/latin");
3409 ok($utf8 =~ /$latin1/i, "utf8/latin runtime");
3410 ok($utf8 =~ /(abc|\xe9)/i, "utf8/latin trie");
3411 ok($utf8 =~ /(abc|$latin1)/i, "utf8/latin trie runtime");
3412
3413 ok("\xe9" =~ /$utf8/i, "# TODO latin/utf8");
3414 ok("\xe9" =~ /(abc|$utf8)/i, "# latin/utf8 trie");
3415 ok($latin1 =~ /$utf8/i, "# TODO latin/utf8 runtime");
3416 ok($latin1 =~ /(abc|$utf8)/i, "# latin/utf8 trie runtime");
809e8e66
DM
3417}
3418
740266bf
NC
3419# [perl #37038] Global regular matches generate invalid pointers
3420
3421{
3422 my $s = "abcd";
3423 $s =~ /(..)(..)/g;
3424 $s = $1;
3425 $s = $2;
3426 ok($s eq 'cd',
4f5010f2 3427 "# assigning to original string should not corrupt match vars");
740266bf
NC
3428}
3429
0523e772
NC
3430{
3431 package wooosh;
3432 sub gloople {
3433 "!";
3434 }
3435 package main;
3436
3437 my $aeek = bless {}, 'wooosh';
3438 eval {$aeek->gloople() =~ /(.)/g;};
547ba77e 3439 ok($@ eq "", "//g match against return value of sub") or print "# $@\n";
0523e772 3440}
740266bf 3441
86f12da2
NC
3442{
3443 sub gloople {
3444 "!";
3445 }
3446 eval {gloople() =~ /(.)/g;};
3447 ok($@ eq "", "# 26410 didn't affect sub calls for some reason")
3448 or print "# $@\n";
3449}
3450
3451{
86f12da2
NC
3452 package lv;
3453 $var = "abc";
3454 sub variable : lvalue { $var }
3455
3456 package main;
3457 my $o = bless [], "lv";
3458 my $f = "";
3459 eval { for (1..2) { $f .= $1 if $o->variable =~ /(.)/g } };
547ba77e 3460 ok($f eq "ab", "pos retained between calls # TODO") or print "# $@\n";
86f12da2
NC
3461}
3462
3463{
86f12da2
NC
3464 $var = "abc";
3465 sub variable : lvalue { $var }
3466
3467 my $f = "";
3468 eval { for (1..2) { $f .= $1 if variable() =~ /(.)/g } };
547ba77e 3469 ok($f eq "ab", "pos retained between calls # TODO") or print "# $@\n";
86f12da2
NC
3470}
3471
9f7f3913
ST
3472# [perl #37836] Simple Regex causes SEGV when run on specific data
3473if ($ordA == 193) {
3474 print "ok $test # Skip: in EBCDIC\n"; $test++;
3475} else {
3476 no warnings 'utf8';
3477 $_ = pack('U0C2', 0xa2, 0xf8); # ill-formed UTF-8
3478 my $ret = 0;
3479 eval { $ret = s/[\0]+//g };
3480 ok($ret == 0, "ill-formed UTF-8 doesn't match NUL in class");
3481}
3482
3483{ # [perl #38293] chr(65535) should be allowed in regexes
3484 no warnings 'utf8'; # to allow non-characters
3485 my($c, $r, $s);
3486
3487 $c = chr 0xffff;
3488 $c =~ s/$c//g;
3489 ok($c eq "", "U+FFFF, parsed as atom");
3490
3491 $c = chr 0xffff;
3492 $r = "\\$c";
3493 $c =~ s/$r//g;
3494 ok($c eq "", "U+FFFF backslashed, parsed as atom");
3495
3496 $c = chr 0xffff;
3497 $c =~ s/[$c]//g;
3498 ok($c eq "", "U+FFFF, parsed in class");
3499
3500 $c = chr 0xffff;
3501 $r = "[\\$c]";
3502 $c =~ s/$r//g;
3503 ok($c eq "", "U+FFFF backslashed, parsed in class");
3504
3505 $s = "A\x{ffff}B";
3506 $s =~ s/\x{ffff}//i;
3507 ok($s eq "AB", "U+FFFF, EXACTF");
3508
3509 $s = "\x{ffff}A";
3510 $s =~ s/\bA//;
3511 ok($s eq "\x{ffff}", "U+FFFF, BOUND");
3512
3513 $s = "\x{ffff}!";
3514 $s =~ s/\B!//;
3515 ok($s eq "\x{ffff}", "U+FFFF, NBOUND");
3516} # non-characters end
3517
a30987ac
YO
3518{
3519 # https://rt.perl.org/rt3/Ticket/Display.html?id=39583
3520
3521 # The printing characters
3522 my @chars = ("A".."Z");
3523 my $delim = ",";
3524 my $size = 32771 - 4;
fc8cd66c 3525 my $str = '';
a30987ac
YO
3526
3527 # create some random junk. Inefficient, but it works.
3528 for ($i = 0 ; $i < $size ; $i++) {
fc8cd66c 3529 $str .= $chars[int(rand(@chars))];
a30987ac
YO
3530 }
3531
fc8cd66c 3532 $str .= ($delim x 4);
a30987ac
YO
3533 my $res;
3534 my $matched;
fc8cd66c 3535 if ($str =~ s/^(.*?)${delim}{4}//s) {
a30987ac
YO
3536 $res = $1;
3537 $matched=1;
3538 }
3539 ok($matched,'pattern matches');
fc8cd66c 3540 ok(length($str)==0,"Empty string");
a30987ac
YO
3541 ok(defined($res) && length($res)==$size,"\$1 is correct size");
3542}
9f7f3913 3543
1749ea0d
ST
3544{ # related to [perl #27940]
3545 ok("\0-A" =~ /\c@-A/, '@- should not be interpolated in a pattern');
3546 ok("\0\0A" =~ /\c@+A/, '@+ should not be interpolated in a pattern');
3547 ok("X\@-A" =~ /X@-A/, '@- should not be interpolated in a pattern');
3548 ok("X\@\@A" =~ /X@+A/, '@+ should not be interpolated in a pattern');
3549
3550 ok("X\0A" =~ /X\c@?A/, '\c@?');
3551 ok("X\0A" =~ /X\c@*A/, '\c@*');
3552 ok("X\0A" =~ /X\c@(A)/, '\c@(');
3553 ok("X\0A" =~ /X(\c@)A/, '\c@)');
3554 ok("X\0A" =~ /X\c@|ZA/, '\c@|');
3555
3556 ok("X\@A" =~ /X@?A/, '@?');
3557 ok("X\@A" =~ /X@*A/, '@*');
3558 ok("X\@A" =~ /X@(A)/, '@(');
3559 ok("X\@A" =~ /X(@)A/, '@)');
3560 ok("X\@A" =~ /X@|ZA/, '@|');
3561
3562 local $" = ','; # non-whitespace and non-RE-specific
3563 ok('abc' =~ /(.)(.)(.)/, 'the last successful match is bogus');
3564 ok("A@+B" =~ /A@{+}B/, 'interpolation of @+ in /@{+}/');
3565 ok("A@-B" =~ /A@{-}B/, 'interpolation of @- in /@{-}/');
3566 ok("A@+B" =~ /A@{+}B/x, 'interpolation of @+ in /@{+}/x');
3567 ok("A@-B" =~ /A@{-}B/x, 'interpolation of @- in /@{-}/x');
3568}
3569
fc8cd66c
YO
3570{
3571 use lib 'lib';
3572 use Cname;
3573
3574 ok('fooB'=~/\N{foo}[\N{B}\N{b}]/,"Passthrough charname");
3575 $test=1233; my $handle=make_must_warn('Ignoring excess chars from');
3576 $handle->('q(xxWxx) =~ /[\N{WARN}]/');
3577 {
3578 my $code;
3579 my $w="";
3580 local $SIG{__WARN__} = sub { $w.=shift };
3581 eval($code=<<'EOFTEST') or die "$@\n$code\n";
3582 {
3583 use warnings;
3584
3585 #1234
3586 ok("\0" !~ /[\N{EMPTY-STR}XY]/,
3587 "Zerolength charname in charclass doesnt match \0");
3588 1;
3589 }
3590EOFTEST
3591 ok($w=~/Ignoring zero length/,
3592 "Got expected zero length warning");
3593 warn $code;
3594
3595 }
3596 $handle= make_must_warn('Ignoring zero length');
3597 $handle->('qq(\\0) =~ /[\N{EMPTY-STR}XY]/');
3598 ok('AB'=~/(\N{EVIL})/ && $1 eq 'A',"Charname caching $1");
3599 ok('ABC'=~/(\N{EVIL})/,"Charname caching $1");
3600 ok('xy'=~/x\N{EMPTY-STR}y/, 'Empty string charname produces NOTHING node');
3601 ok(''=~/\N{EMPTY-STR}/, 'Empty string charname produces NOTHING node 2');
3602
3603}
3604{
3605 print "# MORE LATIN SMALL LETTER SHARP S\n";
3606
3607 use charnames ':full';
3608
3609 #see also test #835
3610 ok("ss" =~ /[\N{LATIN SMALL LETTER SHARP S}x]/i,
3611 "unoptimized named sequence in class 1");
3612 ok("SS" =~ /[\N{LATIN SMALL LETTER SHARP S}x]/i,
3613 "unoptimized named sequence in class 2");
3614 ok("\N{LATIN SMALL LETTER SHARP S}" =~ /[\N{LATIN SMALL LETTER SHARP S}x]/,
3615 "unoptimized named sequence in class 3");
3616 ok("\N{LATIN SMALL LETTER SHARP S}" =~ /[\N{LATIN SMALL LETTER SHARP S}x]/i,
3617 "unoptimized named sequence in class 4");
3618
3619 ok('aabc' !~ /a\N{PLUS SIGN}b/,'/a\N{PLUS SIGN}b/ against aabc');
3620 ok('a+bc' =~ /a\N{PLUS SIGN}b/,'/a\N{PLUS SIGN}b/ against a+bc');
3621 ok('a+bc' =~ /a\N{PLUS SIGN}b/,'/a\N{PLUS SIGN}b/ against a+bc');
3622
3623 ok(' A B'=~/\N{SPACE}\N{U+0041}\N{SPACE}\N{U+0042}/,
3624 'Intermixed named and unicode escapes 1');
3625 ok("\N{SPACE}\N{U+0041}\N{SPACE}\N{U+0042}"=~
3626 /\N{SPACE}\N{U+0041}\N{SPACE}\N{U+0042}/,
3627 'Intermixed named and unicode escapes 2');
3628 ok("\N{SPACE}\N{U+0041}\N{SPACE}\N{U+0042} 3"=~
3629 /[\N{SPACE}\N{U+0041}][\N{SPACE}\N{U+0042}]/,
3630 'Intermixed named and unicode escapes');
3631}
faec1544
DM
3632$brackets = qr{
3633 { (?> [^{}]+ | (??{ $brackets }) )* }
3634 }x;
3635ok("{b{c}d" !~ m/^((??{ $brackets }))/, "bracket mismatch");
3636
6bda09f9
YO
3637SKIP:{
3638 our @stack=();
3639 my @expect=qw(
3640 stuff1
3641 stuff2
3642 <stuff1>and<stuff2>
3643 right
3644 <right>
3645 <<right>>
3646 <<<right>>>
3647 <<stuff1>and<stuff2>><<<<right>>>>
3648 );
3649
3650 local $_='<<<stuff1>and<stuff2>><<<<right>>>>>';
3651 ok(/^(<((?:(?>[^<>]+)|(?1))*)>(?{push @stack, $2 }))$/,
3652 "Recursion should match");
3653 ok(@stack==@expect)
3654 or skip("Won't test individual results as count isn't equal",
3655 0+@expect);
3656 foreach my $idx (@expect) {
3657 ok($expect[$idx] eq $stack[$idx],
3658 "Expecting '$expect' at stack pos #$idx");
3659 }
3660
3661}
81714fb9
YO
3662{
3663 my $s='123453456';
3664 $s=~s/(?<digits>\d+)\k<digits>/$+{digits}/;
3665 ok($s eq '123456','Named capture (angle brackets) s///');
3666 $s='123453456';
3667 $s=~s/(?'digits'\d+)\k'digits'/$+{digits}/;
3668 ok($s eq '123456','Named capture (single quotes) s///');
3669}
e62cc96a
YO
3670sub iseq($$;$) {
3671 my ( $got, $expect, $name)=@_;
3672
3673 $_=defined($_) ? "'$_'" : "undef"
3674 for $got, $expect;
3675
3676 my $ok= $got eq $expect;
3677
f0852a51
YO
3678 printf "%sok %d - %s\n", ($ok ? "" : "not "), $test,
3679 $name||"$Message:".((caller)[2]);
e62cc96a
YO
3680
3681 printf "# Failed test at line %d\n".
3682 "# expected: %s\n".
3683 "# result: %s\n",
3684 (caller)[2], $expect, $got
3685 unless $ok;
3686
3687 $test++;
3688 return $ok;
3689}
81714fb9
YO
3690{
3691 my $s='foo bar baz';
e62cc96a
YO
3692 my (@k,@v,@fetch,$res);
3693 my $count= 0;
3694 my @names=qw($+{A} $+{B} $+{C});
81714fb9
YO
3695 if ($s=~/(?<A>foo)\s+(?<B>bar)?\s+(?<C>baz)/) {
3696 while (my ($k,$v)=each(%+)) {
3697 $count++;
3698 }
3699 @k=sort keys(%+);
3700 @v=sort values(%+);
e62cc96a
YO
3701 $res=1;
3702 push @fetch,
3703 [ "$+{A}", "$1" ],
3704 [ "$+{B}", "$2" ],
3705 [ "$+{C}", "$3" ],
3706 ;
3707 }
3708 foreach (0..2) {
3709 if ($fetch[$_]) {
3710 iseq($fetch[$_][0],$fetch[$_][1],$names[$_]);
3711 } else {
3712 ok(0, $names[$_]);
3713 }
81714fb9 3714 }
e62cc96a
YO
3715 iseq($res,1,"$s~=/(?<A>foo)\s+(?<B>bar)?\s+(?<C>baz)/");
3716 iseq($count,3,"Got 3 keys in %+ via each");
3717 iseq(0+@k, 3, 'Got 3 keys in %+ via keys');
3718 iseq("@k","A B C", "Got expected keys");
3719 iseq("@v","bar baz foo", "Got expected values");
0a4db386
YO
3720 eval'
3721 print for $+{this_key_doesnt_exist};
3722 ';
3723 ok(!$@,'lvalue $+{...} should not throw an exception');
81714fb9 3724}
24b23f37 3725
bfac009d
DM
3726# stress test CURLYX/WHILEM.
3727#
3728# This test includes varying levels of nesting, and according to
3729# profiling done against build 28905, exercises every code line in the
3730# CURLYX and WHILEM blocks, except those related to LONGJMP, the
3731# super-linear cache and warnings. It executes about 0.5M regexes
3732
24b23f37
YO
3733if ($ENV{PERL_SKIP_PSYCHO_TEST}){
3734 printf "ok %d Skip: No psycho tests\n", $test++;
3735} else {
bfac009d
DM
3736 my $r = qr/^
3737 (?:
3738 ( (?:a|z+)+ )
3739 (?:
3740 ( (?:b|z+){3,}? )
3741 (
3742 (?:
c476f425
DM
3743 (?:
3744 (?:c|z+){1,1}?z
3745 )?
bfac009d
DM
3746 (?:c|z+){1,1}
3747 )*
3748 )
3749 (?:z*){2,}
3750 ( (?:z+|d)+ )
3751 (?:
3752 ( (?:e|z+)+ )
3753 )*
3754 ( (?:f|z+)+ )
3755 )*
3756 ( (?:z+|g)+ )
3757 (?:
3758 ( (?:h|z+)+ )
3759 )*
3760 ( (?:i|z+)+ )
3761 )+
3762 ( (?:j|z+)+ )
3763 (?:
3764 ( (?:k|z+)+ )
3765 )*
3766 ( (?:l|z+)+ )
3767 $/x;
3768
3769
3770 my $ok = 1;
3771 my $msg = "CURLYX stress test";
3772 OUTER:
3773 for my $a ("x","a","aa") {
3774 for my $b ("x","bbb","bbbb") {
3775 my $bs = $a.$b;
3776 for my $c ("x","c","cc") {
3777 my $cs = $bs.$c;
3778 for my $d ("x","d","dd") {
3779 my $ds = $cs.$d;
3780 for my $e ("x","e","ee") {
3781 my $es = $ds.$e;
3782 for my $f ("x","f","ff") {
3783 my $fs = $es.$f;
3784 for my $g ("x","g","gg") {
3785 my $gs = $fs.$g;
3786 for my $h ("x","h","hh") {
3787 my $hs = $gs.$h;
3788 for my $i ("x","i","ii") {
3789 my $is = $hs.$i;
3790 for my $j ("x","j","jj") {
3791 my $js = $is.$j;
3792 for my $k ("x","k","kk") {
3793 my $ks = $js.$k;
3794 for my $l ("x","l","ll") {
3795 my $ls = $ks.$l;
3796 if ($ls =~ $r) {
3797 if ($ls =~ /x/) {
3798 $msg .= ": unexpected match for [$ls]";
3799 $ok = 0;
3800 last OUTER;
3801 }
3802 my $cap = "$1$2$3$4$5$6$7$8$9$10$11$12";
3803 unless ($ls eq $cap) {
3804 $msg .= ": capture: [$ls], got [$cap]";
3805 $ok = 0;
3806 last OUTER;
3807 }
3808 }
3809 else {
3810 unless ($ls =~ /x/) {
3811 $msg = ": failed for [$ls]";
3812 $ok = 0;
3813 last OUTER;
3814 }
3815 }
3816 }
3817 }
3818 }
3819 }
3820 }
3821 }
3822 }
3823 }
3824 }
3825 }
3826 }
3827 }
3828 ok($ok, $msg);
3829}
3830
cc74c5bd
ST
3831# \, breaks {3,4}
3832ok("xaaay" !~ /xa{3\,4}y/, "\, in a pattern");
3833ok("xa{3,4}y" =~ /xa{3\,4}y/, "\, in a pattern");
3834
3835# \c\ followed by _
3836ok("x\c_y" !~ /x\c\_y/, "\_ in a pattern");
3837ok("x\c\_y" =~ /x\c\_y/, "\_ in a pattern");
3838
3839# \c\ followed by other characters
3840for my $c ("z", "\0", "!", chr(254), chr(256)) {
3841 my $targ = "a\034$c";
3842 my $reg = "a\\c\\$c";
3843 ok(eval("qq/$targ/ =~ /$reg/"), "\\c\\ in pattern");
3844}
bfac009d 3845
581d1b5b
RGS
3846{
3847 my $str='abc';
3848 my $count=0;
3849 my $mval=0;
3850 my $pval=0;
3851 while ($str=~/b/g) { $mval=$#-; $pval=$#+; $count++ }
3852 iseq($mval,0,"\@- should be empty [RT#36046]");
3853 iseq($pval,0,"\@+ should be empty [RT#36046]");
3854 iseq($count,1,"should have matched once only [RT#36046]");
3855}
3856
5d458dd8 3857{ # Test the (*PRUNE) pattern
24b23f37 3858 our $count = 0;
e2e6a0f1 3859 'aaab'=~/a+b?(?{$count++})(*FAIL)/;
5d458dd8 3860 iseq($count,9,"expect 9 for no (*PRUNE)");
24b23f37 3861 $count = 0;
5d458dd8
YO
3862 'aaab'=~/a+b?(*PRUNE)(?{$count++})(*FAIL)/;
3863 iseq($count,3,"expect 3 with (*PRUNE)");
24b23f37
YO
3864 local $_='aaab';
3865 $count=0;
5d458dd8
YO
3866 1 while /.(*PRUNE)(?{$count++})(*FAIL)/g;
3867 iseq($count,4,"/.(*PRUNE)/");
24b23f37 3868 $count = 0;
5d458dd8
YO
3869 'aaab'=~/a+b?(??{'(*PRUNE)'})(?{$count++})(*FAIL)/;
3870 iseq($count,3,"expect 3 with (*PRUNE)");
24b23f37
YO
3871 local $_='aaab';
3872 $count=0;
5d458dd8
YO
3873 1 while /.(??{'(*PRUNE)'})(?{$count++})(*FAIL)/g;
3874 iseq($count,4,"/.(*PRUNE)/");
24b23f37 3875}
5d458dd8 3876{ # Test the (*SKIP) pattern
24b23f37 3877 our $count = 0;
5d458dd8
YO
3878 'aaab'=~/a+b?(*SKIP)(?{$count++})(*FAIL)/;
3879 iseq($count,1,"expect 1 with (*SKIP)");
24b23f37
YO
3880 local $_='aaab';
3881 $count=0;
5d458dd8
YO
3882 1 while /.(*SKIP)(?{$count++})(*FAIL)/g;
3883 iseq($count,4,"/.(*SKIP)/");
24b23f37
YO
3884 $_='aaabaaab';
3885 $count=0;
3886 our @res=();
5d458dd8
YO
3887 1 while /(a+b?)(*SKIP)(?{$count++; push @res,$1})(*FAIL)/g;
3888 iseq($count,2,"Expect 2 with (*SKIP)" );
3889 iseq("@res","aaab aaab","adjacent (*SKIP) works as expected" );
24b23f37 3890}
5d458dd8 3891{ # Test the (*SKIP) pattern
24b23f37 3892 our $count = 0;
5d458dd8
YO
3893 'aaab'=~/a+b?(*MARK:foo)(*SKIP)(?{$count++})(*FAIL)/;
3894 iseq($count,1,"expect 1 with (*SKIP)");
24b23f37
YO
3895 local $_='aaab';
3896 $count=0;
5d458dd8
YO
3897 1 while /.(*MARK:foo)(*SKIP)(?{$count++})(*FAIL)/g;
3898 iseq($count,4,"/.(*SKIP)/");
24b23f37
YO
3899 $_='aaabaaab';
3900 $count=0;
3901 our @res=();
5d458dd8
YO
3902 1 while /(a+b?)(*MARK:foo)(*SKIP)(?{$count++; push @res,$1})(*FAIL)/g;
3903 iseq($count,2,"Expect 2 with (*SKIP)" );
3904 iseq("@res","aaab aaab","adjacent (*SKIP) works as expected" );
e2e6a0f1 3905}
5d458dd8 3906{ # Test the (*SKIP) pattern
e2e6a0f1 3907 our $count = 0;
5d458dd8
YO
3908 'aaab'=~/a*(*MARK:a)b?(*MARK:b)(*SKIP:a)(?{$count++})(*FAIL)/;
3909 iseq($count,3,"expect 3 with *MARK:a)b?(*MARK:b)(*SKIP:a)");
e2e6a0f1
YO
3910 local $_='aaabaaab';
3911 $count=0;
3912 our @res=();
5d458dd8
YO
3913 1 while /(a*(*MARK:a)b?)(*MARK:x)(*SKIP:a)(?{$count++; push @res,$1})(*FAIL)/g;
3914 iseq($count,5,"Expect 5 with (*MARK:a)b?)(*MARK:x)(*SKIP:a)" );
3915 iseq("@res","aaab b aaab b ","adjacent (*MARK:a)b?)(*MARK:x)(*SKIP:a) works as expected" );
e2e6a0f1
YO
3916}
3917{ # Test the (*COMMIT) pattern
3918 our $count = 0;
3919 'aaabaaab'=~/a+b?(*COMMIT)(?{$count++})(*FAIL)/;
3920 iseq($count,1,"expect 1 with (*COMMIT)");
3921 local $_='aaab';
3922 $count=0;
3923 1 while /.(*COMMIT)(?{$count++})(*FAIL)/g;
3924 iseq($count,1,"/.(*COMMIT)/");
3925 $_='aaabaaab';
3926 $count=0;
3927 our @res=();
3928 1 while /(a+b?)(*COMMIT)(?{$count++; push @res,$1})(*FAIL)/g;
3929 iseq($count,1,"Expect 1 with (*COMMIT)" );
3930 iseq("@res","aaab","adjacent (*COMMIT) works as expected" );
3931}
3932{
3933 # Test named commits and the $REGERROR var
3934 our $REGERROR;
3935 for my $name ('',':foo')
3936 {
5d458dd8
YO
3937 for my $pat ("(*PRUNE$name)",
3938 ($name? "(*MARK$name)" : "")
3939 . "(*SKIP$name)",
3940 "(*COMMIT$name)")
e2e6a0f1
YO
3941 {
3942 for my $suffix ('(*FAIL)','')
3943 {
3944 'aaaab'=~/a+b$pat$suffix/;
3945 iseq(
3946 $REGERROR,
3947 ($suffix ? ($name ? 'foo' : "1") : ""),
3948 "Test $pat and \$REGERROR $suffix"
3949 );
3950 }
3951 }
3952 }
3953}
3954{
3955 # Test named commits and the $REGERROR var
3956 package Fnorble;
3957 our $REGERROR;
3958 for my $name ('',':foo')
3959 {
5d458dd8
YO
3960 for my $pat ("(*PRUNE$name)",
3961 ($name? "(*MARK$name)" : "")
3962 . "(*SKIP$name)",
3963 "(*COMMIT$name)")
e2e6a0f1
YO
3964 {
3965 for my $suffix ('(*FAIL)','')
3966 {
3967 'aaaab'=~/a+b$pat$suffix/;
3968 ::iseq(
3969 $REGERROR,
3970 ($suffix ? ($name ? 'foo' : "1") : ""),
3971 "Test $pat and \$REGERROR $suffix"
3972 );
3973 }
3974 }
3975 }
3976}
3977{
3978 # Test named commits and the $REGERROR var
f0852a51 3979 local $Message = "\$REGERROR";
e2e6a0f1
YO
3980 our $REGERROR;
3981 for $word (qw(bar baz bop)) {
3982 $REGERROR="";
3983 "aaaaa$word"=~/a+(?:bar(*COMMIT:bar)|baz(*COMMIT:baz)|bop(*COMMIT:bop))(*FAIL)/;
3984 iseq($REGERROR,$word);
3985 }
3986}
3987{ #Regression test for perlbug 40684
f0852a51 3988 local $Message = "RT#40684 tests:";
e2e6a0f1
YO
3989 my $s = "abc\ndef";
3990 my $rex = qr'^abc$'m;
3991 ok($s =~ m/$rex/);
3992 ok($s =~ m/^abc$/m);
24b23f37 3993}
5d458dd8
YO
3994{
3995 #Mindnumbingly simple test of (*THEN)
3996 for ("ABC","BAX") {
3997 ok(/A (*THEN) X | B (*THEN) C/x,"Simple (*THEN) test");
3998 }
542fa716
YO
3999}
4000
4001{
f0852a51 4002 local $Message = "Relative Recursion";
542fa716
YO
4003 my $parens=qr/(\((?:[^()]++|(?-1))*+\))/;
4004 local $_='foo((2*3)+4-3) + bar(2*(3+4)-1*(2-3))';
4005 my ($all,$one,$two)=('','','');
4006 if (/foo $parens \s* \+ \s* bar $parens/x) {
4007 $all=$&;
4008 $one=$1;
4009 $two=$2;
4010 }
4011 iseq($one, '((2*3)+4-3)');
4012 iseq($two, '(2*(3+4)-1*(2-3))');
4013 iseq($all, 'foo((2*3)+4-3) + bar(2*(3+4)-1*(2-3))');
4014 iseq($all, $_);
4015}
b515a41d
YO
4016{
4017 my $spaces=" ";
4018 local $_=join 'bar',$spaces,$spaces;
4019 our $count=0;
4020 s/(?>\s+bar)(?{$count++})//g;
4021 iseq($_,$spaces,"SUSPEND final string");
4022 iseq($count,1,"Optimiser should have prevented more than one match");
4023}
f0852a51
YO
4024{
4025 local $Message = "RT#36909 test";
4026 $^R = 'Nothing';
4027 {
4028 local $^R = "Bad";
4029 ok('x foofoo y' =~ m{
4030 (foo) # $^R correctly set
4031 (?{ "last regexp code result" })
4032 }x);
4033 iseq($^R,'last regexp code result');
4034 }
4035 iseq($^R,'Nothing');
4036 {
4037 local $^R = "Bad";
4038
4039 ok('x foofoo y' =~ m{
4040 (?:foo|bar)+ # $^R correctly set
4041 (?{"last regexp code result"})
4042 }x);
4043 iseq($^R,'last regexp code result');
4044 }
4045 iseq($^R,'Nothing');
4046
4047 {
4048 local $^R = "Bad";
4049 ok('x foofoo y' =~ m{
4050 (foo|bar)\1+ # $^R undefined
4051 (?{"last regexp code result"})
4052 }x);
4053 iseq($^R,'last regexp code result');
4054 }
4055 iseq($^R,'Nothing');
4056}
cf2a2b69
YO
4057{
4058 local $Message="RT#22395";
4059 our $count;
4060 for my $l (1,10,100,1000) {
4061 $count=0;
4062 ('a' x $l) =~ /(.*)(?{$count++})[bc]/;
4063 iseq($l+1,$count,"Should be L+1 not L*(L+3)/2 (L=$l)");
4064 }
4065}
04e1c60a 4066{
a678b0e4
YO
4067 local $Message = "RT#22614";
4068 local $_='ab';
4069 our @len=();
4070 /(.){1,}(?{push @len,0+@-})(.){1,}(?{})^/;
4071 iseq("@len","2 2 2");
4072}
4073{
04e1c60a
YO
4074 local $Message = "RT#18209";
4075 my $text = ' word1 word2 word3 word4 word5 word6 ';
4076
4077 my @words = ('word1', 'word3', 'word5');
4078 my $count;
4079 foreach my $word (@words){
4080 $text =~ s/$word\s//gi; # Leave a space to seperate words in the resultant str.
4081 # The following block is not working.
4082 if($&){
4083 $count++;
4084 }
4085 # End bad block
4086 }
4087 iseq($count,3);
4088 iseq($text,' word2 word4 word6 ');
4089}
4090
b515a41d 4091# Test counter is at bottom of file. Put new tests above here.
24b23f37 4092#-------------------------------------------------------------------
6bda09f9 4093# Keep the following tests last -- they may crash perl
c74340f9
YO
4094{
4095 # RT#19049 / RT#38869
4096 my @list = (
4097 'ab cdef', # matches regex
4098 ( 'e' x 40000 ) .'ab c' # matches not, but 'ab c' matches part of it
4099 );
4100 my $y;
4101 my $x;
4102 foreach (@list) {
4103 m/ab(.+)cd/i; # the ignore-case seems to be important
4104 $y = $1; # use $1, which might not be from the last match!
4105 $x = substr($list[0],$-[0],$+[0]-$-[0]);
4106 }
4107 iseq($y,' ',
4108 'pattern in a loop, failure should not affect previous success');
4109 iseq($x,'ab cd',
4110 'pattern in a loop, failure should not affect previous success');
4111}
ea29714e
DD
4112
4113ok(("a" x (2**15 - 10)) =~ /^()(a|bb)*$/, "Recursive stack cracker: #24274")
4114 or print "# Unexpected outcome: should pass or crash perl\n";
4115
6bda09f9
YO
4116ok((q(a)x 100) =~ /^(??{'(.)'x 100})/,
4117 "Regexp /^(??{'(.)'x 100})/ crashes older perls")
4118 or print "# Unexpected outcome: should pass or crash perl\n";
4119
de8c5301 4120{
f0852a51 4121 local $Message = "substituation with lookahead (possible segv)";
de8c5301
YO
4122 $_="ns1ns1ns1";
4123 s/ns(?=\d)/ns_/g;
4124 iseq($_,"ns_1ns_1ns_1");
4125 $_="ns1";
4126 s/ns(?=\d)/ns_/;
4127 iseq($_,"ns_1");
4128 $_="123";
4129 s/(?=\d+)|(?<=\d)/!Bang!/g;
4130 iseq($_,"!Bang!1!Bang!2!Bang!3!Bang!");
4131}
4132
b515a41d 4133# Put new tests above the dotted line about a page above this comment
24b23f37 4134
fc8cd66c 4135# Don't forget to update this!
04e1c60a 4136BEGIN { print "1..1365\n" };