Move Unicode::Collate from ext/ to dist/
[perl.git] / cpan / Unicode-Collate / t / normal.t
1 BEGIN {
2     unless ("A" eq pack('U', 0x41)) {
3         print "1..0 # Unicode::Collate " .
4             "cannot stringify a Unicode code point\n";
5         exit 0;
6     }
7     if ($ENV{PERL_CORE}) {
8         chdir('t') if -d 't';
9         @INC = $^O eq 'MacOS' ? qw(::lib) : qw(../lib);
10     }
11 }
12
13 BEGIN {
14     eval { require Unicode::Normalize; };
15     if ($@) {
16         print "1..0 # skipped: Unicode::Normalize needed for this test\n";
17         print $@;
18         exit;
19     }
20 }
21 use Test;
22 BEGIN { plan tests => 100 };
23
24 use strict;
25 use warnings;
26 use Unicode::Collate;
27
28 our $Aring = pack('U', 0xC5);
29 our $aring = pack('U', 0xE5);
30
31 our $entry = <<'ENTRIES';
32 030A; [.0000.030A.0002] # COMBINING RING ABOVE
33 212B; [.002B.0020.0008] # ANGSTROM SIGN
34 0061; [.0A41.0020.0002] # LATIN SMALL LETTER A
35 0041; [.0A41.0020.0008] # LATIN CAPITAL LETTER A
36 007A; [.0A5A.0020.0002] # LATIN SMALL LETTER Z
37 005A; [.0A5A.0020.0008] # LATIN CAPITAL LETTER Z
38 FF41; [.0A87.0020.0002] # LATIN SMALL LETTER A
39 FF21; [.0A87.0020.0008] # LATIN CAPITAL LETTER A
40 00E5; [.0AC5.0020.0002] # LATIN SMALL LETTER A WITH RING ABOVE
41 00C5; [.0AC5.0020.0008] # LATIN CAPITAL LETTER A WITH RING ABOVE
42 ENTRIES
43
44 # Aong < A+ring < Z < fullA+ring < A-ring
45
46 #########################
47
48 our $noN = Unicode::Collate->new(
49     level => 1,
50     table => undef,
51     normalization => undef,
52     entry => $entry,
53 );
54
55 our $nfc = Unicode::Collate->new(
56   level => 1,
57   table => undef,
58   normalization => 'NFC',
59   entry => $entry,
60 );
61
62 our $nfd = Unicode::Collate->new(
63   level => 1,
64   table => undef,
65   normalization => 'NFD',
66   entry => $entry,
67 );
68
69 our $nfkc = Unicode::Collate->new(
70   level => 1,
71   table => undef,
72   normalization => 'NFKC',
73   entry => $entry,
74 );
75
76 our $nfkd = Unicode::Collate->new(
77   level => 1,
78   table => undef,
79   normalization => 'NFKD',
80   entry => $entry,
81 );
82
83 ok($noN->lt("\x{212B}", "A"));
84 ok($noN->lt("\x{212B}", $Aring));
85 ok($noN->lt("A\x{30A}", $Aring));
86 ok($noN->lt("A",       "\x{FF21}"));
87 ok($noN->lt("Z",       "\x{FF21}"));
88 ok($noN->lt("Z",        $Aring));
89 ok($noN->lt("\x{212B}", $aring));
90 ok($noN->lt("A\x{30A}", $aring));
91 ok($noN->lt("Z",        $aring));
92 ok($noN->lt("a\x{30A}", "Z"));
93
94 ok($nfd->eq("\x{212B}", "A"));
95 ok($nfd->eq("\x{212B}", $Aring));
96 ok($nfd->eq("A\x{30A}", $Aring));
97 ok($nfd->lt("A",       "\x{FF21}"));
98 ok($nfd->lt("Z",       "\x{FF21}"));
99 ok($nfd->gt("Z",        $Aring));
100 ok($nfd->eq("\x{212B}", $aring));
101 ok($nfd->eq("A\x{30A}", $aring));
102 ok($nfd->gt("Z",        $aring));
103 ok($nfd->lt("a\x{30A}", "Z"));
104
105 ok($nfc->gt("\x{212B}", "A"));
106 ok($nfc->eq("\x{212B}", $Aring));
107 ok($nfc->eq("A\x{30A}", $Aring));
108 ok($nfc->lt("A",       "\x{FF21}"));
109 ok($nfc->lt("Z",       "\x{FF21}"));
110 ok($nfc->lt("Z",        $Aring));
111 ok($nfc->eq("\x{212B}", $aring));
112 ok($nfc->eq("A\x{30A}", $aring));
113 ok($nfc->lt("Z",        $aring));
114 ok($nfc->gt("a\x{30A}", "Z"));
115
116 ok($nfkd->eq("\x{212B}", "A"));
117 ok($nfkd->eq("\x{212B}", $Aring));
118 ok($nfkd->eq("A\x{30A}", $Aring));
119 ok($nfkd->eq("A",       "\x{FF21}"));
120 ok($nfkd->gt("Z",       "\x{FF21}"));
121 ok($nfkd->gt("Z",        $Aring));
122 ok($nfkd->eq("\x{212B}", $aring));
123 ok($nfkd->eq("A\x{30A}", $aring));
124 ok($nfkd->gt("Z",        $aring));
125 ok($nfkd->lt("a\x{30A}", "Z"));
126
127 ok($nfkc->gt("\x{212B}", "A"));
128 ok($nfkc->eq("\x{212B}", $Aring));
129 ok($nfkc->eq("A\x{30A}", $Aring));
130 ok($nfkc->eq("A",       "\x{FF21}"));
131 ok($nfkc->gt("Z",       "\x{FF21}"));
132 ok($nfkc->lt("Z",        $Aring));
133 ok($nfkc->eq("\x{212B}", $aring));
134 ok($nfkc->eq("A\x{30A}", $aring));
135 ok($nfkc->lt("Z",        $aring));
136 ok($nfkc->gt("a\x{30A}", "Z"));
137
138 $nfd->change(normalization => undef);
139
140 ok($nfd->lt("\x{212B}", "A"));
141 ok($nfd->lt("\x{212B}", $Aring));
142 ok($nfd->lt("A\x{30A}", $Aring));
143 ok($nfd->lt("A",       "\x{FF21}"));
144 ok($nfd->lt("Z",       "\x{FF21}"));
145 ok($nfd->lt("Z",        $Aring));
146 ok($nfd->lt("\x{212B}", $aring));
147 ok($nfd->lt("A\x{30A}", $aring));
148 ok($nfd->lt("Z",        $aring));
149 ok($nfd->lt("a\x{30A}", "Z"));
150
151 $nfd->change(normalization => 'C');
152
153 ok($nfd->gt("\x{212B}", "A"));
154 ok($nfd->eq("\x{212B}", $Aring));
155 ok($nfd->eq("A\x{30A}", $Aring));
156 ok($nfd->lt("A",       "\x{FF21}"));
157 ok($nfd->lt("Z",       "\x{FF21}"));
158 ok($nfd->lt("Z",        $Aring));
159 ok($nfd->eq("\x{212B}", $aring));
160 ok($nfd->eq("A\x{30A}", $aring));
161 ok($nfd->lt("Z",        $aring));
162 ok($nfd->gt("a\x{30A}", "Z"));
163
164 $nfd->change(normalization => 'D');
165
166 ok($nfd->eq("\x{212B}", "A"));
167 ok($nfd->eq("\x{212B}", $Aring));
168 ok($nfd->eq("A\x{30A}", $Aring));
169 ok($nfd->lt("A",       "\x{FF21}"));
170 ok($nfd->lt("Z",       "\x{FF21}"));
171 ok($nfd->gt("Z",        $Aring));
172 ok($nfd->eq("\x{212B}", $aring));
173 ok($nfd->eq("A\x{30A}", $aring));
174 ok($nfd->gt("Z",        $aring));
175 ok($nfd->lt("a\x{30A}", "Z"));
176
177 $nfd->change(normalization => 'KD');
178
179 ok($nfd->eq("\x{212B}", "A"));
180 ok($nfd->eq("\x{212B}", $Aring));
181 ok($nfd->eq("A\x{30A}", $Aring));
182 ok($nfd->eq("A",       "\x{FF21}"));
183 ok($nfd->gt("Z",       "\x{FF21}"));
184 ok($nfd->gt("Z",        $Aring));
185 ok($nfd->eq("\x{212B}", $aring));
186 ok($nfd->eq("A\x{30A}", $aring));
187 ok($nfd->gt("Z",        $aring));
188 ok($nfd->lt("a\x{30A}", "Z"));
189
190 $nfd->change(normalization => 'KC');
191
192 ok($nfd->gt("\x{212B}", "A"));
193 ok($nfd->eq("\x{212B}", $Aring));
194 ok($nfd->eq("A\x{30A}", $Aring));
195 ok($nfd->eq("A",       "\x{FF21}"));
196 ok($nfd->gt("Z",       "\x{FF21}"));
197 ok($nfd->lt("Z",        $Aring));
198 ok($nfd->eq("\x{212B}", $aring));
199 ok($nfd->eq("A\x{30A}", $aring));
200 ok($nfd->lt("Z",        $aring));
201 ok($nfd->gt("a\x{30A}", "Z"));
202