This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix apidoc for HeUTF8()
[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
YO
13
14my $file="../lib/unicore/CaseFolding.txt";
24df86f6 15open my $fh,"<",$file or die "Failed to read '$file': $!";
a0a388a1
YO
16while (<$fh>) {
17 chomp;
18 my ($line,$comment)= split/\s+#\s+/, $_;
1443f10d 19 my ($cp,$type,@folded)=split/[\s;]+/,$line||'';
a0a388a1 20 next unless $type and ($type eq 'F' or $type eq 'C');
1443f10d
KW
21 my $fold_above_latin1 = grep { hex("0x$_") > 255 } @folded;
22 $_="\\x{$_}" for @folded;
a0a388a1 23 my $cpv=hex("0x$cp");
1443f10d 24 my $chr="\\x{$cp}";
a0a388a1 25 my @str;
1443f10d
KW
26 foreach my $swap (0, 1) { # swap lhs and rhs, or not.
27 foreach my $charclass (0, 1) { # Put rhs in [...], or not
28 my $lhs;
29 my $rhs;
30 if ($swap) {
31 $lhs = join "", @folded;
32 $rhs = $chr;
33 $rhs = "[$rhs]" if $charclass;
34 } else {
35 $lhs = $chr;
36 $rhs = "";
37 foreach my $rhs_char (@folded) {
38 $rhs .= '[' if $charclass;
39 $rhs .= $rhs_char;
40 $rhs .= ']' if $charclass;
41 }
42 }
43 $lhs = "\"$lhs\"";
44 $rhs = "/^$rhs\$/i";
24df86f6 45
1443f10d
KW
46 # Try both Latin1 and Unicode for code points below 256
47 foreach my $upgrade ("", 'utf8::upgrade($c); ') {
48 if ($upgrade) {
49 next if $swap && $fold_above_latin1;
50 next if !$swap && $cpv > 255;
51 }
52 my $eval = "my \$c = $lhs; $upgrade\$c =~ $rhs";
53 #print __LINE__, ": $eval\n";
54 push @tests, qq[ok(eval '$eval', '$eval - $comment')];
55 if (! $swap && ($cp eq '0390' || $cp eq '03B0')) {
56 $tests[-1]="TODO: { local \$::TODO='[13:41] <BinGOs> cue *It is all Greek to me* joke.';\n$tests[-1] }"
57 } elsif ($charclass && @folded > 1 && $swap && ! $upgrade && ! $fold_above_latin1) {
58 $tests[-1]="TODO: { local \$::TODO='Multi-char, non-utf8 folded inside character class [ ] doesnt work';\n$tests[-1] }"
59 } elsif (! $upgrade && $cpv >= 128 && $cpv <= 255 && $cpv != 0xb5) {
60 $tests[-1]="TODO: { local \$::TODO='Most non-utf8 latin1 doesnt work';\n$tests[-1] }"
61 } elsif (! $swap && $charclass && @folded > 1) {
62 # There are a few of these that pass; most fail.
63 $tests[-1]="TODO: { local \$::TODO='Some multi-char, f8 folded inside character class [ ] doesnt work';\n$tests[-1] }"
64 }
65 $count++;
66 }
67 }
a0a388a1 68 }
24df86f6 69}
a0a388a1
YO
70eval join ";\n","plan tests=>".($count-1),@tests,"1"
71 or die $@;
72__DATA__