Retract #9145.
[p5sagit/p5-mst-13.2.git] / t / op / pat.t
CommitLineData
8d063cd8 1#!./perl
8d37f932 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
8269fa76 7print "1..581\n";
8d37f932 8
e4d48cc9 9BEGIN {
10 chdir 't' if -d 't';
20822f61 11 @INC = '../lib';
e4d48cc9 12}
8d37f932 13eval 'use Config'; # Defaults assumed if this fails
8d063cd8 14
15$x = "abc\ndef\n";
16
17if ($x =~ /^abc/) {print "ok 1\n";} else {print "not ok 1\n";}
18if ($x !~ /^def/) {print "ok 2\n";} else {print "not ok 2\n";}
19
20$* = 1;
21if ($x =~ /^def/) {print "ok 3\n";} else {print "not ok 3\n";}
22$* = 0;
23
24$_ = '123';
25if (/^([0-9][0-9]*)/) {print "ok 4\n";} else {print "not ok 4\n";}
26
27if ($x =~ /^xxx/) {print "not ok 5\n";} else {print "ok 5\n";}
28if ($x !~ /^abc/) {print "not ok 6\n";} else {print "ok 6\n";}
29
30if ($x =~ /def/) {print "ok 7\n";} else {print "not ok 7\n";}
31if ($x !~ /def/) {print "not ok 8\n";} else {print "ok 8\n";}
32
33if ($x !~ /.def/) {print "ok 9\n";} else {print "not ok 9\n";}
34if ($x =~ /.def/) {print "not ok 10\n";} else {print "ok 10\n";}
35
36if ($x =~ /\ndef/) {print "ok 11\n";} else {print "not ok 11\n";}
37if ($x !~ /\ndef/) {print "not ok 12\n";} else {print "ok 12\n";}
38
39$_ = 'aaabbbccc';
40if (/(a*b*)(c*)/ && $1 eq 'aaabbb' && $2 eq 'ccc') {
41 print "ok 13\n";
42} else {
43 print "not ok 13\n";
44}
45if (/(a+b+c+)/ && $1 eq 'aaabbbccc') {
46 print "ok 14\n";
47} else {
48 print "not ok 14\n";
49}
50
51if (/a+b?c+/) {print "not ok 15\n";} else {print "ok 15\n";}
52
53$_ = 'aaabccc';
54if (/a+b?c+/) {print "ok 16\n";} else {print "not ok 16\n";}
55if (/a*b+c*/) {print "ok 17\n";} else {print "not ok 17\n";}
56
57$_ = 'aaaccc';
58if (/a*b?c*/) {print "ok 18\n";} else {print "not ok 18\n";}
59if (/a*b+c*/) {print "not ok 19\n";} else {print "ok 19\n";}
60
61$_ = 'abcdef';
62if (/bcd|xyz/) {print "ok 20\n";} else {print "not ok 20\n";}
63if (/xyz|bcd/) {print "ok 21\n";} else {print "not ok 21\n";}
64
65if (m|bc/*d|) {print "ok 22\n";} else {print "not ok 22\n";}
378cc40b 66
67if (/^$_$/) {print "ok 23\n";} else {print "not ok 23\n";}
68
69$* = 1; # test 3 only tested the optimized version--this one is for real
70if ("ab\ncd\n" =~ /^cd/) {print "ok 24\n";} else {print "not ok 24\n";}
71$* = 0;
72
f06c8e5b 73#$XXX{123} = 123;
74#$XXX{234} = 234;
75#$XXX{345} = 345;
76#
77#@XXX = ('ok 25','not ok 25', 'ok 26','not ok 26','not ok 27');
78#while ($_ = shift(@XXX)) {
79# ?(.*)? && (print $1,"\n");
80# /not/ && reset;
81# /not ok 26/ && reset 'X';
82#}
83#
84#while (($key,$val) = each(%XXX)) {
85# print "not ok 27\n";
86# exit;
87#}
88#
89#print "ok 27\n";
90for (25..27) { print "ok $_\n" }
378cc40b 91
378cc40b 92'cde' =~ /[^ab]*/;
93'xyz' =~ //;
94if ($& eq 'xyz') {print "ok 28\n";} else {print "not ok 28\n";}
95
96$foo = '[^ab]*';
97'cde' =~ /$foo/;
98'xyz' =~ //;
99if ($& eq 'xyz') {print "ok 29\n";} else {print "not ok 29\n";}
100
101$foo = '[^ab]*';
102'cde' =~ /$foo/;
103'xyz' =~ /$null/;
104if ($& eq 'xyz') {print "ok 30\n";} else {print "not ok 30\n";}
a687059c 105
106$_ = 'abcdefghi';
107/def/; # optimized up to cmd
108if ("$`:$&:$'" eq 'abc:def:ghi') {print "ok 31\n";} else {print "not ok 31\n";}
109
110/cde/ + 0; # optimized only to spat
111if ("$`:$&:$'" eq 'ab:cde:fghi') {print "ok 32\n";} else {print "not ok 32\n";}
112
113/[d][e][f]/; # not optimized
114if ("$`:$&:$'" eq 'abc:def:ghi') {print "ok 33\n";} else {print "not ok 33\n";}
115
116$_ = 'now is the {time for all} good men to come to.';
117/ {([^}]*)}/;
118if ($1 eq 'time for all') {print "ok 34\n";} else {print "not ok 34 $1\n";}
119
120$_ = 'xxx {3,4} yyy zzz';
121print /( {3,4})/ ? "ok 35\n" : "not ok 35\n";
122print $1 eq ' ' ? "ok 36\n" : "not ok 36\n";
123print /( {4,})/ ? "not ok 37\n" : "ok 37\n";
124print /( {2,3}.)/ ? "ok 38\n" : "not ok 38\n";
125print $1 eq ' y' ? "ok 39\n" : "not ok 39\n";
126print /(y{2,3}.)/ ? "ok 40\n" : "not ok 40\n";
127print $1 eq 'yyy ' ? "ok 41\n" : "not ok 41\n";
128print /x {3,4}/ ? "not ok 42\n" : "ok 42\n";
129print /^xxx {3,4}/ ? "not ok 43\n" : "ok 43\n";
352d5a3a 130
131$_ = "now is the time for all good men to come to.";
132@words = /(\w+)/g;
133print join(':',@words) eq "now:is:the:time:for:all:good:men:to:come:to"
134 ? "ok 44\n"
135 : "not ok 44\n";
136
137@words = ();
138while (/\w+/g) {
139 push(@words, $&);
140}
141print join(':',@words) eq "now:is:the:time:for:all:good:men:to:come:to"
142 ? "ok 45\n"
143 : "not ok 45\n";
144
145@words = ();
71be2cbc 146pos = 0;
352d5a3a 147while (/to/g) {
148 push(@words, $&);
149}
150print join(':',@words) eq "to:to"
151 ? "ok 46\n"
71be2cbc 152 : "not ok 46 `@words'\n";
352d5a3a 153
71be2cbc 154pos $_ = 0;
352d5a3a 155@words = /to/g;
156print join(':',@words) eq "to:to"
157 ? "ok 47\n"
71be2cbc 158 : "not ok 47 `@words'\n";
352d5a3a 159
160$_ = "abcdefghi";
161
162$pat1 = 'def';
163$pat2 = '^def';
164$pat3 = '.def.';
165$pat4 = 'abc';
166$pat5 = '^abc';
167$pat6 = 'abc$';
168$pat7 = 'ghi';
169$pat8 = '\w*ghi';
170$pat9 = 'ghi$';
171
172$t1=$t2=$t3=$t4=$t5=$t6=$t7=$t8=$t9=0;
173
174for $iter (1..5) {
175 $t1++ if /$pat1/o;
176 $t2++ if /$pat2/o;
177 $t3++ if /$pat3/o;
178 $t4++ if /$pat4/o;
179 $t5++ if /$pat5/o;
180 $t6++ if /$pat6/o;
181 $t7++ if /$pat7/o;
182 $t8++ if /$pat8/o;
183 $t9++ if /$pat9/o;
184}
185
186$x = "$t1$t2$t3$t4$t5$t6$t7$t8$t9";
187print $x eq '505550555' ? "ok 48\n" : "not ok 48 $x\n";
1462b684 188
189$xyz = 'xyz';
190print "abc" =~ /^abc$|$xyz/ ? "ok 49\n" : "not ok 49\n";
191
192# perl 4.009 says "unmatched ()"
193eval '"abc" =~ /a(bc$)|$xyz/; $result = "$&:$1"';
194print $@ eq "" ? "ok 50\n" : "not ok 50\n";
195print $result eq "abc:bc" ? "ok 51\n" : "not ok 51\n";
a0d0e21e 196
197
198$_="abcfooabcbar";
199$x=/abc/g;
200print $` eq "" ? "ok 52\n" : "not ok 52\n" if $x;
201$x=/abc/g;
202print $` eq "abcfoo" ? "ok 53\n" : "not ok 53\n" if $x;
203$x=/abc/g;
204print $x == 0 ? "ok 54\n" : "not ok 54\n";
71be2cbc 205pos = 0;
a0d0e21e 206$x=/ABC/gi;
207print $` eq "" ? "ok 55\n" : "not ok 55\n" if $x;
208$x=/ABC/gi;
209print $` eq "abcfoo" ? "ok 56\n" : "not ok 56\n" if $x;
210$x=/ABC/gi;
211print $x == 0 ? "ok 57\n" : "not ok 57\n";
71be2cbc 212pos = 0;
a0d0e21e 213$x=/abc/g;
214print $' eq "fooabcbar" ? "ok 58\n" : "not ok 58\n" if $x;
215$x=/abc/g;
216print $' eq "bar" ? "ok 59\n" : "not ok 59\n" if $x;
217$_ .= '';
218@x=/abc/g;
219print scalar @x == 2 ? "ok 60\n" : "not ok 60\n";
71be2cbc 220
221$_ = "abdc";
222pos $_ = 2;
c90c0ff4 223/\Gc/gc;
71be2cbc 224print "not " if (pos $_) != 2;
225print "ok 61\n";
c90c0ff4 226/\Gc/g;
227print "not " if defined pos $_;
228print "ok 62\n";
c277df42 229
230$out = 1;
231'abc' =~ m'a(?{ $out = 2 })b';
232print "not " if $out != 2;
233print "ok 63\n";
234
235$out = 1;
236'abc' =~ m'a(?{ $out = 3 })c';
237print "not " if $out != 1;
238print "ok 64\n";
239
240$_ = 'foobar1 bar2 foobar3 barfoobar5 foobar6';
241@out = /(?<!foo)bar./g;
242print "not " if "@out" ne 'bar2 barf';
243print "ok 65\n";
244
8d37f932 245# Tests which depend on REG_INFTY
246$reg_infty = defined $Config{reg_infty} ? $Config{reg_infty} : 32767;
247$reg_infty_m = $reg_infty - 1; $reg_infty_p = $reg_infty + 1;
248
249# As well as failing if the pattern matches do unexpected things, the
250# next three tests will fail if you should have picked up a lower-than-
251# default value for $reg_infty from Config.pm, but have not.
252
253undef $@;
254print "not " if eval q(('aaa' =~ /(a{1,$reg_infty_m})/)[0] ne 'aaa') || $@;
255print "ok 66\n";
256
257undef $@;
258print "not " if eval q(('a' x $reg_infty_m) !~ /a{$reg_infty_m}/) || $@;
259print "ok 67\n";
260
261undef $@;
262print "not " if eval q(('a' x ($reg_infty_m - 1)) =~ /a{$reg_infty_m}/) || $@;
263print "ok 68\n";
264
265undef $@;
266eval "'aaa' =~ /a{1,$reg_infty}/";
9baa0206 267print "not " if $@ !~ m%^\QQuantifier in {,} bigger than%;
8d37f932 268print "ok 69\n";
269
270eval "'aaa' =~ /a{1,$reg_infty_p}/";
271print "not "
9baa0206 272 if $@ !~ m%^\QQuantifier in {,} bigger than%;
8d37f932 273print "ok 70\n";
274undef $@;
275
276# Poke a couple more parse failures
277
278$context = 'x' x 256;
279eval qq("${context}y" =~ /(?<=$context)y/);
9baa0206 280print "not " if $@ !~ m%^\QLookbehind longer than 255 not%;
8d37f932 281print "ok 71\n";
282
b8c5462f 283# removed test
8d37f932 284print "ok 72\n";
285
c277df42 286# Long Monsters
8d37f932 287$test = 73;
c277df42 288for $l (125, 140, 250, 270, 300000, 30) { # Ordered to free memory
289 $a = 'a' x $l;
290 print "# length=$l\nnot " unless "ba$a=" =~ /a$a=/;
291 print "ok $test\n";
292 $test++;
293
294 print "not " if "b$a=" =~ /a$a=/;
295 print "ok $test\n";
296 $test++;
297}
298
299# 20000 nodes, each taking 3 words per string, and 1 per branch
300$long_constant_len = join '|', 12120 .. 32645;
301$long_var_len = join '|', 8120 .. 28645;
302%ans = ( 'ax13876y25677lbc' => 1,
303 'ax13876y25677mcb' => 0, # not b.
304 'ax13876y35677nbc' => 0, # Num too big
305 'ax13876y25677y21378obc' => 1,
306 'ax13876y25677y21378zbc' => 0, # Not followed by [k-o]
307 'ax13876y25677y21378y21378kbc' => 1,
308 'ax13876y25677y21378y21378kcb' => 0, # Not b.
309 'ax13876y25677y21378y21378y21378kbc' => 0, # 5 runs
310 );
311
312for ( keys %ans ) {
313 print "# const-len `$_' not => $ans{$_}\nnot "
314 if $ans{$_} xor /a(?=([yx]($long_constant_len)){2,4}[k-o]).*b./o;
315 print "ok $test\n";
316 $test++;
317 print "# var-len `$_' not => $ans{$_}\nnot "
318 if $ans{$_} xor /a(?=([yx]($long_var_len)){2,4}[k-o]).*b./o;
319 print "ok $test\n";
320 $test++;
321}
322
323$_ = " a (bla()) and x(y b((l)u((e))) and b(l(e)e)e";
324$expect = "(bla()) ((l)u((e))) (l(e)e)";
325
326sub matchit {
cc6b7395 327 m/
c277df42 328 (
329 \(
330 (?{ $c = 1 }) # Initialize
331 (?:
332 (?(?{ $c == 0 }) # PREVIOUS iteration was OK, stop the loop
333 (?!
334 ) # Fail: will unwind one iteration back
335 )
336 (?:
337 [^()]+ # Match a big chunk
338 (?=
339 [()]
340 ) # Do not try to match subchunks
341 |
342 \(
343 (?{ ++$c })
344 |
345 \)
346 (?{ --$c })
347 )
348 )+ # This may not match with different subblocks
349 )
350 (?(?{ $c != 0 })
351 (?!
352 ) # Fail
353 ) # Otherwise the chunk 1 may succeed with $c>0
cc6b7395 354 /xg;
c277df42 355}
356
0f5d15d6 357@ans = ();
c277df42 358push @ans, $res while $res = matchit;
359
360print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne "1 1 1";
361print "ok $test\n";
362$test++;
363
364@ans = matchit;
365
366print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne $expect;
367print "ok $test\n";
368$test++;
369
96776eda 370print "not " unless "abc" =~ /^(??{"a"})b/;
371print "ok $test\n";
372$test++;
373
0f5d15d6 374my $matched;
14455d6c 375$matched = qr/\((?:(?>[^()]+)|(??{$matched}))*\)/;
0f5d15d6 376
377@ans = @ans1 = ();
378push(@ans, $res), push(@ans1, $&) while $res = m/$matched/g;
379
380print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne "1 1 1";
381print "ok $test\n";
382$test++;
383
384print "# ans1='@ans1'\n# expect='$expect'\nnot " if "@ans1" ne $expect;
385print "ok $test\n";
386$test++;
387
388@ans = m/$matched/g;
389
390print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne $expect;
391print "ok $test\n";
392$test++;
393
c277df42 394@ans = ('a/b' =~ m%(.*/)?(.*)%); # Stack may be bad
395print "not " if "@ans" ne 'a/ b';
396print "ok $test\n";
397$test++;
398
cc6b7395 399$code = '{$blah = 45}';
c277df42 400$blah = 12;
2cd61cdb 401eval { /(?$code)/ };
402print "not " unless $@ and $@ =~ /not allowed at runtime/ and $blah == 12;
e4d48cc9 403print "ok $test\n";
404$test++;
405
2cd61cdb 406for $code ('{$blah = 45}','=xx') {
407 $blah = 12;
408 $res = eval { "xx" =~ /(?$code)/o };
409 if ($code eq '=xx') {
410 print "#'$@','$res','$blah'\nnot " unless not $@ and $res;
411 } else {
412 print "#'$@','$res','$blah'\nnot " unless $@ and $@ =~ /not allowed at runtime/ and $blah == 12;
413 }
414 print "ok $test\n";
415 $test++;
416}
417
e4d48cc9 418$code = '{$blah = 45}';
419$blah = 12;
420eval "/(?$code)/";
cc6b7395 421print "not " if $blah != 45;
422print "ok $test\n";
423$test++;
424
425$blah = 12;
426/(?{$blah = 45})/;
c277df42 427print "not " if $blah != 45;
428print "ok $test\n";
429$test++;
430
74d6a13a 431$x = 'banana';
432$x =~ /.a/g;
433print "not " unless pos($x) == 2;
434print "ok $test\n";
435$test++;
436
437$x =~ /.z/gc;
438print "not " unless pos($x) == 2;
439print "ok $test\n";
440$test++;
441
442sub f {
443 my $p = $_[0];
444 return $p;
445}
446
447$x =~ /.a/g;
448print "not " unless f(pos($x)) == 4;
449print "ok $test\n";
450$test++;
4599a1de 451
ce862d02 452$x = $^R = 67;
453'foot' =~ /foo(?{$x = 12; 75})[t]/;
454print "not " unless $^R eq '75';
455print "ok $test\n";
456$test++;
457
458$x = $^R = 67;
459'foot' =~ /foo(?{$x = 12; 75})[xy]/;
460print "not " unless $^R eq '67' and $x eq '12';
461print "ok $test\n";
462$test++;
463
464$x = $^R = 67;
465'foot' =~ /foo(?{ $^R + 12 })((?{ $x = 12; $^R + 17 })[xy])?/;
466print "not " unless $^R eq '79' and $x eq '12';
467print "ok $test\n";
468$test++;
469
8782bef2 470print "not " unless qr/\b\v$/i eq '(?i-xsm:\bv$)';
471print "ok $test\n";
472$test++;
473
474print "not " unless qr/\b\v$/s eq '(?s-xim:\bv$)';
475print "ok $test\n";
476$test++;
477
478print "not " unless qr/\b\v$/m eq '(?m-xis:\bv$)';
479print "ok $test\n";
480$test++;
481
482print "not " unless qr/\b\v$/x eq '(?x-ism:\bv$)';
483print "ok $test\n";
484$test++;
485
486print "not " unless qr/\b\v$/xism eq '(?msix:\bv$)';
487print "ok $test\n";
488$test++;
489
490print "not " unless qr/\b\v$/ eq '(?-xism:\bv$)';
97197631 491print "ok $test\n";
492$test++;
493
7e5428c5 494$_ = 'xabcx';
495foreach $ans ('', 'c') {
496 /(?<=(?=a)..)((?=c)|.)/g;
02db2b7b 497 print "# \$1 ='$1'\n# \$ans='$ans'\nnot " unless $1 eq $ans;
7e5428c5 498 print "ok $test\n";
499 $test++;
500}
501
502$_ = 'a';
503foreach $ans ('', 'a', '') {
504 /^|a|$/g;
02db2b7b 505 print "# \$& ='$&'\n# \$ans='$ans'\nnot " unless $& eq $ans;
7e5428c5 506 print "ok $test\n";
507 $test++;
508}
509
09f25ae4 510sub prefixify {
511 my($v,$a,$b,$res) = @_;
512 $v =~ s/\Q$a\E/$b/;
513 print "not " unless $res eq $v;
514 print "ok $test\n";
515 $test++;
516}
517prefixify('/a/b/lib/arch', "/a/b/lib", 'X/lib', 'X/lib/arch');
518prefixify('/a/b/man/arch', "/a/b/man", 'X/man', 'X/man/arch');
519
520$_ = 'var="foo"';
521/(\")/;
522print "not " unless $1 and /$1/;
523print "ok $test\n";
524$test++;
525
8782bef2 526$a=qr/(?{++$b})/;
2cd61cdb 527$b = 7;
528/$a$a/;
529print "not " unless $b eq '9';
530print "ok $test\n";
531$test++;
532
533$c="$a";
534/$a$a/;
535print "not " unless $b eq '11';
536print "ok $test\n";
537$test++;
538
539{
540 use re "eval";
541 /$a$c$a/;
542 print "not " unless $b eq '14';
543 print "ok $test\n";
544 $test++;
545
160cb429 546 local $lex_a = 2;
547 my $lex_a = 43;
548 my $lex_b = 17;
549 my $lex_c = 27;
550 my $lex_res = ($lex_b =~ qr/$lex_b(?{ $lex_c = $lex_a++ })/);
551 print "not " unless $lex_res eq '1';
552 print "ok $test\n";
553 $test++;
554 print "not " unless $lex_a eq '44';
555 print "ok $test\n";
556 $test++;
557 print "not " unless $lex_c eq '43';
558 print "ok $test\n";
559 $test++;
560
561
2cd61cdb 562 no re "eval";
563 $match = eval { /$a$c$a/ };
564 print "not "
565 unless $b eq '14' and $@ =~ /Eval-group not allowed/ and not $match;
566 print "ok $test\n";
567 $test++;
568}
cbce877f 569
570{
160cb429 571 local $lex_a = 2;
572 my $lex_a = 43;
573 my $lex_b = 17;
574 my $lex_c = 27;
575 my $lex_res = ($lex_b =~ qr/17(?{ $lex_c = $lex_a++ })/);
576 print "not " unless $lex_res eq '1';
577 print "ok $test\n";
578 $test++;
579 print "not " unless $lex_a eq '44';
580 print "ok $test\n";
581 $test++;
582 print "not " unless $lex_c eq '43';
583 print "ok $test\n";
584 $test++;
585}
586
587{
cbce877f 588 package aa;
589 $c = 2;
590 $::c = 3;
591 '' =~ /(?{ $c = 4 })/;
592 print "not " unless $c == 4;
593}
594print "ok $test\n";
595$test++;
596print "not " unless $c == 3;
597print "ok $test\n";
598$test++;
2cd61cdb 599
4599a1de 600sub must_warn_pat {
601 my $warn_pat = shift;
602 return sub { print "not " unless $_[0] =~ /$warn_pat/ }
603}
604
605sub must_warn {
606 my ($warn_pat, $code) = @_;
9f1b1f2d 607 local %SIG;
608 eval 'BEGIN { use warnings; $SIG{__WARN__} = $warn_pat };' . $code;
4599a1de 609 print "ok $test\n";
610 $test++;
611}
612
613
614sub make_must_warn {
615 my $warn_pat = shift;
616 return sub { must_warn(must_warn_pat($warn_pat)) }
617}
618
619my $for_future = make_must_warn('reserved for future extensions');
620
621&$for_future('q(a:[b]:) =~ /[x[:foo:]]/');
9baa0206 622
623#&$for_future('q(a=[b]=) =~ /[x[=foo=]]/');
624print "ok $test\n"; $test++; # now a fatal croak
625
626#&$for_future('q(a.[b].) =~ /[x[.foo.]]/');
627print "ok $test\n"; $test++; # now a fatal croak
f7e33566 628
629# test if failure of patterns returns empty list
630$_ = 'aaa';
631@_ = /bbb/;
632print "not " if @_;
633print "ok $test\n";
634$test++;
635
636@_ = /bbb/g;
637print "not " if @_;
638print "ok $test\n";
639$test++;
640
641@_ = /(bbb)/;
642print "not " if @_;
643print "ok $test\n";
644$test++;
645
646@_ = /(bbb)/g;
647print "not " if @_;
648print "ok $test\n";
649$test++;
650
6cef1e77 651/a(?=.$)/;
652print "not " if $#+ != 0 or $#- != 0;
653print "ok $test\n";
654$test++;
655
656print "not " if $+[0] != 2 or $-[0] != 1;
657print "ok $test\n";
658$test++;
659
660print "not "
661 if defined $+[1] or defined $-[1] or defined $+[2] or defined $-[2];
662print "ok $test\n";
663$test++;
664
665/a(a)(a)/;
666print "not " if $#+ != 2 or $#- != 2;
667print "ok $test\n";
668$test++;
669
670print "not " if $+[0] != 3 or $-[0] != 0;
671print "ok $test\n";
672$test++;
673
674print "not " if $+[1] != 2 or $-[1] != 1;
675print "ok $test\n";
676$test++;
677
678print "not " if $+[2] != 3 or $-[2] != 2;
679print "ok $test\n";
680$test++;
681
682print "not "
683 if defined $+[3] or defined $-[3] or defined $+[4] or defined $-[4];
684print "ok $test\n";
685$test++;
686
687/.(a)(b)?(a)/;
688print "not " if $#+ != 3 or $#- != 3;
689print "ok $test\n";
690$test++;
691
692print "not " if $+[0] != 3 or $-[0] != 0;
693print "ok $test\n";
694$test++;
695
696print "not " if $+[1] != 2 or $-[1] != 1;
697print "ok $test\n";
698$test++;
699
700print "not " if $+[3] != 3 or $-[3] != 2;
701print "ok $test\n";
702$test++;
703
704print "not "
705 if defined $+[2] or defined $-[2] or defined $+[4] or defined $-[4];
706print "ok $test\n";
707$test++;
708
709/.(a)/;
710print "not " if $#+ != 1 or $#- != 1;
711print "ok $test\n";
712$test++;
713
714print "not " if $+[0] != 2 or $-[0] != 0;
715print "ok $test\n";
716$test++;
717
718print "not " if $+[1] != 2 or $-[1] != 1;
719print "ok $test\n";
720$test++;
721
722print "not "
723 if defined $+[2] or defined $-[2] or defined $+[3] or defined $-[3];
724print "ok $test\n";
725$test++;
726
03a27ae7 727eval { $+[0] = 13; };
728print "not "
729 if $@ !~ /^Modification of a read-only value attempted/;
730print "ok $test\n";
731$test++;
732
733eval { $-[0] = 13; };
734print "not "
735 if $@ !~ /^Modification of a read-only value attempted/;
736print "ok $test\n";
737$test++;
738
739eval { @+ = (7, 6, 5); };
740print "not "
741 if $@ !~ /^Modification of a read-only value attempted/;
742print "ok $test\n";
743$test++;
744
745eval { @- = qw(foo bar); };
746print "not "
747 if $@ !~ /^Modification of a read-only value attempted/;
748print "ok $test\n";
749$test++;
750
8f580fb8 751/.(a)(ba*)?/;
752print "#$#-..$#+\nnot " if $#+ != 2 or $#- != 1;
753print "ok $test\n";
754$test++;
755
ad94a511 756$_ = 'aaa';
757pos = 1;
758@a = /\Ga/g;
759print "not " unless "@a" eq "a a";
760print "ok $test\n";
761$test++;
762
22e551b9 763$str = 'abcde';
764pos $str = 2;
765
766print "not " if $str =~ /^\G/;
767print "ok $test\n";
768$test++;
769
770print "not " if $str =~ /^.\G/;
771print "ok $test\n";
772$test++;
773
774print "not " unless $str =~ /^..\G/;
775print "ok $test\n";
776$test++;
777
778print "not " if $str =~ /^...\G/;
779print "ok $test\n";
780$test++;
781
782print "not " unless $str =~ /.\G./ and $& eq 'bc';
783print "ok $test\n";
784$test++;
785
786print "not " unless $str =~ /\G../ and $& eq 'cd';
787print "ok $test\n";
788$test++;
789
9661b544 790undef $foo; undef $bar;
791print "#'$str','$foo','$bar'\nnot "
792 unless $str =~ /b(?{$foo = $_; $bar = pos})c/
793 and $foo eq 'abcde' and $bar eq 2;
794print "ok $test\n";
795$test++;
796
797undef $foo; undef $bar;
798pos $str = undef;
799print "#'$str','$foo','$bar'\nnot "
800 unless $str =~ /b(?{$foo = $_; $bar = pos})c/g
801 and $foo eq 'abcde' and $bar eq 2 and pos $str eq 3;
802print "ok $test\n";
803$test++;
804
805$_ = $str;
806
807undef $foo; undef $bar;
808print "#'$str','$foo','$bar'\nnot "
809 unless /b(?{$foo = $_; $bar = pos})c/
810 and $foo eq 'abcde' and $bar eq 2;
811print "ok $test\n";
812$test++;
813
814undef $foo; undef $bar;
815print "#'$str','$foo','$bar'\nnot "
816 unless /b(?{$foo = $_; $bar = pos})c/g
817 and $foo eq 'abcde' and $bar eq 2 and pos eq 3;
818print "ok $test\n";
819$test++;
820
821undef $foo; undef $bar;
822pos = undef;
8231 while /b(?{$foo = $_; $bar = pos})c/g;
824print "#'$str','$foo','$bar'\nnot "
825 unless $foo eq 'abcde' and $bar eq 2 and not defined pos;
826print "ok $test\n";
827$test++;
828
829undef $foo; undef $bar;
830$_ = 'abcde|abcde';
831print "#'$str','$foo','$bar','$_'\nnot "
832 unless s/b(?{$foo = $_; $bar = pos})c/x/g and $foo eq 'abcde|abcde'
833 and $bar eq 8 and $_ eq 'axde|axde';
834print "ok $test\n";
835$test++;
836
5c5e4c24 837@res = ();
838# List context:
839$_ = 'abcde|abcde';
840@dummy = /([ace]).(?{push @res, $1,$2})([ce])(?{push @res, $1,$2})/g;
841@res = map {defined $_ ? "'$_'" : 'undef'} @res;
842$res = "@res";
843print "#'@res' '$_'\nnot "
844 unless "@res" eq "'a' undef 'a' 'c' 'e' undef 'a' undef 'a' 'c'";
845print "ok $test\n";
846$test++;
847
848@res = ();
849@dummy = /([ace]).(?{push @res, $`,$&,$'})([ce])(?{push @res, $`,$&,$'})/g;
850@res = map {defined $_ ? "'$_'" : 'undef'} @res;
851$res = "@res";
852print "#'@res' '$_'\nnot "
853 unless "@res" eq
854 "'' 'ab' 'cde|abcde' " .
855 "'' 'abc' 'de|abcde' " .
856 "'abcd' 'e|' 'abcde' " .
857 "'abcde|' 'ab' 'cde' " .
858 "'abcde|' 'abc' 'de'" ;
859print "ok $test\n";
860$test++;
861
b7a35066 862#Some more \G anchor checks
863$foo='aabbccddeeffgg';
864
865pos($foo)=1;
866
867$foo=~/.\G(..)/g;
868print "not " unless($1 eq 'ab');
869print "ok $test\n";
870$test++;
871
872pos($foo) += 1;
873$foo=~/.\G(..)/g;
874print "not " unless($1 eq 'cc');
875print "ok $test\n";
876$test++;
877
878pos($foo) += 1;
879$foo=~/.\G(..)/g;
880print "not " unless($1 eq 'de');
881print "ok $test\n";
882$test++;
883
0ef3e39e 884print "not " unless $foo =~ /\Gef/g;
885print "ok $test\n";
886$test++;
887
b7a35066 888undef pos $foo;
889
890$foo=~/\G(..)/g;
891print "not " unless($1 eq 'aa');
892print "ok $test\n";
893$test++;
894
895$foo=~/\G(..)/g;
896print "not " unless($1 eq 'bb');
897print "ok $test\n";
898$test++;
899
900pos($foo)=5;
901$foo=~/\G(..)/g;
902print "not " unless($1 eq 'cd');
903print "ok $test\n";
904$test++;
905
e60df1fa 906$_='123x123';
907@res = /(\d*|x)/g;
908print "not " unless('123||x|123|' eq join '|', @res);
909print "ok $test\n";
910$test++;
911
9d080a66 912# see if matching against temporaries (created via pp_helem()) is safe
913{ foo => "ok $test\n".$^X }->{foo} =~ /^(.*)\n/g;
914print "$1\n";
915$test++;
916
cf93c79d 917# See if $i work inside (?{}) in the presense of saved substrings and
918# changing $_
919@a = qw(foo bar);
920@b = ();
921s/(\w)(?{push @b, $1})/,$1,/g for @a;
922
923print "# \@b='@b', expect 'f o o b a r'\nnot " unless("@b" eq "f o o b a r");
924print "ok $test\n";
925$test++;
926
927print "not " unless("@a" eq ",f,,o,,o, ,b,,a,,r,");
928print "ok $test\n";
929$test++;
930
2c914db6 931$brackets = qr{
14455d6c 932 { (?> [^{}]+ | (??{ $brackets }) )* }
2c914db6 933 }x;
934
935"{{}" =~ $brackets;
936print "ok $test\n"; # Did we survive?
937$test++;
938
939"something { long { and } hairy" =~ $brackets;
940print "ok $test\n"; # Did we survive?
941$test++;
942
14455d6c 943"something { long { and } hairy" =~ m/((??{ $brackets }))/;
2c914db6 944print "not " unless $1 eq "{ and }";
945print "ok $test\n";
946$test++;
947
30944b6d 948$_ = "a-a\nxbb";
949pos=1;
950m/^-.*bb/mg and print "not ";
951print "ok $test\n";
952$test++;
30382c73 953
954$text = "aaXbXcc";
955pos($text)=0;
956$text =~ /\GXb*X/g and print 'not ';
957print "ok $test\n";
958$test++;
3cf5c195 959
960$text = "xA\n" x 500;
961$text =~ /^\s*A/m and print 'not ';
962print "ok $test\n";
963$test++;
d506a20d 964
965$text = "abc dbf";
966@res = ($text =~ /.*?(b).*?\b/g);
967"@res" eq 'b b' or print 'not ';
968print "ok $test\n";
969$test++;
970
9442cb0e 971@a = map chr,0..255;
aeaf5620 972
973@b = grep(/\S/,@a);
974@c = grep(/[^\s]/,@a);
975print "not " if "@b" ne "@c";
9442cb0e 976print "ok $test\n";
977$test++;
978
aeaf5620 979@b = grep(/\S/,@a);
980@c = grep(/[\S]/,@a);
981print "not " if "@b" ne "@c";
9442cb0e 982print "ok $test\n";
983$test++;
984
aeaf5620 985@b = grep(/\s/,@a);
986@c = grep(/[^\S]/,@a);
987print "not " if "@b" ne "@c";
9442cb0e 988print "ok $test\n";
989$test++;
990
aeaf5620 991@b = grep(/\s/,@a);
992@c = grep(/[\s]/,@a);
993print "not " if "@b" ne "@c";
9442cb0e 994print "ok $test\n";
995$test++;
996
aeaf5620 997@b = grep(/\D/,@a);
998@c = grep(/[^\d]/,@a);
999print "not " if "@b" ne "@c";
9442cb0e 1000print "ok $test\n";
1001$test++;
1002
aeaf5620 1003@b = grep(/\D/,@a);
1004@c = grep(/[\D]/,@a);
1005print "not " if "@b" ne "@c";
9442cb0e 1006print "ok $test\n";
1007$test++;
1008
aeaf5620 1009@b = grep(/\d/,@a);
1010@c = grep(/[^\D]/,@a);
1011print "not " if "@b" ne "@c";
9442cb0e 1012print "ok $test\n";
1013$test++;
1014
aeaf5620 1015@b = grep(/\d/,@a);
1016@c = grep(/[\d]/,@a);
1017print "not " if "@b" ne "@c";
9442cb0e 1018print "ok $test\n";
1019$test++;
1020
aeaf5620 1021@b = grep(/\W/,@a);
1022@c = grep(/[^\w]/,@a);
1023print "not " if "@b" ne "@c";
9442cb0e 1024print "ok $test\n";
1025$test++;
1026
aeaf5620 1027@b = grep(/\W/,@a);
1028@c = grep(/[\W]/,@a);
1029print "not " if "@b" ne "@c";
9442cb0e 1030print "ok $test\n";
1031$test++;
1032
aeaf5620 1033@b = grep(/\w/,@a);
1034@c = grep(/[^\W]/,@a);
1035print "not " if "@b" ne "@c";
9442cb0e 1036print "ok $test\n";
1037$test++;
1038
aeaf5620 1039@b = grep(/\w/,@a);
1040@c = grep(/[\w]/,@a);
1041print "not " if "@b" ne "@c";
9442cb0e 1042print "ok $test\n";
1043$test++;
1aeab75a 1044
1045# see if backtracking optimization works correctly
1046"\n\n" =~ /\n $ \n/x or print "not ";
1047print "ok $test\n";
1048$test++;
1049
1050"\n\n" =~ /\n* $ \n/x or print "not ";
1051print "ok $test\n";
1052$test++;
1053
1054"\n\n" =~ /\n+ $ \n/x or print "not ";
1055print "ok $test\n";
1056$test++;
05b4157f 1057
1058[] =~ /^ARRAY/ or print "# [] \nnot ";
1059print "ok $test\n";
1060$test++;
1061
1062eval << 'EOE';
1063{
1064 package S;
1065 use overload '""' => sub { 'Object S' };
1066 sub new { bless [] }
1067}
1068$a = 'S'->new;
1069EOE
1070
1071$a and $a =~ /^Object\sS/ or print "# '$a' \nnot ";
1072print "ok $test\n";
1073$test++;
815d35b9 1074
1075# test result of match used as match (!)
1076'a1b' =~ ('xyz' =~ /y/) and $` eq 'a' or print "not ";
1077print "ok $test\n";
1078$test++;
1079
1080'a1b' =~ ('xyz' =~ /t/) and $` eq 'a' or print "not ";
1081print "ok $test\n";
1082$test++;
5e39e1e5 1083
1084$w = 0;
1085{
1086 local $SIG{__WARN__} = sub { $w = 1 };
1087 local $^W = 1;
1088 $w = 1 if ("1\n" x 102) =~ /^\s*\n/m;
1089}
1090print $w ? "not " : "", "ok $test\n";
1091$test++;
aaa51d5e 1092
1093my %space = ( spc => " ",
1094 tab => "\t",
1095 cr => "\r",
1096 lf => "\n",
1097 ff => "\f",
75369ccb 1098# There's no \v but the vertical tabulator seems miraculously
1099# be 11 both in ASCII and EBCDIC.
aaa51d5e 1100 vt => chr(11),
1101 false => "space" );
1102
1103my @space0 = sort grep { $space{$_} =~ /\s/ } keys %space;
1104my @space1 = sort grep { $space{$_} =~ /[[:space:]]/ } keys %space;
1105my @space2 = sort grep { $space{$_} =~ /[[:blank:]]/ } keys %space;
1106
1107print "not " unless "@space0" eq "cr ff lf spc tab";
3bec3564 1108print "ok $test # @space0\n";
aaa51d5e 1109$test++;
1110
1111print "not " unless "@space1" eq "cr ff lf spc tab vt";
3bec3564 1112print "ok $test # @space1\n";
aaa51d5e 1113$test++;
1114
1115print "not " unless "@space2" eq "spc tab";
3bec3564 1116print "ok $test # @space2\n";
aaa51d5e 1117$test++;
1118
a1933d95 1119# bugid 20001021.005 - this caused a SEGV
1120print "not " unless undef =~ /^([^\/]*)(.*)$/;
1121print "ok $test\n";
1122$test++;
b91bb191 1123
1124# bugid 20000731.001
1125
1126print "not " unless "A \x{263a} B z C" =~ /A . B (??{ "z" }) C/;
1127print "ok $test\n";
1128$test++;
1129
3baa4c62 1130$_ = "a\x{100}b";
1131if (/(.)(\C)(\C)(.)/) {
1132 print "ok 232\n";
1133 if ($1 eq "a") {
1134 print "ok 233\n";
1135 } else {
1136 print "not ok 233\n";
1137 }
1138 if ($2 eq "\xC4") {
1139 print "ok 234\n";
1140 } else {
1141 print "not ok 234\n";
1142 }
1143 if ($3 eq "\x80") {
1144 print "ok 235\n";
1145 } else {
1146 print "not ok 235\n";
1147 }
1148 if ($4 eq "b") {
1149 print "ok 236\n";
1150 } else {
1151 print "not ok 236\n";
1152 }
1153} else {
1154 for (232..236) {
1155 print "not ok $_\n";
1156 }
1157}
1158$_ = "\x{100}";
1159if (/(\C)/g) {
1160 print "ok 237\n";
1161 if ($1 eq "\xC4") {
1162 print "ok 238\n";
1163 } else {
1164 print "not ok 238\n";
1165 }
1166} else {
1167 for (237..238) {
1168 print "not ok $_\n";
1169 }
1170}
1171if (/(\C)/g) {
1172 print "ok 239\n";
1173 if ($1 eq "\x80") {
1174 print "ok 240\n";
1175 } else {
1176 print "not ok 240\n";
1177 }
1178} else {
1179 for (239..240) {
1180 print "not ok $_\n";
1181 }
1182}
b485d051 1183
db615365 1184{
1185 # japhy -- added 03/03/2001
1186 () = (my $str = "abc") =~ /(...)/;
1187 $str = "def";
1188 print "not " if $1 ne "abc";
fd291da9 1189 print "ok 241\n";
1190}
1191
1192# The 242 and 243 go with the 244 and 245.
1193# The trick is that in EBCDIC the explicit numeric range should match
1194# (as also in non-EBCDIC) but the explicit alphabetic range should not match.
1195
1196if ("\x8e" =~ /[\x89-\x91]/) {
1197 print "ok 242\n";
1198} else {
1199 print "not ok 242\n";
1200}
1201
1202if ("\xce" =~ /[\xc9-\xd1]/) {
db615365 1203 print "ok 243\n";
fd291da9 1204} else {
1205 print "not ok 243\n";
1206}
1207
1208# In most places these tests would succeed since \x8e does not
1209# in most character sets match 'i' or 'j' nor would \xce match
1210# 'I' or 'J', but strictly speaking these tests are here for
1211# the good of EBCDIC, so let's test these only there.
1212if (ord('i') == 0x89 && ord('J') == 0xd1) { # EBCDIC
1213 if ("\x8e" !~ /[i-j]/) {
1214 print "ok 244\n";
1215 } else {
1216 print "not ok 244\n";
1217 }
1218 if ("\xce" !~ /[I-J]/) {
1219 print "ok 245\n";
1220 } else {
1221 print "not ok 245\n";
1222 }
1223} else {
1224 for (244..245) {
1225 print "ok $_ # Skip: not EBCDIC\n";
1226 }
db615365 1227}
4765795a 1228
1229print "not " unless "\x{ab}" =~ /\x{ab}/;
1230print "ok 246\n";
1231
1232print "not " unless "\x{abcd}" =~ /\x{abcd}/;
1233print "ok 247\n";
1234
1235{
1236 # bug id 20001008.001
1237
4765795a 1238 my $test = 248;
1239 my @x = ("stra\337e 138","stra\337e 138");
1240 for (@x) {
1241 s/(\d+)\s*([\w\-]+)/$1 . uc $2/e;
1242 my($latin) = /^(.+)(?:\s+\d)/;
1243 print $latin eq "stra\337e" ? "ok $test\n" : # 248,249
1244 "#latin[$latin]\nnot ok $test\n";
1245 $test++;
1246 $latin =~ s/stra\337e/straße/; # \303\237 after the 2nd a
1247 use utf8;
1248 $latin =~ s!(s)tr(?:aß|s+e)!$1tr.!; # \303\237 after the a
1249 }
1250}
1251
1252{
1253 print "not " unless "ba\xd4c" =~ /([a\xd4]+)/ && $1 eq "a\xd4";
1254 print "ok 250\n";
1255
1256 print "not " unless "ba\xd4c" =~ /([a\xd4]+)/ && $1 eq "a\x{d4}";
1257 print "ok 251\n";
1258
1259 print "not " unless "ba\x{d4}c" =~ /([a\xd4]+)/ && $1 eq "a\x{d4}";
1260 print "ok 252\n";
1261
1262 print "not " unless "ba\x{d4}c" =~ /([a\xd4]+)/ && $1 eq "a\xd4";
1263 print "ok 253\n";
1264
1265 print "not " unless "ba\xd4c" =~ /([a\x{d4}]+)/ && $1 eq "a\xd4";
1266 print "ok 254\n";
1267
1268 print "not " unless "ba\xd4c" =~ /([a\x{d4}]+)/ && $1 eq "a\x{d4}";
1269 print "ok 255\n";
1270
1271 print "not " unless "ba\x{d4}c" =~ /([a\x{d4}]+)/ && $1 eq "a\x{d4}";
1272 print "ok 256\n";
1273
1274 print "not " unless "ba\x{d4}c" =~ /([a\x{d4}]+)/ && $1 eq "a\xd4";
1275 print "ok 257\n";
1276}
1277
1278{
1279 # the first half of 20001028.003
1280
1281 my $X = chr(1448);
1282 my ($Y) = $X =~ /(.*)/;
1283 print "not " unless $Y eq v1448 && length($Y) == 1;
1284 print "ok 258\n";
1285}
1286
1287{
1288 # 20001108.001
1289
1290 my $X = "Szab\x{f3},Bal\x{e1}zs";
1291 my $Y = $X;
1292 $Y =~ s/(B)/$1/ for 0..3;
1293 print "not " unless $Y eq $X && $X eq "Szab\x{f3},Bal\x{e1}zs";
1294 print "ok 259\n";
1295}
1296
1297{
1298 # the second half of 20001028.003
1299
1300 $X =~ s/^/chr(1488)/e;
1301 print "not " unless length $X == 1 && ord($X) == 1488;
1302 print "ok 260\n";
1303}
1304
1305{
1306 # 20000517.001
1307
1308 my $x = "\x{100}A";
1309
1310 $x =~ s/A/B/;
1311
1312 print "not " unless $x eq "\x{100}B" && length($x) == 2;
1313 print "ok 261\n";
1314}
1315
1316{
1317 # bug id 20001230.002
1318
1319 print "not " unless "École" =~ /^\C\C(.)/ && $1 eq 'c';
1320 print "ok 262\n";
1321
1322 print "not " unless "École" =~ /^\C\C(c)/;
1323 print "ok 263\n";
1324}
1325
1326{
1327 my $test = 264; # till 575
1328
1329 use charnames ':full';
1330
1331 # This is far from complete testing, there are dozens of character
1332 # classes in Unicode. The mixing of literals and \N{...} is
1333 # intentional so that in non-Latin-1 places we test the native
1334 # characters, not the Unicode code points.
1335
1336 my %s = (
1337 "a" => 'Ll',
1338 "\N{CYRILLIC SMALL LETTER A}" => 'Ll',
1339 "A" => 'Lu',
1340 "\N{GREEK CAPITAL LETTER ALPHA}" => 'Lu',
1341 "\N{HIRAGANA LETTER SMALL A}" => 'Lo',
1342 "\N{COMBINING GRAVE ACCENT}" => 'Mn',
1343 "0" => 'Nd',
1344 "\N{ARABIC-INDIC DIGIT ZERO}" => 'Nd',
1345 "_" => 'N',
1346 "!" => 'P',
1347 " " => 'Zs',
1348 "\0" => 'Cc',
1349 );
1350
1351 for my $char (keys %s) {
1352 my $class = $s{$char};
1353 my $code = sprintf("%04x", ord($char));
1354 printf "# 0x$code\n";
1355 print "# IsAlpha\n";
1356 if ($class =~ /^[LM]/) {
1357 print "not " unless $char =~ /\p{IsAlpha}/;
1358 print "ok $test\n"; $test++;
1359 print "not " if $char =~ /\P{IsAlpha}/;
1360 print "ok $test\n"; $test++;
1361 } else {
1362 print "not " if $char =~ /\p{IsAlpha}/;
1363 print "ok $test\n"; $test++;
1364 print "not " unless $char =~ /\P{IsAlpha}/;
1365 print "ok $test\n"; $test++;
1366 }
1367 print "# IsAlnum\n";
1368 if ($class =~ /^[LMN]/ && $char ne "_") {
1369 print "not " unless $char =~ /\p{IsAlnum}/;
1370 print "ok $test\n"; $test++;
1371 print "not " if $char =~ /\P{IsAlnum}/;
1372 print "ok $test\n"; $test++;
1373 } else {
1374 print "not " if $char =~ /\p{IsAlnum}/;
1375 print "ok $test\n"; $test++;
1376 print "not " unless $char =~ /\P{IsAlnum}/;
1377 print "ok $test\n"; $test++;
1378 }
1379 print "# IsASCII\n";
1380 if ($code <= 127) {
1381 print "not " unless $char =~ /\p{IsASCII}/;
1382 print "ok $test\n"; $test++;
1383 print "not " if $char =~ /\P{IsASCII}/;
1384 print "ok $test\n"; $test++;
1385 } else {
1386 print "not " if $char =~ /\p{IsASCII}/;
1387 print "ok $test\n"; $test++;
1388 print "not " unless $char =~ /\P{IsASCII}/;
1389 print "ok $test\n"; $test++;
1390 }
1391 print "# IsCntrl\n";
1392 if ($class =~ /^C/) {
1393 print "not " unless $char =~ /\p{IsCntrl}/;
1394 print "ok $test\n"; $test++;
1395 print "not " if $char =~ /\P{IsCntrl}/;
1396 print "ok $test\n"; $test++;
1397 } else {
1398 print "not " if $char =~ /\p{IsCntrl}/;
1399 print "ok $test\n"; $test++;
1400 print "not " unless $char =~ /\P{IsCntrl}/;
1401 print "ok $test\n"; $test++;
1402 }
1403 print "# IsBlank\n";
1404 if ($class =~ /^Z[lp]/ || $char eq " ") {
1405 print "not " unless $char =~ /\p{IsBlank}/;
1406 print "ok $test\n"; $test++;
1407 print "not " if $char =~ /\P{IsBlank}/;
1408 print "ok $test\n"; $test++;
1409 } else {
1410 print "not " if $char =~ /\p{IsBlank}/;
1411 print "ok $test\n"; $test++;
1412 print "not " unless $char =~ /\P{IsBlank}/;
1413 print "ok $test\n"; $test++;
1414 }
1415 print "# IsDigit\n";
1416 if ($class =~ /^Nd$/) {
1417 print "not " unless $char =~ /\p{IsDigit}/;
1418 print "ok $test\n"; $test++;
1419 print "not " if $char =~ /\P{IsDigit}/;
1420 print "ok $test\n"; $test++;
1421 } else {
1422 print "not " if $char =~ /\p{IsDigit}/;
1423 print "ok $test\n"; $test++;
1424 print "not " unless $char =~ /\P{IsDigit}/;
1425 print "ok $test\n"; $test++;
1426 }
1427 print "# IsGraph\n";
1428 if ($class =~ /^([LMNPS])|Co/) {
1429 print "not " unless $char =~ /\p{IsGraph}/;
1430 print "ok $test\n"; $test++;
1431 print "not " if $char =~ /\P{IsGraph}/;
1432 print "ok $test\n"; $test++;
1433 } else {
1434 print "not " if $char =~ /\p{IsGraph}/;
1435 print "ok $test\n"; $test++;
1436 print "not " unless $char =~ /\P{IsGraph}/;
1437 print "ok $test\n"; $test++;
1438 }
1439 print "# IsLower\n";
1440 if ($class =~ /^Ll$/) {
1441 print "not " unless $char =~ /\p{IsLower}/;
1442 print "ok $test\n"; $test++;
1443 print "not " if $char =~ /\P{IsLower}/;
1444 print "ok $test\n"; $test++;
1445 } else {
1446 print "not " if $char =~ /\p{IsLower}/;
1447 print "ok $test\n"; $test++;
1448 print "not " unless $char =~ /\P{IsLower}/;
1449 print "ok $test\n"; $test++;
1450 }
1451 print "# IsPrint\n";
1452 if ($class =~ /^([LMNPS])|Co|Zs/) {
1453 print "not " unless $char =~ /\p{IsPrint}/;
1454 print "ok $test\n"; $test++;
1455 print "not " if $char =~ /\P{IsPrint}/;
1456 print "ok $test\n"; $test++;
1457 } else {
1458 print "not " if $char =~ /\p{IsPrint}/;
1459 print "ok $test\n"; $test++;
1460 print "not " unless $char =~ /\P{IsPrint}/;
1461 print "ok $test\n"; $test++;
1462 }
1463 print "# IsPunct\n";
1464 if ($class =~ /^P/ || $char eq "_") {
1465 print "not " unless $char =~ /\p{IsPunct}/;
1466 print "ok $test\n"; $test++;
1467 print "not " if $char =~ /\P{IsPunct}/;
1468 print "ok $test\n"; $test++;
1469 } else {
1470 print "not " if $char =~ /\p{IsPunct}/;
1471 print "ok $test\n"; $test++;
1472 print "not " unless $char =~ /\P{IsPunct}/;
1473 print "ok $test\n"; $test++;
1474 }
1475 print "# IsSpace\n";
1476 if ($class =~ /^Z/ || ($code =~ /^(0009|000A|000B|000C|000D)$/)) {
1477 print "not " unless $char =~ /\p{IsSpace}/;
1478 print "ok $test\n"; $test++;
1479 print "not " if $char =~ /\P{IsSpace}/;
1480 print "ok $test\n"; $test++;
1481 } else {
1482 print "not " if $char =~ /\p{IsSpace}/;
1483 print "ok $test\n"; $test++;
1484 print "not " unless $char =~ /\P{IsSpace}/;
1485 print "ok $test\n"; $test++;
1486 }
1487 print "# IsUpper\n";
1488 if ($class =~ /^L[ut]/) {
1489 print "not " unless $char =~ /\p{IsUpper}/;
1490 print "ok $test\n"; $test++;
1491 print "not " if $char =~ /\P{IsUpper}/;
1492 print "ok $test\n"; $test++;
1493 } else {
1494 print "not " if $char =~ /\p{IsUpper}/;
1495 print "ok $test\n"; $test++;
1496 print "not " unless $char =~ /\P{IsUpper}/;
1497 print "ok $test\n"; $test++;
1498 }
1499 print "# IsWord\n";
1500 if ($class =~ /^[LMN]/ || $char eq "_") {
1501 print "not " unless $char =~ /\p{IsWord}/;
1502 print "ok $test\n"; $test++;
1503 print "not " if $char =~ /\P{IsWord}/;
1504 print "ok $test\n"; $test++;
1505 } else {
1506 print "not " if $char =~ /\p{IsWord}/;
1507 print "ok $test\n"; $test++;
1508 print "not " unless $char =~ /\P{IsWord}/;
1509 print "ok $test\n"; $test++;
1510 }
1511 }
1512}
1513
1514{
1515 $_ = "abc\x{100}\x{200}\x{300}\x{380}\x{400}defg";
1516
1517 if (/(.\x{300})./) {
1518 print "ok 576\n";
1519
1520 print "not " unless $` eq "abc\x{100}" && length($`) == 4;
1521 print "ok 577\n";
1522
1523 print "not " unless $& eq "\x{200}\x{300}\x{380}" && length($&) == 3;
1524 print "ok 578\n";
1525
1526 print "not " unless $' eq "\x{400}defg" && length($') == 5;
1527 print "ok 579\n";
1528
1529 print "not " unless $1 eq "\x{200}\x{300}" && length($1) == 2;
1530 print "ok 580\n";
a8a2fe91 1531 } else {
1532 for (576..580) { print "not ok $_\n" }
4765795a 1533 }
1534}
8269fa76 1535
1536{
1537 # bug id 20010306.008
1538
1539 $a = "a\x{1234}";
1540 # The original bug report had 'no utf8' here but that was irrelevant.
1541 $a =~ m/\w/; # used to core dump
1542
1543 print "ok 581\n";
1544}