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