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)) {
85 # print "not ok 27\n";
90 for (25..27) { print "ok $_\n" }
94 if ($& eq 'xyz') {print "ok 28\n";} else {print "not ok 28\n";}
99 if ($& eq 'xyz') {print "ok 29\n";} else {print "not ok 29\n";}
104 if ($& eq 'xyz') {print "ok 30\n";} else {print "not ok 30\n";}
107 /def/; # optimized up to cmd
108 if ("$`:$&:$'" eq 'abc:def:ghi') {print "ok 31\n";} else {print "not ok 31\n";}
110 /cde/ + 0; # optimized only to spat
111 if ("$`:$&:$'" eq 'ab:cde:fghi') {print "ok 32\n";} else {print "not ok 32\n";}
113 /[d][e][f]/; # not optimized
114 if ("$`:$&:$'" eq 'abc:def:ghi') {print "ok 33\n";} else {print "not ok 33\n";}
116 $_ = 'now is the {time for all} good men to come to.';
118 if ($1 eq 'time for all') {print "ok 34\n";} else {print "not ok 34 $1\n";}
120 $_ = 'xxx {3,4} yyy zzz';
121 print /( {3,4})/ ? "ok 35\n" : "not ok 35\n";
122 print $1 eq ' ' ? "ok 36\n" : "not ok 36\n";
123 print /( {4,})/ ? "not ok 37\n" : "ok 37\n";
124 print /( {2,3}.)/ ? "ok 38\n" : "not ok 38\n";
125 print $1 eq ' y' ? "ok 39\n" : "not ok 39\n";
126 print /(y{2,3}.)/ ? "ok 40\n" : "not ok 40\n";
127 print $1 eq 'yyy ' ? "ok 41\n" : "not ok 41\n";
128 print /x {3,4}/ ? "not ok 42\n" : "ok 42\n";
129 print /^xxx {3,4}/ ? "not ok 43\n" : "ok 43\n";
131 $_ = "now is the time for all good men to come to.";
133 print join(':',@words) eq "now:is:the:time:for:all:good:men:to:come:to"
141 print join(':',@words) eq "now:is:the:time:for:all:good:men:to:come:to"
150 print join(':',@words) eq "to:to"
152 : "not ok 46 `@words'\n";
156 print join(':',@words) eq "to:to"
158 : "not ok 47 `@words'\n";
172 $t1=$t2=$t3=$t4=$t5=$t6=$t7=$t8=$t9=0;
186 $x = "$t1$t2$t3$t4$t5$t6$t7$t8$t9";
187 print $x eq '505550555' ? "ok 48\n" : "not ok 48 $x\n";
190 print "abc" =~ /^abc$|$xyz/ ? "ok 49\n" : "not ok 49\n";
192 # perl 4.009 says "unmatched ()"
193 eval '"abc" =~ /a(bc$)|$xyz/; $result = "$&:$1"';
194 print $@ eq "" ? "ok 50\n" : "not ok 50\n";
195 print $result eq "abc:bc" ? "ok 51\n" : "not ok 51\n";
200 print $` eq "" ? "ok 52\n" : "not ok 52\n" if $x;
202 print $` eq "abcfoo" ? "ok 53\n" : "not ok 53\n" if $x;
204 print $x == 0 ? "ok 54\n" : "not ok 54\n";
207 print $` eq "" ? "ok 55\n" : "not ok 55\n" if $x;
209 print $` eq "abcfoo" ? "ok 56\n" : "not ok 56\n" if $x;
211 print $x == 0 ? "ok 57\n" : "not ok 57\n";
214 print $' eq "fooabcbar" ? "ok 58\n" : "not ok 58\n" if $x;
216 print $' eq "bar" ? "ok 59\n" : "not ok 59\n" if $x;
219 print scalar @x == 2 ? "ok 60\n" : "not ok 60\n";
224 print "not " if (pos $_) != 2;
227 print "not " if defined pos $_;
231 'abc' =~ m'a(?{ $out = 2 })b';
232 print "not " if $out != 2;
236 'abc' =~ m'a(?{ $out = 3 })c';
237 print "not " if $out != 1;
240 $_ = 'foobar1 bar2 foobar3 barfoobar5 foobar6';
241 @out = /(?<!foo)bar./g;
242 print "not " if "@out" ne 'bar2 barf';
245 # Tests which depend on REG_INFTY
246 $reg_infty = defined $Config{reg_infty} ? $Config{reg_infty} : 32767;
247 $reg_infty_m = $reg_infty - 1; $reg_infty_p = $reg_infty + 1;
249 # As well as failing if the pattern matches do unexpected things, the
250 # next three tests will fail if you should have picked up a lower-than-
251 # default value for $reg_infty from Config.pm, but have not.
254 print "not " if eval q(('aaa' =~ /(a{1,$reg_infty_m})/)[0] ne 'aaa') || $@;
258 print "not " if eval q(('a' x $reg_infty_m) !~ /a{$reg_infty_m}/) || $@;
262 print "not " if eval q(('a' x ($reg_infty_m - 1)) =~ /a{$reg_infty_m}/) || $@;
266 eval "'aaa' =~ /a{1,$reg_infty}/";
267 print "not " if $@ !~ m%^\QQuantifier in {,} bigger than%;
270 eval "'aaa' =~ /a{1,$reg_infty_p}/";
272 if $@ !~ m%^\QQuantifier in {,} bigger than%;
276 # Poke a couple more parse failures
278 $context = 'x' x 256;
279 eval qq("${context}y" =~ /(?<=$context)y/);
280 print "not " if $@ !~ m%^\QLookbehind longer than 255 not%;
288 for $l (125, 140, 250, 270, 300000, 30) { # Ordered to free memory
290 print "# length=$l\nnot " unless "ba$a=" =~ /a$a=/;
294 print "not " if "b$a=" =~ /a$a=/;
299 # 20000 nodes, each taking 3 words per string, and 1 per branch
300 $long_constant_len = join '|', 12120 .. 32645;
301 $long_var_len = join '|', 8120 .. 28645;
302 %ans = ( 'ax13876y25677lbc' => 1,
303 'ax13876y25677mcb' => 0, # not b.
304 'ax13876y35677nbc' => 0, # Num too big
305 'ax13876y25677y21378obc' => 1,
306 'ax13876y25677y21378zbc' => 0, # Not followed by [k-o]
307 'ax13876y25677y21378y21378kbc' => 1,
308 'ax13876y25677y21378y21378kcb' => 0, # Not b.
309 'ax13876y25677y21378y21378y21378kbc' => 0, # 5 runs
313 print "# const-len `$_' not => $ans{$_}\nnot "
314 if $ans{$_} xor /a(?=([yx]($long_constant_len)){2,4}[k-o]).*b./o;
317 print "# var-len `$_' not => $ans{$_}\nnot "
318 if $ans{$_} xor /a(?=([yx]($long_var_len)){2,4}[k-o]).*b./o;
323 $_ = " a (bla()) and x(y b((l)u((e))) and b(l(e)e)e";
324 $expect = "(bla()) ((l)u((e))) (l(e)e)";
330 (?{ $c = 1 }) # Initialize
332 (?(?{ $c == 0 }) # PREVIOUS iteration was OK, stop the loop
334 ) # Fail: will unwind one iteration back
337 [^()]+ # Match a big chunk
340 ) # Do not try to match subchunks
348 )+ # This may not match with different subblocks
353 ) # Otherwise the chunk 1 may succeed with $c>0
358 push @ans, $res while $res = matchit;
360 print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne "1 1 1";
366 print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne $expect;
370 print "not " unless "abc" =~ /^(??{"a"})b/;
375 $matched = qr/\((?:(?>[^()]+)|(??{$matched}))*\)/;
378 push(@ans, $res), push(@ans1, $&) while $res = m/$matched/g;
380 print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne "1 1 1";
384 print "# ans1='@ans1'\n# expect='$expect'\nnot " if "@ans1" ne $expect;
390 print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne $expect;
394 @ans = ('a/b' =~ m%(.*/)?(.*)%); # Stack may be bad
395 print "not " if "@ans" ne 'a/ b';
399 $code = '{$blah = 45}';
402 print "not " unless $@ and $@ =~ /not allowed at runtime/ and $blah == 12;
406 for $code ('{$blah = 45}','=xx') {
408 $res = eval { "xx" =~ /(?$code)/o };
409 if ($code eq '=xx') {
410 print "#'$@','$res','$blah'\nnot " unless not $@ and $res;
412 print "#'$@','$res','$blah'\nnot " unless $@ and $@ =~ /not allowed at runtime/ and $blah == 12;
418 $code = '{$blah = 45}';
421 print "not " if $blah != 45;
427 print "not " if $blah != 45;
433 print "not " unless pos($x) == 2;
438 print "not " unless pos($x) == 2;
448 print "not " unless f(pos($x)) == 4;
453 'foot' =~ /foo(?{$x = 12; 75})[t]/;
454 print "not " unless $^R eq '75';
459 'foot' =~ /foo(?{$x = 12; 75})[xy]/;
460 print "not " unless $^R eq '67' and $x eq '12';
465 'foot' =~ /foo(?{ $^R + 12 })((?{ $x = 12; $^R + 17 })[xy])?/;
466 print "not " unless $^R eq '79' and $x eq '12';
470 print "not " unless qr/\b\v$/i eq '(?i-xsm:\bv$)';
474 print "not " unless qr/\b\v$/s eq '(?s-xim:\bv$)';
478 print "not " unless qr/\b\v$/m eq '(?m-xis:\bv$)';
482 print "not " unless qr/\b\v$/x eq '(?x-ism:\bv$)';
486 print "not " unless qr/\b\v$/xism eq '(?msix:\bv$)';
490 print "not " unless qr/\b\v$/ eq '(?-xism:\bv$)';
495 foreach $ans ('', 'c') {
496 /(?<=(?=a)..)((?=c)|.)/g;
497 print "# \$1 ='$1'\n# \$ans='$ans'\nnot " unless $1 eq $ans;
503 foreach $ans ('', 'a', '') {
505 print "# \$& ='$&'\n# \$ans='$ans'\nnot " unless $& eq $ans;
511 my($v,$a,$b,$res) = @_;
513 print "not " unless $res eq $v;
517 prefixify('/a/b/lib/arch', "/a/b/lib", 'X/lib', 'X/lib/arch');
518 prefixify('/a/b/man/arch', "/a/b/man", 'X/man', 'X/man/arch');
522 print "not " unless $1 and /$1/;
529 print "not " unless $b eq '9';
535 print "not " unless $b eq '11';
542 print "not " unless $b eq '14';
550 my $lex_res = ($lex_b =~ qr/$lex_b(?{ $lex_c = $lex_a++ })/);
551 print "not " unless $lex_res eq '1';
554 print "not " unless $lex_a eq '44';
557 print "not " unless $lex_c eq '43';
563 $match = eval { /$a$c$a/ };
565 unless $b eq '14' and $@ =~ /Eval-group not allowed/ and not $match;
575 my $lex_res = ($lex_b =~ qr/17(?{ $lex_c = $lex_a++ })/);
576 print "not " unless $lex_res eq '1';
579 print "not " unless $lex_a eq '44';
582 print "not " unless $lex_c eq '43';
591 '' =~ /(?{ $c = 4 })/;
592 print "not " unless $c == 4;
596 print "not " unless $c == 3;
601 my $warn_pat = shift;
602 return sub { print "not " unless $_[0] =~ /$warn_pat/ }
606 my ($warn_pat, $code) = @_;
608 eval 'BEGIN { use warnings; $SIG{__WARN__} = $warn_pat };' . $code;
615 my $warn_pat = shift;
616 return sub { must_warn(must_warn_pat($warn_pat)) }
619 my $for_future = make_must_warn('reserved for future extensions');
621 &$for_future('q(a:[b]:) =~ /[x[:foo:]]/');
623 #&$for_future('q(a=[b]=) =~ /[x[=foo=]]/');
624 print "ok $test\n"; $test++; # now a fatal croak
626 #&$for_future('q(a.[b].) =~ /[x[.foo.]]/');
627 print "ok $test\n"; $test++; # now a fatal croak
629 # test if failure of patterns returns empty list
652 print "not " if $#+ != 0 or $#- != 0;
656 print "not " if $+[0] != 2 or $-[0] != 1;
661 if defined $+[1] or defined $-[1] or defined $+[2] or defined $-[2];
666 print "not " if $#+ != 2 or $#- != 2;
670 print "not " if $+[0] != 3 or $-[0] != 0;
674 print "not " if $+[1] != 2 or $-[1] != 1;
678 print "not " if $+[2] != 3 or $-[2] != 2;
683 if defined $+[3] or defined $-[3] or defined $+[4] or defined $-[4];
688 print "not " if $#+ != 3 or $#- != 3;
692 print "not " if $+[0] != 3 or $-[0] != 0;
696 print "not " if $+[1] != 2 or $-[1] != 1;
700 print "not " if $+[3] != 3 or $-[3] != 2;
705 if defined $+[2] or defined $-[2] or defined $+[4] or defined $-[4];
710 print "not " if $#+ != 1 or $#- != 1;
714 print "not " if $+[0] != 2 or $-[0] != 0;
718 print "not " if $+[1] != 2 or $-[1] != 1;
723 if defined $+[2] or defined $-[2] or defined $+[3] or defined $-[3];
727 eval { $+[0] = 13; };
729 if $@ !~ /^Modification of a read-only value attempted/;
733 eval { $-[0] = 13; };
735 if $@ !~ /^Modification of a read-only value attempted/;
739 eval { @+ = (7, 6, 5); };
741 if $@ !~ /^Modification of a read-only value attempted/;
745 eval { @- = qw(foo bar); };
747 if $@ !~ /^Modification of a read-only value attempted/;
752 print "#$#-..$#+\nnot " if $#+ != 2 or $#- != 1;
759 print "not " unless "@a" eq "a a";
766 print "not " if $str =~ /^\G/;
770 print "not " if $str =~ /^.\G/;
774 print "not " unless $str =~ /^..\G/;
778 print "not " if $str =~ /^...\G/;
782 print "not " unless $str =~ /.\G./ and $& eq 'bc';
786 print "not " unless $str =~ /\G../ and $& eq 'cd';
790 undef $foo; undef $bar;
791 print "#'$str','$foo','$bar'\nnot "
792 unless $str =~ /b(?{$foo = $_; $bar = pos})c/
793 and $foo eq 'abcde' and $bar eq 2;
797 undef $foo; undef $bar;
799 print "#'$str','$foo','$bar'\nnot "
800 unless $str =~ /b(?{$foo = $_; $bar = pos})c/g
801 and $foo eq 'abcde' and $bar eq 2 and pos $str eq 3;
807 undef $foo; undef $bar;
808 print "#'$str','$foo','$bar'\nnot "
809 unless /b(?{$foo = $_; $bar = pos})c/
810 and $foo eq 'abcde' and $bar eq 2;
814 undef $foo; undef $bar;
815 print "#'$str','$foo','$bar'\nnot "
816 unless /b(?{$foo = $_; $bar = pos})c/g
817 and $foo eq 'abcde' and $bar eq 2 and pos eq 3;
821 undef $foo; undef $bar;
823 1 while /b(?{$foo = $_; $bar = pos})c/g;
824 print "#'$str','$foo','$bar'\nnot "
825 unless $foo eq 'abcde' and $bar eq 2 and not defined pos;
829 undef $foo; undef $bar;
831 print "#'$str','$foo','$bar','$_'\nnot "
832 unless s/b(?{$foo = $_; $bar = pos})c/x/g and $foo eq 'abcde|abcde'
833 and $bar eq 8 and $_ eq 'axde|axde';
840 @dummy = /([ace]).(?{push @res, $1,$2})([ce])(?{push @res, $1,$2})/g;
841 @res = map {defined $_ ? "'$_'" : 'undef'} @res;
843 print "#'@res' '$_'\nnot "
844 unless "@res" eq "'a' undef 'a' 'c' 'e' undef 'a' undef 'a' 'c'";
849 @dummy = /([ace]).(?{push @res, $`,$&,$'})([ce])(?{push @res, $`,$&,$'})/g;
850 @res = map {defined $_ ? "'$_'" : 'undef'} @res;
852 print "#'@res' '$_'\nnot "
854 "'' 'ab' 'cde|abcde' " .
855 "'' 'abc' 'de|abcde' " .
856 "'abcd' 'e|' 'abcde' " .
857 "'abcde|' 'ab' 'cde' " .
858 "'abcde|' 'abc' 'de'" ;
862 #Some more \G anchor checks
863 $foo='aabbccddeeffgg';
868 print "not " unless($1 eq 'ab');
874 print "not " unless($1 eq 'cc');
880 print "not " unless($1 eq 'de');
884 print "not " unless $foo =~ /\Gef/g;
891 print "not " unless($1 eq 'aa');
896 print "not " unless($1 eq 'bb');
902 print "not " unless($1 eq 'cd');
908 print "not " unless('123||x|123|' eq join '|', @res);
912 # see if matching against temporaries (created via pp_helem()) is safe
913 { foo => "ok $test\n".$^X }->{foo} =~ /^(.*)\n/g;
917 # See if $i work inside (?{}) in the presense of saved substrings and
921 s/(\w)(?{push @b, $1})/,$1,/g for @a;
923 print "# \@b='@b', expect 'f o o b a r'\nnot " unless("@b" eq "f o o b a r");
927 print "not " unless("@a" eq ",f,,o,,o, ,b,,a,,r,");
932 { (?> [^{}]+ | (??{ $brackets }) )* }
936 print "ok $test\n"; # Did we survive?
939 "something { long { and } hairy" =~ $brackets;
940 print "ok $test\n"; # Did we survive?
943 "something { long { and } hairy" =~ m/((??{ $brackets }))/;
944 print "not " unless $1 eq "{ and }";
950 m/^-.*bb/mg and print "not ";
956 $text =~ /\GXb*X/g and print 'not ';
960 $text = "xA\n" x 500;
961 $text =~ /^\s*A/m and print 'not ';
966 @res = ($text =~ /.*?(b).*?\b/g);
967 "@res" eq 'b b' or print 'not ';
974 @c = grep(/[^\s]/,@a);
975 print "not " if "@b" ne "@c";
980 @c = grep(/[\S]/,@a);
981 print "not " if "@b" ne "@c";
986 @c = grep(/[^\S]/,@a);
987 print "not " if "@b" ne "@c";
992 @c = grep(/[\s]/,@a);
993 print "not " if "@b" ne "@c";
998 @c = grep(/[^\d]/,@a);
999 print "not " if "@b" ne "@c";
1004 @c = grep(/[\D]/,@a);
1005 print "not " if "@b" ne "@c";
1010 @c = grep(/[^\D]/,@a);
1011 print "not " if "@b" ne "@c";
1016 @c = grep(/[\d]/,@a);
1017 print "not " if "@b" ne "@c";
1022 @c = grep(/[^\w]/,@a);
1023 print "not " if "@b" ne "@c";
1028 @c = grep(/[\W]/,@a);
1029 print "not " if "@b" ne "@c";
1034 @c = grep(/[^\W]/,@a);
1035 print "not " if "@b" ne "@c";
1040 @c = grep(/[\w]/,@a);
1041 print "not " if "@b" ne "@c";
1045 # see if backtracking optimization works correctly
1046 "\n\n" =~ /\n $ \n/x or print "not ";
1050 "\n\n" =~ /\n* $ \n/x or print "not ";
1054 "\n\n" =~ /\n+ $ \n/x or print "not ";
1058 [] =~ /^ARRAY/ or print "# [] \nnot ";
1065 use overload '""' => sub { 'Object S' };
1066 sub new { bless [] }
1071 $a and $a =~ /^Object\sS/ or print "# '$a' \nnot ";
1075 # test result of match used as match (!)
1076 'a1b' =~ ('xyz' =~ /y/) and $` eq 'a' or print "not ";
1080 'a1b' =~ ('xyz' =~ /t/) and $` eq 'a' or print "not ";
1086 local $SIG{__WARN__} = sub { $w = 1 };
1088 $w = 1 if ("1\n" x 102) =~ /^\s*\n/m;
1090 print $w ? "not " : "", "ok $test\n";
1093 my %space = ( spc => " ",
1098 # There's no \v but the vertical tabulator seems miraculously
1099 # be 11 both in ASCII and EBCDIC.
1103 my @space0 = sort grep { $space{$_} =~ /\s/ } keys %space;
1104 my @space1 = sort grep { $space{$_} =~ /[[:space:]]/ } keys %space;
1105 my @space2 = sort grep { $space{$_} =~ /[[:blank:]]/ } keys %space;
1107 print "not " unless "@space0" eq "cr ff lf spc tab";
1108 print "ok $test # @space0\n";
1111 print "not " unless "@space1" eq "cr ff lf spc tab vt";
1112 print "ok $test # @space1\n";
1115 print "not " unless "@space2" eq "spc tab";
1116 print "ok $test # @space2\n";
1119 # bugid 20001021.005 - this caused a SEGV
1120 print "not " unless undef =~ /^([^\/]*)(.*)$/;
1124 # bugid 20000731.001
1126 print "not " unless "A \x{263a} B z C" =~ /A . B (??{ "z" }) C/;
1131 if (/(.)(\C)(\C)(.)/) {
1136 print "not ok 233\n";
1141 print "not ok 234\n";
1146 print "not ok 235\n";
1151 print "not ok 236\n";
1155 print "not ok $_\n";
1164 print "not ok 238\n";
1168 print "not ok $_\n";
1176 print "not ok 240\n";
1180 print "not ok $_\n";
1185 # japhy -- added 03/03/2001
1186 () = (my $str = "abc") =~ /(...)/;
1188 print "not " if $1 ne "abc";
1192 # The 242 and 243 go with the 244 and 245.
1193 # The trick is that in EBCDIC the explicit numeric range should match
1194 # (as also in non-EBCDIC) but the explicit alphabetic range should not match.
1196 if ("\x8e" =~ /[\x89-\x91]/) {
1199 print "not ok 242\n";
1202 if ("\xce" =~ /[\xc9-\xd1]/) {
1205 print "not ok 243\n";
1208 # In most places these tests would succeed since \x8e does not
1209 # in most character sets match 'i' or 'j' nor would \xce match
1210 # 'I' or 'J', but strictly speaking these tests are here for
1211 # the good of EBCDIC, so let's test these only there.
1212 if (ord('i') == 0x89 && ord('J') == 0xd1) { # EBCDIC
1213 if ("\x8e" !~ /[i-j]/) {
1216 print "not ok 244\n";
1218 if ("\xce" !~ /[I-J]/) {
1221 print "not ok 245\n";
1225 print "ok $_ # Skip: not EBCDIC\n";
1229 print "not " unless "\x{ab}" =~ /\x{ab}/;
1232 print "not " unless "\x{abcd}" =~ /\x{abcd}/;
1236 # bug id 20001008.001
1239 my @x = ("stra\337e 138","stra\337e 138");
1241 s/(\d+)\s*([\w\-]+)/$1 . uc $2/e;
1242 my($latin) = /^(.+)(?:\s+\d)/;
1243 print $latin eq "stra\337e" ? "ok $test\n" : # 248,249
1244 "#latin[$latin]\nnot ok $test\n";
1246 $latin =~ s/stra\337e/straße/; # \303\237 after the 2nd a
1248 $latin =~ s!(s)tr(?:aß|s+e)!$1tr.!; # \303\237 after the a
1253 print "not " unless "ba\xd4c" =~ /([a\xd4]+)/ && $1 eq "a\xd4";
1256 print "not " unless "ba\xd4c" =~ /([a\xd4]+)/ && $1 eq "a\x{d4}";
1259 print "not " unless "ba\x{d4}c" =~ /([a\xd4]+)/ && $1 eq "a\x{d4}";
1262 print "not " unless "ba\x{d4}c" =~ /([a\xd4]+)/ && $1 eq "a\xd4";
1265 print "not " unless "ba\xd4c" =~ /([a\x{d4}]+)/ && $1 eq "a\xd4";
1268 print "not " unless "ba\xd4c" =~ /([a\x{d4}]+)/ && $1 eq "a\x{d4}";
1271 print "not " unless "ba\x{d4}c" =~ /([a\x{d4}]+)/ && $1 eq "a\x{d4}";
1274 print "not " unless "ba\x{d4}c" =~ /([a\x{d4}]+)/ && $1 eq "a\xd4";
1279 # the first half of 20001028.003
1282 my ($Y) = $X =~ /(.*)/;
1283 print "not " unless $Y eq v1448 && length($Y) == 1;
1290 my $X = "Szab\x{f3},Bal\x{e1}zs";
1292 $Y =~ s/(B)/$1/ for 0..3;
1293 print "not " unless $Y eq $X && $X eq "Szab\x{f3},Bal\x{e1}zs";
1298 # the second half of 20001028.003
1300 $X =~ s/^/chr(1488)/e;
1301 print "not " unless length $X == 1 && ord($X) == 1488;
1312 print "not " unless $x eq "\x{100}B" && length($x) == 2;
1317 # bug id 20001230.002
1319 print "not " unless "École" =~ /^\C\C(.)/ && $1 eq 'c';
1322 print "not " unless "École" =~ /^\C\C(c)/;
1327 my $test = 264; # till 575
1329 use charnames ':full';
1331 # This is far from complete testing, there are dozens of character
1332 # classes in Unicode. The mixing of literals and \N{...} is
1333 # intentional so that in non-Latin-1 places we test the native
1334 # characters, not the Unicode code points.
1338 "\N{CYRILLIC SMALL LETTER A}" => 'Ll',
1340 "\N{GREEK CAPITAL LETTER ALPHA}" => 'Lu',
1341 "\N{HIRAGANA LETTER SMALL A}" => 'Lo',
1342 "\N{COMBINING GRAVE ACCENT}" => 'Mn',
1344 "\N{ARABIC-INDIC DIGIT ZERO}" => 'Nd',
1351 for my $char (keys %s) {
1352 my $class = $s{$char};
1353 my $code = sprintf("%04x", ord($char));
1354 printf "# 0x$code\n";
1355 print "# IsAlpha\n";
1356 if ($class =~ /^[LM]/) {
1357 print "not " unless $char =~ /\p{IsAlpha}/;
1358 print "ok $test\n"; $test++;
1359 print "not " if $char =~ /\P{IsAlpha}/;
1360 print "ok $test\n"; $test++;
1362 print "not " if $char =~ /\p{IsAlpha}/;
1363 print "ok $test\n"; $test++;
1364 print "not " unless $char =~ /\P{IsAlpha}/;
1365 print "ok $test\n"; $test++;
1367 print "# IsAlnum\n";
1368 if ($class =~ /^[LMN]/ && $char ne "_") {
1369 print "not " unless $char =~ /\p{IsAlnum}/;
1370 print "ok $test\n"; $test++;
1371 print "not " if $char =~ /\P{IsAlnum}/;
1372 print "ok $test\n"; $test++;
1374 print "not " if $char =~ /\p{IsAlnum}/;
1375 print "ok $test\n"; $test++;
1376 print "not " unless $char =~ /\P{IsAlnum}/;
1377 print "ok $test\n"; $test++;
1379 print "# IsASCII\n";
1381 print "not " unless $char =~ /\p{IsASCII}/;
1382 print "ok $test\n"; $test++;
1383 print "not " if $char =~ /\P{IsASCII}/;
1384 print "ok $test\n"; $test++;
1386 print "not " if $char =~ /\p{IsASCII}/;
1387 print "ok $test\n"; $test++;
1388 print "not " unless $char =~ /\P{IsASCII}/;
1389 print "ok $test\n"; $test++;
1391 print "# IsCntrl\n";
1392 if ($class =~ /^C/) {
1393 print "not " unless $char =~ /\p{IsCntrl}/;
1394 print "ok $test\n"; $test++;
1395 print "not " if $char =~ /\P{IsCntrl}/;
1396 print "ok $test\n"; $test++;
1398 print "not " if $char =~ /\p{IsCntrl}/;
1399 print "ok $test\n"; $test++;
1400 print "not " unless $char =~ /\P{IsCntrl}/;
1401 print "ok $test\n"; $test++;
1403 print "# IsBlank\n";
1404 if ($class =~ /^Z[lp]/ || $char eq " ") {
1405 print "not " unless $char =~ /\p{IsBlank}/;
1406 print "ok $test\n"; $test++;
1407 print "not " if $char =~ /\P{IsBlank}/;
1408 print "ok $test\n"; $test++;
1410 print "not " if $char =~ /\p{IsBlank}/;
1411 print "ok $test\n"; $test++;
1412 print "not " unless $char =~ /\P{IsBlank}/;
1413 print "ok $test\n"; $test++;
1415 print "# IsDigit\n";
1416 if ($class =~ /^Nd$/) {
1417 print "not " unless $char =~ /\p{IsDigit}/;
1418 print "ok $test\n"; $test++;
1419 print "not " if $char =~ /\P{IsDigit}/;
1420 print "ok $test\n"; $test++;
1422 print "not " if $char =~ /\p{IsDigit}/;
1423 print "ok $test\n"; $test++;
1424 print "not " unless $char =~ /\P{IsDigit}/;
1425 print "ok $test\n"; $test++;
1427 print "# IsGraph\n";
1428 if ($class =~ /^([LMNPS])|Co/) {
1429 print "not " unless $char =~ /\p{IsGraph}/;
1430 print "ok $test\n"; $test++;
1431 print "not " if $char =~ /\P{IsGraph}/;
1432 print "ok $test\n"; $test++;
1434 print "not " if $char =~ /\p{IsGraph}/;
1435 print "ok $test\n"; $test++;
1436 print "not " unless $char =~ /\P{IsGraph}/;
1437 print "ok $test\n"; $test++;
1439 print "# IsLower\n";
1440 if ($class =~ /^Ll$/) {
1441 print "not " unless $char =~ /\p{IsLower}/;
1442 print "ok $test\n"; $test++;
1443 print "not " if $char =~ /\P{IsLower}/;
1444 print "ok $test\n"; $test++;
1446 print "not " if $char =~ /\p{IsLower}/;
1447 print "ok $test\n"; $test++;
1448 print "not " unless $char =~ /\P{IsLower}/;
1449 print "ok $test\n"; $test++;
1451 print "# IsPrint\n";
1452 if ($class =~ /^([LMNPS])|Co|Zs/) {
1453 print "not " unless $char =~ /\p{IsPrint}/;
1454 print "ok $test\n"; $test++;
1455 print "not " if $char =~ /\P{IsPrint}/;
1456 print "ok $test\n"; $test++;
1458 print "not " if $char =~ /\p{IsPrint}/;
1459 print "ok $test\n"; $test++;
1460 print "not " unless $char =~ /\P{IsPrint}/;
1461 print "ok $test\n"; $test++;
1463 print "# IsPunct\n";
1464 if ($class =~ /^P/ || $char eq "_") {
1465 print "not " unless $char =~ /\p{IsPunct}/;
1466 print "ok $test\n"; $test++;
1467 print "not " if $char =~ /\P{IsPunct}/;
1468 print "ok $test\n"; $test++;
1470 print "not " if $char =~ /\p{IsPunct}/;
1471 print "ok $test\n"; $test++;
1472 print "not " unless $char =~ /\P{IsPunct}/;
1473 print "ok $test\n"; $test++;
1475 print "# IsSpace\n";
1476 if ($class =~ /^Z/ || ($code =~ /^(0009|000A|000B|000C|000D)$/)) {
1477 print "not " unless $char =~ /\p{IsSpace}/;
1478 print "ok $test\n"; $test++;
1479 print "not " if $char =~ /\P{IsSpace}/;
1480 print "ok $test\n"; $test++;
1482 print "not " if $char =~ /\p{IsSpace}/;
1483 print "ok $test\n"; $test++;
1484 print "not " unless $char =~ /\P{IsSpace}/;
1485 print "ok $test\n"; $test++;
1487 print "# IsUpper\n";
1488 if ($class =~ /^L[ut]/) {
1489 print "not " unless $char =~ /\p{IsUpper}/;
1490 print "ok $test\n"; $test++;
1491 print "not " if $char =~ /\P{IsUpper}/;
1492 print "ok $test\n"; $test++;
1494 print "not " if $char =~ /\p{IsUpper}/;
1495 print "ok $test\n"; $test++;
1496 print "not " unless $char =~ /\P{IsUpper}/;
1497 print "ok $test\n"; $test++;
1500 if ($class =~ /^[LMN]/ || $char eq "_") {
1501 print "not " unless $char =~ /\p{IsWord}/;
1502 print "ok $test\n"; $test++;
1503 print "not " if $char =~ /\P{IsWord}/;
1504 print "ok $test\n"; $test++;
1506 print "not " if $char =~ /\p{IsWord}/;
1507 print "ok $test\n"; $test++;
1508 print "not " unless $char =~ /\P{IsWord}/;
1509 print "ok $test\n"; $test++;
1515 $_ = "abc\x{100}\x{200}\x{300}\x{380}\x{400}defg";
1517 if (/(.\x{300})./) {
1520 print "not " unless $` eq "abc\x{100}" && length($`) == 4;
1523 print "not " unless $& eq "\x{200}\x{300}\x{380}" && length($&) == 3;
1526 print "not " unless $' eq "\x{400}defg" && length($') == 5;
1529 print "not " unless $1 eq "\x{200}\x{300}" && length($1) == 2;
1532 for (576..580) { print "not ok $_\n" }
1537 # bug id 20010306.008
1540 # The original bug report had 'no utf8' here but that was irrelevant.
1541 $a =~ m/\w/; # used to core dump