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