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