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.
13 eval 'use Config'; # Defaults assumed if this fails
17 if ($x =~ /^abc/) {print "ok 1\n";} else {print "not ok 1\n";}
18 if ($x !~ /^def/) {print "ok 2\n";} else {print "not ok 2\n";}
21 if ($x =~ /^def/) {print "ok 3\n";} else {print "not ok 3\n";}
25 if (/^([0-9][0-9]*)/) {print "ok 4\n";} else {print "not ok 4\n";}
27 if ($x =~ /^xxx/) {print "not ok 5\n";} else {print "ok 5\n";}
28 if ($x !~ /^abc/) {print "not ok 6\n";} else {print "ok 6\n";}
30 if ($x =~ /def/) {print "ok 7\n";} else {print "not ok 7\n";}
31 if ($x !~ /def/) {print "not ok 8\n";} else {print "ok 8\n";}
33 if ($x !~ /.def/) {print "ok 9\n";} else {print "not ok 9\n";}
34 if ($x =~ /.def/) {print "not ok 10\n";} else {print "ok 10\n";}
36 if ($x =~ /\ndef/) {print "ok 11\n";} else {print "not ok 11\n";}
37 if ($x !~ /\ndef/) {print "not ok 12\n";} else {print "ok 12\n";}
40 if (/(a*b*)(c*)/ && $1 eq 'aaabbb' && $2 eq 'ccc') {
45 if (/(a+b+c+)/ && $1 eq 'aaabbbccc') {
51 if (/a+b?c+/) {print "not ok 15\n";} else {print "ok 15\n";}
54 if (/a+b?c+/) {print "ok 16\n";} else {print "not ok 16\n";}
55 if (/a*b+c*/) {print "ok 17\n";} else {print "not ok 17\n";}
58 if (/a*b?c*/) {print "ok 18\n";} else {print "not ok 18\n";}
59 if (/a*b+c*/) {print "not ok 19\n";} else {print "ok 19\n";}
62 if (/bcd|xyz/) {print "ok 20\n";} else {print "not ok 20\n";}
63 if (/xyz|bcd/) {print "ok 21\n";} else {print "not ok 21\n";}
65 if (m|bc/*d|) {print "ok 22\n";} else {print "not ok 22\n";}
67 if (/^$_$/) {print "ok 23\n";} else {print "not ok 23\n";}
69 $* = 1; # test 3 only tested the optimized version--this one is for real
70 if ("ab\ncd\n" =~ /^cd/) {print "ok 24\n";} else {print "not ok 24\n";}
77 @XXX = ('ok 25','not ok 25', 'ok 26','not ok 26','not ok 27');
78 while ($_ = shift(@XXX)) {
79 ?(.*)? && (print $1,"\n");
81 /not ok 26/ && reset 'X';
84 while (($key,$val) = each(%XXX)) {
93 if ($& eq 'xyz') {print "ok 28\n";} else {print "not ok 28\n";}
98 if ($& eq 'xyz') {print "ok 29\n";} else {print "not ok 29\n";}
103 if ($& eq 'xyz') {print "ok 30\n";} else {print "not ok 30\n";}
106 /def/; # optimized up to cmd
107 if ("$`:$&:$'" eq 'abc:def:ghi') {print "ok 31\n";} else {print "not ok 31\n";}
109 /cde/ + 0; # optimized only to spat
110 if ("$`:$&:$'" eq 'ab:cde:fghi') {print "ok 32\n";} else {print "not ok 32\n";}
112 /[d][e][f]/; # not optimized
113 if ("$`:$&:$'" eq 'abc:def:ghi') {print "ok 33\n";} else {print "not ok 33\n";}
115 $_ = 'now is the {time for all} good men to come to.';
117 if ($1 eq 'time for all') {print "ok 34\n";} else {print "not ok 34 $1\n";}
119 $_ = 'xxx {3,4} yyy zzz';
120 print /( {3,4})/ ? "ok 35\n" : "not ok 35\n";
121 print $1 eq ' ' ? "ok 36\n" : "not ok 36\n";
122 print /( {4,})/ ? "not ok 37\n" : "ok 37\n";
123 print /( {2,3}.)/ ? "ok 38\n" : "not ok 38\n";
124 print $1 eq ' y' ? "ok 39\n" : "not ok 39\n";
125 print /(y{2,3}.)/ ? "ok 40\n" : "not ok 40\n";
126 print $1 eq 'yyy ' ? "ok 41\n" : "not ok 41\n";
127 print /x {3,4}/ ? "not ok 42\n" : "ok 42\n";
128 print /^xxx {3,4}/ ? "not ok 43\n" : "ok 43\n";
130 $_ = "now is the time for all good men to come to.";
132 print join(':',@words) eq "now:is:the:time:for:all:good:men:to:come:to"
140 print join(':',@words) eq "now:is:the:time:for:all:good:men:to:come:to"
149 print join(':',@words) eq "to:to"
151 : "not ok 46 `@words'\n";
155 print join(':',@words) eq "to:to"
157 : "not ok 47 `@words'\n";
171 $t1=$t2=$t3=$t4=$t5=$t6=$t7=$t8=$t9=0;
185 $x = "$t1$t2$t3$t4$t5$t6$t7$t8$t9";
186 print $x eq '505550555' ? "ok 48\n" : "not ok 48 $x\n";
189 print "abc" =~ /^abc$|$xyz/ ? "ok 49\n" : "not ok 49\n";
191 # perl 4.009 says "unmatched ()"
192 eval '"abc" =~ /a(bc$)|$xyz/; $result = "$&:$1"';
193 print $@ eq "" ? "ok 50\n" : "not ok 50\n";
194 print $result eq "abc:bc" ? "ok 51\n" : "not ok 51\n";
199 print $` eq "" ? "ok 52\n" : "not ok 52\n" if $x;
201 print $` eq "abcfoo" ? "ok 53\n" : "not ok 53\n" if $x;
203 print $x == 0 ? "ok 54\n" : "not ok 54\n";
206 print $` eq "" ? "ok 55\n" : "not ok 55\n" if $x;
208 print $` eq "abcfoo" ? "ok 56\n" : "not ok 56\n" if $x;
210 print $x == 0 ? "ok 57\n" : "not ok 57\n";
213 print $' eq "fooabcbar" ? "ok 58\n" : "not ok 58\n" if $x;
215 print $' eq "bar" ? "ok 59\n" : "not ok 59\n" if $x;
218 print scalar @x == 2 ? "ok 60\n" : "not ok 60\n";
223 print "not " if (pos $_) != 2;
226 print "not " if defined pos $_;
230 'abc' =~ m'a(?{ $out = 2 })b';
231 print "not " if $out != 2;
235 'abc' =~ m'a(?{ $out = 3 })c';
236 print "not " if $out != 1;
239 $_ = 'foobar1 bar2 foobar3 barfoobar5 foobar6';
240 @out = /(?<!foo)bar./g;
241 print "not " if "@out" ne 'bar2 barf';
244 # Tests which depend on REG_INFTY
245 $reg_infty = defined $Config{reg_infty} ? $Config{reg_infty} : 32767;
246 $reg_infty_m = $reg_infty - 1; $reg_infty_p = $reg_infty + 1;
248 # As well as failing if the pattern matches do unexpected things, the
249 # next three tests will fail if you should have picked up a lower-than-
250 # default value for $reg_infty from Config.pm, but have not.
253 print "not " if eval q(('aaa' =~ /(a{1,$reg_infty_m})/)[0] ne 'aaa') || $@;
257 print "not " if eval q(('a' x $reg_infty_m) !~ /a{$reg_infty_m}/) || $@;
261 print "not " if eval q(('a' x ($reg_infty_m - 1)) =~ /a{$reg_infty_m}/) || $@;
265 eval "'aaa' =~ /a{1,$reg_infty}/";
266 print "not " if $@ !~ m%^\QQuantifier in {,} bigger than%;
269 eval "'aaa' =~ /a{1,$reg_infty_p}/";
271 if $@ !~ m%^\QQuantifier in {,} bigger than%;
275 # Poke a couple more parse failures
277 $context = 'x' x 256;
278 eval qq("${context}y" =~ /(?<=$context)y/);
279 print "not " if $@ !~ m%^\QLookbehind longer than 255 not%;
287 for $l (125, 140, 250, 270, 300000, 30) { # Ordered to free memory
289 print "# length=$l\nnot " unless "ba$a=" =~ /a$a=/;
293 print "not " if "b$a=" =~ /a$a=/;
298 # 20000 nodes, each taking 3 words per string, and 1 per branch
299 $long_constant_len = join '|', 12120 .. 32645;
300 $long_var_len = join '|', 8120 .. 28645;
301 %ans = ( 'ax13876y25677lbc' => 1,
302 'ax13876y25677mcb' => 0, # not b.
303 'ax13876y35677nbc' => 0, # Num too big
304 'ax13876y25677y21378obc' => 1,
305 'ax13876y25677y21378zbc' => 0, # Not followed by [k-o]
306 'ax13876y25677y21378y21378kbc' => 1,
307 'ax13876y25677y21378y21378kcb' => 0, # Not b.
308 'ax13876y25677y21378y21378y21378kbc' => 0, # 5 runs
312 print "# const-len `$_' not => $ans{$_}\nnot "
313 if $ans{$_} xor /a(?=([yx]($long_constant_len)){2,4}[k-o]).*b./o;
316 print "# var-len `$_' not => $ans{$_}\nnot "
317 if $ans{$_} xor /a(?=([yx]($long_var_len)){2,4}[k-o]).*b./o;
322 $_ = " a (bla()) and x(y b((l)u((e))) and b(l(e)e)e";
323 $expect = "(bla()) ((l)u((e))) (l(e)e)";
329 (?{ $c = 1 }) # Initialize
331 (?(?{ $c == 0 }) # PREVIOUS iteration was OK, stop the loop
333 ) # Fail: will unwind one iteration back
336 [^()]+ # Match a big chunk
339 ) # Do not try to match subchunks
347 )+ # This may not match with different subblocks
352 ) # Otherwise the chunk 1 may succeed with $c>0
357 push @ans, $res while $res = matchit;
359 print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne "1 1 1";
365 print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne $expect;
369 print "not " unless "abc" =~ /^(??{"a"})b/;
374 $matched = qr/\((?:(?>[^()]+)|(??{$matched}))*\)/;
377 push(@ans, $res), push(@ans1, $&) while $res = m/$matched/g;
379 print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne "1 1 1";
383 print "# ans1='@ans1'\n# expect='$expect'\nnot " if "@ans1" ne $expect;
389 print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne $expect;
393 @ans = ('a/b' =~ m%(.*/)?(.*)%); # Stack may be bad
394 print "not " if "@ans" ne 'a/ b';
398 $code = '{$blah = 45}';
401 print "not " unless $@ and $@ =~ /not allowed at runtime/ and $blah == 12;
405 for $code ('{$blah = 45}','=xx') {
407 $res = eval { "xx" =~ /(?$code)/o };
408 if ($code eq '=xx') {
409 print "#'$@','$res','$blah'\nnot " unless not $@ and $res;
411 print "#'$@','$res','$blah'\nnot " unless $@ and $@ =~ /not allowed at runtime/ and $blah == 12;
417 $code = '{$blah = 45}';
420 print "not " if $blah != 45;
426 print "not " if $blah != 45;
432 print "not " unless pos($x) == 2;
437 print "not " unless pos($x) == 2;
447 print "not " unless f(pos($x)) == 4;
452 'foot' =~ /foo(?{$x = 12; 75})[t]/;
453 print "not " unless $^R eq '75';
458 'foot' =~ /foo(?{$x = 12; 75})[xy]/;
459 print "not " unless $^R eq '67' and $x eq '12';
464 'foot' =~ /foo(?{ $^R + 12 })((?{ $x = 12; $^R + 17 })[xy])?/;
465 print "not " unless $^R eq '79' and $x eq '12';
469 print "not " unless qr/\b\v$/i eq '(?i-xsm:\bv$)';
473 print "not " unless qr/\b\v$/s eq '(?s-xim:\bv$)';
477 print "not " unless qr/\b\v$/m eq '(?m-xis:\bv$)';
481 print "not " unless qr/\b\v$/x eq '(?x-ism:\bv$)';
485 print "not " unless qr/\b\v$/xism eq '(?msix:\bv$)';
489 print "not " unless qr/\b\v$/ eq '(?-xism:\bv$)';
494 foreach $ans ('', 'c') {
495 /(?<=(?=a)..)((?=c)|.)/g;
496 print "# \$1 ='$1'\n# \$ans='$ans'\nnot " unless $1 eq $ans;
502 foreach $ans ('', 'a', '') {
504 print "# \$& ='$&'\n# \$ans='$ans'\nnot " unless $& eq $ans;
510 my($v,$a,$b,$res) = @_;
512 print "not " unless $res eq $v;
516 prefixify('/a/b/lib/arch', "/a/b/lib", 'X/lib', 'X/lib/arch');
517 prefixify('/a/b/man/arch', "/a/b/man", 'X/man', 'X/man/arch');
521 print "not " unless $1 and /$1/;
528 print "not " unless $b eq '9';
534 print "not " unless $b eq '11';
541 print "not " unless $b eq '14';
549 my $lex_res = ($lex_b =~ qr/$lex_b(?{ $lex_c = $lex_a++ })/);
550 print "not " unless $lex_res eq '1';
553 print "not " unless $lex_a eq '44';
556 print "not " unless $lex_c eq '43';
562 $match = eval { /$a$c$a/ };
564 unless $b eq '14' and $@ =~ /Eval-group not allowed/ and not $match;
574 my $lex_res = ($lex_b =~ qr/17(?{ $lex_c = $lex_a++ })/);
575 print "not " unless $lex_res eq '1';
578 print "not " unless $lex_a eq '44';
581 print "not " unless $lex_c eq '43';
590 '' =~ /(?{ $c = 4 })/;
591 print "not " unless $c == 4;
595 print "not " unless $c == 3;
600 my $warn_pat = shift;
601 return sub { print "not " unless $_[0] =~ /$warn_pat/ }
605 my ($warn_pat, $code) = @_;
607 eval 'BEGIN { use warnings; $SIG{__WARN__} = $warn_pat };' . $code;
614 my $warn_pat = shift;
615 return sub { must_warn(must_warn_pat($warn_pat)) }
618 my $for_future = make_must_warn('reserved for future extensions');
620 &$for_future('q(a:[b]:) =~ /[x[:foo:]]/');
622 #&$for_future('q(a=[b]=) =~ /[x[=foo=]]/');
623 print "ok $test\n"; $test++; # now a fatal croak
625 #&$for_future('q(a.[b].) =~ /[x[.foo.]]/');
626 print "ok $test\n"; $test++; # now a fatal croak
628 # test if failure of patterns returns empty list
651 print "not " if $#+ != 0 or $#- != 0;
655 print "not " if $+[0] != 2 or $-[0] != 1;
660 if defined $+[1] or defined $-[1] or defined $+[2] or defined $-[2];
665 print "not " if $#+ != 2 or $#- != 2;
669 print "not " if $+[0] != 3 or $-[0] != 0;
673 print "not " if $+[1] != 2 or $-[1] != 1;
677 print "not " if $+[2] != 3 or $-[2] != 2;
682 if defined $+[3] or defined $-[3] or defined $+[4] or defined $-[4];
687 print "not " if $#+ != 3 or $#- != 3;
691 print "not " if $+[0] != 3 or $-[0] != 0;
695 print "not " if $+[1] != 2 or $-[1] != 1;
699 print "not " if $+[3] != 3 or $-[3] != 2;
704 if defined $+[2] or defined $-[2] or defined $+[4] or defined $-[4];
709 print "not " if $#+ != 1 or $#- != 1;
713 print "not " if $+[0] != 2 or $-[0] != 0;
717 print "not " if $+[1] != 2 or $-[1] != 1;
722 if defined $+[2] or defined $-[2] or defined $+[3] or defined $-[3];
726 eval { $+[0] = 13; };
728 if $@ !~ /^Modification of a read-only value attempted/;
732 eval { $-[0] = 13; };
734 if $@ !~ /^Modification of a read-only value attempted/;
738 eval { @+ = (7, 6, 5); };
740 if $@ !~ /^Modification of a read-only value attempted/;
744 eval { @- = qw(foo bar); };
746 if $@ !~ /^Modification of a read-only value attempted/;
751 print "#$#-..$#+\nnot " if $#+ != 2 or $#- != 1;
758 print "not " unless "@a" eq "a a";
765 print "not " if $str =~ /^\G/;
769 print "not " if $str =~ /^.\G/;
773 print "not " unless $str =~ /^..\G/;
777 print "not " if $str =~ /^...\G/;
781 print "not " unless $str =~ /.\G./ and $& eq 'bc';
785 print "not " unless $str =~ /\G../ and $& eq 'cd';
789 undef $foo; undef $bar;
790 print "#'$str','$foo','$bar'\nnot "
791 unless $str =~ /b(?{$foo = $_; $bar = pos})c/
792 and $foo eq 'abcde' and $bar eq 2;
796 undef $foo; undef $bar;
798 print "#'$str','$foo','$bar'\nnot "
799 unless $str =~ /b(?{$foo = $_; $bar = pos})c/g
800 and $foo eq 'abcde' and $bar eq 2 and pos $str eq 3;
806 undef $foo; undef $bar;
807 print "#'$str','$foo','$bar'\nnot "
808 unless /b(?{$foo = $_; $bar = pos})c/
809 and $foo eq 'abcde' and $bar eq 2;
813 undef $foo; undef $bar;
814 print "#'$str','$foo','$bar'\nnot "
815 unless /b(?{$foo = $_; $bar = pos})c/g
816 and $foo eq 'abcde' and $bar eq 2 and pos eq 3;
820 undef $foo; undef $bar;
822 1 while /b(?{$foo = $_; $bar = pos})c/g;
823 print "#'$str','$foo','$bar'\nnot "
824 unless $foo eq 'abcde' and $bar eq 2 and not defined pos;
828 undef $foo; undef $bar;
830 print "#'$str','$foo','$bar','$_'\nnot "
831 unless s/b(?{$foo = $_; $bar = pos})c/x/g and $foo eq 'abcde|abcde'
832 and $bar eq 8 and $_ eq 'axde|axde';
839 @dummy = /([ace]).(?{push @res, $1,$2})([ce])(?{push @res, $1,$2})/g;
840 @res = map {defined $_ ? "'$_'" : 'undef'} @res;
842 print "#'@res' '$_'\nnot "
843 unless "@res" eq "'a' undef 'a' 'c' 'e' undef 'a' undef 'a' 'c'";
848 @dummy = /([ace]).(?{push @res, $`,$&,$'})([ce])(?{push @res, $`,$&,$'})/g;
849 @res = map {defined $_ ? "'$_'" : 'undef'} @res;
851 print "#'@res' '$_'\nnot "
853 "'' 'ab' 'cde|abcde' " .
854 "'' 'abc' 'de|abcde' " .
855 "'abcd' 'e|' 'abcde' " .
856 "'abcde|' 'ab' 'cde' " .
857 "'abcde|' 'abc' 'de'" ;
861 #Some more \G anchor checks
862 $foo='aabbccddeeffgg';
867 print "not " unless($1 eq 'ab');
873 print "not " unless($1 eq 'cc');
879 print "not " unless($1 eq 'de');
883 print "not " unless $foo =~ /\Gef/g;
890 print "not " unless($1 eq 'aa');
895 print "not " unless($1 eq 'bb');
901 print "not " unless($1 eq 'cd');
907 print "not " unless('123||x|123|' eq join '|', @res);
911 # see if matching against temporaries (created via pp_helem()) is safe
912 { foo => "ok $test\n".$^X }->{foo} =~ /^(.*)\n/g;
916 # See if $i work inside (?{}) in the presense of saved substrings and
920 s/(\w)(?{push @b, $1})/,$1,/g for @a;
922 print "# \@b='@b', expect 'f o o b a r'\nnot " unless("@b" eq "f o o b a r");
926 print "not " unless("@a" eq ",f,,o,,o, ,b,,a,,r,");
931 { (?> [^{}]+ | (??{ $brackets }) )* }
935 print "ok $test\n"; # Did we survive?
938 "something { long { and } hairy" =~ $brackets;
939 print "ok $test\n"; # Did we survive?
942 "something { long { and } hairy" =~ m/((??{ $brackets }))/;
943 print "not " unless $1 eq "{ and }";
949 m/^-.*bb/mg and print "not ";
955 $text =~ /\GXb*X/g and print 'not ';
959 $text = "xA\n" x 500;
960 $text =~ /^\s*A/m and print 'not ';
965 @res = ($text =~ /.*?(b).*?\b/g);
966 "@res" eq 'b b' or print 'not ';
973 @c = grep(/[^\s]/,@a);
974 print "not " if "@b" ne "@c";
979 @c = grep(/[\S]/,@a);
980 print "not " if "@b" ne "@c";
985 @c = grep(/[^\S]/,@a);
986 print "not " if "@b" ne "@c";
991 @c = grep(/[\s]/,@a);
992 print "not " if "@b" ne "@c";
997 @c = grep(/[^\d]/,@a);
998 print "not " if "@b" ne "@c";
1003 @c = grep(/[\D]/,@a);
1004 print "not " if "@b" ne "@c";
1009 @c = grep(/[^\D]/,@a);
1010 print "not " if "@b" ne "@c";
1015 @c = grep(/[\d]/,@a);
1016 print "not " if "@b" ne "@c";
1021 @c = grep(/[^\w]/,@a);
1022 print "not " if "@b" ne "@c";
1027 @c = grep(/[\W]/,@a);
1028 print "not " if "@b" ne "@c";
1033 @c = grep(/[^\W]/,@a);
1034 print "not " if "@b" ne "@c";
1039 @c = grep(/[\w]/,@a);
1040 print "not " if "@b" ne "@c";
1044 # see if backtracking optimization works correctly
1045 "\n\n" =~ /\n $ \n/x or print "not ";
1049 "\n\n" =~ /\n* $ \n/x or print "not ";
1053 "\n\n" =~ /\n+ $ \n/x or print "not ";
1057 [] =~ /^ARRAY/ or print "# [] \nnot ";
1064 use overload '""' => sub { 'Object S' };
1065 sub new { bless [] }
1070 $a and $a =~ /^Object\sS/ or print "# '$a' \nnot ";
1074 # test result of match used as match (!)
1075 'a1b' =~ ('xyz' =~ /y/) and $` eq 'a' or print "not ";
1079 'a1b' =~ ('xyz' =~ /t/) and $` eq 'a' or print "not ";
1085 local $SIG{__WARN__} = sub { $w = 1 };
1087 $w = 1 if ("1\n" x 102) =~ /^\s*\n/m;
1089 print $w ? "not " : "", "ok $test\n";
1092 my %space = ( spc => " ",
1097 # There's no \v but the vertical tabulator seems miraculously
1098 # be 11 both in ASCII and EBCDIC.
1102 my @space0 = sort grep { $space{$_} =~ /\s/ } keys %space;
1103 my @space1 = sort grep { $space{$_} =~ /[[:space:]]/ } keys %space;
1104 my @space2 = sort grep { $space{$_} =~ /[[:blank:]]/ } keys %space;
1106 print "not " unless "@space0" eq "cr ff lf spc tab";
1107 print "ok $test # @space0\n";
1110 print "not " unless "@space1" eq "cr ff lf spc tab vt";
1111 print "ok $test # @space1\n";
1114 print "not " unless "@space2" eq "spc tab";
1115 print "ok $test # @space2\n";
1118 # bugid 20001021.005 - this caused a SEGV
1119 print "not " unless undef =~ /^([^\/]*)(.*)$/;
1123 # bugid 20000731.001
1125 print "not " unless "A \x{263a} B z C" =~ /A . B (??{ "z" }) C/;
1130 if (/(.)(\C)(\C)(.)/) {
1135 print "not ok 233\n";
1140 print "not ok 234\n";
1145 print "not ok 235\n";
1150 print "not ok 236\n";
1154 print "not ok $_\n";
1163 print "not ok 238\n";
1167 print "not ok $_\n";
1175 print "not ok 240\n";
1179 print "not ok $_\n";
1184 # japhy -- added 03/03/2001
1185 () = (my $str = "abc") =~ /(...)/;
1187 print "not " if $1 ne "abc";
1191 # The 242 and 243 go with the 244 and 245.
1192 # The trick is that in EBCDIC the explicit numeric range should match
1193 # (as also in non-EBCDIC) but the explicit alphabetic range should not match.
1195 if ("\x8e" =~ /[\x89-\x91]/) {
1198 print "not ok 242\n";
1201 if ("\xce" =~ /[\xc9-\xd1]/) {
1204 print "not ok 243\n";
1207 # In most places these tests would succeed since \x8e does not
1208 # in most character sets match 'i' or 'j' nor would \xce match
1209 # 'I' or 'J', but strictly speaking these tests are here for
1210 # the good of EBCDIC, so let's test these only there.
1211 if (ord('i') == 0x89 && ord('J') == 0xd1) { # EBCDIC
1212 if ("\x8e" !~ /[i-j]/) {
1215 print "not ok 244\n";
1217 if ("\xce" !~ /[I-J]/) {
1220 print "not ok 245\n";
1224 print "ok $_ # Skip: not EBCDIC\n";
1228 print "not " unless "\x{ab}" =~ /\x{ab}/;
1231 print "not " unless "\x{abcd}" =~ /\x{abcd}/;
1235 # bug id 20001008.001
1238 my @x = ("stra\337e 138","stra\337e 138");
1240 s/(\d+)\s*([\w\-]+)/$1 . uc $2/e;
1241 my($latin) = /^(.+)(?:\s+\d)/;
1242 print $latin eq "stra\337e" ? "ok $test\n" : # 248,249
1243 "#latin[$latin]\nnot ok $test\n";
1245 $latin =~ s/stra\337e/straße/; # \303\237 after the 2nd a
1247 $latin =~ s!(s)tr(?:aß|s+e)!$1tr.!; # \303\237 after the a
1252 print "not " unless "ba\xd4c" =~ /([a\xd4]+)/ && $1 eq "a\xd4";
1255 print "not " unless "ba\xd4c" =~ /([a\xd4]+)/ && $1 eq "a\x{d4}";
1258 print "not " unless "ba\x{d4}c" =~ /([a\xd4]+)/ && $1 eq "a\x{d4}";
1261 print "not " unless "ba\x{d4}c" =~ /([a\xd4]+)/ && $1 eq "a\xd4";
1264 print "not " unless "ba\xd4c" =~ /([a\x{d4}]+)/ && $1 eq "a\xd4";
1267 print "not " unless "ba\xd4c" =~ /([a\x{d4}]+)/ && $1 eq "a\x{d4}";
1270 print "not " unless "ba\x{d4}c" =~ /([a\x{d4}]+)/ && $1 eq "a\x{d4}";
1273 print "not " unless "ba\x{d4}c" =~ /([a\x{d4}]+)/ && $1 eq "a\xd4";
1278 # the first half of 20001028.003
1281 my ($Y) = $X =~ /(.*)/;
1282 print "not " unless $Y eq v1448 && length($Y) == 1;
1289 my $X = "Szab\x{f3},Bal\x{e1}zs";
1291 $Y =~ s/(B)/$1/ for 0..3;
1292 print "not " unless $Y eq $X && $X eq "Szab\x{f3},Bal\x{e1}zs";
1297 # the second half of 20001028.003
1299 $X =~ s/^/chr(1488)/e;
1300 print "not " unless length $X == 1 && ord($X) == 1488;
1311 print "not " unless $x eq "\x{100}B" && length($x) == 2;
1316 # bug id 20001230.002
1318 print "not " unless "École" =~ /^\C\C(.)/ && $1 eq 'c';
1321 print "not " unless "École" =~ /^\C\C(c)/;
1326 my $test = 264; # till 575
1328 use charnames ':full';
1330 # This is far from complete testing, there are dozens of character
1331 # classes in Unicode. The mixing of literals and \N{...} is
1332 # intentional so that in non-Latin-1 places we test the native
1333 # characters, not the Unicode code points.
1337 "\N{CYRILLIC SMALL LETTER A}" => 'Ll',
1339 "\N{GREEK CAPITAL LETTER ALPHA}" => 'Lu',
1340 "\N{HIRAGANA LETTER SMALL A}" => 'Lo',
1341 "\N{COMBINING GRAVE ACCENT}" => 'Mn',
1343 "\N{ARABIC-INDIC DIGIT ZERO}" => 'Nd',
1350 for my $char (keys %s) {
1351 my $class = $s{$char};
1352 my $code = sprintf("%04x", ord($char));
1353 printf "# 0x$code\n";
1354 print "# IsAlpha\n";
1355 if ($class =~ /^[LM]/) {
1356 print "not " unless $char =~ /\p{IsAlpha}/;
1357 print "ok $test\n"; $test++;
1358 print "not " if $char =~ /\P{IsAlpha}/;
1359 print "ok $test\n"; $test++;
1361 print "not " if $char =~ /\p{IsAlpha}/;
1362 print "ok $test\n"; $test++;
1363 print "not " unless $char =~ /\P{IsAlpha}/;
1364 print "ok $test\n"; $test++;
1366 print "# IsAlnum\n";
1367 if ($class =~ /^[LMN]/ && $char ne "_") {
1368 print "not " unless $char =~ /\p{IsAlnum}/;
1369 print "ok $test\n"; $test++;
1370 print "not " if $char =~ /\P{IsAlnum}/;
1371 print "ok $test\n"; $test++;
1373 print "not " if $char =~ /\p{IsAlnum}/;
1374 print "ok $test\n"; $test++;
1375 print "not " unless $char =~ /\P{IsAlnum}/;
1376 print "ok $test\n"; $test++;
1378 print "# IsASCII\n";
1380 print "not " unless $char =~ /\p{IsASCII}/;
1381 print "ok $test\n"; $test++;
1382 print "not " if $char =~ /\P{IsASCII}/;
1383 print "ok $test\n"; $test++;
1385 print "not " if $char =~ /\p{IsASCII}/;
1386 print "ok $test\n"; $test++;
1387 print "not " unless $char =~ /\P{IsASCII}/;
1388 print "ok $test\n"; $test++;
1390 print "# IsCntrl\n";
1391 if ($class =~ /^C/) {
1392 print "not " unless $char =~ /\p{IsCntrl}/;
1393 print "ok $test\n"; $test++;
1394 print "not " if $char =~ /\P{IsCntrl}/;
1395 print "ok $test\n"; $test++;
1397 print "not " if $char =~ /\p{IsCntrl}/;
1398 print "ok $test\n"; $test++;
1399 print "not " unless $char =~ /\P{IsCntrl}/;
1400 print "ok $test\n"; $test++;
1402 print "# IsBlank\n";
1403 if ($class =~ /^Z[lp]/ || $char eq " ") {
1404 print "not " unless $char =~ /\p{IsBlank}/;
1405 print "ok $test\n"; $test++;
1406 print "not " if $char =~ /\P{IsBlank}/;
1407 print "ok $test\n"; $test++;
1409 print "not " if $char =~ /\p{IsBlank}/;
1410 print "ok $test\n"; $test++;
1411 print "not " unless $char =~ /\P{IsBlank}/;
1412 print "ok $test\n"; $test++;
1414 print "# IsDigit\n";
1415 if ($class =~ /^Nd$/) {
1416 print "not " unless $char =~ /\p{IsDigit}/;
1417 print "ok $test\n"; $test++;
1418 print "not " if $char =~ /\P{IsDigit}/;
1419 print "ok $test\n"; $test++;
1421 print "not " if $char =~ /\p{IsDigit}/;
1422 print "ok $test\n"; $test++;
1423 print "not " unless $char =~ /\P{IsDigit}/;
1424 print "ok $test\n"; $test++;
1426 print "# IsGraph\n";
1427 if ($class =~ /^([LMNPS])|Co/) {
1428 print "not " unless $char =~ /\p{IsGraph}/;
1429 print "ok $test\n"; $test++;
1430 print "not " if $char =~ /\P{IsGraph}/;
1431 print "ok $test\n"; $test++;
1433 print "not " if $char =~ /\p{IsGraph}/;
1434 print "ok $test\n"; $test++;
1435 print "not " unless $char =~ /\P{IsGraph}/;
1436 print "ok $test\n"; $test++;
1438 print "# IsLower\n";
1439 if ($class =~ /^Ll$/) {
1440 print "not " unless $char =~ /\p{IsLower}/;
1441 print "ok $test\n"; $test++;
1442 print "not " if $char =~ /\P{IsLower}/;
1443 print "ok $test\n"; $test++;
1445 print "not " if $char =~ /\p{IsLower}/;
1446 print "ok $test\n"; $test++;
1447 print "not " unless $char =~ /\P{IsLower}/;
1448 print "ok $test\n"; $test++;
1450 print "# IsPrint\n";
1451 if ($class =~ /^([LMNPS])|Co|Zs/) {
1452 print "not " unless $char =~ /\p{IsPrint}/;
1453 print "ok $test\n"; $test++;
1454 print "not " if $char =~ /\P{IsPrint}/;
1455 print "ok $test\n"; $test++;
1457 print "not " if $char =~ /\p{IsPrint}/;
1458 print "ok $test\n"; $test++;
1459 print "not " unless $char =~ /\P{IsPrint}/;
1460 print "ok $test\n"; $test++;
1462 print "# IsPunct\n";
1463 if ($class =~ /^P/ || $char eq "_") {
1464 print "not " unless $char =~ /\p{IsPunct}/;
1465 print "ok $test\n"; $test++;
1466 print "not " if $char =~ /\P{IsPunct}/;
1467 print "ok $test\n"; $test++;
1469 print "not " if $char =~ /\p{IsPunct}/;
1470 print "ok $test\n"; $test++;
1471 print "not " unless $char =~ /\P{IsPunct}/;
1472 print "ok $test\n"; $test++;
1474 print "# IsSpace\n";
1475 if ($class =~ /^Z/ || ($code =~ /^(0009|000A|000B|000C|000D)$/)) {
1476 print "not " unless $char =~ /\p{IsSpace}/;
1477 print "ok $test\n"; $test++;
1478 print "not " if $char =~ /\P{IsSpace}/;
1479 print "ok $test\n"; $test++;
1481 print "not " if $char =~ /\p{IsSpace}/;
1482 print "ok $test\n"; $test++;
1483 print "not " unless $char =~ /\P{IsSpace}/;
1484 print "ok $test\n"; $test++;
1486 print "# IsUpper\n";
1487 if ($class =~ /^L[ut]/) {
1488 print "not " unless $char =~ /\p{IsUpper}/;
1489 print "ok $test\n"; $test++;
1490 print "not " if $char =~ /\P{IsUpper}/;
1491 print "ok $test\n"; $test++;
1493 print "not " if $char =~ /\p{IsUpper}/;
1494 print "ok $test\n"; $test++;
1495 print "not " unless $char =~ /\P{IsUpper}/;
1496 print "ok $test\n"; $test++;
1499 if ($class =~ /^[LMN]/ || $char eq "_") {
1500 print "not " unless $char =~ /\p{IsWord}/;
1501 print "ok $test\n"; $test++;
1502 print "not " if $char =~ /\P{IsWord}/;
1503 print "ok $test\n"; $test++;
1505 print "not " if $char =~ /\p{IsWord}/;
1506 print "ok $test\n"; $test++;
1507 print "not " unless $char =~ /\P{IsWord}/;
1508 print "ok $test\n"; $test++;
1514 $_ = "abc\x{100}\x{200}\x{300}\x{380}\x{400}defg";
1516 if (/(.\x{300})./) {
1519 print "not " unless $` eq "abc\x{100}" && length($`) == 4;
1522 print "not " unless $& eq "\x{200}\x{300}\x{380}" && length($&) == 3;
1525 print "not " unless $' eq "\x{400}defg" && length($') == 5;
1528 print "not " unless $1 eq "\x{200}\x{300}" && length($1) == 2;
1531 for (576..580) { print "not ok $_\n" }
1536 # bug id 20010306.008
1539 # The original bug report had 'no utf8' here but that was irrelevant.
1540 $a =~ m/\w/; # used to core dump