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