Retract #9145.
[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 $x = "abc\ndef\n";
16
17 if ($x =~ /^abc/) {print "ok 1\n";} else {print "not ok 1\n";}
18 if ($x !~ /^def/) {print "ok 2\n";} else {print "not ok 2\n";}
19
20 $* = 1;
21 if ($x =~ /^def/) {print "ok 3\n";} else {print "not ok 3\n";}
22 $* = 0;
23
24 $_ = '123';
25 if (/^([0-9][0-9]*)/) {print "ok 4\n";} else {print "not ok 4\n";}
26
27 if ($x =~ /^xxx/) {print "not ok 5\n";} else {print "ok 5\n";}
28 if ($x !~ /^abc/) {print "not ok 6\n";} else {print "ok 6\n";}
29
30 if ($x =~ /def/) {print "ok 7\n";} else {print "not ok 7\n";}
31 if ($x !~ /def/) {print "not ok 8\n";} else {print "ok 8\n";}
32
33 if ($x !~ /.def/) {print "ok 9\n";} else {print "not ok 9\n";}
34 if ($x =~ /.def/) {print "not ok 10\n";} else {print "ok 10\n";}
35
36 if ($x =~ /\ndef/) {print "ok 11\n";} else {print "not ok 11\n";}
37 if ($x !~ /\ndef/) {print "not ok 12\n";} else {print "ok 12\n";}
38
39 $_ = 'aaabbbccc';
40 if (/(a*b*)(c*)/ && $1 eq 'aaabbb' && $2 eq 'ccc') {
41         print "ok 13\n";
42 } else {
43         print "not ok 13\n";
44 }
45 if (/(a+b+c+)/ && $1 eq 'aaabbbccc') {
46         print "ok 14\n";
47 } else {
48         print "not ok 14\n";
49 }
50
51 if (/a+b?c+/) {print "not ok 15\n";} else {print "ok 15\n";}
52
53 $_ = 'aaabccc';
54 if (/a+b?c+/) {print "ok 16\n";} else {print "not ok 16\n";}
55 if (/a*b+c*/) {print "ok 17\n";} else {print "not ok 17\n";}
56
57 $_ = 'aaaccc';
58 if (/a*b?c*/) {print "ok 18\n";} else {print "not ok 18\n";}
59 if (/a*b+c*/) {print "not ok 19\n";} else {print "ok 19\n";}
60
61 $_ = 'abcdef';
62 if (/bcd|xyz/) {print "ok 20\n";} else {print "not ok 20\n";}
63 if (/xyz|bcd/) {print "ok 21\n";} else {print "not ok 21\n";}
64
65 if (m|bc/*d|) {print "ok 22\n";} else {print "not ok 22\n";}
66
67 if (/^$_$/) {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
70 if ("ab\ncd\n" =~ /^cd/) {print "ok 24\n";} else {print "not ok 24\n";}
71 $* = 0;
72
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";
90 for (25..27) { print "ok $_\n" }
91
92 'cde' =~ /[^ab]*/;
93 'xyz' =~ //;
94 if ($& eq 'xyz') {print "ok 28\n";} else {print "not ok 28\n";}
95
96 $foo = '[^ab]*';
97 'cde' =~ /$foo/;
98 'xyz' =~ //;
99 if ($& eq 'xyz') {print "ok 29\n";} else {print "not ok 29\n";}
100
101 $foo = '[^ab]*';
102 'cde' =~ /$foo/;
103 'xyz' =~ /$null/;
104 if ($& eq 'xyz') {print "ok 30\n";} else {print "not ok 30\n";}
105
106 $_ = 'abcdefghi';
107 /def/;          # optimized up to cmd
108 if ("$`:$&:$'" eq 'abc:def:ghi') {print "ok 31\n";} else {print "not ok 31\n";}
109
110 /cde/ + 0;      # optimized only to spat
111 if ("$`:$&:$'" eq 'ab:cde:fghi') {print "ok 32\n";} else {print "not ok 32\n";}
112
113 /[d][e][f]/;    # not optimized
114 if ("$`:$&:$'" 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 / {([^}]*)}/;
118 if ($1 eq 'time for all') {print "ok 34\n";} else {print "not ok 34 $1\n";}
119
120 $_ = 'xxx {3,4}  yyy   zzz';
121 print /( {3,4})/ ? "ok 35\n" : "not ok 35\n";
122 print $1 eq '   ' ? "ok 36\n" : "not ok 36\n";
123 print /( {4,})/ ? "not ok 37\n" : "ok 37\n";
124 print /( {2,3}.)/ ? "ok 38\n" : "not ok 38\n";
125 print $1 eq '  y' ? "ok 39\n" : "not ok 39\n";
126 print /(y{2,3}.)/ ? "ok 40\n" : "not ok 40\n";
127 print $1 eq 'yyy ' ? "ok 41\n" : "not ok 41\n";
128 print /x {3,4}/ ? "not ok 42\n" : "ok 42\n";
129 print /^xxx {3,4}/ ? "not ok 43\n" : "ok 43\n";
130
131 $_ = "now is the time for all good men to come to.";
132 @words = /(\w+)/g;
133 print 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 = ();
138 while (/\w+/g) {
139     push(@words, $&);
140 }
141 print 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 = ();
146 pos = 0;
147 while (/to/g) {
148     push(@words, $&);
149 }
150 print join(':',@words) eq "to:to"
151     ? "ok 46\n"
152     : "not ok 46 `@words'\n";
153
154 pos $_ = 0;
155 @words = /to/g;
156 print join(':',@words) eq "to:to"
157     ? "ok 47\n"
158     : "not ok 47 `@words'\n";
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
174 for $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";
187 print $x eq '505550555' ? "ok 48\n" : "not ok 48 $x\n";
188
189 $xyz = 'xyz';
190 print "abc" =~ /^abc$|$xyz/ ? "ok 49\n" : "not ok 49\n";
191
192 # perl 4.009 says "unmatched ()"
193 eval '"abc" =~ /a(bc$)|$xyz/; $result = "$&:$1"';
194 print $@ eq "" ? "ok 50\n" : "not ok 50\n";
195 print $result eq "abc:bc" ? "ok 51\n" : "not ok 51\n";
196
197
198 $_="abcfooabcbar";
199 $x=/abc/g;
200 print $` eq "" ? "ok 52\n" : "not ok 52\n" if $x;
201 $x=/abc/g;
202 print $` eq "abcfoo" ? "ok 53\n" : "not ok 53\n" if $x;
203 $x=/abc/g;
204 print $x == 0 ? "ok 54\n" : "not ok 54\n";
205 pos = 0;
206 $x=/ABC/gi;
207 print $` eq "" ? "ok 55\n" : "not ok 55\n" if $x;
208 $x=/ABC/gi;
209 print $` eq "abcfoo" ? "ok 56\n" : "not ok 56\n" if $x;
210 $x=/ABC/gi;
211 print $x == 0 ? "ok 57\n" : "not ok 57\n";
212 pos = 0;
213 $x=/abc/g;
214 print $' eq "fooabcbar" ? "ok 58\n" : "not ok 58\n" if $x;
215 $x=/abc/g;
216 print $' eq "bar" ? "ok 59\n" : "not ok 59\n" if $x;
217 $_ .= '';
218 @x=/abc/g;
219 print scalar @x == 2 ? "ok 60\n" : "not ok 60\n";
220
221 $_ = "abdc";
222 pos $_ = 2;
223 /\Gc/gc;
224 print "not " if (pos $_) != 2;
225 print "ok 61\n";
226 /\Gc/g;
227 print "not " if defined pos $_;
228 print "ok 62\n";
229
230 $out = 1;
231 'abc' =~ m'a(?{ $out = 2 })b';
232 print "not " if $out != 2;
233 print "ok 63\n";
234
235 $out = 1;
236 'abc' =~ m'a(?{ $out = 3 })c';
237 print "not " if $out != 1;
238 print "ok 64\n";
239
240 $_ = 'foobar1 bar2 foobar3 barfoobar5 foobar6';
241 @out = /(?<!foo)bar./g;
242 print "not " if "@out" ne 'bar2 barf';
243 print "ok 65\n";
244
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
253 undef $@;
254 print "not " if eval q(('aaa' =~ /(a{1,$reg_infty_m})/)[0] ne 'aaa') || $@;
255 print "ok 66\n";
256
257 undef $@;
258 print "not " if eval q(('a' x $reg_infty_m) !~ /a{$reg_infty_m}/) || $@;
259 print "ok 67\n";
260
261 undef $@;
262 print "not " if eval q(('a' x ($reg_infty_m - 1)) =~ /a{$reg_infty_m}/) || $@;
263 print "ok 68\n";
264
265 undef $@;
266 eval "'aaa' =~ /a{1,$reg_infty}/";
267 print "not " if $@ !~ m%^\QQuantifier in {,} bigger than%;
268 print "ok 69\n";
269
270 eval "'aaa' =~ /a{1,$reg_infty_p}/";
271 print "not "
272         if $@ !~ m%^\QQuantifier in {,} bigger than%;
273 print "ok 70\n";
274 undef $@;
275
276 # Poke a couple more parse failures
277
278 $context = 'x' x 256;
279 eval qq("${context}y" =~ /(?<=$context)y/);
280 print "not " if $@ !~ m%^\QLookbehind longer than 255 not%;
281 print "ok 71\n";
282
283 # removed test
284 print "ok 72\n";
285
286 # Long Monsters
287 $test = 73;
288 for $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
312 for ( 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
326 sub matchit { 
327   m/
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
354    /xg;
355 }
356
357 @ans = ();
358 push @ans, $res while $res = matchit;
359
360 print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne "1 1 1";
361 print "ok $test\n";
362 $test++;
363
364 @ans = matchit;
365
366 print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne $expect;
367 print "ok $test\n";
368 $test++;
369
370 print "not " unless "abc" =~ /^(??{"a"})b/;
371 print "ok $test\n";
372 $test++;
373
374 my $matched;
375 $matched = qr/\((?:(?>[^()]+)|(??{$matched}))*\)/;
376
377 @ans = @ans1 = ();
378 push(@ans, $res), push(@ans1, $&) while $res = m/$matched/g;
379
380 print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne "1 1 1";
381 print "ok $test\n";
382 $test++;
383
384 print "# ans1='@ans1'\n# expect='$expect'\nnot " if "@ans1" ne $expect;
385 print "ok $test\n";
386 $test++;
387
388 @ans = m/$matched/g;
389
390 print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne $expect;
391 print "ok $test\n";
392 $test++;
393
394 @ans = ('a/b' =~ m%(.*/)?(.*)%);        # Stack may be bad
395 print "not " if "@ans" ne 'a/ b';
396 print "ok $test\n";
397 $test++;
398
399 $code = '{$blah = 45}';
400 $blah = 12;
401 eval { /(?$code)/ };
402 print "not " unless $@ and $@ =~ /not allowed at runtime/ and $blah == 12;
403 print "ok $test\n";
404 $test++;
405
406 for $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
418 $code = '{$blah = 45}';
419 $blah = 12;
420 eval "/(?$code)/";                      
421 print "not " if $blah != 45;
422 print "ok $test\n";
423 $test++;
424
425 $blah = 12;
426 /(?{$blah = 45})/;                      
427 print "not " if $blah != 45;
428 print "ok $test\n";
429 $test++;
430
431 $x = 'banana';
432 $x =~ /.a/g;
433 print "not " unless pos($x) == 2;
434 print "ok $test\n";
435 $test++;
436
437 $x =~ /.z/gc;
438 print "not " unless pos($x) == 2;
439 print "ok $test\n";
440 $test++;
441
442 sub f {
443     my $p = $_[0];
444     return $p;
445 }
446
447 $x =~ /.a/g;
448 print "not " unless f(pos($x)) == 4;
449 print "ok $test\n";
450 $test++;
451
452 $x = $^R = 67;
453 'foot' =~ /foo(?{$x = 12; 75})[t]/;
454 print "not " unless $^R eq '75';
455 print "ok $test\n";
456 $test++;
457
458 $x = $^R = 67;
459 'foot' =~ /foo(?{$x = 12; 75})[xy]/;
460 print "not " unless $^R eq '67' and $x eq '12';
461 print "ok $test\n";
462 $test++;
463
464 $x = $^R = 67;
465 'foot' =~ /foo(?{ $^R + 12 })((?{ $x = 12; $^R + 17 })[xy])?/;
466 print "not " unless $^R eq '79' and $x eq '12';
467 print "ok $test\n";
468 $test++;
469
470 print "not " unless qr/\b\v$/i eq '(?i-xsm:\bv$)';
471 print "ok $test\n";
472 $test++;
473
474 print "not " unless qr/\b\v$/s eq '(?s-xim:\bv$)';
475 print "ok $test\n";
476 $test++;
477
478 print "not " unless qr/\b\v$/m eq '(?m-xis:\bv$)';
479 print "ok $test\n";
480 $test++;
481
482 print "not " unless qr/\b\v$/x eq '(?x-ism:\bv$)';
483 print "ok $test\n";
484 $test++;
485
486 print "not " unless qr/\b\v$/xism eq '(?msix:\bv$)';
487 print "ok $test\n";
488 $test++;
489
490 print "not " unless qr/\b\v$/ eq '(?-xism:\bv$)';
491 print "ok $test\n";
492 $test++;
493
494 $_ = 'xabcx';
495 foreach $ans ('', 'c') {
496   /(?<=(?=a)..)((?=c)|.)/g;
497   print "# \$1  ='$1'\n# \$ans='$ans'\nnot " unless $1 eq $ans;
498   print "ok $test\n";
499   $test++;
500 }
501
502 $_ = 'a';
503 foreach $ans ('', 'a', '') {
504   /^|a|$/g;
505   print "# \$&  ='$&'\n# \$ans='$ans'\nnot " unless $& eq $ans;
506   print "ok $test\n";
507   $test++;
508 }
509
510 sub 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 }
517 prefixify('/a/b/lib/arch', "/a/b/lib", 'X/lib', 'X/lib/arch');
518 prefixify('/a/b/man/arch', "/a/b/man", 'X/man', 'X/man/arch');
519
520 $_ = 'var="foo"';
521 /(\")/;
522 print "not " unless $1 and /$1/;
523 print "ok $test\n";
524 $test++;
525
526 $a=qr/(?{++$b})/; 
527 $b = 7;
528 /$a$a/; 
529 print "not " unless $b eq '9'; 
530 print "ok $test\n";
531 $test++;
532
533 $c="$a"; 
534 /$a$a/; 
535 print "not " unless $b eq '11'; 
536 print "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
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
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 }
569
570 {
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 {
588   package aa;
589   $c = 2;
590   $::c = 3;
591   '' =~ /(?{ $c = 4 })/;
592   print "not " unless $c == 4;
593 }
594 print "ok $test\n";
595 $test++;
596 print "not " unless $c == 3;
597 print "ok $test\n";
598 $test++;  
599   
600 sub must_warn_pat {
601     my $warn_pat = shift;
602     return sub { print "not " unless $_[0] =~ /$warn_pat/ }
603 }
604
605 sub must_warn {
606     my ($warn_pat, $code) = @_;
607     local %SIG;
608     eval 'BEGIN { use warnings; $SIG{__WARN__} = $warn_pat };' . $code;
609     print "ok $test\n";
610     $test++;
611 }
612
613
614 sub make_must_warn {
615     my $warn_pat = shift;
616     return sub { must_warn(must_warn_pat($warn_pat)) }
617 }
618
619 my $for_future = make_must_warn('reserved for future extensions');
620
621 &$for_future('q(a:[b]:) =~ /[x[:foo:]]/');
622
623 #&$for_future('q(a=[b]=) =~ /[x[=foo=]]/');
624 print "ok $test\n"; $test++; # now a fatal croak
625
626 #&$for_future('q(a.[b].) =~ /[x[.foo.]]/');
627 print "ok $test\n"; $test++; # now a fatal croak
628
629 # test if failure of patterns returns empty list
630 $_ = 'aaa';
631 @_ = /bbb/;
632 print "not " if @_;
633 print "ok $test\n";
634 $test++;
635
636 @_ = /bbb/g;
637 print "not " if @_;
638 print "ok $test\n";
639 $test++;
640
641 @_ = /(bbb)/;
642 print "not " if @_;
643 print "ok $test\n";
644 $test++;
645
646 @_ = /(bbb)/g;
647 print "not " if @_;
648 print "ok $test\n";
649 $test++;
650
651 /a(?=.$)/;
652 print "not " if $#+ != 0 or $#- != 0;
653 print "ok $test\n";
654 $test++;
655
656 print "not " if $+[0] != 2 or $-[0] != 1;
657 print "ok $test\n";
658 $test++;
659
660 print "not " 
661    if defined $+[1] or defined $-[1] or defined $+[2] or defined $-[2];
662 print "ok $test\n";
663 $test++;
664
665 /a(a)(a)/;
666 print "not " if $#+ != 2 or $#- != 2;
667 print "ok $test\n";
668 $test++;
669
670 print "not " if $+[0] != 3 or $-[0] != 0;
671 print "ok $test\n";
672 $test++;
673
674 print "not " if $+[1] != 2 or $-[1] != 1;
675 print "ok $test\n";
676 $test++;
677
678 print "not " if $+[2] != 3 or $-[2] != 2;
679 print "ok $test\n";
680 $test++;
681
682 print "not " 
683    if defined $+[3] or defined $-[3] or defined $+[4] or defined $-[4];
684 print "ok $test\n";
685 $test++;
686
687 /.(a)(b)?(a)/;
688 print "not " if $#+ != 3 or $#- != 3;
689 print "ok $test\n";
690 $test++;
691
692 print "not " if $+[0] != 3 or $-[0] != 0;
693 print "ok $test\n";
694 $test++;
695
696 print "not " if $+[1] != 2 or $-[1] != 1;
697 print "ok $test\n";
698 $test++;
699
700 print "not " if $+[3] != 3 or $-[3] != 2;
701 print "ok $test\n";
702 $test++;
703
704 print "not " 
705    if defined $+[2] or defined $-[2] or defined $+[4] or defined $-[4];
706 print "ok $test\n";
707 $test++;
708
709 /.(a)/;
710 print "not " if $#+ != 1 or $#- != 1;
711 print "ok $test\n";
712 $test++;
713
714 print "not " if $+[0] != 2 or $-[0] != 0;
715 print "ok $test\n";
716 $test++;
717
718 print "not " if $+[1] != 2 or $-[1] != 1;
719 print "ok $test\n";
720 $test++;
721
722 print "not " 
723    if defined $+[2] or defined $-[2] or defined $+[3] or defined $-[3];
724 print "ok $test\n";
725 $test++;
726
727 eval { $+[0] = 13; };
728 print "not " 
729    if $@ !~ /^Modification of a read-only value attempted/;
730 print "ok $test\n";
731 $test++;
732
733 eval { $-[0] = 13; };
734 print "not " 
735    if $@ !~ /^Modification of a read-only value attempted/;
736 print "ok $test\n";
737 $test++;
738
739 eval { @+ = (7, 6, 5); };
740 print "not " 
741    if $@ !~ /^Modification of a read-only value attempted/;
742 print "ok $test\n";
743 $test++;
744
745 eval { @- = qw(foo bar); };
746 print "not " 
747    if $@ !~ /^Modification of a read-only value attempted/;
748 print "ok $test\n";
749 $test++;
750
751 /.(a)(ba*)?/;
752 print "#$#-..$#+\nnot " if $#+ != 2 or $#- != 1;
753 print "ok $test\n";
754 $test++;
755
756 $_ = 'aaa';
757 pos = 1;
758 @a = /\Ga/g;
759 print "not " unless "@a" eq "a a";
760 print "ok $test\n";
761 $test++;
762
763 $str = 'abcde';
764 pos $str = 2;
765
766 print "not " if $str =~ /^\G/;
767 print "ok $test\n";
768 $test++;
769
770 print "not " if $str =~ /^.\G/;
771 print "ok $test\n";
772 $test++;
773
774 print "not " unless $str =~ /^..\G/;
775 print "ok $test\n";
776 $test++;
777
778 print "not " if $str =~ /^...\G/;
779 print "ok $test\n";
780 $test++;
781
782 print "not " unless $str =~ /.\G./ and $& eq 'bc';
783 print "ok $test\n";
784 $test++;
785
786 print "not " unless $str =~ /\G../ and $& eq 'cd';
787 print "ok $test\n";
788 $test++;
789
790 undef $foo; undef $bar;
791 print "#'$str','$foo','$bar'\nnot "
792     unless $str =~ /b(?{$foo = $_; $bar = pos})c/ 
793         and $foo eq 'abcde' and $bar eq 2;
794 print "ok $test\n";
795 $test++;
796
797 undef $foo; undef $bar;
798 pos $str = undef;
799 print "#'$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;
802 print "ok $test\n";
803 $test++;
804
805 $_ = $str;
806
807 undef $foo; undef $bar;
808 print "#'$str','$foo','$bar'\nnot "
809     unless /b(?{$foo = $_; $bar = pos})c/ 
810         and $foo eq 'abcde' and $bar eq 2;
811 print "ok $test\n";
812 $test++;
813
814 undef $foo; undef $bar;
815 print "#'$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;
818 print "ok $test\n";
819 $test++;
820
821 undef $foo; undef $bar;
822 pos = undef;
823 1 while /b(?{$foo = $_; $bar = pos})c/g;
824 print "#'$str','$foo','$bar'\nnot "
825     unless $foo eq 'abcde' and $bar eq 2 and not defined pos;
826 print "ok $test\n";
827 $test++;
828
829 undef $foo; undef $bar;
830 $_ = 'abcde|abcde';
831 print "#'$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';
834 print "ok $test\n";
835 $test++;
836
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";
843 print "#'@res' '$_'\nnot "
844     unless "@res" eq "'a' undef 'a' 'c' 'e' undef 'a' undef 'a' 'c'";
845 print "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";
852 print "#'@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'" ;
859 print "ok $test\n";
860 $test++;
861
862 #Some more \G anchor checks
863 $foo='aabbccddeeffgg';
864
865 pos($foo)=1;
866
867 $foo=~/.\G(..)/g;
868 print "not " unless($1 eq 'ab');
869 print "ok $test\n";
870 $test++;
871
872 pos($foo) += 1;
873 $foo=~/.\G(..)/g;
874 print "not " unless($1 eq 'cc');
875 print "ok $test\n";
876 $test++;
877
878 pos($foo) += 1;
879 $foo=~/.\G(..)/g;
880 print "not " unless($1 eq 'de');
881 print "ok $test\n";
882 $test++;
883
884 print "not " unless $foo =~ /\Gef/g;
885 print "ok $test\n";
886 $test++;
887
888 undef pos $foo;
889
890 $foo=~/\G(..)/g;
891 print "not " unless($1  eq 'aa');
892 print "ok $test\n";
893 $test++;
894
895 $foo=~/\G(..)/g;
896 print "not " unless($1  eq 'bb');
897 print "ok $test\n";
898 $test++;
899
900 pos($foo)=5;
901 $foo=~/\G(..)/g;
902 print "not " unless($1  eq 'cd');
903 print "ok $test\n";
904 $test++;
905
906 $_='123x123'; 
907 @res = /(\d*|x)/g;
908 print "not " unless('123||x|123|' eq join '|', @res);
909 print "ok $test\n";
910 $test++;
911
912 # see if matching against temporaries (created via pp_helem()) is safe
913 { foo => "ok $test\n".$^X }->{foo} =~ /^(.*)\n/g;
914 print "$1\n";
915 $test++;
916
917 # See if $i work inside (?{}) in the presense of saved substrings and
918 # changing $_
919 @a = qw(foo bar);
920 @b = ();
921 s/(\w)(?{push @b, $1})/,$1,/g for @a;
922
923 print "# \@b='@b', expect 'f o o b a r'\nnot " unless("@b" eq "f o o b a r");
924 print "ok $test\n";
925 $test++;
926
927 print "not " unless("@a" eq ",f,,o,,o, ,b,,a,,r,");
928 print "ok $test\n";
929 $test++;
930
931 $brackets = qr{
932                  {  (?> [^{}]+ | (??{ $brackets }) )* }
933               }x;
934
935 "{{}" =~ $brackets;
936 print "ok $test\n";             # Did we survive?
937 $test++;
938
939 "something { long { and } hairy" =~ $brackets;
940 print "ok $test\n";             # Did we survive?
941 $test++;
942
943 "something { long { and } hairy" =~ m/((??{ $brackets }))/;
944 print "not " unless $1 eq "{ and }";
945 print "ok $test\n";
946 $test++;
947
948 $_ = "a-a\nxbb";
949 pos=1;
950 m/^-.*bb/mg and print "not ";
951 print "ok $test\n";
952 $test++;
953
954 $text = "aaXbXcc";
955 pos($text)=0;
956 $text =~ /\GXb*X/g and print 'not ';
957 print "ok $test\n";
958 $test++;
959
960 $text = "xA\n" x 500;
961 $text =~ /^\s*A/m and print 'not ';
962 print "ok $test\n";
963 $test++;
964
965 $text = "abc dbf";
966 @res = ($text =~ /.*?(b).*?\b/g);
967 "@res" eq 'b b' or print 'not ';
968 print "ok $test\n";
969 $test++;
970
971 @a = map chr,0..255;
972
973 @b = grep(/\S/,@a);
974 @c = grep(/[^\s]/,@a);
975 print "not " if "@b" ne "@c";
976 print "ok $test\n";
977 $test++;
978
979 @b = grep(/\S/,@a);
980 @c = grep(/[\S]/,@a);
981 print "not " if "@b" ne "@c";
982 print "ok $test\n";
983 $test++;
984
985 @b = grep(/\s/,@a);
986 @c = grep(/[^\S]/,@a);
987 print "not " if "@b" ne "@c";
988 print "ok $test\n";
989 $test++;
990
991 @b = grep(/\s/,@a);
992 @c = grep(/[\s]/,@a);
993 print "not " if "@b" ne "@c";
994 print "ok $test\n";
995 $test++;
996
997 @b = grep(/\D/,@a);
998 @c = grep(/[^\d]/,@a);
999 print "not " if "@b" ne "@c";
1000 print "ok $test\n";
1001 $test++;
1002
1003 @b = grep(/\D/,@a);
1004 @c = grep(/[\D]/,@a);
1005 print "not " if "@b" ne "@c";
1006 print "ok $test\n";
1007 $test++;
1008
1009 @b = grep(/\d/,@a);
1010 @c = grep(/[^\D]/,@a);
1011 print "not " if "@b" ne "@c";
1012 print "ok $test\n";
1013 $test++;
1014
1015 @b = grep(/\d/,@a);
1016 @c = grep(/[\d]/,@a);
1017 print "not " if "@b" ne "@c";
1018 print "ok $test\n";
1019 $test++;
1020
1021 @b = grep(/\W/,@a);
1022 @c = grep(/[^\w]/,@a);
1023 print "not " if "@b" ne "@c";
1024 print "ok $test\n";
1025 $test++;
1026
1027 @b = grep(/\W/,@a);
1028 @c = grep(/[\W]/,@a);
1029 print "not " if "@b" ne "@c";
1030 print "ok $test\n";
1031 $test++;
1032
1033 @b = grep(/\w/,@a);
1034 @c = grep(/[^\W]/,@a);
1035 print "not " if "@b" ne "@c";
1036 print "ok $test\n";
1037 $test++;
1038
1039 @b = grep(/\w/,@a);
1040 @c = grep(/[\w]/,@a);
1041 print "not " if "@b" ne "@c";
1042 print "ok $test\n";
1043 $test++;
1044
1045 # see if backtracking optimization works correctly
1046 "\n\n" =~ /\n  $ \n/x or print "not ";
1047 print "ok $test\n";
1048 $test++;
1049
1050 "\n\n" =~ /\n* $ \n/x or print "not ";
1051 print "ok $test\n";
1052 $test++;
1053
1054 "\n\n" =~ /\n+ $ \n/x or print "not ";
1055 print "ok $test\n";
1056 $test++;
1057
1058 [] =~ /^ARRAY/ or print "# [] \nnot ";
1059 print "ok $test\n";
1060 $test++;
1061
1062 eval << 'EOE';
1063 {
1064  package S;
1065  use overload '""' => sub { 'Object S' };
1066  sub new { bless [] }
1067 }
1068 $a = 'S'->new;
1069 EOE
1070
1071 $a and $a =~ /^Object\sS/ or print "# '$a' \nnot ";
1072 print "ok $test\n";
1073 $test++;
1074
1075 # test result of match used as match (!)
1076 'a1b' =~ ('xyz' =~ /y/) and $` eq 'a' or print "not ";
1077 print "ok $test\n";
1078 $test++;
1079
1080 'a1b' =~ ('xyz' =~ /t/) and $` eq 'a' or print "not ";
1081 print "ok $test\n";
1082 $test++;
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 }
1090 print $w ? "not " : "", "ok $test\n";
1091 $test++;
1092
1093 my %space = ( spc   => " ",
1094               tab   => "\t",
1095               cr    => "\r",
1096               lf    => "\n",
1097               ff    => "\f",
1098 # There's no \v but the vertical tabulator seems miraculously
1099 # be 11 both in ASCII and EBCDIC.
1100               vt    => chr(11),
1101               false => "space" );
1102
1103 my @space0 = sort grep { $space{$_} =~ /\s/ }          keys %space;
1104 my @space1 = sort grep { $space{$_} =~ /[[:space:]]/ } keys %space;
1105 my @space2 = sort grep { $space{$_} =~ /[[:blank:]]/ } keys %space;
1106
1107 print "not " unless "@space0" eq "cr ff lf spc tab";
1108 print "ok $test # @space0\n";
1109 $test++;
1110
1111 print "not " unless "@space1" eq "cr ff lf spc tab vt";
1112 print "ok $test # @space1\n";
1113 $test++;
1114
1115 print "not " unless "@space2" eq "spc tab";
1116 print "ok $test # @space2\n";
1117 $test++;
1118  
1119 # bugid 20001021.005 - this caused a SEGV
1120 print "not " unless undef =~ /^([^\/]*)(.*)$/;
1121 print "ok $test\n";
1122 $test++;
1123
1124 # bugid 20000731.001
1125
1126 print "not " unless "A \x{263a} B z C" =~ /A . B (??{ "z" }) C/;
1127 print "ok $test\n";
1128 $test++;
1129
1130 $_ = "a\x{100}b";
1131 if (/(.)(\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}";
1159 if (/(\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 }
1171 if (/(\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 }
1183
1184 {
1185   # japhy -- added 03/03/2001
1186   () = (my $str = "abc") =~ /(...)/;
1187   $str = "def";
1188   print "not " if $1 ne "abc";
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
1196 if ("\x8e" =~ /[\x89-\x91]/) {
1197   print "ok 242\n";
1198 } else {
1199   print "not ok 242\n";
1200 }
1201
1202 if ("\xce" =~ /[\xc9-\xd1]/) {
1203   print "ok 243\n";
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.
1212 if (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   }
1227 }
1228
1229 print "not " unless "\x{ab}" =~ /\x{ab}/;
1230 print "ok 246\n";
1231
1232 print "not " unless "\x{abcd}" =~ /\x{abcd}/;
1233 print "ok 247\n";
1234
1235 {
1236     # bug id 20001008.001
1237
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"; 
1531     } else {
1532         for (576..580) { print "not ok $_\n" }
1533     }
1534 }
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 }