This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Correct comment in mro_isa_changed_in
[perl5.git] / t / re / reg_fold.t
CommitLineData
24df86f6
RGS
1#!perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
0214bff6 6 require './test.pl';
24df86f6
RGS
7}
8
a0a388a1
YO
9use strict;
10use warnings;
a0a388a1
YO
11my $count=1;
12my @tests;
a0a388a1 13
2f7760b5
DM
14my %todo_pass = map { $_ => 1 }
15 qw(00DF 1E9E FB00 FB01 FB02 FB03 FB04 FB05 FB06);
16
a0a388a1 17my $file="../lib/unicore/CaseFolding.txt";
24df86f6 18open my $fh,"<",$file or die "Failed to read '$file': $!";
a0a388a1
YO
19while (<$fh>) {
20 chomp;
21 my ($line,$comment)= split/\s+#\s+/, $_;
1443f10d 22 my ($cp,$type,@folded)=split/[\s;]+/,$line||'';
a0a388a1 23 next unless $type and ($type eq 'F' or $type eq 'C');
1443f10d
KW
24 my $fold_above_latin1 = grep { hex("0x$_") > 255 } @folded;
25 $_="\\x{$_}" for @folded;
a0a388a1 26 my $cpv=hex("0x$cp");
1443f10d 27 my $chr="\\x{$cp}";
a0a388a1 28 my @str;
1443f10d
KW
29 foreach my $swap (0, 1) { # swap lhs and rhs, or not.
30 foreach my $charclass (0, 1) { # Put rhs in [...], or not
31 my $lhs;
32 my $rhs;
33 if ($swap) {
34 $lhs = join "", @folded;
35 $rhs = $chr;
36 $rhs = "[$rhs]" if $charclass;
37 } else {
38 $lhs = $chr;
39 $rhs = "";
40 foreach my $rhs_char (@folded) {
41 $rhs .= '[' if $charclass;
42 $rhs .= $rhs_char;
43 $rhs .= ']' if $charclass;
44 }
45 }
46 $lhs = "\"$lhs\"";
47 $rhs = "/^$rhs\$/i";
24df86f6 48
1443f10d
KW
49 # Try both Latin1 and Unicode for code points below 256
50 foreach my $upgrade ("", 'utf8::upgrade($c); ') {
51 if ($upgrade) {
52 next if $swap && $fold_above_latin1;
53 next if !$swap && $cpv > 255;
54 }
55 my $eval = "my \$c = $lhs; $upgrade\$c =~ $rhs";
56 #print __LINE__, ": $eval\n";
57 push @tests, qq[ok(eval '$eval', '$eval - $comment')];
58 if (! $swap && ($cp eq '0390' || $cp eq '03B0')) {
59 $tests[-1]="TODO: { local \$::TODO='[13:41] <BinGOs> cue *It is all Greek to me* joke.';\n$tests[-1] }"
60 } elsif ($charclass && @folded > 1 && $swap && ! $upgrade && ! $fold_above_latin1) {
61 $tests[-1]="TODO: { local \$::TODO='Multi-char, non-utf8 folded inside character class [ ] doesnt work';\n$tests[-1] }"
62 } elsif (! $upgrade && $cpv >= 128 && $cpv <= 255 && $cpv != 0xb5) {
63 $tests[-1]="TODO: { local \$::TODO='Most non-utf8 latin1 doesnt work';\n$tests[-1] }"
2f7760b5
DM
64 } elsif (! $swap && $charclass && @folded > 1
65 && ! $todo_pass{$cp})
66 {
1443f10d
KW
67 # There are a few of these that pass; most fail.
68 $tests[-1]="TODO: { local \$::TODO='Some multi-char, f8 folded inside character class [ ] doesnt work';\n$tests[-1] }"
69 }
70 $count++;
71 }
72 }
a0a388a1 73 }
24df86f6 74}
2726813d
KW
75
76push @tests, qq[like chr(0x0430), qr/[=\x{0410}-\x{0411}]/i, 'Bug #71752 Unicode /i char in a range'];
77$count++;
78push @tests, qq[like 'a', qr/\\p{Upper}/i, "'a' =~ /\\\\p{Upper}/i"];
79$count++;
80
a0a388a1
YO
81eval join ";\n","plan tests=>".($count-1),@tests,"1"
82 or die $@;
83__DATA__