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)) {
91 if ($& eq 'xyz') {print "ok 28\n";} else {print "not ok 28\n";}
96 if ($& eq 'xyz') {print "ok 29\n";} else {print "not ok 29\n";}
101 if ($& eq 'xyz') {print "ok 30\n";} else {print "not ok 30\n";}
104 /def/; # optimized up to cmd
105 if ("$`:$&:$'" eq 'abc:def:ghi') {print "ok 31\n";} else {print "not ok 31\n";}
107 /cde/ + 0; # optimized only to spat
108 if ("$`:$&:$'" eq 'ab:cde:fghi') {print "ok 32\n";} else {print "not ok 32\n";}
110 /[d][e][f]/; # not optimized
111 if ("$`:$&:$'" eq 'abc:def:ghi') {print "ok 33\n";} else {print "not ok 33\n";}
113 $_ = 'now is the {time for all} good men to come to.';
115 if ($1 eq 'time for all') {print "ok 34\n";} else {print "not ok 34 $1\n";}
117 $_ = 'xxx {3,4} yyy zzz';
118 print /( {3,4})/ ? "ok 35\n" : "not ok 35\n";
119 print $1 eq ' ' ? "ok 36\n" : "not ok 36\n";
120 print /( {4,})/ ? "not ok 37\n" : "ok 37\n";
121 print /( {2,3}.)/ ? "ok 38\n" : "not ok 38\n";
122 print $1 eq ' y' ? "ok 39\n" : "not ok 39\n";
123 print /(y{2,3}.)/ ? "ok 40\n" : "not ok 40\n";
124 print $1 eq 'yyy ' ? "ok 41\n" : "not ok 41\n";
125 print /x {3,4}/ ? "not ok 42\n" : "ok 42\n";
126 print /^xxx {3,4}/ ? "not ok 43\n" : "ok 43\n";
128 $_ = "now is the time for all good men to come to.";
130 print join(':',@words) eq "now:is:the:time:for:all:good:men:to:come:to"
138 print join(':',@words) eq "now:is:the:time:for:all:good:men:to:come:to"
147 print join(':',@words) eq "to:to"
149 : "not ok 46 `@words'\n";
153 print join(':',@words) eq "to:to"
155 : "not ok 47 `@words'\n";
169 $t1=$t2=$t3=$t4=$t5=$t6=$t7=$t8=$t9=0;
183 $x = "$t1$t2$t3$t4$t5$t6$t7$t8$t9";
184 print $x eq '505550555' ? "ok 48\n" : "not ok 48 $x\n";
187 print "abc" =~ /^abc$|$xyz/ ? "ok 49\n" : "not ok 49\n";
189 # perl 4.009 says "unmatched ()"
190 eval '"abc" =~ /a(bc$)|$xyz/; $result = "$&:$1"';
191 print $@ eq "" ? "ok 50\n" : "not ok 50\n";
192 print $result eq "abc:bc" ? "ok 51\n" : "not ok 51\n";
197 print $` eq "" ? "ok 52\n" : "not ok 52\n" if $x;
199 print $` eq "abcfoo" ? "ok 53\n" : "not ok 53\n" if $x;
201 print $x == 0 ? "ok 54\n" : "not ok 54\n";
204 print $` eq "" ? "ok 55\n" : "not ok 55\n" if $x;
206 print $` eq "abcfoo" ? "ok 56\n" : "not ok 56\n" if $x;
208 print $x == 0 ? "ok 57\n" : "not ok 57\n";
211 print $' eq "fooabcbar" ? "ok 58\n" : "not ok 58\n" if $x;
213 print $' eq "bar" ? "ok 59\n" : "not ok 59\n" if $x;
216 print scalar @x == 2 ? "ok 60\n" : "not ok 60\n";
221 print "not " if (pos $_) != 2;
224 print "not " if defined pos $_;
228 'abc' =~ m'a(?{ $out = 2 })b';
229 print "not " if $out != 2;
233 'abc' =~ m'a(?{ $out = 3 })c';
234 print "not " if $out != 1;
237 $_ = 'foobar1 bar2 foobar3 barfoobar5 foobar6';
238 @out = /(?<!foo)bar./g;
239 print "not " if "@out" ne 'bar2 barf';
242 # Tests which depend on REG_INFTY
243 $reg_infty = defined $Config{reg_infty} ? $Config{reg_infty} : 32767;
244 $reg_infty_m = $reg_infty - 1; $reg_infty_p = $reg_infty + 1;
246 # As well as failing if the pattern matches do unexpected things, the
247 # next three tests will fail if you should have picked up a lower-than-
248 # default value for $reg_infty from Config.pm, but have not.
251 print "not " if eval q(('aaa' =~ /(a{1,$reg_infty_m})/)[0] ne 'aaa') || $@;
255 print "not " if eval q(('a' x $reg_infty_m) !~ /a{$reg_infty_m}/) || $@;
259 print "not " if eval q(('a' x ($reg_infty_m - 1)) =~ /a{$reg_infty_m}/) || $@;
263 eval "'aaa' =~ /a{1,$reg_infty}/";
264 print "not " if $@ !~ m%^\QQuantifier in {,} bigger than%;
267 eval "'aaa' =~ /a{1,$reg_infty_p}/";
269 if $@ !~ m%^\QQuantifier in {,} bigger than%;
273 # Poke a couple more parse failures
275 $context = 'x' x 256;
276 eval qq("${context}y" =~ /(?<=$context)y/);
277 print "not " if $@ !~ m%^\QLookbehind longer than 255 not%;
285 for $l (125, 140, 250, 270, 300000, 30) { # Ordered to free memory
287 print "# length=$l\nnot " unless "ba$a=" =~ /a$a=/;
291 print "not " if "b$a=" =~ /a$a=/;
296 # 20000 nodes, each taking 3 words per string, and 1 per branch
297 $long_constant_len = join '|', 12120 .. 32645;
298 $long_var_len = join '|', 8120 .. 28645;
299 %ans = ( 'ax13876y25677lbc' => 1,
300 'ax13876y25677mcb' => 0, # not b.
301 'ax13876y35677nbc' => 0, # Num too big
302 'ax13876y25677y21378obc' => 1,
303 'ax13876y25677y21378zbc' => 0, # Not followed by [k-o]
304 'ax13876y25677y21378y21378kbc' => 1,
305 'ax13876y25677y21378y21378kcb' => 0, # Not b.
306 'ax13876y25677y21378y21378y21378kbc' => 0, # 5 runs
310 print "# const-len `$_' not => $ans{$_}\nnot "
311 if $ans{$_} xor /a(?=([yx]($long_constant_len)){2,4}[k-o]).*b./o;
314 print "# var-len `$_' not => $ans{$_}\nnot "
315 if $ans{$_} xor /a(?=([yx]($long_var_len)){2,4}[k-o]).*b./o;
320 $_ = " a (bla()) and x(y b((l)u((e))) and b(l(e)e)e";
321 $expect = "(bla()) ((l)u((e))) (l(e)e)";
327 (?{ $c = 1 }) # Initialize
329 (?(?{ $c == 0 }) # PREVIOUS iteration was OK, stop the loop
331 ) # Fail: will unwind one iteration back
334 [^()]+ # Match a big chunk
337 ) # Do not try to match subchunks
345 )+ # This may not match with different subblocks
350 ) # Otherwise the chunk 1 may succeed with $c>0
355 push @ans, $res while $res = matchit;
357 print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne "1 1 1";
363 print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne $expect;
367 print "not " unless "abc" =~ /^(??{"a"})b/;
372 $matched = qr/\((?:(?>[^()]+)|(??{$matched}))*\)/;
375 push(@ans, $res), push(@ans1, $&) while $res = m/$matched/g;
377 print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne "1 1 1";
381 print "# ans1='@ans1'\n# expect='$expect'\nnot " if "@ans1" ne $expect;
387 print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne $expect;
391 @ans = ('a/b' =~ m%(.*/)?(.*)%); # Stack may be bad
392 print "not " if "@ans" ne 'a/ b';
396 $code = '{$blah = 45}';
399 print "not " unless $@ and $@ =~ /not allowed at runtime/ and $blah == 12;
403 for $code ('{$blah = 45}','=xx') {
405 $res = eval { "xx" =~ /(?$code)/o };
406 if ($code eq '=xx') {
407 print "#'$@','$res','$blah'\nnot " unless not $@ and $res;
409 print "#'$@','$res','$blah'\nnot " unless $@ and $@ =~ /not allowed at runtime/ and $blah == 12;
415 $code = '{$blah = 45}';
418 print "not " if $blah != 45;
424 print "not " if $blah != 45;
430 print "not " unless pos($x) == 2;
435 print "not " unless pos($x) == 2;
445 print "not " unless f(pos($x)) == 4;
450 'foot' =~ /foo(?{$x = 12; 75})[t]/;
451 print "not " unless $^R eq '75';
456 'foot' =~ /foo(?{$x = 12; 75})[xy]/;
457 print "not " unless $^R eq '67' and $x eq '12';
462 'foot' =~ /foo(?{ $^R + 12 })((?{ $x = 12; $^R + 17 })[xy])?/;
463 print "not " unless $^R eq '79' and $x eq '12';
467 print "not " unless qr/\b\v$/i eq '(?i-xsm:\bv$)';
471 print "not " unless qr/\b\v$/s eq '(?s-xim:\bv$)';
475 print "not " unless qr/\b\v$/m eq '(?m-xis:\bv$)';
479 print "not " unless qr/\b\v$/x eq '(?x-ism:\bv$)';
483 print "not " unless qr/\b\v$/xism eq '(?msix:\bv$)';
487 print "not " unless qr/\b\v$/ eq '(?-xism:\bv$)';
492 foreach $ans ('', 'c') {
493 /(?<=(?=a)..)((?=c)|.)/g;
494 print "# \$1 ='$1'\n# \$ans='$ans'\nnot " unless $1 eq $ans;
500 foreach $ans ('', 'a', '') {
502 print "# \$& ='$&'\n# \$ans='$ans'\nnot " unless $& eq $ans;
508 my($v,$a,$b,$res) = @_;
510 print "not " unless $res eq $v;
514 prefixify('/a/b/lib/arch', "/a/b/lib", 'X/lib', 'X/lib/arch');
515 prefixify('/a/b/man/arch', "/a/b/man", 'X/man', 'X/man/arch');
519 print "not " unless $1 and /$1/;
526 print "not " unless $b eq '9';
532 print "not " unless $b eq '11';
539 print "not " unless $b eq '14';
547 my $lex_res = ($lex_b =~ qr/$lex_b(?{ $lex_c = $lex_a++ })/);
548 print "not " unless $lex_res eq '1';
551 print "not " unless $lex_a eq '44';
554 print "not " unless $lex_c eq '43';
560 $match = eval { /$a$c$a/ };
562 unless $b eq '14' and $@ =~ /Eval-group not allowed/ and not $match;
572 my $lex_res = ($lex_b =~ qr/17(?{ $lex_c = $lex_a++ })/);
573 print "not " unless $lex_res eq '1';
576 print "not " unless $lex_a eq '44';
579 print "not " unless $lex_c eq '43';
588 '' =~ /(?{ $c = 4 })/;
589 print "not " unless $c == 4;
593 print "not " unless $c == 3;
598 my $warn_pat = shift;
599 return sub { print "not " unless $_[0] =~ /$warn_pat/ }
603 my ($warn_pat, $code) = @_;
605 eval 'BEGIN { use warnings; $SIG{__WARN__} = $warn_pat };' . $code;
612 my $warn_pat = shift;
613 return sub { must_warn(must_warn_pat($warn_pat)) }
616 my $for_future = make_must_warn('reserved for future extensions');
618 &$for_future('q(a:[b]:) =~ /[x[:foo:]]/');
620 #&$for_future('q(a=[b]=) =~ /[x[=foo=]]/');
621 print "ok $test\n"; $test++; # now a fatal croak
623 #&$for_future('q(a.[b].) =~ /[x[.foo.]]/');
624 print "ok $test\n"; $test++; # now a fatal croak
626 # test if failure of patterns returns empty list
649 print "not " if $#+ != 0 or $#- != 0;
653 print "not " if $+[0] != 2 or $-[0] != 1;
658 if defined $+[1] or defined $-[1] or defined $+[2] or defined $-[2];
663 print "not " if $#+ != 2 or $#- != 2;
667 print "not " if $+[0] != 3 or $-[0] != 0;
671 print "not " if $+[1] != 2 or $-[1] != 1;
675 print "not " if $+[2] != 3 or $-[2] != 2;
680 if defined $+[3] or defined $-[3] or defined $+[4] or defined $-[4];
685 print "not " if $#+ != 3 or $#- != 3;
689 print "not " if $+[0] != 3 or $-[0] != 0;
693 print "not " if $+[1] != 2 or $-[1] != 1;
697 print "not " if $+[3] != 3 or $-[3] != 2;
702 if defined $+[2] or defined $-[2] or defined $+[4] or defined $-[4];
707 print "not " if $#+ != 1 or $#- != 1;
711 print "not " if $+[0] != 2 or $-[0] != 0;
715 print "not " if $+[1] != 2 or $-[1] != 1;
720 if defined $+[2] or defined $-[2] or defined $+[3] or defined $-[3];
724 eval { $+[0] = 13; };
726 if $@ !~ /^Modification of a read-only value attempted/;
730 eval { $-[0] = 13; };
732 if $@ !~ /^Modification of a read-only value attempted/;
736 eval { @+ = (7, 6, 5); };
738 if $@ !~ /^Modification of a read-only value attempted/;
742 eval { @- = qw(foo bar); };
744 if $@ !~ /^Modification of a read-only value attempted/;
749 print "#$#-..$#+\nnot " if $#+ != 2 or $#- != 1;
756 print "not " unless "@a" eq "a a";
763 print "not " if $str =~ /^\G/;
767 print "not " if $str =~ /^.\G/;
771 print "not " unless $str =~ /^..\G/;
775 print "not " if $str =~ /^...\G/;
779 print "not " unless $str =~ /.\G./ and $& eq 'bc';
783 print "not " unless $str =~ /\G../ and $& eq 'cd';
787 undef $foo; undef $bar;
788 print "#'$str','$foo','$bar'\nnot "
789 unless $str =~ /b(?{$foo = $_; $bar = pos})c/
790 and $foo eq 'abcde' and $bar eq 2;
794 undef $foo; undef $bar;
796 print "#'$str','$foo','$bar'\nnot "
797 unless $str =~ /b(?{$foo = $_; $bar = pos})c/g
798 and $foo eq 'abcde' and $bar eq 2 and pos $str eq 3;
804 undef $foo; undef $bar;
805 print "#'$str','$foo','$bar'\nnot "
806 unless /b(?{$foo = $_; $bar = pos})c/
807 and $foo eq 'abcde' and $bar eq 2;
811 undef $foo; undef $bar;
812 print "#'$str','$foo','$bar'\nnot "
813 unless /b(?{$foo = $_; $bar = pos})c/g
814 and $foo eq 'abcde' and $bar eq 2 and pos eq 3;
818 undef $foo; undef $bar;
820 1 while /b(?{$foo = $_; $bar = pos})c/g;
821 print "#'$str','$foo','$bar'\nnot "
822 unless $foo eq 'abcde' and $bar eq 2 and not defined pos;
826 undef $foo; undef $bar;
828 print "#'$str','$foo','$bar','$_'\nnot "
829 unless s/b(?{$foo = $_; $bar = pos})c/x/g and $foo eq 'abcde|abcde'
830 and $bar eq 8 and $_ eq 'axde|axde';
837 @dummy = /([ace]).(?{push @res, $1,$2})([ce])(?{push @res, $1,$2})/g;
838 @res = map {defined $_ ? "'$_'" : 'undef'} @res;
840 print "#'@res' '$_'\nnot "
841 unless "@res" eq "'a' undef 'a' 'c' 'e' undef 'a' undef 'a' 'c'";
846 @dummy = /([ace]).(?{push @res, $`,$&,$'})([ce])(?{push @res, $`,$&,$'})/g;
847 @res = map {defined $_ ? "'$_'" : 'undef'} @res;
849 print "#'@res' '$_'\nnot "
851 "'' 'ab' 'cde|abcde' " .
852 "'' 'abc' 'de|abcde' " .
853 "'abcd' 'e|' 'abcde' " .
854 "'abcde|' 'ab' 'cde' " .
855 "'abcde|' 'abc' 'de'" ;
859 #Some more \G anchor checks
860 $foo='aabbccddeeffgg';
865 print "not " unless($1 eq 'ab');
871 print "not " unless($1 eq 'cc');
877 print "not " unless($1 eq 'de');
881 print "not " unless $foo =~ /\Gef/g;
888 print "not " unless($1 eq 'aa');
893 print "not " unless($1 eq 'bb');
899 print "not " unless($1 eq 'cd');
905 print "not " unless('123||x|123|' eq join '|', @res);
909 # see if matching against temporaries (created via pp_helem()) is safe
910 { foo => "ok $test\n".$^X }->{foo} =~ /^(.*)\n/g;
914 # See if $i work inside (?{}) in the presense of saved substrings and
918 s/(\w)(?{push @b, $1})/,$1,/g for @a;
920 print "# \@b='@b', expect 'f o o b a r'\nnot " unless("@b" eq "f o o b a r");
924 print "not " unless("@a" eq ",f,,o,,o, ,b,,a,,r,");
929 { (?> [^{}]+ | (??{ $brackets }) )* }
933 print "ok $test\n"; # Did we survive?
936 "something { long { and } hairy" =~ $brackets;
937 print "ok $test\n"; # Did we survive?
940 "something { long { and } hairy" =~ m/((??{ $brackets }))/;
941 print "not " unless $1 eq "{ and }";
947 m/^-.*bb/mg and print "not ";
953 $text =~ /\GXb*X/g and print 'not ';
957 $text = "xA\n" x 500;
958 $text =~ /^\s*A/m and print 'not ';
963 @res = ($text =~ /.*?(b).*?\b/g);
964 "@res" eq 'b b' or print 'not ';
971 @c = grep(/[^\s]/,@a);
972 print "not " if "@b" ne "@c";
977 @c = grep(/[\S]/,@a);
978 print "not " if "@b" ne "@c";
983 @c = grep(/[^\S]/,@a);
984 print "not " if "@b" ne "@c";
989 @c = grep(/[\s]/,@a);
990 print "not " if "@b" ne "@c";
995 @c = grep(/[^\d]/,@a);
996 print "not " if "@b" ne "@c";
1001 @c = grep(/[\D]/,@a);
1002 print "not " if "@b" ne "@c";
1007 @c = grep(/[^\D]/,@a);
1008 print "not " if "@b" ne "@c";
1013 @c = grep(/[\d]/,@a);
1014 print "not " if "@b" ne "@c";
1019 @c = grep(/[^\w]/,@a);
1020 print "not " if "@b" ne "@c";
1025 @c = grep(/[\W]/,@a);
1026 print "not " if "@b" ne "@c";
1031 @c = grep(/[^\W]/,@a);
1032 print "not " if "@b" ne "@c";
1037 @c = grep(/[\w]/,@a);
1038 print "not " if "@b" ne "@c";
1042 # see if backtracking optimization works correctly
1043 "\n\n" =~ /\n $ \n/x or print "not ";
1047 "\n\n" =~ /\n* $ \n/x or print "not ";
1051 "\n\n" =~ /\n+ $ \n/x or print "not ";
1055 [] =~ /^ARRAY/ or print "# [] \nnot ";
1062 use overload '""' => sub { 'Object S' };
1063 sub new { bless [] }
1068 $a and $a =~ /^Object\sS/ or print "# '$a' \nnot ";
1072 # test result of match used as match (!)
1073 'a1b' =~ ('xyz' =~ /y/) and $` eq 'a' or print "not ";
1077 'a1b' =~ ('xyz' =~ /t/) and $` eq 'a' or print "not ";
1083 local $SIG{__WARN__} = sub { $w = 1 };
1085 $w = 1 if ("1\n" x 102) =~ /^\s*\n/m;
1087 print $w ? "not " : "", "ok $test\n";
1090 my %space = ( spc => " ",
1095 # There's no \v but the vertical tabulator seems miraculously
1096 # be 11 both in ASCII and EBCDIC.
1100 my @space0 = sort grep { $space{$_} =~ /\s/ } keys %space;
1101 my @space1 = sort grep { $space{$_} =~ /[[:space:]]/ } keys %space;
1102 my @space2 = sort grep { $space{$_} =~ /[[:blank:]]/ } keys %space;
1104 print "not " unless "@space0" eq "cr ff lf spc tab";
1105 print "ok $test # @space0\n";
1108 print "not " unless "@space1" eq "cr ff lf spc tab vt";
1109 print "ok $test # @space1\n";
1112 print "not " unless "@space2" eq "spc tab";
1113 print "ok $test # @space2\n";
1116 # bugid 20001021.005 - this caused a SEGV
1117 print "not " unless undef =~ /^([^\/]*)(.*)$/;
1121 # bugid 20000731.001
1123 print "not " unless "A \x{263a} B z C" =~ /A . B (??{ "z" }) C/;
1128 if (/(.)(\C)(\C)(.)/) {
1133 print "not ok 233\n";
1138 print "not ok 234\n";
1143 print "not ok 235\n";
1148 print "not ok 236\n";
1152 print "not ok $_\n";
1161 print "not ok 238\n";
1165 print "not ok $_\n";
1173 print "not ok 240\n";
1177 print "not ok $_\n";
1182 # japhy -- added 03/03/2001
1183 () = (my $str = "abc") =~ /(...)/;
1185 print "not " if $1 ne "abc";
1189 # The 242 and 243 go with the 244 and 245.
1190 # The trick is that in EBCDIC the explicit numeric range should match
1191 # (as also in non-EBCDIC) but the explicit alphabetic range should not match.
1193 if ("\x8e" =~ /[\x89-\x91]/) {
1196 print "not ok 242\n";
1199 if ("\xce" =~ /[\xc9-\xd1]/) {
1202 print "not ok 243\n";
1205 # In most places these tests would succeed since \x8e does not
1206 # in most character sets match 'i' or 'j' nor would \xce match
1207 # 'I' or 'J', but strictly speaking these tests are here for
1208 # the good of EBCDIC, so let's test these only there.
1209 if (ord('i') == 0x89 && ord('J') == 0xd1) { # EBCDIC
1210 if ("\x8e" !~ /[i-j]/) {
1213 print "not ok 244\n";
1215 if ("\xce" !~ /[I-J]/) {
1218 print "not ok 245\n";
1222 print "ok $_ # Skip: not EBCDIC\n";
1226 print "not " unless "\x{ab}" =~ /\x{ab}/;
1229 print "not " unless "\x{abcd}" =~ /\x{abcd}/;
1233 # bug id 20001008.001
1236 my @x = ("stra\337e 138","stra\337e 138");
1238 s/(\d+)\s*([\w\-]+)/$1 . uc $2/e;
1239 my($latin) = /^(.+)(?:\s+\d)/;
1240 print $latin eq "stra\337e" ? "ok $test\n" : # 248,249
1241 "#latin[$latin]\nnot ok $test\n";
1243 $latin =~ s/stra\337e/straße/; # \303\237 after the 2nd a
1245 $latin =~ s!(s)tr(?:aß|s+e)!$1tr.!; # \303\237 after the a
1250 print "not " unless "ba\xd4c" =~ /([a\xd4]+)/ && $1 eq "a\xd4";
1253 print "not " unless "ba\xd4c" =~ /([a\xd4]+)/ && $1 eq "a\x{d4}";
1256 print "not " unless "ba\x{d4}c" =~ /([a\xd4]+)/ && $1 eq "a\x{d4}";
1259 print "not " unless "ba\x{d4}c" =~ /([a\xd4]+)/ && $1 eq "a\xd4";
1262 print "not " unless "ba\xd4c" =~ /([a\x{d4}]+)/ && $1 eq "a\xd4";
1265 print "not " unless "ba\xd4c" =~ /([a\x{d4}]+)/ && $1 eq "a\x{d4}";
1268 print "not " unless "ba\x{d4}c" =~ /([a\x{d4}]+)/ && $1 eq "a\x{d4}";
1271 print "not " unless "ba\x{d4}c" =~ /([a\x{d4}]+)/ && $1 eq "a\xd4";
1276 # the first half of 20001028.003
1279 my ($Y) = $X =~ /(.*)/;
1280 print "not " unless $Y eq v1448 && length($Y) == 1;
1287 my $X = "Szab\x{f3},Bal\x{e1}zs";
1289 $Y =~ s/(B)/$1/ for 0..3;
1290 print "not " unless $Y eq $X && $X eq "Szab\x{f3},Bal\x{e1}zs";
1295 # the second half of 20001028.003
1297 $X =~ s/^/chr(1488)/e;
1298 print "not " unless length $X == 1 && ord($X) == 1488;
1309 print "not " unless $x eq "\x{100}B" && length($x) == 2;
1314 # bug id 20001230.002
1316 print "not " unless "École" =~ /^\C\C(.)/ && $1 eq 'c';
1319 print "not " unless "École" =~ /^\C\C(c)/;
1324 my $test = 264; # till 575
1326 use charnames ':full';
1328 # This is far from complete testing, there are dozens of character
1329 # classes in Unicode. The mixing of literals and \N{...} is
1330 # intentional so that in non-Latin-1 places we test the native
1331 # characters, not the Unicode code points.
1335 "\N{CYRILLIC SMALL LETTER A}" => 'Ll',
1337 "\N{GREEK CAPITAL LETTER ALPHA}" => 'Lu',
1338 "\N{HIRAGANA LETTER SMALL A}" => 'Lo',
1339 "\N{COMBINING GRAVE ACCENT}" => 'Mn',
1341 "\N{ARABIC-INDIC DIGIT ZERO}" => 'Nd',
1348 for my $char (keys %s) {
1349 my $class = $s{$char};
1350 my $code = sprintf("%04x", ord($char));
1351 printf "# 0x$code\n";
1352 print "# IsAlpha\n";
1353 if ($class =~ /^[LM]/) {
1354 print "not " unless $char =~ /\p{IsAlpha}/;
1355 print "ok $test\n"; $test++;
1356 print "not " if $char =~ /\P{IsAlpha}/;
1357 print "ok $test\n"; $test++;
1359 print "not " if $char =~ /\p{IsAlpha}/;
1360 print "ok $test\n"; $test++;
1361 print "not " unless $char =~ /\P{IsAlpha}/;
1362 print "ok $test\n"; $test++;
1364 print "# IsAlnum\n";
1365 if ($class =~ /^[LMN]/ && $char ne "_") {
1366 print "not " unless $char =~ /\p{IsAlnum}/;
1367 print "ok $test\n"; $test++;
1368 print "not " if $char =~ /\P{IsAlnum}/;
1369 print "ok $test\n"; $test++;
1371 print "not " if $char =~ /\p{IsAlnum}/;
1372 print "ok $test\n"; $test++;
1373 print "not " unless $char =~ /\P{IsAlnum}/;
1374 print "ok $test\n"; $test++;
1376 print "# IsASCII\n";
1378 print "not " unless $char =~ /\p{IsASCII}/;
1379 print "ok $test\n"; $test++;
1380 print "not " if $char =~ /\P{IsASCII}/;
1381 print "ok $test\n"; $test++;
1383 print "not " if $char =~ /\p{IsASCII}/;
1384 print "ok $test\n"; $test++;
1385 print "not " unless $char =~ /\P{IsASCII}/;
1386 print "ok $test\n"; $test++;
1388 print "# IsCntrl\n";
1389 if ($class =~ /^C/) {
1390 print "not " unless $char =~ /\p{IsCntrl}/;
1391 print "ok $test\n"; $test++;
1392 print "not " if $char =~ /\P{IsCntrl}/;
1393 print "ok $test\n"; $test++;
1395 print "not " if $char =~ /\p{IsCntrl}/;
1396 print "ok $test\n"; $test++;
1397 print "not " unless $char =~ /\P{IsCntrl}/;
1398 print "ok $test\n"; $test++;
1400 print "# IsBlank\n";
1401 if ($class =~ /^Z[lp]/ || $char eq " ") {
1402 print "not " unless $char =~ /\p{IsBlank}/;
1403 print "ok $test\n"; $test++;
1404 print "not " if $char =~ /\P{IsBlank}/;
1405 print "ok $test\n"; $test++;
1407 print "not " if $char =~ /\p{IsBlank}/;
1408 print "ok $test\n"; $test++;
1409 print "not " unless $char =~ /\P{IsBlank}/;
1410 print "ok $test\n"; $test++;
1412 print "# IsDigit\n";
1413 if ($class =~ /^Nd$/) {
1414 print "not " unless $char =~ /\p{IsDigit}/;
1415 print "ok $test\n"; $test++;
1416 print "not " if $char =~ /\P{IsDigit}/;
1417 print "ok $test\n"; $test++;
1419 print "not " if $char =~ /\p{IsDigit}/;
1420 print "ok $test\n"; $test++;
1421 print "not " unless $char =~ /\P{IsDigit}/;
1422 print "ok $test\n"; $test++;
1424 print "# IsGraph\n";
1425 if ($class =~ /^([LMNPS])|Co/) {
1426 print "not " unless $char =~ /\p{IsGraph}/;
1427 print "ok $test\n"; $test++;
1428 print "not " if $char =~ /\P{IsGraph}/;
1429 print "ok $test\n"; $test++;
1431 print "not " if $char =~ /\p{IsGraph}/;
1432 print "ok $test\n"; $test++;
1433 print "not " unless $char =~ /\P{IsGraph}/;
1434 print "ok $test\n"; $test++;
1436 print "# IsLower\n";
1437 if ($class =~ /^Ll$/) {
1438 print "not " unless $char =~ /\p{IsLower}/;
1439 print "ok $test\n"; $test++;
1440 print "not " if $char =~ /\P{IsLower}/;
1441 print "ok $test\n"; $test++;
1443 print "not " if $char =~ /\p{IsLower}/;
1444 print "ok $test\n"; $test++;
1445 print "not " unless $char =~ /\P{IsLower}/;
1446 print "ok $test\n"; $test++;
1448 print "# IsPrint\n";
1449 if ($class =~ /^([LMNPS])|Co|Zs/) {
1450 print "not " unless $char =~ /\p{IsPrint}/;
1451 print "ok $test\n"; $test++;
1452 print "not " if $char =~ /\P{IsPrint}/;
1453 print "ok $test\n"; $test++;
1455 print "not " if $char =~ /\p{IsPrint}/;
1456 print "ok $test\n"; $test++;
1457 print "not " unless $char =~ /\P{IsPrint}/;
1458 print "ok $test\n"; $test++;
1460 print "# IsPunct\n";
1461 if ($class =~ /^P/ || $char eq "_") {
1462 print "not " unless $char =~ /\p{IsPunct}/;
1463 print "ok $test\n"; $test++;
1464 print "not " if $char =~ /\P{IsPunct}/;
1465 print "ok $test\n"; $test++;
1467 print "not " if $char =~ /\p{IsPunct}/;
1468 print "ok $test\n"; $test++;
1469 print "not " unless $char =~ /\P{IsPunct}/;
1470 print "ok $test\n"; $test++;
1472 print "# IsSpace\n";
1473 if ($class =~ /^Z/ || ($code =~ /^(0009|000A|000B|000C|000D)$/)) {
1474 print "not " unless $char =~ /\p{IsSpace}/;
1475 print "ok $test\n"; $test++;
1476 print "not " if $char =~ /\P{IsSpace}/;
1477 print "ok $test\n"; $test++;
1479 print "not " if $char =~ /\p{IsSpace}/;
1480 print "ok $test\n"; $test++;
1481 print "not " unless $char =~ /\P{IsSpace}/;
1482 print "ok $test\n"; $test++;
1484 print "# IsUpper\n";
1485 if ($class =~ /^L[ut]/) {
1486 print "not " unless $char =~ /\p{IsUpper}/;
1487 print "ok $test\n"; $test++;
1488 print "not " if $char =~ /\P{IsUpper}/;
1489 print "ok $test\n"; $test++;
1491 print "not " if $char =~ /\p{IsUpper}/;
1492 print "ok $test\n"; $test++;
1493 print "not " unless $char =~ /\P{IsUpper}/;
1494 print "ok $test\n"; $test++;
1497 if ($class =~ /^[LMN]/ || $char eq "_") {
1498 print "not " unless $char =~ /\p{IsWord}/;
1499 print "ok $test\n"; $test++;
1500 print "not " if $char =~ /\P{IsWord}/;
1501 print "ok $test\n"; $test++;
1503 print "not " if $char =~ /\p{IsWord}/;
1504 print "ok $test\n"; $test++;
1505 print "not " unless $char =~ /\P{IsWord}/;
1506 print "ok $test\n"; $test++;
1512 $_ = "abc\x{100}\x{200}\x{300}\x{380}\x{400}defg";
1514 if (/(.\x{300})./) {
1517 print "not " unless $` eq "abc\x{100}" && length($`) == 4;
1520 print "not " unless $& eq "\x{200}\x{300}\x{380}" && length($&) == 3;
1523 print "not " unless $' eq "\x{400}defg" && length($') == 5;
1526 print "not " unless $1 eq "\x{200}\x{300}" && length($1) == 2;
1529 for (576..580) { print "not ok $_\n" }
1534 # bug id 20010306.008
1537 # The original bug report had 'no utf8' here but that was irrelevant.
1538 $a =~ m/\w/; # used to core dump