936a690343a081b6520f0ad9f5c41324a17b1817
[p5sagit/p5-mst-13.2.git] / t / uni / fold.t
1 BEGIN {
2     chdir 't' if -d 't';
3     @INC = '../lib';
4 }
5
6 use File::Spec;
7
8 my $CF = File::Spec->catfile(File::Spec->catdir(File::Spec->updir,
9                                                "lib", "unicore"),
10                             "CaseFolding.txt");
11
12 use constant EBCDIC => ord 'A' == 193;
13
14 if (open(CF, $CF)) {
15     my @CF;
16
17     while (<CF>) {
18         if (/^([0-9A-F]+); ([CFSI]); ((?:[0-9A-F]+)(?: [0-9A-F]+)*); \# (.+)/) {
19             next if $2 eq 'S'; # we are going for 'F'ull case folding
20             next if EBCDIC && hex $1 < 0x100;
21             push @CF, [$1, $2, $3, $4];
22         }
23     }
24
25     die qq[$0: failed to find casefoldings from "$CF"\n] unless @CF;
26
27     print "1..", scalar @CF, "\n";
28
29     my $i = 0;
30     for my $cf (@CF) {
31         my ($code, $status, $mapping, $name) = @$cf;
32         $i++;
33         my $a = pack("U0U*", hex $code);
34         my $b = pack("U0U*", map { hex } split " ", $mapping);
35         my $t0 = ":$a:" =~ /:$a:/    ? 1 : 0;
36         my $t1 = ":$a:" =~ /:$a:/i   ? 1 : 0;
37         my $t2 = ":$a:" =~ /:[$a]:/  ? 1 : 0;
38         my $t3 = ":$a:" =~ /:[$a]:/i ? 1 : 0;
39         my $t4 = ":$a:" =~ /:$b:/i   ? 1 : 0;
40         my $t5 = ":$a:" =~ /:[$b]:/i ? 1 : 0;
41         my $t6 = ":$b:" =~ /:$a:/i   ? 1 : 0;
42         my $t7 = ":$b:" =~ /:[$a]:/i ? 1 : 0;
43         print $t0 && $t1 && $t2 && $t3 && $t4 && $t5 && $t6 && $t7 ?
44             "ok $i \# - $code - $name - $mapping - $status\n" :
45             "not ok $i \# - $code - $name - $mapping - $status - $t0 $t1 $t2 $t3 $t4 $t5 $t6 $t7\n";
46     }
47 } else {
48     die qq[$0: failed to open "$CF": $!\n];
49 }