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