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.
16 use re 'asciirange'; # Compute ranges in ASCII space
18 eval 'use Config'; # Defaults assumed if this fails
22 if ($x =~ /^abc/) {print "ok 1\n";} else {print "not ok 1\n";}
23 if ($x !~ /^def/) {print "ok 2\n";} else {print "not ok 2\n";}
26 if ($x =~ /^def/) {print "ok 3\n";} else {print "not ok 3\n";}
30 if (/^([0-9][0-9]*)/) {print "ok 4\n";} else {print "not ok 4\n";}
32 if ($x =~ /^xxx/) {print "not ok 5\n";} else {print "ok 5\n";}
33 if ($x !~ /^abc/) {print "not ok 6\n";} else {print "ok 6\n";}
35 if ($x =~ /def/) {print "ok 7\n";} else {print "not ok 7\n";}
36 if ($x !~ /def/) {print "not ok 8\n";} else {print "ok 8\n";}
38 if ($x !~ /.def/) {print "ok 9\n";} else {print "not ok 9\n";}
39 if ($x =~ /.def/) {print "not ok 10\n";} else {print "ok 10\n";}
41 if ($x =~ /\ndef/) {print "ok 11\n";} else {print "not ok 11\n";}
42 if ($x !~ /\ndef/) {print "not ok 12\n";} else {print "ok 12\n";}
45 if (/(a*b*)(c*)/ && $1 eq 'aaabbb' && $2 eq 'ccc') {
50 if (/(a+b+c+)/ && $1 eq 'aaabbbccc') {
56 if (/a+b?c+/) {print "not ok 15\n";} else {print "ok 15\n";}
59 if (/a+b?c+/) {print "ok 16\n";} else {print "not ok 16\n";}
60 if (/a*b+c*/) {print "ok 17\n";} else {print "not ok 17\n";}
63 if (/a*b?c*/) {print "ok 18\n";} else {print "not ok 18\n";}
64 if (/a*b+c*/) {print "not ok 19\n";} else {print "ok 19\n";}
67 if (/bcd|xyz/) {print "ok 20\n";} else {print "not ok 20\n";}
68 if (/xyz|bcd/) {print "ok 21\n";} else {print "not ok 21\n";}
70 if (m|bc/*d|) {print "ok 22\n";} else {print "not ok 22\n";}
72 if (/^$_$/) {print "ok 23\n";} else {print "not ok 23\n";}
74 $* = 1; # test 3 only tested the optimized version--this one is for real
75 if ("ab\ncd\n" =~ /^cd/) {print "ok 24\n";} else {print "not ok 24\n";}
82 @XXX = ('ok 25','not ok 25', 'ok 26','not ok 26','not ok 27');
83 while ($_ = shift(@XXX)) {
84 ?(.*)? && (print $1,"\n");
86 /not ok 26/ && reset 'X';
89 while (($key,$val) = each(%XXX)) {
98 if ($& eq 'xyz') {print "ok 28\n";} else {print "not ok 28\n";}
103 if ($& eq 'xyz') {print "ok 29\n";} else {print "not ok 29\n";}
108 if ($& eq 'xyz') {print "ok 30\n";} else {print "not ok 30\n";}
111 /def/; # optimized up to cmd
112 if ("$`:$&:$'" eq 'abc:def:ghi') {print "ok 31\n";} else {print "not ok 31\n";}
114 /cde/ + 0; # optimized only to spat
115 if ("$`:$&:$'" eq 'ab:cde:fghi') {print "ok 32\n";} else {print "not ok 32\n";}
117 /[d][e][f]/; # not optimized
118 if ("$`:$&:$'" eq 'abc:def:ghi') {print "ok 33\n";} else {print "not ok 33\n";}
120 $_ = 'now is the {time for all} good men to come to.';
122 if ($1 eq 'time for all') {print "ok 34\n";} else {print "not ok 34 $1\n";}
124 $_ = 'xxx {3,4} yyy zzz';
125 print /( {3,4})/ ? "ok 35\n" : "not ok 35\n";
126 print $1 eq ' ' ? "ok 36\n" : "not ok 36\n";
127 print /( {4,})/ ? "not ok 37\n" : "ok 37\n";
128 print /( {2,3}.)/ ? "ok 38\n" : "not ok 38\n";
129 print $1 eq ' y' ? "ok 39\n" : "not ok 39\n";
130 print /(y{2,3}.)/ ? "ok 40\n" : "not ok 40\n";
131 print $1 eq 'yyy ' ? "ok 41\n" : "not ok 41\n";
132 print /x {3,4}/ ? "not ok 42\n" : "ok 42\n";
133 print /^xxx {3,4}/ ? "not ok 43\n" : "ok 43\n";
135 $_ = "now is the time for all good men to come to.";
137 print join(':',@words) eq "now:is:the:time:for:all:good:men:to:come:to"
145 print join(':',@words) eq "now:is:the:time:for:all:good:men:to:come:to"
154 print join(':',@words) eq "to:to"
156 : "not ok 46 `@words'\n";
160 print join(':',@words) eq "to:to"
162 : "not ok 47 `@words'\n";
176 $t1=$t2=$t3=$t4=$t5=$t6=$t7=$t8=$t9=0;
190 $x = "$t1$t2$t3$t4$t5$t6$t7$t8$t9";
191 print $x eq '505550555' ? "ok 48\n" : "not ok 48 $x\n";
194 print "abc" =~ /^abc$|$xyz/ ? "ok 49\n" : "not ok 49\n";
196 # perl 4.009 says "unmatched ()"
197 eval '"abc" =~ /a(bc$)|$xyz/; $result = "$&:$1"';
198 print $@ eq "" ? "ok 50\n" : "not ok 50\n";
199 print $result eq "abc:bc" ? "ok 51\n" : "not ok 51\n";
204 print $` eq "" ? "ok 52\n" : "not ok 52\n" if $x;
206 print $` eq "abcfoo" ? "ok 53\n" : "not ok 53\n" if $x;
208 print $x == 0 ? "ok 54\n" : "not ok 54\n";
211 print $` eq "" ? "ok 55\n" : "not ok 55\n" if $x;
213 print $` eq "abcfoo" ? "ok 56\n" : "not ok 56\n" if $x;
215 print $x == 0 ? "ok 57\n" : "not ok 57\n";
218 print $' eq "fooabcbar" ? "ok 58\n" : "not ok 58\n" if $x;
220 print $' eq "bar" ? "ok 59\n" : "not ok 59\n" if $x;
223 print scalar @x == 2 ? "ok 60\n" : "not ok 60\n";
228 print "not " if (pos $_) != 2;
231 print "not " if defined pos $_;
235 'abc' =~ m'a(?{ $out = 2 })b';
236 print "not " if $out != 2;
240 'abc' =~ m'a(?{ $out = 3 })c';
241 print "not " if $out != 1;
244 $_ = 'foobar1 bar2 foobar3 barfoobar5 foobar6';
245 @out = /(?<!foo)bar./g;
246 print "not " if "@out" ne 'bar2 barf';
249 # Tests which depend on REG_INFTY
250 $reg_infty = defined $Config{reg_infty} ? $Config{reg_infty} : 32767;
251 $reg_infty_m = $reg_infty - 1; $reg_infty_p = $reg_infty + 1;
253 # As well as failing if the pattern matches do unexpected things, the
254 # next three tests will fail if you should have picked up a lower-than-
255 # default value for $reg_infty from Config.pm, but have not.
258 print "not " if eval q(('aaa' =~ /(a{1,$reg_infty_m})/)[0] ne 'aaa') || $@;
262 print "not " if eval q(('a' x $reg_infty_m) !~ /a{$reg_infty_m}/) || $@;
266 print "not " if eval q(('a' x ($reg_infty_m - 1)) =~ /a{$reg_infty_m}/) || $@;
270 eval "'aaa' =~ /a{1,$reg_infty}/";
271 print "not " if $@ !~ m%^\QQuantifier in {,} bigger than%;
274 eval "'aaa' =~ /a{1,$reg_infty_p}/";
276 if $@ !~ m%^\QQuantifier in {,} bigger than%;
280 # Poke a couple more parse failures
282 $context = 'x' x 256;
283 eval qq("${context}y" =~ /(?<=$context)y/);
284 print "not " if $@ !~ m%^\QLookbehind longer than 255 not%;
292 for $l (125, 140, 250, 270, 300000, 30) { # Ordered to free memory
294 print "# length=$l\nnot " unless "ba$a=" =~ /a$a=/;
298 print "not " if "b$a=" =~ /a$a=/;
303 # 20000 nodes, each taking 3 words per string, and 1 per branch
304 $long_constant_len = join '|', 12120 .. 32645;
305 $long_var_len = join '|', 8120 .. 28645;
306 %ans = ( 'ax13876y25677lbc' => 1,
307 'ax13876y25677mcb' => 0, # not b.
308 'ax13876y35677nbc' => 0, # Num too big
309 'ax13876y25677y21378obc' => 1,
310 'ax13876y25677y21378zbc' => 0, # Not followed by [k-o]
311 'ax13876y25677y21378y21378kbc' => 1,
312 'ax13876y25677y21378y21378kcb' => 0, # Not b.
313 'ax13876y25677y21378y21378y21378kbc' => 0, # 5 runs
317 print "# const-len `$_' not => $ans{$_}\nnot "
318 if $ans{$_} xor /a(?=([yx]($long_constant_len)){2,4}[k-o]).*b./o;
321 print "# var-len `$_' not => $ans{$_}\nnot "
322 if $ans{$_} xor /a(?=([yx]($long_var_len)){2,4}[k-o]).*b./o;
327 $_ = " a (bla()) and x(y b((l)u((e))) and b(l(e)e)e";
328 $expect = "(bla()) ((l)u((e))) (l(e)e)";
334 (?{ $c = 1 }) # Initialize
336 (?(?{ $c == 0 }) # PREVIOUS iteration was OK, stop the loop
338 ) # Fail: will unwind one iteration back
341 [^()]+ # Match a big chunk
344 ) # Do not try to match subchunks
352 )+ # This may not match with different subblocks
357 ) # Otherwise the chunk 1 may succeed with $c>0
362 push @ans, $res while $res = matchit;
364 print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne "1 1 1";
370 print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne $expect;
374 print "not " unless "abc" =~ /^(??{"a"})b/;
379 $matched = qr/\((?:(?>[^()]+)|(??{$matched}))*\)/;
382 push(@ans, $res), push(@ans1, $&) while $res = m/$matched/g;
384 print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne "1 1 1";
388 print "# ans1='@ans1'\n# expect='$expect'\nnot " if "@ans1" ne $expect;
394 print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne $expect;
398 @ans = ('a/b' =~ m%(.*/)?(.*)%); # Stack may be bad
399 print "not " if "@ans" ne 'a/ b';
403 $code = '{$blah = 45}';
406 print "not " unless $@ and $@ =~ /not allowed at runtime/ and $blah == 12;
410 for $code ('{$blah = 45}','=xx') {
412 $res = eval { "xx" =~ /(?$code)/o };
413 if ($code eq '=xx') {
414 print "#'$@','$res','$blah'\nnot " unless not $@ and $res;
416 print "#'$@','$res','$blah'\nnot " unless $@ and $@ =~ /not allowed at runtime/ and $blah == 12;
422 $code = '{$blah = 45}';
425 print "not " if $blah != 45;
431 print "not " if $blah != 45;
437 print "not " unless pos($x) == 2;
442 print "not " unless pos($x) == 2;
452 print "not " unless f(pos($x)) == 4;
457 'foot' =~ /foo(?{$x = 12; 75})[t]/;
458 print "not " unless $^R eq '75';
463 'foot' =~ /foo(?{$x = 12; 75})[xy]/;
464 print "not " unless $^R eq '67' and $x eq '12';
469 'foot' =~ /foo(?{ $^R + 12 })((?{ $x = 12; $^R + 17 })[xy])?/;
470 print "not " unless $^R eq '79' and $x eq '12';
474 print "not " unless qr/\b\v$/i eq '(?i-xsm:\bv$)';
478 print "not " unless qr/\b\v$/s eq '(?s-xim:\bv$)';
482 print "not " unless qr/\b\v$/m eq '(?m-xis:\bv$)';
486 print "not " unless qr/\b\v$/x eq '(?x-ism:\bv$)';
490 print "not " unless qr/\b\v$/xism eq '(?msix:\bv$)';
494 print "not " unless qr/\b\v$/ eq '(?-xism:\bv$)';
499 foreach $ans ('', 'c') {
500 /(?<=(?=a)..)((?=c)|.)/g;
501 print "# \$1 ='$1'\n# \$ans='$ans'\nnot " unless $1 eq $ans;
507 foreach $ans ('', 'a', '') {
509 print "# \$& ='$&'\n# \$ans='$ans'\nnot " unless $& eq $ans;
515 my($v,$a,$b,$res) = @_;
517 print "not " unless $res eq $v;
521 prefixify('/a/b/lib/arch', "/a/b/lib", 'X/lib', 'X/lib/arch');
522 prefixify('/a/b/man/arch', "/a/b/man", 'X/man', 'X/man/arch');
526 print "not " unless $1 and /$1/;
533 print "not " unless $b eq '9';
539 print "not " unless $b eq '11';
546 print "not " unless $b eq '14';
554 my $lex_res = ($lex_b =~ qr/$lex_b(?{ $lex_c = $lex_a++ })/);
555 print "not " unless $lex_res eq '1';
558 print "not " unless $lex_a eq '44';
561 print "not " unless $lex_c eq '43';
567 $match = eval { /$a$c$a/ };
569 unless $b eq '14' and $@ =~ /Eval-group not allowed/ and not $match;
579 my $lex_res = ($lex_b =~ qr/17(?{ $lex_c = $lex_a++ })/);
580 print "not " unless $lex_res eq '1';
583 print "not " unless $lex_a eq '44';
586 print "not " unless $lex_c eq '43';
595 '' =~ /(?{ $c = 4 })/;
596 print "not " unless $c == 4;
600 print "not " unless $c == 3;
605 my $warn_pat = shift;
606 return sub { print "not " unless $_[0] =~ /$warn_pat/ }
610 my ($warn_pat, $code) = @_;
612 eval 'BEGIN { use warnings; $SIG{__WARN__} = $warn_pat };' . $code;
619 my $warn_pat = shift;
620 return sub { must_warn(must_warn_pat($warn_pat)) }
623 my $for_future = make_must_warn('reserved for future extensions');
625 &$for_future('q(a:[b]:) =~ /[x[:foo:]]/');
627 #&$for_future('q(a=[b]=) =~ /[x[=foo=]]/');
628 print "ok $test\n"; $test++; # now a fatal croak
630 #&$for_future('q(a.[b].) =~ /[x[.foo.]]/');
631 print "ok $test\n"; $test++; # now a fatal croak
633 # test if failure of patterns returns empty list
656 print "not " if $#+ != 0 or $#- != 0;
660 print "not " if $+[0] != 2 or $-[0] != 1;
665 if defined $+[1] or defined $-[1] or defined $+[2] or defined $-[2];
670 print "not " if $#+ != 2 or $#- != 2;
674 print "not " if $+[0] != 3 or $-[0] != 0;
678 print "not " if $+[1] != 2 or $-[1] != 1;
682 print "not " if $+[2] != 3 or $-[2] != 2;
687 if defined $+[3] or defined $-[3] or defined $+[4] or defined $-[4];
692 print "not " if $#+ != 3 or $#- != 3;
696 print "not " if $+[0] != 3 or $-[0] != 0;
700 print "not " if $+[1] != 2 or $-[1] != 1;
704 print "not " if $+[3] != 3 or $-[3] != 2;
709 if defined $+[2] or defined $-[2] or defined $+[4] or defined $-[4];
714 print "not " if $#+ != 1 or $#- != 1;
718 print "not " if $+[0] != 2 or $-[0] != 0;
722 print "not " if $+[1] != 2 or $-[1] != 1;
727 if defined $+[2] or defined $-[2] or defined $+[3] or defined $-[3];
731 eval { $+[0] = 13; };
733 if $@ !~ /^Modification of a read-only value attempted/;
737 eval { $-[0] = 13; };
739 if $@ !~ /^Modification of a read-only value attempted/;
743 eval { @+ = (7, 6, 5); };
745 if $@ !~ /^Modification of a read-only value attempted/;
749 eval { @- = qw(foo bar); };
751 if $@ !~ /^Modification of a read-only value attempted/;
756 print "#$#-..$#+\nnot " if $#+ != 2 or $#- != 1;
763 print "not " unless "@a" eq "a a";
770 print "not " if $str =~ /^\G/;
774 print "not " if $str =~ /^.\G/;
778 print "not " unless $str =~ /^..\G/;
782 print "not " if $str =~ /^...\G/;
786 print "not " unless $str =~ /.\G./ and $& eq 'bc';
790 print "not " unless $str =~ /\G../ and $& eq 'cd';
794 undef $foo; undef $bar;
795 print "#'$str','$foo','$bar'\nnot "
796 unless $str =~ /b(?{$foo = $_; $bar = pos})c/
797 and $foo eq 'abcde' and $bar eq 2;
801 undef $foo; undef $bar;
803 print "#'$str','$foo','$bar'\nnot "
804 unless $str =~ /b(?{$foo = $_; $bar = pos})c/g
805 and $foo eq 'abcde' and $bar eq 2 and pos $str eq 3;
811 undef $foo; undef $bar;
812 print "#'$str','$foo','$bar'\nnot "
813 unless /b(?{$foo = $_; $bar = pos})c/
814 and $foo eq 'abcde' and $bar eq 2;
818 undef $foo; undef $bar;
819 print "#'$str','$foo','$bar'\nnot "
820 unless /b(?{$foo = $_; $bar = pos})c/g
821 and $foo eq 'abcde' and $bar eq 2 and pos eq 3;
825 undef $foo; undef $bar;
827 1 while /b(?{$foo = $_; $bar = pos})c/g;
828 print "#'$str','$foo','$bar'\nnot "
829 unless $foo eq 'abcde' and $bar eq 2 and not defined pos;
833 undef $foo; undef $bar;
835 print "#'$str','$foo','$bar','$_'\nnot "
836 unless s/b(?{$foo = $_; $bar = pos})c/x/g and $foo eq 'abcde|abcde'
837 and $bar eq 8 and $_ eq 'axde|axde';
844 @dummy = /([ace]).(?{push @res, $1,$2})([ce])(?{push @res, $1,$2})/g;
845 @res = map {defined $_ ? "'$_'" : 'undef'} @res;
847 print "#'@res' '$_'\nnot "
848 unless "@res" eq "'a' undef 'a' 'c' 'e' undef 'a' undef 'a' 'c'";
853 @dummy = /([ace]).(?{push @res, $`,$&,$'})([ce])(?{push @res, $`,$&,$'})/g;
854 @res = map {defined $_ ? "'$_'" : 'undef'} @res;
856 print "#'@res' '$_'\nnot "
858 "'' 'ab' 'cde|abcde' " .
859 "'' 'abc' 'de|abcde' " .
860 "'abcd' 'e|' 'abcde' " .
861 "'abcde|' 'ab' 'cde' " .
862 "'abcde|' 'abc' 'de'" ;
866 #Some more \G anchor checks
867 $foo='aabbccddeeffgg';
872 print "not " unless($1 eq 'ab');
878 print "not " unless($1 eq 'cc');
884 print "not " unless($1 eq 'de');
888 print "not " unless $foo =~ /\Gef/g;
895 print "not " unless($1 eq 'aa');
900 print "not " unless($1 eq 'bb');
906 print "not " unless($1 eq 'cd');
912 print "not " unless('123||x|123|' eq join '|', @res);
916 # see if matching against temporaries (created via pp_helem()) is safe
917 { foo => "ok $test\n".$^X }->{foo} =~ /^(.*)\n/g;
921 # See if $i work inside (?{}) in the presense of saved substrings and
925 s/(\w)(?{push @b, $1})/,$1,/g for @a;
927 print "# \@b='@b', expect 'f o o b a r'\nnot " unless("@b" eq "f o o b a r");
931 print "not " unless("@a" eq ",f,,o,,o, ,b,,a,,r,");
936 { (?> [^{}]+ | (??{ $brackets }) )* }
940 print "ok $test\n"; # Did we survive?
943 "something { long { and } hairy" =~ $brackets;
944 print "ok $test\n"; # Did we survive?
947 "something { long { and } hairy" =~ m/((??{ $brackets }))/;
948 print "not " unless $1 eq "{ and }";
954 m/^-.*bb/mg and print "not ";
960 $text =~ /\GXb*X/g and print 'not ';
964 $text = "xA\n" x 500;
965 $text =~ /^\s*A/m and print 'not ';
970 @res = ($text =~ /.*?(b).*?\b/g);
971 "@res" eq 'b b' or print 'not ';
978 @c = grep(/[^\s]/,@a);
979 print "not " if "@b" ne "@c";
984 @c = grep(/[\S]/,@a);
985 print "not " if "@b" ne "@c";
990 @c = grep(/[^\S]/,@a);
991 print "not " if "@b" ne "@c";
996 @c = grep(/[\s]/,@a);
997 print "not " if "@b" ne "@c";
1002 @c = grep(/[^\d]/,@a);
1003 print "not " if "@b" ne "@c";
1008 @c = grep(/[\D]/,@a);
1009 print "not " if "@b" ne "@c";
1014 @c = grep(/[^\D]/,@a);
1015 print "not " if "@b" ne "@c";
1020 @c = grep(/[\d]/,@a);
1021 print "not " if "@b" ne "@c";
1026 @c = grep(/[^\w]/,@a);
1027 print "not " if "@b" ne "@c";
1032 @c = grep(/[\W]/,@a);
1033 print "not " if "@b" ne "@c";
1038 @c = grep(/[^\W]/,@a);
1039 print "not " if "@b" ne "@c";
1044 @c = grep(/[\w]/,@a);
1045 print "not " if "@b" ne "@c";
1049 # see if backtracking optimization works correctly
1050 "\n\n" =~ /\n $ \n/x or print "not ";
1054 "\n\n" =~ /\n* $ \n/x or print "not ";
1058 "\n\n" =~ /\n+ $ \n/x or print "not ";
1062 [] =~ /^ARRAY/ or print "# [] \nnot ";
1069 use overload '""' => sub { 'Object S' };
1070 sub new { bless [] }
1075 $a and $a =~ /^Object\sS/ or print "# '$a' \nnot ";
1079 # test result of match used as match (!)
1080 'a1b' =~ ('xyz' =~ /y/) and $` eq 'a' or print "not ";
1084 'a1b' =~ ('xyz' =~ /t/) and $` eq 'a' or print "not ";
1090 local $SIG{__WARN__} = sub { $w = 1 };
1092 $w = 1 if ("1\n" x 102) =~ /^\s*\n/m;
1094 print $w ? "not " : "", "ok $test\n";
1097 my %space = ( spc => " ",
1102 # There's no \v but the vertical tabulator seems miraculously
1103 # be 11 both in ASCII and EBCDIC.
1107 my @space0 = sort grep { $space{$_} =~ /\s/ } keys %space;
1108 my @space1 = sort grep { $space{$_} =~ /[[:space:]]/ } keys %space;
1109 my @space2 = sort grep { $space{$_} =~ /[[:blank:]]/ } keys %space;
1111 print "not " unless "@space0" eq "cr ff lf spc tab";
1112 print "ok $test # @space0\n";
1115 print "not " unless "@space1" eq "cr ff lf spc tab vt";
1116 print "ok $test # @space1\n";
1119 print "not " unless "@space2" eq "spc tab";
1120 print "ok $test # @space2\n";
1123 # bugid 20001021.005 - this caused a SEGV
1124 print "not " unless undef =~ /^([^\/]*)(.*)$/;
1128 # bugid 20000731.001
1130 print "not " unless "A \x{263a} B z C" =~ /A . B (??{ "z" }) C/;
1135 if (/(.)(\C)(\C)(.)/) {
1140 print "not ok 233\n";
1145 print "not ok 234\n";
1150 print "not ok 235\n";
1155 print "not ok 236\n";
1159 print "not ok $_\n";
1165 # currently \C are still tagged as UTF-8
1169 print "not ok 238\n";
1173 print "not ok $_\n";
1178 # currently \C are still tagged as UTF-8
1182 print "not ok 240\n";
1186 print "not ok $_\n";
1191 # japhy -- added 03/03/2001
1192 () = (my $str = "abc") =~ /(...)/;
1194 print "not " if $1 ne "abc";
1198 # The 242 and 243 go with the 244 and 245.
1199 # The trick is that in EBCDIC the explicit numeric range should match
1200 # (as also in non-EBCDIC) but the explicit alphabetic range should not match.
1202 if ("\x8e" =~ /[\x89-\x91]/) {
1205 print "not ok 242\n";
1208 if ("\xce" =~ /[\xc9-\xd1]/) {
1211 print "not ok 243\n";
1214 # In most places these tests would succeed since \x8e does not
1215 # in most character sets match 'i' or 'j' nor would \xce match
1216 # 'I' or 'J', but strictly speaking these tests are here for
1217 # the good of EBCDIC, so let's test these only there.
1218 if (ord('i') == 0x89 && ord('J') == 0xd1) { # EBCDIC
1219 if ("\x8e" !~ /[i-j]/) {
1222 print "not ok 244\n";
1224 if ("\xce" !~ /[I-J]/) {
1227 print "not ok 245\n";
1231 print "ok $_ # Skip: only in EBCDIC\n";
1235 print "not " unless "\x{ab}" =~ /\x{ab}/;
1238 print "not " unless "\x{abcd}" =~ /\x{abcd}/;
1242 # bug id 20001008.001
1245 my @x = ("stra\337e 138","stra\337e 138");
1247 s/(\d+)\s*([\w\-]+)/$1 . uc $2/e;
1248 my($latin) = /^(.+)(?:\s+\d)/;
1249 print $latin eq "stra\337e" ? "ok $test\n" : # 248,249
1250 "#latin[$latin]\nnot ok $test\n";
1252 $latin =~ s/stra\337e/straße/; # \303\237 after the 2nd a
1254 $latin =~ s!(s)tr(?:aß|s+e)!$1tr.!; # \303\237 after the a
1259 print "not " unless "ba\xd4c" =~ /([a\xd4]+)/ && $1 eq "a\xd4";
1262 print "not " unless "ba\xd4c" =~ /([a\xd4]+)/ && $1 eq "a\x{d4}";
1265 print "not " unless "ba\x{d4}c" =~ /([a\xd4]+)/ && $1 eq "a\x{d4}";
1268 print "not " unless "ba\x{d4}c" =~ /([a\xd4]+)/ && $1 eq "a\xd4";
1271 print "not " unless "ba\xd4c" =~ /([a\x{d4}]+)/ && $1 eq "a\xd4";
1274 print "not " unless "ba\xd4c" =~ /([a\x{d4}]+)/ && $1 eq "a\x{d4}";
1277 print "not " unless "ba\x{d4}c" =~ /([a\x{d4}]+)/ && $1 eq "a\x{d4}";
1280 print "not " unless "ba\x{d4}c" =~ /([a\x{d4}]+)/ && $1 eq "a\xd4";
1285 # the first half of 20001028.003
1288 my ($Y) = $X =~ /(.*)/;
1289 print "not " unless $Y eq v1448 && length($Y) == 1;
1296 my $X = "Szab\x{f3},Bal\x{e1}zs";
1298 $Y =~ s/(B)/$1/ for 0..3;
1299 print "not " unless $Y eq $X && $X eq "Szab\x{f3},Bal\x{e1}zs";
1304 # the second half of 20001028.003
1307 $X =~ s/^/chr(1488)/e;
1308 print "not " unless length $X == 1 && ord($X) == 1488;
1319 print "not " unless $x eq "\x{100}B" && length($x) == 2;
1324 # bug id 20001230.002
1326 print "not " unless "École" =~ /^\C\C(.)/ && $1 eq 'c';
1329 print "not " unless "École" =~ /^\C\C(c)/;
1334 my $test = 264; # till 575
1336 use charnames ':full';
1338 # This is far from complete testing, there are dozens of character
1339 # classes in Unicode. The mixing of literals and \N{...} is
1340 # intentional so that in non-Latin-1 places we test the native
1341 # characters, not the Unicode code points.
1345 "\N{CYRILLIC SMALL LETTER A}" => 'Ll',
1347 "\N{GREEK CAPITAL LETTER ALPHA}" => 'Lu',
1348 "\N{HIRAGANA LETTER SMALL A}" => 'Lo',
1349 "\N{COMBINING GRAVE ACCENT}" => 'Mn',
1351 "\N{ARABIC-INDIC DIGIT ZERO}" => 'Nd',
1358 for my $char (map { s/^\S+ //; $_ }
1359 sort map { sprintf("%06x", ord($_))." $_" } keys %s) {
1360 my $class = $s{$char};
1361 my $code = sprintf("%06x", ord($char));
1362 printf "#\n# 0x$code\n#\n";
1363 print "# IsAlpha\n";
1364 if ($class =~ /^[LM]/) {
1365 print "not " unless $char =~ /\p{IsAlpha}/;
1366 print "ok $test\n"; $test++;
1367 print "not " if $char =~ /\P{IsAlpha}/;
1368 print "ok $test\n"; $test++;
1370 print "not " if $char =~ /\p{IsAlpha}/;
1371 print "ok $test\n"; $test++;
1372 print "not " unless $char =~ /\P{IsAlpha}/;
1373 print "ok $test\n"; $test++;
1375 print "# IsAlnum\n";
1376 if ($class =~ /^[LMN]/ && $char ne "_") {
1377 print "not " unless $char =~ /\p{IsAlnum}/;
1378 print "ok $test\n"; $test++;
1379 print "not " if $char =~ /\P{IsAlnum}/;
1380 print "ok $test\n"; $test++;
1382 print "not " if $char =~ /\p{IsAlnum}/;
1383 print "ok $test\n"; $test++;
1384 print "not " unless $char =~ /\P{IsAlnum}/;
1385 print "ok $test\n"; $test++;
1387 print "# IsASCII\n";
1388 if ($code le '00007f') {
1389 print "not " unless $char =~ /\p{IsASCII}/;
1390 print "ok $test\n"; $test++;
1391 print "not " if $char =~ /\P{IsASCII}/;
1392 print "ok $test\n"; $test++;
1394 print "not " if $char =~ /\p{IsASCII}/;
1395 print "ok $test\n"; $test++;
1396 print "not " unless $char =~ /\P{IsASCII}/;
1397 print "ok $test\n"; $test++;
1399 print "# IsCntrl\n";
1400 if ($class =~ /^C/) {
1401 print "not " unless $char =~ /\p{IsCntrl}/;
1402 print "ok $test\n"; $test++;
1403 print "not " if $char =~ /\P{IsCntrl}/;
1404 print "ok $test\n"; $test++;
1406 print "not " if $char =~ /\p{IsCntrl}/;
1407 print "ok $test\n"; $test++;
1408 print "not " unless $char =~ /\P{IsCntrl}/;
1409 print "ok $test\n"; $test++;
1411 print "# IsBlank\n";
1412 if ($class =~ /^Z[lp]/ || $char eq " ") {
1413 print "not " unless $char =~ /\p{IsBlank}/;
1414 print "ok $test\n"; $test++;
1415 print "not " if $char =~ /\P{IsBlank}/;
1416 print "ok $test\n"; $test++;
1418 print "not " if $char =~ /\p{IsBlank}/;
1419 print "ok $test\n"; $test++;
1420 print "not " unless $char =~ /\P{IsBlank}/;
1421 print "ok $test\n"; $test++;
1423 print "# IsDigit\n";
1424 if ($class =~ /^Nd$/) {
1425 print "not " unless $char =~ /\p{IsDigit}/;
1426 print "ok $test\n"; $test++;
1427 print "not " if $char =~ /\P{IsDigit}/;
1428 print "ok $test\n"; $test++;
1430 print "not " if $char =~ /\p{IsDigit}/;
1431 print "ok $test\n"; $test++;
1432 print "not " unless $char =~ /\P{IsDigit}/;
1433 print "ok $test\n"; $test++;
1435 print "# IsGraph\n";
1436 if ($class =~ /^([LMNPS])|Co/) {
1437 print "not " unless $char =~ /\p{IsGraph}/;
1438 print "ok $test\n"; $test++;
1439 print "not " if $char =~ /\P{IsGraph}/;
1440 print "ok $test\n"; $test++;
1442 print "not " if $char =~ /\p{IsGraph}/;
1443 print "ok $test\n"; $test++;
1444 print "not " unless $char =~ /\P{IsGraph}/;
1445 print "ok $test\n"; $test++;
1447 print "# IsLower\n";
1448 if ($class =~ /^Ll$/) {
1449 print "not " unless $char =~ /\p{IsLower}/;
1450 print "ok $test\n"; $test++;
1451 print "not " if $char =~ /\P{IsLower}/;
1452 print "ok $test\n"; $test++;
1454 print "not " if $char =~ /\p{IsLower}/;
1455 print "ok $test\n"; $test++;
1456 print "not " unless $char =~ /\P{IsLower}/;
1457 print "ok $test\n"; $test++;
1459 print "# IsPrint\n";
1460 if ($class =~ /^([LMNPS])|Co|Zs/) {
1461 print "not " unless $char =~ /\p{IsPrint}/;
1462 print "ok $test\n"; $test++;
1463 print "not " if $char =~ /\P{IsPrint}/;
1464 print "ok $test\n"; $test++;
1466 print "not " if $char =~ /\p{IsPrint}/;
1467 print "ok $test\n"; $test++;
1468 print "not " unless $char =~ /\P{IsPrint}/;
1469 print "ok $test\n"; $test++;
1471 print "# IsPunct\n";
1472 if ($class =~ /^P/ || $char eq "_") {
1473 print "not " unless $char =~ /\p{IsPunct}/;
1474 print "ok $test\n"; $test++;
1475 print "not " if $char =~ /\P{IsPunct}/;
1476 print "ok $test\n"; $test++;
1478 print "not " if $char =~ /\p{IsPunct}/;
1479 print "ok $test\n"; $test++;
1480 print "not " unless $char =~ /\P{IsPunct}/;
1481 print "ok $test\n"; $test++;
1483 print "# IsSpace\n";
1484 if ($class =~ /^Z/ || ($code =~ /^(0009|000A|000B|000C|000D)$/)) {
1485 print "not " unless $char =~ /\p{IsSpace}/;
1486 print "ok $test\n"; $test++;
1487 print "not " if $char =~ /\P{IsSpace}/;
1488 print "ok $test\n"; $test++;
1490 print "not " if $char =~ /\p{IsSpace}/;
1491 print "ok $test\n"; $test++;
1492 print "not " unless $char =~ /\P{IsSpace}/;
1493 print "ok $test\n"; $test++;
1495 print "# IsUpper\n";
1496 if ($class =~ /^L[ut]/) {
1497 print "not " unless $char =~ /\p{IsUpper}/;
1498 print "ok $test\n"; $test++;
1499 print "not " if $char =~ /\P{IsUpper}/;
1500 print "ok $test\n"; $test++;
1502 print "not " if $char =~ /\p{IsUpper}/;
1503 print "ok $test\n"; $test++;
1504 print "not " unless $char =~ /\P{IsUpper}/;
1505 print "ok $test\n"; $test++;
1508 if ($class =~ /^[LMN]/ || $char eq "_") {
1509 print "not " unless $char =~ /\p{IsWord}/;
1510 print "ok $test\n"; $test++;
1511 print "not " if $char =~ /\P{IsWord}/;
1512 print "ok $test\n"; $test++;
1514 print "not " if $char =~ /\p{IsWord}/;
1515 print "ok $test\n"; $test++;
1516 print "not " unless $char =~ /\P{IsWord}/;
1517 print "ok $test\n"; $test++;
1523 $_ = "abc\x{100}\x{200}\x{300}\x{380}\x{400}defg";
1525 if (/(.\x{300})./) {
1528 print "not " unless $` eq "abc\x{100}" && length($`) == 4;
1531 print "not " unless $& eq "\x{200}\x{300}\x{380}" && length($&) == 3;
1534 print "not " unless $' eq "\x{400}defg" && length($') == 5;
1537 print "not " unless $1 eq "\x{200}\x{300}" && length($1) == 2;
1540 for (576..580) { print "not ok $_\n" }
1545 # bug id 20010306.008
1548 # The original bug report had 'no utf8' here but that was irrelevant.
1549 $a =~ m/\w/; # used to core dump
1557 # bugid 20010410.006
1559 '/(.*?)\{(.*?)\}/csg',
1560 '/(.*?)\{(.*?)\}/cg',
1561 '/(.*?)\{(.*?)\}/sg',
1562 '/(.*?)\{(.*?)\}/g',
1563 '/(.+?)\{(.+?)\}/csg',
1569 $input = "a{b}c{d}";
1571 while (eval \$input =~ $rx) {
1572 print "# \\\$1 = '\$1' \\\$2 = '\$2'\n";
1576 print "not " unless $i == 2;
1577 print "ok " . $test++ . "\n";
1582 # from Robin Houston
1584 my $x = "\x{12345678}";
1586 print "not " unless ord($x) == 0x12345678 && length($x) == 1;
1593 print "not " if $x =~ /[\x80-\xff]/;
1596 print "not " if $x =~ /[\x80-\x{100}]/;
1599 print "not " if $x =~ /[\x{100}]/;
1602 print "not " if $x =~ /\p{InLatin1Supplement}/;
1605 print "not " unless $x =~ /\P{InLatin1Supplement}/;
1608 print "not " if $x =~ /\p{InLatinExtendedA}/;
1611 print "not " unless $x =~ /\P{InLatinExtendedA}/;
1618 print "not " unless $x =~ /[\x80-\xff]/;
1621 print "not " unless $x =~ /[\x80-\x{100}]/;
1624 print "not " if $x =~ /[\x{100}]/;
1627 print "not " unless $x =~ /\p{InLatin1Supplement}/;
1630 print "not " if $x =~ /\P{InLatin1Supplement}/;
1633 print "not " if $x =~ /\p{InLatinExtendedA}/;
1636 print "not " unless $x =~ /\P{InLatinExtendedA}/;
1643 print "not " unless $x =~ /[\x80-\xff]/;
1646 print "not " unless $x =~ /[\x80-\x{100}]/;
1649 print "not " if $x =~ /[\x{100}]/;
1652 print "not " unless $x =~ /\p{InLatin1Supplement}/;
1655 print "not " if $x =~ /\P{InLatin1Supplement}/;
1658 print "not " if $x =~ /\p{InLatinExtendedA}/;
1661 print "not " unless $x =~ /\P{InLatinExtendedA}/;
1668 print "not " if $x =~ /[\x80-\xff]/;
1671 print "not " unless $x =~ /[\x80-\x{100}]/;
1674 print "not " unless $x =~ /[\x{100}]/;
1677 print "not " if $x =~ /\p{InLatin1Supplement}/;
1680 print "not " unless $x =~ /\P{InLatin1Supplement}/;
1683 print "not " unless $x =~ /\p{InLatinExtendedA}/;
1686 print "not " if $x =~ /\P{InLatinExtendedA}/;