4 join " ", map { sprintf "%04X", $_ } unpack "U*", $_[0];
8 my ($already_run, $base, $spec, @funcs) = @_;
9 # For each provided function run it, and run a version with some extra
10 # characters afterwards. Use a recycling symbol, as it doesn't change case.
11 # $already_run is the number of extra tests the caller has run before this
13 my $ballast = chr (0x2672) x 3;
14 @funcs = map {my $f = $_;
16 sub {my $r = $f->($_[0] . $ballast); # Add it before
17 $r =~ s/$ballast\z//so # Remove it afterwards
18 or die "'$_[0]' to '$r' mangled";
19 $r; # Result with $ballast removed.
23 my $file = "../lib/unicore/To/$base.pl";
24 my $simple = do $file or die $@;
26 for my $i (split(/\n/, $simple)) {
27 my ($k, $v) = split(' ', $i);
32 for my $i (sort keys %simple) {
35 print "# ", scalar keys %simple, " simple mappings\n";
39 for my $i (sort keys %$spec) {
40 if (++$seen{$i} == 2) {
41 warn sprintf "$base: $i seen twice\n";
45 print "# ", scalar keys %$spec, " special mappings\n";
50 for my $i (map { ord } split //,
51 "\e !\"#\$%&'()+,-./0123456789:;<=>?\@[\\]^_{|}~\b") {
52 next if pack("U0U", $i) =~ /\w/;
53 $none{$i}++ unless $seen{$i};
55 print "# ", scalar keys %none, " noncase mappings\n";
59 ((scalar keys %simple) +
60 (scalar keys %$spec) +
61 (scalar keys %none)) * @funcs;
63 my $test = $already_run + 1;
65 for my $i (sort keys %simple) {
67 my $c = pack "U0U", hex $i;
68 foreach my $func (@funcs) {
71 print $d eq pack("U0U", hex $simple{$i}) ?
72 "ok $test # $i -> $w\n" : "not ok $test # $i -> $e ($w)\n";
77 for my $i (sort keys %$spec) {
78 my $w = unidump($spec->{$i});
79 if (ord('A') == 193 && $i eq "\x8A\x73") {
80 $w = '0178'; # It's a Latin small Y with diaeresis and not a Latin small letter sharp 's'.
82 my $u = unpack "C0U", $i;
83 my $h = sprintf "%04X", $u;
84 my $c = chr($u); $c .= chr(0x100); chop $c;
85 foreach my $func (@funcs) {
88 if (ord "A" == 193) { # EBCDIC
89 # We need to a little bit of remapping.
91 # For example, in titlecase (ucfirst) mapping
92 # of U+0149 the Unicode mapping is U+02BC U+004E.
93 # The 4E is N, which in EBCDIC is 2B--
94 # and the ucfirst() does that right.
95 # The problem is that our reference
96 # data is in Unicode code points.
98 # The Right Way here would be to use, say,
99 # Encode, to remap the less-than 0x100 code points,
100 # but let's try to be Encode-independent here.
102 # These are the titlecase exceptions:
104 # Unicode Unicode+EBCDIC
106 # 0149 -> 02BC 004E (02BC 002B)
107 # 01F0 -> 004A 030C (00A2 030C)
108 # 1E96 -> 0048 0331 (00E7 0331)
109 # 1E97 -> 0054 0308 (00E8 0308)
110 # 1E98 -> 0057 030A (00EF 030A)
111 # 1E99 -> 0059 030A (00DF 030A)
112 # 1E9A -> 0041 02BE (00A0 02BE)
114 # The uppercase exceptions are identical.
116 # The lowercase has one more:
118 # Unicode Unicode+EBCDIC
120 # 0130 -> 0069 0307 (00D1 0307)
122 if ($h =~ /^(0130|0149|01F0|1E96|1E97|1E98|1E99|1E9A)$/) {
123 $e =~ s/004E/002B/; # N
124 $e =~ s/004A/00A2/; # J
125 $e =~ s/0048/00E7/; # H
126 $e =~ s/0054/00E8/; # T
127 $e =~ s/0057/00EF/; # W
128 $e =~ s/0059/00DF/; # Y
129 $e =~ s/0041/00A0/; # A
130 $e =~ s/0069/00D1/; # i
132 # We have to map the output, not the input, because
133 # pack/unpack U has been EBCDICified, too, it would
134 # just undo our remapping.
137 "ok $test # $i -> $w\n" : "not ok $test # $h -> $e ($w)\n";
142 for my $i (sort { $a <=> $b } keys %none) {
143 my $w = $i = sprintf "%04X", $i;
144 my $c = pack "U0U", hex $i;
145 foreach my $func (@funcs) {
149 "ok $test # $i -> $w\n" : "not ok $test # $i -> $e ($w)\n";