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 eval 'use Config'; # Defaults assumed if this fails
20 if ($x =~ /^abc/) {print "ok 1\n";} else {print "not ok 1\n";}
21 if ($x !~ /^def/) {print "ok 2\n";} else {print "not ok 2\n";}
24 if ($x =~ /^def/) {print "ok 3\n";} else {print "not ok 3\n";}
28 if (/^([0-9][0-9]*)/) {print "ok 4\n";} else {print "not ok 4\n";}
30 if ($x =~ /^xxx/) {print "not ok 5\n";} else {print "ok 5\n";}
31 if ($x !~ /^abc/) {print "not ok 6\n";} else {print "ok 6\n";}
33 if ($x =~ /def/) {print "ok 7\n";} else {print "not ok 7\n";}
34 if ($x !~ /def/) {print "not ok 8\n";} else {print "ok 8\n";}
36 if ($x !~ /.def/) {print "ok 9\n";} else {print "not ok 9\n";}
37 if ($x =~ /.def/) {print "not ok 10\n";} else {print "ok 10\n";}
39 if ($x =~ /\ndef/) {print "ok 11\n";} else {print "not ok 11\n";}
40 if ($x !~ /\ndef/) {print "not ok 12\n";} else {print "ok 12\n";}
43 if (/(a*b*)(c*)/ && $1 eq 'aaabbb' && $2 eq 'ccc') {
48 if (/(a+b+c+)/ && $1 eq 'aaabbbccc') {
54 if (/a+b?c+/) {print "not ok 15\n";} else {print "ok 15\n";}
57 if (/a+b?c+/) {print "ok 16\n";} else {print "not ok 16\n";}
58 if (/a*b+c*/) {print "ok 17\n";} else {print "not ok 17\n";}
61 if (/a*b?c*/) {print "ok 18\n";} else {print "not ok 18\n";}
62 if (/a*b+c*/) {print "not ok 19\n";} else {print "ok 19\n";}
65 if (/bcd|xyz/) {print "ok 20\n";} else {print "not ok 20\n";}
66 if (/xyz|bcd/) {print "ok 21\n";} else {print "not ok 21\n";}
68 if (m|bc/*d|) {print "ok 22\n";} else {print "not ok 22\n";}
70 if (/^$_$/) {print "ok 23\n";} else {print "not ok 23\n";}
72 $* = 1; # test 3 only tested the optimized version--this one is for real
73 if ("ab\ncd\n" =~ /^cd/) {print "ok 24\n";} else {print "not ok 24\n";}
80 @XXX = ('ok 25','not ok 25', 'ok 26','not ok 26','not ok 27');
81 while ($_ = shift(@XXX)) {
82 ?(.*)? && (print $1,"\n");
84 /not ok 26/ && reset 'X';
87 while (($key,$val) = each(%XXX)) {
96 if ($& eq 'xyz') {print "ok 28\n";} else {print "not ok 28\n";}
101 if ($& eq 'xyz') {print "ok 29\n";} else {print "not ok 29\n";}
106 if ($& eq 'xyz') {print "ok 30\n";} else {print "not ok 30\n";}
109 /def/; # optimized up to cmd
110 if ("$`:$&:$'" eq 'abc:def:ghi') {print "ok 31\n";} else {print "not ok 31\n";}
112 /cde/ + 0; # optimized only to spat
113 if ("$`:$&:$'" eq 'ab:cde:fghi') {print "ok 32\n";} else {print "not ok 32\n";}
115 /[d][e][f]/; # not optimized
116 if ("$`:$&:$'" eq 'abc:def:ghi') {print "ok 33\n";} else {print "not ok 33\n";}
118 $_ = 'now is the {time for all} good men to come to.';
120 if ($1 eq 'time for all') {print "ok 34\n";} else {print "not ok 34 $1\n";}
122 $_ = 'xxx {3,4} yyy zzz';
123 print /( {3,4})/ ? "ok 35\n" : "not ok 35\n";
124 print $1 eq ' ' ? "ok 36\n" : "not ok 36\n";
125 print /( {4,})/ ? "not ok 37\n" : "ok 37\n";
126 print /( {2,3}.)/ ? "ok 38\n" : "not ok 38\n";
127 print $1 eq ' y' ? "ok 39\n" : "not ok 39\n";
128 print /(y{2,3}.)/ ? "ok 40\n" : "not ok 40\n";
129 print $1 eq 'yyy ' ? "ok 41\n" : "not ok 41\n";
130 print /x {3,4}/ ? "not ok 42\n" : "ok 42\n";
131 print /^xxx {3,4}/ ? "not ok 43\n" : "ok 43\n";
133 $_ = "now is the time for all good men to come to.";
135 print join(':',@words) eq "now:is:the:time:for:all:good:men:to:come:to"
143 print join(':',@words) eq "now:is:the:time:for:all:good:men:to:come:to"
152 print join(':',@words) eq "to:to"
154 : "not ok 46 `@words'\n";
158 print join(':',@words) eq "to:to"
160 : "not ok 47 `@words'\n";
174 $t1=$t2=$t3=$t4=$t5=$t6=$t7=$t8=$t9=0;
188 $x = "$t1$t2$t3$t4$t5$t6$t7$t8$t9";
189 print $x eq '505550555' ? "ok 48\n" : "not ok 48 $x\n";
192 print "abc" =~ /^abc$|$xyz/ ? "ok 49\n" : "not ok 49\n";
194 # perl 4.009 says "unmatched ()"
195 eval '"abc" =~ /a(bc$)|$xyz/; $result = "$&:$1"';
196 print $@ eq "" ? "ok 50\n" : "not ok 50\n";
197 print $result eq "abc:bc" ? "ok 51\n" : "not ok 51\n";
202 print $` eq "" ? "ok 52\n" : "not ok 52\n" if $x;
204 print $` eq "abcfoo" ? "ok 53\n" : "not ok 53\n" if $x;
206 print $x == 0 ? "ok 54\n" : "not ok 54\n";
209 print $` eq "" ? "ok 55\n" : "not ok 55\n" if $x;
211 print $` eq "abcfoo" ? "ok 56\n" : "not ok 56\n" if $x;
213 print $x == 0 ? "ok 57\n" : "not ok 57\n";
216 print $' eq "fooabcbar" ? "ok 58\n" : "not ok 58\n" if $x;
218 print $' eq "bar" ? "ok 59\n" : "not ok 59\n" if $x;
221 print scalar @x == 2 ? "ok 60\n" : "not ok 60\n";
226 print "not " if (pos $_) != 2;
229 print "not " if defined pos $_;
233 'abc' =~ m'a(?{ $out = 2 })b';
234 print "not " if $out != 2;
238 'abc' =~ m'a(?{ $out = 3 })c';
239 print "not " if $out != 1;
242 $_ = 'foobar1 bar2 foobar3 barfoobar5 foobar6';
243 @out = /(?<!foo)bar./g;
244 print "not " if "@out" ne 'bar2 barf';
247 # Tests which depend on REG_INFTY
248 $reg_infty = defined $Config{reg_infty} ? $Config{reg_infty} : 32767;
249 $reg_infty_m = $reg_infty - 1; $reg_infty_p = $reg_infty + 1;
251 # As well as failing if the pattern matches do unexpected things, the
252 # next three tests will fail if you should have picked up a lower-than-
253 # default value for $reg_infty from Config.pm, but have not.
256 print "not " if eval q(('aaa' =~ /(a{1,$reg_infty_m})/)[0] ne 'aaa') || $@;
260 print "not " if eval q(('a' x $reg_infty_m) !~ /a{$reg_infty_m}/) || $@;
264 print "not " if eval q(('a' x ($reg_infty_m - 1)) =~ /a{$reg_infty_m}/) || $@;
268 eval "'aaa' =~ /a{1,$reg_infty}/";
269 print "not " if $@ !~ m%^\QQuantifier in {,} bigger than%;
272 eval "'aaa' =~ /a{1,$reg_infty_p}/";
274 if $@ !~ m%^\QQuantifier in {,} bigger than%;
278 # Poke a couple more parse failures
280 $context = 'x' x 256;
281 eval qq("${context}y" =~ /(?<=$context)y/);
282 print "not " if $@ !~ m%^\QLookbehind longer than 255 not%;
290 for $l (125, 140, 250, 270, 300000, 30) { # Ordered to free memory
292 print "# length=$l\nnot " unless "ba$a=" =~ /a$a=/;
296 print "not " if "b$a=" =~ /a$a=/;
301 # 20000 nodes, each taking 3 words per string, and 1 per branch
302 $long_constant_len = join '|', 12120 .. 32645;
303 $long_var_len = join '|', 8120 .. 28645;
304 %ans = ( 'ax13876y25677lbc' => 1,
305 'ax13876y25677mcb' => 0, # not b.
306 'ax13876y35677nbc' => 0, # Num too big
307 'ax13876y25677y21378obc' => 1,
308 'ax13876y25677y21378zbc' => 0, # Not followed by [k-o]
309 'ax13876y25677y21378y21378kbc' => 1,
310 'ax13876y25677y21378y21378kcb' => 0, # Not b.
311 'ax13876y25677y21378y21378y21378kbc' => 0, # 5 runs
315 print "# const-len `$_' not => $ans{$_}\nnot "
316 if $ans{$_} xor /a(?=([yx]($long_constant_len)){2,4}[k-o]).*b./o;
319 print "# var-len `$_' not => $ans{$_}\nnot "
320 if $ans{$_} xor /a(?=([yx]($long_var_len)){2,4}[k-o]).*b./o;
325 $_ = " a (bla()) and x(y b((l)u((e))) and b(l(e)e)e";
326 $expect = "(bla()) ((l)u((e))) (l(e)e)";
332 (?{ $c = 1 }) # Initialize
334 (?(?{ $c == 0 }) # PREVIOUS iteration was OK, stop the loop
336 ) # Fail: will unwind one iteration back
339 [^()]+ # Match a big chunk
342 ) # Do not try to match subchunks
350 )+ # This may not match with different subblocks
355 ) # Otherwise the chunk 1 may succeed with $c>0
360 push @ans, $res while $res = matchit;
362 print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne "1 1 1";
368 print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne $expect;
372 print "not " unless "abc" =~ /^(??{"a"})b/;
377 $matched = qr/\((?:(?>[^()]+)|(??{$matched}))*\)/;
380 push(@ans, $res), push(@ans1, $&) while $res = m/$matched/g;
382 print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne "1 1 1";
386 print "# ans1='@ans1'\n# expect='$expect'\nnot " if "@ans1" ne $expect;
392 print "# ans='@ans'\n# expect='$expect'\nnot " if "@ans" ne $expect;
396 @ans = ('a/b' =~ m%(.*/)?(.*)%); # Stack may be bad
397 print "not " if "@ans" ne 'a/ b';
401 $code = '{$blah = 45}';
404 print "not " unless $@ and $@ =~ /not allowed at runtime/ and $blah == 12;
408 for $code ('{$blah = 45}','=xx') {
410 $res = eval { "xx" =~ /(?$code)/o };
411 if ($code eq '=xx') {
412 print "#'$@','$res','$blah'\nnot " unless not $@ and $res;
414 print "#'$@','$res','$blah'\nnot " unless $@ and $@ =~ /not allowed at runtime/ and $blah == 12;
420 $code = '{$blah = 45}';
423 print "not " if $blah != 45;
429 print "not " if $blah != 45;
435 print "not " unless pos($x) == 2;
440 print "not " unless pos($x) == 2;
450 print "not " unless f(pos($x)) == 4;
455 'foot' =~ /foo(?{$x = 12; 75})[t]/;
456 print "not " unless $^R eq '75';
461 'foot' =~ /foo(?{$x = 12; 75})[xy]/;
462 print "not " unless $^R eq '67' and $x eq '12';
467 'foot' =~ /foo(?{ $^R + 12 })((?{ $x = 12; $^R + 17 })[xy])?/;
468 print "not " unless $^R eq '79' and $x eq '12';
472 print "not " unless qr/\b\v$/i eq '(?i-xsm:\bv$)';
476 print "not " unless qr/\b\v$/s eq '(?s-xim:\bv$)';
480 print "not " unless qr/\b\v$/m eq '(?m-xis:\bv$)';
484 print "not " unless qr/\b\v$/x eq '(?x-ism:\bv$)';
488 print "not " unless qr/\b\v$/xism eq '(?msix:\bv$)';
492 print "not " unless qr/\b\v$/ eq '(?-xism:\bv$)';
497 foreach $ans ('', 'c') {
498 /(?<=(?=a)..)((?=c)|.)/g;
499 print "# \$1 ='$1'\n# \$ans='$ans'\nnot " unless $1 eq $ans;
505 foreach $ans ('', 'a', '') {
507 print "# \$& ='$&'\n# \$ans='$ans'\nnot " unless $& eq $ans;
513 my($v,$a,$b,$res) = @_;
515 print "not " unless $res eq $v;
519 prefixify('/a/b/lib/arch', "/a/b/lib", 'X/lib', 'X/lib/arch');
520 prefixify('/a/b/man/arch', "/a/b/man", 'X/man', 'X/man/arch');
524 print "not " unless $1 and /$1/;
531 print "not " unless $b eq '9';
537 print "not " unless $b eq '11';
544 print "not " unless $b eq '14';
552 my $lex_res = ($lex_b =~ qr/$lex_b(?{ $lex_c = $lex_a++ })/);
553 print "not " unless $lex_res eq '1';
556 print "not " unless $lex_a eq '44';
559 print "not " unless $lex_c eq '43';
565 $match = eval { /$a$c$a/ };
567 unless $b eq '14' and $@ =~ /Eval-group not allowed/ and not $match;
577 my $lex_res = ($lex_b =~ qr/17(?{ $lex_c = $lex_a++ })/);
578 print "not " unless $lex_res eq '1';
581 print "not " unless $lex_a eq '44';
584 print "not " unless $lex_c eq '43';
593 '' =~ /(?{ $c = 4 })/;
594 print "not " unless $c == 4;
598 print "not " unless $c == 3;
603 my $warn_pat = shift;
604 return sub { print "not " unless $_[0] =~ /$warn_pat/ }
608 my ($warn_pat, $code) = @_;
610 eval 'BEGIN { use warnings; $SIG{__WARN__} = $warn_pat };' . $code;
617 my $warn_pat = shift;
618 return sub { must_warn(must_warn_pat($warn_pat)) }
621 my $for_future = make_must_warn('reserved for future extensions');
623 &$for_future('q(a:[b]:) =~ /[x[:foo:]]/');
625 #&$for_future('q(a=[b]=) =~ /[x[=foo=]]/');
626 print "ok $test\n"; $test++; # now a fatal croak
628 #&$for_future('q(a.[b].) =~ /[x[.foo.]]/');
629 print "ok $test\n"; $test++; # now a fatal croak
631 # test if failure of patterns returns empty list
654 print "not " if $#+ != 0 or $#- != 0;
658 print "not " if $+[0] != 2 or $-[0] != 1;
663 if defined $+[1] or defined $-[1] or defined $+[2] or defined $-[2];
668 print "not " if $#+ != 2 or $#- != 2;
672 print "not " if $+[0] != 3 or $-[0] != 0;
676 print "not " if $+[1] != 2 or $-[1] != 1;
680 print "not " if $+[2] != 3 or $-[2] != 2;
685 if defined $+[3] or defined $-[3] or defined $+[4] or defined $-[4];
690 print "not " if $#+ != 3 or $#- != 3;
694 print "not " if $+[0] != 3 or $-[0] != 0;
698 print "not " if $+[1] != 2 or $-[1] != 1;
702 print "not " if $+[3] != 3 or $-[3] != 2;
707 if defined $+[2] or defined $-[2] or defined $+[4] or defined $-[4];
712 print "not " if $#+ != 1 or $#- != 1;
716 print "not " if $+[0] != 2 or $-[0] != 0;
720 print "not " if $+[1] != 2 or $-[1] != 1;
725 if defined $+[2] or defined $-[2] or defined $+[3] or defined $-[3];
729 eval { $+[0] = 13; };
731 if $@ !~ /^Modification of a read-only value attempted/;
735 eval { $-[0] = 13; };
737 if $@ !~ /^Modification of a read-only value attempted/;
741 eval { @+ = (7, 6, 5); };
743 if $@ !~ /^Modification of a read-only value attempted/;
747 eval { @- = qw(foo bar); };
749 if $@ !~ /^Modification of a read-only value attempted/;
754 print "#$#-..$#+\nnot " if $#+ != 2 or $#- != 1;
761 print "not " unless "@a" eq "a a";
768 print "not " if $str =~ /^\G/;
772 print "not " if $str =~ /^.\G/;
776 print "not " unless $str =~ /^..\G/;
780 print "not " if $str =~ /^...\G/;
784 print "not " unless $str =~ /.\G./ and $& eq 'bc';
788 print "not " unless $str =~ /\G../ and $& eq 'cd';
792 undef $foo; undef $bar;
793 print "#'$str','$foo','$bar'\nnot "
794 unless $str =~ /b(?{$foo = $_; $bar = pos})c/
795 and $foo eq 'abcde' and $bar eq 2;
799 undef $foo; undef $bar;
801 print "#'$str','$foo','$bar'\nnot "
802 unless $str =~ /b(?{$foo = $_; $bar = pos})c/g
803 and $foo eq 'abcde' and $bar eq 2 and pos $str eq 3;
809 undef $foo; undef $bar;
810 print "#'$str','$foo','$bar'\nnot "
811 unless /b(?{$foo = $_; $bar = pos})c/
812 and $foo eq 'abcde' and $bar eq 2;
816 undef $foo; undef $bar;
817 print "#'$str','$foo','$bar'\nnot "
818 unless /b(?{$foo = $_; $bar = pos})c/g
819 and $foo eq 'abcde' and $bar eq 2 and pos eq 3;
823 undef $foo; undef $bar;
825 1 while /b(?{$foo = $_; $bar = pos})c/g;
826 print "#'$str','$foo','$bar'\nnot "
827 unless $foo eq 'abcde' and $bar eq 2 and not defined pos;
831 undef $foo; undef $bar;
833 print "#'$str','$foo','$bar','$_'\nnot "
834 unless s/b(?{$foo = $_; $bar = pos})c/x/g and $foo eq 'abcde|abcde'
835 and $bar eq 8 and $_ eq 'axde|axde';
842 @dummy = /([ace]).(?{push @res, $1,$2})([ce])(?{push @res, $1,$2})/g;
843 @res = map {defined $_ ? "'$_'" : 'undef'} @res;
845 print "#'@res' '$_'\nnot "
846 unless "@res" eq "'a' undef 'a' 'c' 'e' undef 'a' undef 'a' 'c'";
851 @dummy = /([ace]).(?{push @res, $`,$&,$'})([ce])(?{push @res, $`,$&,$'})/g;
852 @res = map {defined $_ ? "'$_'" : 'undef'} @res;
854 print "#'@res' '$_'\nnot "
856 "'' 'ab' 'cde|abcde' " .
857 "'' 'abc' 'de|abcde' " .
858 "'abcd' 'e|' 'abcde' " .
859 "'abcde|' 'ab' 'cde' " .
860 "'abcde|' 'abc' 'de'" ;
864 #Some more \G anchor checks
865 $foo='aabbccddeeffgg';
870 print "not " unless($1 eq 'ab');
876 print "not " unless($1 eq 'cc');
882 print "not " unless($1 eq 'de');
886 print "not " unless $foo =~ /\Gef/g;
893 print "not " unless($1 eq 'aa');
898 print "not " unless($1 eq 'bb');
904 print "not " unless($1 eq 'cd');
910 print "not " unless('123||x|123|' eq join '|', @res);
914 # see if matching against temporaries (created via pp_helem()) is safe
915 { foo => "ok $test\n".$^X }->{foo} =~ /^(.*)\n/g;
919 # See if $i work inside (?{}) in the presense of saved substrings and
923 s/(\w)(?{push @b, $1})/,$1,/g for @a;
925 print "# \@b='@b', expect 'f o o b a r'\nnot " unless("@b" eq "f o o b a r");
929 print "not " unless("@a" eq ",f,,o,,o, ,b,,a,,r,");
934 { (?> [^{}]+ | (??{ $brackets }) )* }
938 print "ok $test\n"; # Did we survive?
941 "something { long { and } hairy" =~ $brackets;
942 print "ok $test\n"; # Did we survive?
945 "something { long { and } hairy" =~ m/((??{ $brackets }))/;
946 print "not " unless $1 eq "{ and }";
952 m/^-.*bb/mg and print "not ";
958 $text =~ /\GXb*X/g and print 'not ';
962 $text = "xA\n" x 500;
963 $text =~ /^\s*A/m and print 'not ';
968 @res = ($text =~ /.*?(b).*?\b/g);
969 "@res" eq 'b b' or print 'not ';
976 @c = grep(/[^\s]/,@a);
977 print "not " if "@b" ne "@c";
982 @c = grep(/[\S]/,@a);
983 print "not " if "@b" ne "@c";
988 @c = grep(/[^\S]/,@a);
989 print "not " if "@b" ne "@c";
994 @c = grep(/[\s]/,@a);
995 print "not " if "@b" ne "@c";
1000 @c = grep(/[^\d]/,@a);
1001 print "not " if "@b" ne "@c";
1006 @c = grep(/[\D]/,@a);
1007 print "not " if "@b" ne "@c";
1012 @c = grep(/[^\D]/,@a);
1013 print "not " if "@b" ne "@c";
1018 @c = grep(/[\d]/,@a);
1019 print "not " if "@b" ne "@c";
1024 @c = grep(/[^\w]/,@a);
1025 print "not " if "@b" ne "@c";
1030 @c = grep(/[\W]/,@a);
1031 print "not " if "@b" ne "@c";
1036 @c = grep(/[^\W]/,@a);
1037 print "not " if "@b" ne "@c";
1042 @c = grep(/[\w]/,@a);
1043 print "not " if "@b" ne "@c";
1047 # see if backtracking optimization works correctly
1048 "\n\n" =~ /\n $ \n/x or print "not ";
1052 "\n\n" =~ /\n* $ \n/x or print "not ";
1056 "\n\n" =~ /\n+ $ \n/x or print "not ";
1060 [] =~ /^ARRAY/ or print "# [] \nnot ";
1067 use overload '""' => sub { 'Object S' };
1068 sub new { bless [] }
1073 $a and $a =~ /^Object\sS/ or print "# '$a' \nnot ";
1077 # test result of match used as match (!)
1078 'a1b' =~ ('xyz' =~ /y/) and $` eq 'a' or print "not ";
1082 'a1b' =~ ('xyz' =~ /t/) and $` eq 'a' or print "not ";
1088 local $SIG{__WARN__} = sub { $w = 1 };
1090 $w = 1 if ("1\n" x 102) =~ /^\s*\n/m;
1092 print $w ? "not " : "", "ok $test\n";
1095 my %space = ( spc => " ",
1100 # There's no \v but the vertical tabulator seems miraculously
1101 # be 11 both in ASCII and EBCDIC.
1105 my @space0 = sort grep { $space{$_} =~ /\s/ } keys %space;
1106 my @space1 = sort grep { $space{$_} =~ /[[:space:]]/ } keys %space;
1107 my @space2 = sort grep { $space{$_} =~ /[[:blank:]]/ } keys %space;
1109 print "not " unless "@space0" eq "cr ff lf spc tab";
1110 print "ok $test # @space0\n";
1113 print "not " unless "@space1" eq "cr ff lf spc tab vt";
1114 print "ok $test # @space1\n";
1117 print "not " unless "@space2" eq "spc tab";
1118 print "ok $test # @space2\n";
1121 # bugid 20001021.005 - this caused a SEGV
1122 print "not " unless undef =~ /^([^\/]*)(.*)$/;
1126 # bugid 20000731.001
1128 print "not " unless "A \x{263a} B z C" =~ /A . B (??{ "z" }) C/;
1132 my $ordA = ord('A');
1135 if (/(.)(\C)(\C)(.)/) {
1140 print "not ok 233\n";
1142 if ($ordA == 65) { # ASCII (or equivalent), should be UTF-8
1146 print "not ok 234\n";
1151 print "not ok 235\n";
1153 } elsif ($ordA == 193) { # EBCDIC (or equivalent), should be UTF-EBCDIC
1157 print "not ok 234\n";
1162 print "not ok 235\n";
1166 print "not ok $_ # ord('A') == $ordA\n";
1172 print "not ok 236\n";
1176 print "not ok $_\n";
1182 # currently \C are still tagged as UTF-8
1187 print "not ok 238\n";
1189 } elsif ($ordA == 193) {
1193 print "not ok 238\n";
1196 print "not ok 238 # ord('A') == $ordA\n";
1200 print "not ok $_\n";
1205 # currently \C are still tagged as UTF-8
1210 print "not ok 240\n";
1212 } elsif ($ordA == 193) {
1216 print "not ok 240\n";
1219 print "not ok 240 # ord('A') == $ordA\n";
1223 print "not ok $_\n";
1228 # japhy -- added 03/03/2001
1229 () = (my $str = "abc") =~ /(...)/;
1231 print "not " if $1 ne "abc";
1235 # The 242 and 243 go with the 244 and 245.
1236 # The trick is that in EBCDIC the explicit numeric range should match
1237 # (as also in non-EBCDIC) but the explicit alphabetic range should not match.
1239 if ("\x8e" =~ /[\x89-\x91]/) {
1242 print "not ok 242\n";
1245 if ("\xce" =~ /[\xc9-\xd1]/) {
1248 print "not ok 243\n";
1251 # In most places these tests would succeed since \x8e does not
1252 # in most character sets match 'i' or 'j' nor would \xce match
1253 # 'I' or 'J', but strictly speaking these tests are here for
1254 # the good of EBCDIC, so let's test these only there.
1255 if (ord('i') == 0x89 && ord('J') == 0xd1) { # EBCDIC
1256 if ("\x8e" !~ /[i-j]/) {
1259 print "not ok 244\n";
1261 if ("\xce" !~ /[I-J]/) {
1264 print "not ok 245\n";
1268 print "ok $_ # Skip: only in EBCDIC\n";
1272 print "not " unless "\x{ab}" =~ /\x{ab}/;
1275 print "not " unless "\x{abcd}" =~ /\x{abcd}/;
1279 # bug id 20001008.001
1282 my @x = ("stra\337e 138","stra\337e 138");
1284 s/(\d+)\s*([\w\-]+)/$1 . uc $2/e;
1285 my($latin) = /^(.+)(?:\s+\d)/;
1286 print $latin eq "stra\337e" ? "ok $test\n" : # 248,249
1287 "#latin[$latin]\nnot ok $test\n";
1289 $latin =~ s/stra\337e/straße/; # \303\237 after the 2nd a
1290 use utf8; # needed for the raw UTF-8
1291 $latin =~ s!(s)tr(?:aß|s+e)!$1tr.!; # \303\237 after the a
1296 print "not " unless "ba\xd4c" =~ /([a\xd4]+)/ && $1 eq "a\xd4";
1299 print "not " unless "ba\xd4c" =~ /([a\xd4]+)/ && $1 eq "a\x{d4}";
1302 print "not " unless "ba\x{d4}c" =~ /([a\xd4]+)/ && $1 eq "a\x{d4}";
1305 print "not " unless "ba\x{d4}c" =~ /([a\xd4]+)/ && $1 eq "a\xd4";
1308 print "not " unless "ba\xd4c" =~ /([a\x{d4}]+)/ && $1 eq "a\xd4";
1311 print "not " unless "ba\xd4c" =~ /([a\x{d4}]+)/ && $1 eq "a\x{d4}";
1314 print "not " unless "ba\x{d4}c" =~ /([a\x{d4}]+)/ && $1 eq "a\x{d4}";
1317 print "not " unless "ba\x{d4}c" =~ /([a\x{d4}]+)/ && $1 eq "a\xd4";
1322 # the first half of 20001028.003
1325 my ($Y) = $X =~ /(.*)/;
1326 print "not " unless $Y eq v1448 && length($Y) == 1;
1333 my $X = "Szab\x{f3},Bal\x{e1}zs";
1335 $Y =~ s/(B)/$1/ for 0..3;
1336 print "not " unless $Y eq $X && $X eq "Szab\x{f3},Bal\x{e1}zs";
1341 # the second half of 20001028.003
1344 $X =~ s/^/chr(1488)/e;
1345 print "not " unless length $X == 1 && ord($X) == 1488;
1356 print "not " unless $x eq "\x{100}B" && length($x) == 2;
1361 # bug id 20001230.002
1363 print "not " unless "École" =~ /^\C\C(.)/ && $1 eq 'c';
1366 print "not " unless "École" =~ /^\C\C(c)/;
1371 my $test = 264; # till 575
1373 use charnames ':full';
1375 # This is far from complete testing, there are dozens of character
1376 # classes in Unicode. The mixing of literals and \N{...} is
1377 # intentional so that in non-Latin-1 places we test the native
1378 # characters, not the Unicode code points.
1382 "\N{CYRILLIC SMALL LETTER A}" => 'Ll',
1384 "\N{GREEK CAPITAL LETTER ALPHA}" => 'Lu',
1385 "\N{HIRAGANA LETTER SMALL A}" => 'Lo',
1386 "\N{COMBINING GRAVE ACCENT}" => 'Mn',
1388 "\N{ARABIC-INDIC DIGIT ZERO}" => 'Nd',
1395 for my $char (map { s/^\S+ //; $_ }
1396 sort map { sprintf("%06x", ord($_))." $_" } keys %s) {
1397 my $class = $s{$char};
1398 my $code = sprintf("%06x", ord($char));
1399 printf "#\n# 0x$code\n#\n";
1400 print "# IsAlpha\n";
1401 if ($class =~ /^[LM]/) {
1402 print "not " unless $char =~ /\p{IsAlpha}/;
1403 print "ok $test\n"; $test++;
1404 print "not " if $char =~ /\P{IsAlpha}/;
1405 print "ok $test\n"; $test++;
1407 print "not " if $char =~ /\p{IsAlpha}/;
1408 print "ok $test\n"; $test++;
1409 print "not " unless $char =~ /\P{IsAlpha}/;
1410 print "ok $test\n"; $test++;
1412 print "# IsAlnum\n";
1413 if ($class =~ /^[LMN]/ && $char ne "_") {
1414 print "not " unless $char =~ /\p{IsAlnum}/;
1415 print "ok $test\n"; $test++;
1416 print "not " if $char =~ /\P{IsAlnum}/;
1417 print "ok $test\n"; $test++;
1419 print "not " if $char =~ /\p{IsAlnum}/;
1420 print "ok $test\n"; $test++;
1421 print "not " unless $char =~ /\P{IsAlnum}/;
1422 print "ok $test\n"; $test++;
1424 print "# IsASCII\n";
1425 if (ord("A") == 193) {
1426 print "ok $test # Skip: in EBCDIC\n"; $test++;
1427 print "ok $test # Skip: in EBCDIC\n"; $test++;
1429 if ($code le '00007f') {
1430 print "not " unless $char =~ /\p{IsASCII}/;
1431 print "ok $test\n"; $test++;
1432 print "not " if $char =~ /\P{IsASCII}/;
1433 print "ok $test\n"; $test++;
1435 print "not " if $char =~ /\p{IsASCII}/;
1436 print "ok $test\n"; $test++;
1437 print "not " unless $char =~ /\P{IsASCII}/;
1438 print "ok $test\n"; $test++;
1441 print "# IsCntrl\n";
1442 if ($class =~ /^C/) {
1443 print "not " unless $char =~ /\p{IsCntrl}/;
1444 print "ok $test\n"; $test++;
1445 print "not " if $char =~ /\P{IsCntrl}/;
1446 print "ok $test\n"; $test++;
1448 print "not " if $char =~ /\p{IsCntrl}/;
1449 print "ok $test\n"; $test++;
1450 print "not " unless $char =~ /\P{IsCntrl}/;
1451 print "ok $test\n"; $test++;
1453 print "# IsBlank\n";
1454 if ($class =~ /^Z[lp]/ || $char eq " ") {
1455 print "not " unless $char =~ /\p{IsBlank}/;
1456 print "ok $test\n"; $test++;
1457 print "not " if $char =~ /\P{IsBlank}/;
1458 print "ok $test\n"; $test++;
1460 print "not " if $char =~ /\p{IsBlank}/;
1461 print "ok $test\n"; $test++;
1462 print "not " unless $char =~ /\P{IsBlank}/;
1463 print "ok $test\n"; $test++;
1465 print "# IsDigit\n";
1466 if ($class =~ /^Nd$/) {
1467 print "not " unless $char =~ /\p{IsDigit}/;
1468 print "ok $test\n"; $test++;
1469 print "not " if $char =~ /\P{IsDigit}/;
1470 print "ok $test\n"; $test++;
1472 print "not " if $char =~ /\p{IsDigit}/;
1473 print "ok $test\n"; $test++;
1474 print "not " unless $char =~ /\P{IsDigit}/;
1475 print "ok $test\n"; $test++;
1477 print "# IsGraph\n";
1478 if ($class =~ /^([LMNPS])|Co/) {
1479 print "not " unless $char =~ /\p{IsGraph}/;
1480 print "ok $test\n"; $test++;
1481 print "not " if $char =~ /\P{IsGraph}/;
1482 print "ok $test\n"; $test++;
1484 print "not " if $char =~ /\p{IsGraph}/;
1485 print "ok $test\n"; $test++;
1486 print "not " unless $char =~ /\P{IsGraph}/;
1487 print "ok $test\n"; $test++;
1489 print "# IsLower\n";
1490 if ($class =~ /^Ll$/) {
1491 print "not " unless $char =~ /\p{IsLower}/;
1492 print "ok $test\n"; $test++;
1493 print "not " if $char =~ /\P{IsLower}/;
1494 print "ok $test\n"; $test++;
1496 print "not " if $char =~ /\p{IsLower}/;
1497 print "ok $test\n"; $test++;
1498 print "not " unless $char =~ /\P{IsLower}/;
1499 print "ok $test\n"; $test++;
1501 print "# IsPrint\n";
1502 if ($class =~ /^([LMNPS])|Co|Zs/) {
1503 print "not " unless $char =~ /\p{IsPrint}/;
1504 print "ok $test\n"; $test++;
1505 print "not " if $char =~ /\P{IsPrint}/;
1506 print "ok $test\n"; $test++;
1508 print "not " if $char =~ /\p{IsPrint}/;
1509 print "ok $test\n"; $test++;
1510 print "not " unless $char =~ /\P{IsPrint}/;
1511 print "ok $test\n"; $test++;
1513 print "# IsPunct\n";
1514 if ($class =~ /^P/ || $char eq "_") {
1515 print "not " unless $char =~ /\p{IsPunct}/;
1516 print "ok $test\n"; $test++;
1517 print "not " if $char =~ /\P{IsPunct}/;
1518 print "ok $test\n"; $test++;
1520 print "not " if $char =~ /\p{IsPunct}/;
1521 print "ok $test\n"; $test++;
1522 print "not " unless $char =~ /\P{IsPunct}/;
1523 print "ok $test\n"; $test++;
1525 print "# IsSpace\n";
1526 if ($class =~ /^Z/ || ($code =~ /^(0009|000A|000B|000C|000D)$/)) {
1527 print "not " unless $char =~ /\p{IsSpace}/;
1528 print "ok $test\n"; $test++;
1529 print "not " if $char =~ /\P{IsSpace}/;
1530 print "ok $test\n"; $test++;
1532 print "not " if $char =~ /\p{IsSpace}/;
1533 print "ok $test\n"; $test++;
1534 print "not " unless $char =~ /\P{IsSpace}/;
1535 print "ok $test\n"; $test++;
1537 print "# IsUpper\n";
1538 if ($class =~ /^L[ut]/) {
1539 print "not " unless $char =~ /\p{IsUpper}/;
1540 print "ok $test\n"; $test++;
1541 print "not " if $char =~ /\P{IsUpper}/;
1542 print "ok $test\n"; $test++;
1544 print "not " if $char =~ /\p{IsUpper}/;
1545 print "ok $test\n"; $test++;
1546 print "not " unless $char =~ /\P{IsUpper}/;
1547 print "ok $test\n"; $test++;
1550 if ($class =~ /^[LMN]/ || $char eq "_") {
1551 print "not " unless $char =~ /\p{IsWord}/;
1552 print "ok $test\n"; $test++;
1553 print "not " if $char =~ /\P{IsWord}/;
1554 print "ok $test\n"; $test++;
1556 print "not " if $char =~ /\p{IsWord}/;
1557 print "ok $test\n"; $test++;
1558 print "not " unless $char =~ /\P{IsWord}/;
1559 print "ok $test\n"; $test++;
1565 $_ = "abc\x{100}\x{200}\x{300}\x{380}\x{400}defg";
1567 if (/(.\x{300})./) {
1570 print "not " unless $` eq "abc\x{100}" && length($`) == 4;
1573 print "not " unless $& eq "\x{200}\x{300}\x{380}" && length($&) == 3;
1576 print "not " unless $' eq "\x{400}defg" && length($') == 5;
1579 print "not " unless $1 eq "\x{200}\x{300}" && length($1) == 2;
1582 for (576..580) { print "not ok $_\n" }
1587 # bug id 20010306.008
1590 # The original bug report had 'no utf8' here but that was irrelevant.
1591 $a =~ m/\w/; # used to core dump
1599 # bugid 20010410.006
1601 '/(.*?)\{(.*?)\}/csg',
1602 '/(.*?)\{(.*?)\}/cg',
1603 '/(.*?)\{(.*?)\}/sg',
1604 '/(.*?)\{(.*?)\}/g',
1605 '/(.+?)\{(.+?)\}/csg',
1611 $input = "a{b}c{d}";
1613 while (eval \$input =~ $rx) {
1614 print "# \\\$1 = '\$1' \\\$2 = '\$2'\n";
1618 print "not " unless $i == 2;
1619 print "ok " . $test++ . "\n";
1624 # from Robin Houston
1626 my $x = "\x{10FFFD}";
1628 print "not " unless ord($x) == 0x10FFFD && length($x) == 1;
1635 print "not " if $x =~ /[\x80-\xff]/;
1638 print "not " if $x =~ /[\x80-\x{100}]/;
1641 print "not " if $x =~ /[\x{100}]/;
1644 print "not " if $x =~ /\p{InLatin1Supplement}/;
1647 print "not " unless $x =~ /\P{InLatin1Supplement}/;
1650 print "not " if $x =~ /\p{InLatinExtendedA}/;
1653 print "not " unless $x =~ /\P{InLatinExtendedA}/;
1660 print "not " unless $x =~ /[\x80-\xff]/;
1663 print "not " unless $x =~ /[\x80-\x{100}]/;
1666 print "not " if $x =~ /[\x{100}]/;
1669 print "not " unless $x =~ /\p{InLatin1Supplement}/;
1672 print "not " if $x =~ /\P{InLatin1Supplement}/;
1675 print "not " if $x =~ /\p{InLatinExtendedA}/;
1678 print "not " unless $x =~ /\P{InLatinExtendedA}/;
1685 print "not " unless $x =~ /[\x80-\xff]/;
1688 print "not " unless $x =~ /[\x80-\x{100}]/;
1691 print "not " if $x =~ /[\x{100}]/;
1694 print "not " unless $x =~ /\p{InLatin1Supplement}/;
1697 print "not " if $x =~ /\P{InLatin1Supplement}/;
1700 print "not " if $x =~ /\p{InLatinExtendedA}/;
1703 print "not " unless $x =~ /\P{InLatinExtendedA}/;
1710 print "not " if $x =~ /[\x80-\xff]/;
1713 print "not " unless $x =~ /[\x80-\x{100}]/;
1716 print "not " unless $x =~ /[\x{100}]/;
1719 print "not " if $x =~ /\p{InLatin1Supplement}/;
1722 print "not " unless $x =~ /\P{InLatin1Supplement}/;
1725 print "not " unless $x =~ /\p{InLatinExtendedA}/;
1728 print "not " if $x =~ /\P{InLatinExtendedA}/;
1736 local $SIG{__WARN__} = sub { $w .= shift };
1740 print "not " if $w !~ /^Useless \(\?c\)/;
1745 print "not " if $w !~ /^Useless \(\?-c\)/;
1750 print "not " if $w !~ /^Useless \(\?g\)/;
1755 print "not " if $w !~ /^Useless \(\?-g\)/;
1760 print "not " if $w !~ /^Useless \(\?o\)/;
1765 print "not " if $w !~ /^Useless \(\?-o\)/;
1768 # now test multi-error regexes
1772 print "not " if $w !~ /^Useless \(\?g\).*\nUseless \(\?-o\)/;
1777 print "not " if $w !~ /^Useless \(\?g\).*\nUseless \(\?-c\)/;
1781 eval 'qr/(?o-cg)/'; # (?c) means (?g) error won't be thrown
1782 print "not " if $w !~ /^Useless \(\?o\).*\nUseless \(\?-c\)/;
1787 print "not " if $w !~ /^Useless \(\?o\).*\nUseless \(\?g\).*\nUseless \(\?c\)/;
1791 # More Unicode "class" tests
1794 use charnames ':full';
1796 print "not " unless "\N{LATIN CAPITAL LETTER A}" =~ /\p{InBasicLatin}/;
1799 print "not " unless "\N{LATIN CAPITAL LETTER A WITH GRAVE}" =~ /\p{InLatin1Supplement}/;
1802 print "not " unless "\N{LATIN CAPITAL LETTER A WITH MACRON}" =~ /\p{InLatinExtendedA}/;
1805 print "not " unless "\N{LATIN SMALL LETTER B WITH STROKE}" =~ /\p{InLatinExtendedB}/;
1808 print "not " unless "\N{KATAKANA LETTER SMALL A}" =~ /\p{InKatakana}/;
1814 eval <<"EOT"; die if $@;
1819 /x && print "ok 631\n";
1822 eval <<"EOT"; die if $@;
1827 /x && print "ok 632\n";
1831 sub test_o { $_[0] =~/$_[1]/o; return $1}
1832 if(test_o('abc','(.)..') eq 'a') {
1835 print "not ok 633\n";
1837 if(test_o('abc','..(.)') eq 'a') {
1840 print "not ok 634\n";
1843 # 635..639: ID 20010619.003 (only the space character is
1844 # supposed to be [:print:], not the whole isprint()).
1846 print "not " if "\n" =~ /[[:print:]]/;
1849 print "not " if "\t" =~ /[[:print:]]/;
1852 # Amazingly vertical tabulator is the same in ASCII and EBCDIC.
1853 print "not " if "\014" =~ /[[:print:]]/;
1856 print "not " if "\r" =~ /[[:print:]]/;
1859 print "not " unless " " =~ /[[:print:]]/;
1863 ## Test basic $^N usage outside of a regex
1866 $T="ok 640\n";if ($x =~ /cde/ and not defined $^N) {print $T} else {print "not $T"};
1867 $T="ok 641\n";if ($x =~ /(cde)/ and $^N eq "cde") {print $T} else {print "not $T"};
1868 $T="ok 642\n";if ($x =~ /(c)(d)(e)/ and $^N eq "e") {print $T} else {print "not $T"};
1869 $T="ok 643\n";if ($x =~ /(c(d)e)/ and $^N eq "cde") {print $T} else {print "not $T"};
1870 $T="ok 644\n";if ($x =~ /(foo)|(c(d)e)/ and $^N eq "cde") {print $T} else {print "not $T"};
1871 $T="ok 645\n";if ($x =~ /(c(d)e)|(foo)/ and $^N eq "cde") {print $T} else {print "not $T"};
1872 $T="ok 646\n";if ($x =~ /(c(d)e)|(abc)/ and $^N eq "abc") {print $T} else {print "not $T"};
1873 $T="ok 647\n";if ($x =~ /(c(d)e)|(abc)x/ and $^N eq "cde") {print $T} else {print "not $T"};
1874 $T="ok 648\n";if ($x =~ /(c(d)e)(abc)?/ and $^N eq "cde") {print $T} else {print "not $T"};
1875 $T="ok 649\n";if ($x =~ /(?:c(d)e)/ and $^N eq "d" ) {print $T} else {print "not $T"};
1876 $T="ok 650\n";if ($x =~ /(?:c(d)e)(?:f)/ and $^N eq "d" ) {print $T} else {print "not $T"};
1877 $T="ok 651\n";if ($x =~ /(?:([abc])|([def]))*/ and $^N eq "f" ){print $T} else {print "not $T"};
1878 $T="ok 652\n";if ($x =~ /(?:([ace])|([bdf]))*/ and $^N eq "f" ){print $T} else {print "not $T"};
1879 $T="ok 653\n";if ($x =~ /(([ace])|([bd]))*/ and $^N eq "e" ){print $T} else {print "not $T"};
1881 $T="ok 654\n";if($x =~ /(([ace])|([bdf]))*/ and $^N eq "f" ){print $T} else {print "not $T"};
1883 ## test to see if $^N is automatically localized -- it should now
1884 ## have the value set in test 653
1885 $T="ok 655\n";if ($^N eq "e" ){print $T} else {print "not $T"};
1888 ## Now test inside (?{...})
1890 $T="ok 656\n";if ($x =~ /a([abc])(?{$y=$^N})c/ and $y eq "b" ){print $T} else {print "not $T"};
1891 $T="ok 657\n";if ($x =~ /a([abc]+)(?{$y=$^N})d/ and $y eq "bc"){print $T} else {print "not $T"};
1892 $T="ok 658\n";if ($x =~ /a([abcdefg]+)(?{$y=$^N})d/ and $y eq "bc"){print $T} else {print "not $T"};
1893 $T="ok 659\n";if ($x =~ /(a([abcdefg]+)(?{$y=$^N})d)(?{$z=$^N})e/ and $y eq "bc" and $z eq "abcd")
1894 {print $T} else {print "not $T"};
1895 $T="ok 660\n";if ($x =~ /(a([abcdefg]+)(?{$y=$^N})de)(?{$z=$^N})/ and $y eq "bc" and $z eq "abcde")
1896 {print $T} else {print "not $T"};
1898 # Test the Unicode script classes
1900 print "not " unless chr(0x100) =~ /\p{IsLatin}/; # outside Latin-1
1903 print "not " unless chr(0x212b) =~ /\p{IsLatin}/; # Angstrom sign, very outside
1906 print "not " unless chr(0x5d0) =~ /\p{IsHebrew}/; # inside InHebrew
1909 print "not " unless chr(0xfb4f) =~ /\p{IsHebrew}/; # outside InHebrew
1912 print "not " unless chr(0xb5) =~ /\p{IsGreek}/; # singleton (not in a range)
1915 print "not " unless chr(0x37a) =~ /\p{IsGreek}/; # singleton
1918 print "not " unless chr(0x386) =~ /\p{IsGreek}/; # singleton
1921 print "not " unless chr(0x387) =~ /\P{IsGreek}/; # not there
1924 print "not " unless chr(0x388) =~ /\p{IsGreek}/; # range
1927 print "not " unless chr(0x38a) =~ /\p{IsGreek}/; # range
1930 print "not " unless chr(0x38b) =~ /\P{IsGreek}/; # not there
1933 print "not " unless chr(0x38c) =~ /\p{IsGreek}/; # singleton
1936 if (ord("A") == 65) {
1938 ## Test [:cntrl:]...
1940 ## Should probably put in tests for all the POSIX stuff, but not sure how to
1941 ## guarantee a specific locale......
1943 $AllBytes = join('', map { chr($_) } 0..255);
1944 ($x = $AllBytes) =~ s/[[:cntrl:]]//g;
1945 if ($x ne join('', map { chr($_) } 0x20..0x7E, 0x80..0xFF)) {
1950 ($x = $AllBytes) =~ s/[^[:cntrl:]]//g;
1951 if ($x ne join('', map { chr($_) } 0..0x1F, 0x7F)) { print "not " }
1954 print "ok $_ # Skip: EBCDIC\n" for 673..674;
1957 # With /s modifier UTF8 chars were interpreted as bytes
1959 my $a = "Hello \x{263A} World";
1961 my @a = ($a =~ /./gs);
1963 print "not " unless $#a == 12;
1967 @a = ("foo\nbar" =~ /./g);
1968 print "ok 676\n" if @a == 6 && "@a" eq "f o o b a r";
1970 @a = ("foo\nbar" =~ /./gs);
1971 print "ok 677\n" if @a == 7 && "@a" eq "f o o \n b a r";
1973 @a = ("foo\nbar" =~ /\C/g);
1974 print "ok 678\n" if @a == 7 && "@a" eq "f o o \n b a r";
1976 @a = ("foo\nbar" =~ /\C/gs);
1977 print "ok 679\n" if @a == 7 && "@a" eq "f o o \n b a r";
1979 @a = ("foo\n\x{100}bar" =~ /./g);
1980 print "ok 680\n" if @a == 7 && "@a" eq "f o o \x{100} b a r";
1982 @a = ("foo\n\x{100}bar" =~ /./gs);
1983 print "ok 681\n" if @a == 8 && "@a" eq "f o o \n \x{100} b a r";
1985 ($a, $b) = map { chr } ord('A') == 65 ? (0xc4, 0x80) : (0x8c, 0x41);
1987 @a = ("foo\n\x{100}bar" =~ /\C/g);
1988 print "ok 682\n" if @a == 9 && "@a" eq "f o o \n $a $b b a r";
1990 @a = ("foo\n\x{100}bar" =~ /\C/gs);
1991 print "ok 683\n" if @a == 9 && "@a" eq "f o o \n $a $b b a r";
1994 # [ID 20010814.004] pos() doesn't work when using =~m// in list context
1996 $a = join ":", /b./gc;
1997 $b = join ":", /a./gc;
1999 print "$a $b $c" eq 'ba:ba ad:ae 10' ? "ok 684\n" : "not ok 684\t# $a $b $c\n";
2003 # [ID 20010407.006] matching utf8 return values from functions does not work
2005 package ID_20010407_006;
2014 $x =~ /(..)/; $y = $1;
2015 print "not " unless length($y) == 2 && $y eq $x;
2018 x =~ /(..)/; $y = $1;
2019 print "not " unless length($y) == 2 && $y eq $x;
2026 # Force scalar context on the patern match
2028 my($ok, $name) = @_;
2030 printf "%sok %d - %s\n", ($ok ? "" : "not "), $test, $name;
2032 printf "# Failed test at line %d\n", (caller)[2] unless $ok;
2039 # Check that \x## works. 5.6.1 and 5.005_03 fail some of these.
2041 ok ($x =~ /^\x4EE$/, "Check only 2 bytes of hex are matched.");
2044 ok ($x =~ /^\x4Ei$/, "Check that invalid hex digit stops it (2)");
2047 ok ($x =~ /^\x4j$/, "Check that invalid hex digit stops it (1)");
2050 ok ($x =~ /^\xk$/, "Check that invalid hex digit stops it (0)");
2053 ok ($x =~ /^\xx$/, "\\xx isn't to be treated as \\0");
2056 ok ($x =~ /^\xxa$/, "\\xxa isn't to be treated as \\xa");
2059 ok ($x =~ /^\x9_b$/, "\\x9_b isn't to be treated as \\x9b");
2061 print "# and now again in [] ranges\n";
2064 ok ($x =~ /^[\x4EE]{2}$/, "Check only 2 bytes of hex are matched.");
2067 ok ($x =~ /^[\x4Ei]{2}$/, "Check that invalid hex digit stops it (2)");
2070 ok ($x =~ /^[\x4j]{2}$/, "Check that invalid hex digit stops it (1)");
2073 ok ($x =~ /^[\xk]{2}$/, "Check that invalid hex digit stops it (0)");
2076 ok ($x =~ /^[\xx]{2}$/, "\\xx isn't to be treated as \\0");
2079 ok ($x =~ /^[\xxa]{3}$/, "\\xxa isn't to be treated as \\xa");
2082 ok ($x =~ /^[\x9_b]{3}$/, "\\x9_b isn't to be treated as \\x9b");
2087 # Check that \x{##} works. 5.6.1 fails quite a few of these.
2090 ok ($x =~ /^\x{9_b}$/, "\\x{9_b} is to be treated as \\x9b");
2093 ok ($x =~ /^\x{9_b}y$/, "\\x{9_b} is to be treated as \\x9b (again)");
2096 ok ($x =~ /^\x{9b_}y$/, "\\x{9b_} is to be treated as \\x9b");
2099 ok ($x =~ /^\x{9_bq}y$/, "\\x{9_bc} is to be treated as \\x9b");
2102 ok ($x =~ /^\x{x9b}y$/, "\\x{x9b} is to be treated as \\x0");
2105 ok ($x =~ /^\x{0x9b}y$/, "\\x{0x9b} is to be treated as \\x0");
2108 ok ($x =~ /^\x{09b}y$/, "\\x{09b} is to be treated as \\x9b");
2110 print "# and now again in [] ranges\n";
2113 ok ($x =~ /^[\x{9_b}]$/, "\\x{9_b} is to be treated as \\x9b");
2116 ok ($x =~ /^[\x{9_b}y]{2}$/, "\\x{9_b} is to be treated as \\x9b (again)");
2119 ok ($x =~ /^[\x{9b_}y]{2}$/, "\\x{9b_} is to be treated as \\x9b");
2122 ok ($x =~ /^[\x{9_bq}y]{2}$/, "\\x{9_bc} is to be treated as \\x9b");
2125 ok ($x =~ /^[\x{x9b}y]{2}$/, "\\x{x9b} is to be treated as \\x0");
2128 ok ($x =~ /^[\x{0x9b}y]{2}$/, "\\x{0x9b} is to be treated as \\x0");
2131 ok ($x =~ /^[\x{09b}y]{2}$/, "\\x{09b} is to be treated as \\x9b");
2135 # high bit bug -- japhy
2137 $x =~ /.*?\200/ or print "not ";
2141 print "# some Unicode properties\n";
2144 # Dashes, underbars, case.
2145 print "not " unless "\x80" =~ /\p{in-latin1_SUPPLEMENT}/;
2148 # Complement, leading and trailing whitespace.
2149 print "not " unless "\x80" =~ /\P{ ^ In Latin 1 Supplement }/;
2152 # No ^In, dashes, case, dash, any intervening (word-break) whitespace.
2153 # (well, newlines don't work...)
2154 print "not " unless "\x80" =~ /\p{latin-1 supplement}/;
2159 print "not " unless "a" =~ /\pL/;
2162 print "not " unless "a" =~ /\p{IsLl}/;
2165 print "not " if "a" =~ /\p{IsLu}/;
2168 print "not " unless "a" =~ /\p{Ll}/;
2171 print "not " if "a" =~ /\p{Lu}/;
2174 print "not " unless "A" =~ /\pL/;
2177 print "not " unless "A" =~ /\p{IsLu}/;
2180 print "not " if "A" =~ /\p{IsLl}/;
2183 print "not " unless "A" =~ /\p{Lu}/;
2186 print "not " if "A" =~ /\p{Ll}/;
2189 print "not " if "a" =~ /\PL/;
2192 print "not " if "a" =~ /\P{IsLl}/;
2195 print "not " unless "a" =~ /\P{IsLu}/;
2198 print "not " if "a" =~ /\P{Ll}/;
2201 print "not " unless "a" =~ /\P{Lu}/;
2204 print "not " if "A" =~ /\PL/;
2207 print "not " if "A" =~ /\P{IsLu}/;
2210 print "not " unless "A" =~ /\P{IsLl}/;
2213 print "not " if "A" =~ /\P{Lu}/;
2216 print "not " unless "A" =~ /\P{Ll}/;
2222 print "not " if "a" =~ /\p{Common}/;
2225 print "not " unless "1" =~ /\p{Common}/;
2230 print "not " if "a" =~ /\p{Inherited}/;
2233 print "not " unless "\x{300}" =~ /\p{Inherited}/;
2238 print "not " unless "a" =~ /\p{L&}/;
2241 print "not " if "1" =~ /\p{L&}/;
2246 print "not " unless "a" =~ /\p{Lowercase Letter}/;
2249 print "not " if "A" =~ /\p{lowercaseletter}/;
2254 print "not " unless "\x{AC00}" =~ /\p{HangulSyllables}/;
2259 # Script=, Block=, Category=
2261 print "not " unless "\x{0100}" =~ /\p{Script=Latin}/;
2264 print "not " unless "\x{0100}" =~ /\p{Block=LatinExtendedA}/;
2267 print "not " unless "\x{0100}" =~ /\p{Category=UppercaseLetter}/;
2272 print "# the basic character classes and Unicode \n";
2274 # 0100;LATIN CAPITAL LETTER A WITH MACRON;Lu;0;L;0041 0304;;;;N;LATIN CAPITAL LETTER A MACRON;;;0101;
2275 print "not " unless "\x{0100}" =~ /\w/;
2278 # 0660;ARABIC-INDIC DIGIT ZERO;Nd;0;AN;;0;0;0;N;;;;;
2279 print "not " unless "\x{0660}" =~ /\d/;
2282 # 1680;OGHAM SPACE MARK;Zs;0;WS;;;;;N;;;;;
2283 print "not " unless "\x{1680}" =~ /\s/;
2288 print "# folding matches and Unicode\n";
2290 print "not " unless "a\x{100}" =~ /A/i;
2293 print "not " unless "A\x{100}" =~ /a/i;
2296 print "not " unless "a\x{100}" =~ /a/i;
2299 print "not " unless "A\x{100}" =~ /A/i;
2302 print "not " unless "\x{101}a" =~ /\x{100}/i;
2305 print "not " unless "\x{100}a" =~ /\x{100}/i;
2308 print "not " unless "\x{101}a" =~ /\x{101}/i;
2311 print "not " unless "\x{100}a" =~ /\x{101}/i;
2314 print "not " unless "a\x{100}" =~ /A\x{100}/i;
2317 print "not " unless "A\x{100}" =~ /a\x{100}/i;
2320 print "not " unless "a\x{100}" =~ /a\x{100}/i;
2323 print "not " unless "A\x{100}" =~ /A\x{100}/i;
2326 print "not " unless "a\x{100}" =~ /[A]/i;
2329 print "not " unless "A\x{100}" =~ /[a]/i;
2332 print "not " unless "a\x{100}" =~ /[a]/i;
2335 print "not " unless "A\x{100}" =~ /[A]/i;
2338 print "not " unless "\x{101}a" =~ /[\x{100}]/i;
2341 print "not " unless "\x{100}a" =~ /[\x{100}]/i;
2344 print "not " unless "\x{101}a" =~ /[\x{101}]/i;
2347 print "not " unless "\x{100}a" =~ /[\x{101}]/i;
2353 use charnames ':full';
2355 print "# LATIN LETTER A WITH GRAVE\n";
2356 my $lower = "\N{LATIN SMALL LETTER A WITH GRAVE}";
2357 my $UPPER = "\N{LATIN CAPITAL LETTER A WITH GRAVE}";
2359 print $lower =~ m/$UPPER/i ? "ok 774\n" : "not ok 774\n";
2360 print $UPPER =~ m/$lower/i ? "ok 775\n" : "not ok 775\n";
2361 print $lower =~ m/[$UPPER]/i ? "ok 776\n" : "not ok 776\n";
2362 print $UPPER =~ m/[$lower]/i ? "ok 777\n" : "not ok 777\n";
2364 print "# GREEK LETTER ALPHA WITH VRACHY\n";
2366 $lower = "\N{GREEK CAPITAL LETTER ALPHA WITH VRACHY}";
2367 $UPPER = "\N{GREEK SMALL LETTER ALPHA WITH VRACHY}";
2369 print $lower =~ m/$UPPER/i ? "ok 778\n" : "not ok 778\n";
2370 print $UPPER =~ m/$lower/i ? "ok 779\n" : "not ok 779\n";
2371 print $lower =~ m/[$UPPER]/i ? "ok 780\n" : "not ok 780\n";
2372 print $UPPER =~ m/[$lower]/i ? "ok 781\n" : "not ok 781\n";
2374 print "# LATIN LETTER Y WITH DIAERESIS\n";
2376 $lower = "\N{LATIN CAPITAL LETTER Y WITH DIAERESIS}";
2377 $UPPER = "\N{LATIN SMALL LETTER Y WITH DIAERESIS}";
2378 print $lower =~ m/$UPPER/i ? "ok 782\n" : "not ok 782\n";
2379 print $UPPER =~ m/$lower/i ? "ok 783\n" : "not ok 783\n";
2380 print $lower =~ m/[$UPPER]/i ? "ok 784\n" : "not ok 784\n";
2381 print $UPPER =~ m/[$lower]/i ? "ok 785\n" : "not ok 785\n";
2386 use charnames ':full';
2388 print "# GREEK CAPITAL LETTER SIGMA vs COMBINING GREEK PERISPOMENI\n";
2390 my $SIGMA = "\N{GREEK CAPITAL LETTER SIGMA}";
2391 my $char = "\N{COMBINING GREEK PERISPOMENI}";
2393 # Before #13843 this was failing by matching falsely.
2394 print "_:$char:_" =~ m/_:$SIGMA:_/i ? "not ok 786\n" : "ok 786\n";
2400 use charnames ':full';
2402 print "a!" =~ /^(\X)!/ && $1 eq "a" ?
2403 "ok 787\n" : "not ok 787 # $1\n";
2404 print "\xDF!" =~ /^(\X)!/ && $1 eq "\xDF" ?
2405 "ok 788\n" : "not ok 788 # $1\n";
2406 print "\x{100}!" =~ /^(\X)!/ && $1 eq "\x{100}" ?
2407 "ok 789\n" : "not ok 789 # $1\n";
2408 print "\x{100}\x{300}!" =~ /^(\X)!/ && $1 eq "\x{100}\x{300}" ?
2409 "ok 790\n" : "not ok 790 # $1\n";
2410 print "\N{LATIN CAPITAL LETTER E}!" =~ /^(\X)!/ &&
2411 $1 eq "\N{LATIN CAPITAL LETTER E}" ?
2412 "ok 791\n" : "not ok 791 # $1\n";
2413 print "\N{LATIN CAPITAL LETTER E}\N{COMBINING GRAVE ACCENT}!" =~
2415 $1 eq "\N{LATIN CAPITAL LETTER E}\N{COMBINING GRAVE ACCENT}" ?
2416 "ok 792\n" : "not ok 792 # $1\n";
2420 print "#\\C and \\X\n";
2422 print "!abc!" =~ /a\Cc/ ? "ok 793\n" : "not ok 793\n";
2423 print "!abc!" =~ /a\Xc/ ? "ok 794\n" : "not ok 794\n";
2427 print "# FINAL SIGMA\n";
2429 my $SIGMA = "\x{03A3}"; # CAPITAL
2430 my $Sigma = "\x{03C2}"; # SMALL FINAL
2431 my $sigma = "\x{03C3}"; # SMALL
2433 print $SIGMA =~ /$SIGMA/i ? "ok 795\n" : "not ok 795\n";
2434 print $SIGMA =~ /$Sigma/i ? "ok 796\n" : "not ok 796\n";
2435 print $SIGMA =~ /$sigma/i ? "ok 797\n" : "not ok 797\n";
2437 print $Sigma =~ /$SIGMA/i ? "ok 798\n" : "not ok 798\n";
2438 print $Sigma =~ /$Sigma/i ? "ok 799\n" : "not ok 799\n";
2439 print $Sigma =~ /$sigma/i ? "ok 800\n" : "not ok 800\n";
2441 print $sigma =~ /$SIGMA/i ? "ok 801\n" : "not ok 801\n";
2442 print $sigma =~ /$Sigma/i ? "ok 802\n" : "not ok 802\n";
2443 print $sigma =~ /$sigma/i ? "ok 803\n" : "not ok 803\n";
2445 print $SIGMA =~ /[$SIGMA]/i ? "ok 804\n" : "not ok 804\n";
2446 print $SIGMA =~ /[$Sigma]/i ? "ok 805\n" : "not ok 805\n";
2447 print $SIGMA =~ /[$sigma]/i ? "ok 806\n" : "not ok 806\n";
2449 print $Sigma =~ /[$SIGMA]/i ? "ok 807\n" : "not ok 807\n";
2450 print $Sigma =~ /[$Sigma]/i ? "ok 808\n" : "not ok 808\n";
2451 print $Sigma =~ /[$sigma]/i ? "ok 809\n" : "not ok 809\n";
2453 print $sigma =~ /[$SIGMA]/i ? "ok 810\n" : "not ok 810\n";
2454 print $sigma =~ /[$Sigma]/i ? "ok 811\n" : "not ok 811\n";
2455 print $sigma =~ /[$sigma]/i ? "ok 812\n" : "not ok 812\n";
2459 print "# parlez-vous?\n";
2461 use charnames ':full';
2463 print "fran\N{LATIN SMALL LETTER C}ais" =~
2466 "ok 813\n" : "not ok 813\n";
2468 print "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" =~
2470 $& eq "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" ?
2471 "ok 814\n" : "not ok 814\n";
2473 print "fran\N{LATIN SMALL LETTER C}ais" =~
2476 "ok 815\n" : "not ok 815\n";
2478 print "franc\N{COMBINING CEDILLA}ais" =~
2479 /franc\C\Cais/ ? # COMBINING CEDILLA is two bytes when encoded
2480 "ok 816\n" : "not ok 816\n";
2482 print "fran\N{LATIN SMALL LETTER C}ais" =~
2485 "ok 817\n" : "not ok 817\n";
2487 print "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" =~
2489 $& eq "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" ?
2490 "ok 818\n" : "not ok 818\n";
2492 print "franc\N{COMBINING CEDILLA}ais" =~
2494 $& eq "franc\N{COMBINING CEDILLA}ais" ?
2495 "ok 819\n" : "not ok 819\n";
2497 print "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" =~
2498 /fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais/ &&
2499 $& eq "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" ?
2500 "ok 820\n" : "not ok 820\n";
2502 print "franc\N{COMBINING CEDILLA}ais" =~
2503 /franc\N{COMBINING CEDILLA}ais/ &&
2504 $& eq "franc\N{COMBINING CEDILLA}ais" ?
2505 "ok 821\n" : "not ok 821\n";
2507 print "fran\N{LATIN SMALL LETTER C}ais" =~
2508 /fran(?:c\N{COMBINING CEDILLA}?|\N{LATIN SMALL LETTER C WITH CEDILLA})ais/ &&
2510 "ok 822\n" : "not ok 822\n";
2512 print "fran\N{LATIN SMALL LETTER C}ais" =~
2513 /fran(?:c\N{COMBINING CEDILLA}?|\N{LATIN SMALL LETTER C WITH CEDILLA})ais/ &&
2515 "ok 823\n" : "not ok 823\n";
2517 print "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" =~
2518 /fran(?:c\N{COMBINING CEDILLA}?|\N{LATIN SMALL LETTER C WITH CEDILLA})ais/ &&
2519 $& eq "fran\N{LATIN SMALL LETTER C WITH CEDILLA}ais" ?
2520 "ok 824\n" : "not ok 824\n";
2522 print "franc\N{COMBINING CEDILLA}ais" =~
2523 /fran(?:c\N{COMBINING CEDILLA}?|\N{LATIN SMALL LETTER C WITH CEDILLA})ais/ &&
2524 $& eq "franc\N{COMBINING CEDILLA}ais" ?
2525 "ok 825\n" : "not ok 825\n";
2529 print "# Does lingering (and useless) UTF8 flag mess up /i matching?\n";
2532 my $regex = "ABcde";
2533 my $string = "abcDE\x{100}";
2535 if ($string =~ m/$regex/i) {
2538 print "not ok 826\n";
2543 my $regex = "ABcde\x{100}";
2544 my $string = "abcDE";
2546 if ($string =~ m/$regex/i) {
2549 print "not ok 827\n";
2554 my $regex = "ABcde\x{100}";
2555 my $string = "abcDE\x{100}";
2558 if ($string =~ m/$regex/i) {
2561 print "not ok 828\n";
2567 print "# more SIGMAs\n";
2569 my $SIGMA = "\x{03A3}"; # CAPITAL
2570 my $Sigma = "\x{03C2}"; # SMALL FINAL
2571 my $sigma = "\x{03C3}"; # SMALL
2573 my $S3 = "$SIGMA$Sigma$sigma";
2575 print ":$S3:" =~ /:(($SIGMA)+):/i && $1 eq $S3 && $2 eq $sigma ?
2576 "ok 829\n" : "not ok 829\n";
2577 print ":$S3:" =~ /:(($Sigma)+):/i && $1 eq $S3 && $2 eq $sigma ?
2578 "ok 830\n" : "not ok 830\n";
2579 print ":$S3:" =~ /:(($sigma)+):/i && $1 eq $S3 && $2 eq $sigma ?
2580 "ok 831\n" : "not ok 831\n";
2582 print ":$S3:" =~ /:(([$SIGMA])+):/i && $1 eq $S3 && $2 eq $sigma ?
2583 "ok 832\n" : "not ok 832\n";
2584 print ":$S3:" =~ /:(([$Sigma])+):/i && $1 eq $S3 && $2 eq $sigma ?
2585 "ok 833\n" : "not ok 833\n";
2586 print ":$S3:" =~ /:(([$sigma])+):/i && $1 eq $S3 && $2 eq $sigma ?
2587 "ok 834\n" : "not ok 834\n";
2591 print "# LATIN SMALL LETTER SHARP S\n";
2593 use charnames ':full';
2595 print "\N{LATIN SMALL LETTER SHARP S}" =~
2596 /\N{LATIN SMALL LETTER SHARP S}/ ? "ok 835\n" : "not ok 835\n";
2598 print "\N{LATIN SMALL LETTER SHARP S}" =~
2599 /\N{LATIN SMALL LETTER SHARP S}/i ? "ok 836\n" : "not ok 836\n";
2601 print "\N{LATIN SMALL LETTER SHARP S}" =~
2602 /[\N{LATIN SMALL LETTER SHARP S}]/ ? "ok 837\n" : "not ok 837\n";
2604 print "\N{LATIN SMALL LETTER SHARP S}" =~
2605 /[\N{LATIN SMALL LETTER SHARP S}]/i ? "ok 838\n" : "not ok 838\n";
2608 /\N{LATIN SMALL LETTER SHARP S}/i ? "ok 839\n" : "not ok 839\n";
2611 /\N{LATIN SMALL LETTER SHARP S}/i ? "ok 840\n" : "not ok 840\n";
2614 /[\N{LATIN SMALL LETTER SHARP S}]/i ? "ok 841\n" : "not ok 841\n";
2617 /[\N{LATIN SMALL LETTER SHARP S}]/i ? "ok 842\n" : "not ok 842\n";
2619 print "\N{LATIN SMALL LETTER SHARP S}" =~ /ss/i ?
2620 "ok 843\n" : "not ok 843\n";
2622 print "\N{LATIN SMALL LETTER SHARP S}" =~ /SS/i ?
2623 "ok 844\n" : "not ok 844\n";
2627 print "# more whitespace: U+0085, U+2028, U+2029\n";
2629 # U+0085 needs to be forced to be Unicode, the \x{100} does that.
2630 print "<\x{100}\x{0085}>" =~ /<\x{100}\s>/ ? "ok 845\n" : "not ok 845\n";
2631 print "<\x{2028}>" =~ /<\s>/ ? "ok 846\n" : "not ok 846\n";
2632 print "<\x{2029}>" =~ /<\s>/ ? "ok 847\n" : "not ok 847\n";
2636 print "# . with /s should work on characters, as opposed to bytes\n";
2638 my $s = "\x{e4}\x{100}";
2640 # This is not expected to match: the point is that
2641 # neither should we get "Malformed UTF-8" warnings.
2642 print $s =~ /\G(.+?)\n/gcs ?
2643 "not ok 848\n" : "ok 848\n";
2647 while ($s =~ /\G(.)/gs) {
2651 print join("", @c) eq $s ? "ok 849\n" : "not ok 849\n";
2653 my $t1 = "Q003\n\n\x{e4}\x{f6}\n\nQ004\n\n\x{e7}"; # test only chars < 256
2655 while ($t1 =~ / \G ( .+? ) \n\s+ ( .+? ) ( $ | \n\s+ ) /xgcs) {
2659 my $t2 = $t1 . "\x{100}"; # repeat with a larger char
2661 while ($t2 =~ / \G ( .+? ) \n\s+ ( .+? ) ( $ | \n\s+ ) /xgcs) {
2665 print $r1 eq $r2 ? "ok 850\n" : "not ok 850\n";
2669 print "# Unicode lookbehind\n";
2671 print "A\x{100}B" =~ /(?<=A.)B/ ? "ok 851\n" : "not ok 851\n";
2672 print "A\x{200}\x{300}B" =~ /(?<=A..)B/ ? "ok 852\n" : "not ok 852\n";
2673 print "\x{400}AB" =~ /(?<=\x{400}.)B/ ? "ok 853\n" : "not ok 853\n";
2674 print "\x{500\x{600}}B" =~ /(?<=\x{500}.)B/ ? "ok 854\n" : "not ok 854\n";
2678 print "# [ID 20020124.005]\n";
2683 $x = "$char b $char";
2690 print $x eq "x b x" ? "ok 855\n" : "not ok 855\n";
2694 print "# UTF-8 hash keys and /\$/\n";
2695 # http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2002-01/msg01327.html
2698 my $v = substr($u,0,1);
2699 my $w = substr($u,1,1);
2700 my %u = ( $u => $u, $v => $v, $w => $w );
2703 my $m1 = /^\w*$/ ? 1 : 0;
2704 my $m2 = $u{$_}=~/^\w*$/ ? 1 : 0;
2705 print $m1 == $m2 ? "ok $i\n" : "not ok $i # $m1 $m2\n";