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