4 # re/fold_grind.t has more complex tests, but doesn't test every fold
5 # This file also tests the fc() keyword.
11 skip_all_without_unicode_tables();
12 require Config; import Config;
13 require './charset_tools.pl';
14 require './loc_tools.pl'; # Contains find_utf8_ctype_locale()
17 use feature 'unicode_strings';
18 use Unicode::UCD qw(all_casefolds);
20 binmode *STDOUT, ":utf8";
26 # Read in the official case folding definitions.
27 my $casefolds = all_casefolds();
35 foreach my $decimal_code_point (sort { $a <=> $b } keys %$casefolds) {
36 # We only use simple folds in fc(), since the regex engine uses full case
39 my $name = charnames::viacode($decimal_code_point);
40 my $type = $casefolds->{$decimal_code_point}{'status'};
41 my $code = $casefolds->{$decimal_code_point}{'code'};
42 my $simple = $casefolds->{$decimal_code_point}{'simple'};
43 my $full = $casefolds->{$decimal_code_point}{'full'};
45 if ($simple && $simple ne $full) { # If there is a distinction
46 push @simple_folds, [ $code, $simple, $type, $name ];
49 push @CF, [ $code, $full, $type, $name ];
51 # Get the inverse fold for single-char mappings.
52 $reverse_fold{pack "W*", hex $simple} = pack "W*", $decimal_code_point if $simple;
55 foreach my $test_ref ( @simple_folds ) {
57 my ($code, $mapping, $type, $name) = @$test_ref;
58 my $c = pack("W*", hex $code);
60 my $f = pack("W*", map { hex } split " ", $mapping);
62 my $against = join "", "qq{", map("\\x{$_}", split " ", $mapping), "}";
64 isnt(fc($c), $f, "$code - $name - $mapping - $type - Full casefolding, fc(\\x{$code}) ne $against");
65 isnt("\F$c", $f, "$code - $name - $mapping - $type - Full casefolding, qq{\\F\\x{$code}} ne $against");
69 foreach my $test_ref (@CF) {
70 my ($code, $mapping, $type, $name) = @$test_ref;
71 my $c = pack("W*", hex $code);
73 my $f = pack("W*", map { hex } split " ", $mapping);
74 my $f_length = length $f;
77 qq[":$c:" =~ /:$c:/i],
78 qq[":$c:" =~ /:[_$c]:/], # Place two chars in [] so doesn't get
79 # optimized to a non-charclass
80 qq[":$c:" =~ /:[_$c]:/i],
81 qq[":$c:" =~ /:$f:/i],
82 qq[":$f:" =~ /:$c:/i],
84 ok eval $test, "$code - $name - $mapping - $type - $test";
89 my $against = join "", "qq{", map("\\x{$_}", split " ", $mapping), "}";
91 "$code - $name - $mapping - $type - fc(\\x{$code}) eq $against");
92 is("\F$c", $f, "$code - $name - $mapping - $type - qq{\\F\\x{$code}} eq $against");
94 # And here we test bytes. For [A-Za-z0-9], the fold is the same as lc under
95 # bytes. For everything else, it's the bytes that formed the original string.
96 if ( $c =~ /[A-Za-z0-9]/ ) {
98 is(CORE::fc($c), lc($c), "$code - $name - fc and use bytes, ascii");
102 is($copy, do { use bytes; CORE::fc($c) }, "$code - $name - fc and use bytes");
105 # Certain tests weren't convenient to put in the list above since they are
106 # TODO's in multi-character folds.
107 if ($f_length == 1) {
109 # The qq loses the utf8ness of ":$f:". These tests are not about
110 # finding bugs in utf8ness, so make sure it's utf8.
111 my $test = qq[my \$s = ":$f:"; utf8::upgrade(\$s); \$s =~ /:[_$c]:/i];
112 ok eval $test, "$code - $name - $mapping - $type - $test";
113 $test = qq[":$c:" =~ /:[_$f]:/i];
114 ok eval $test, "$code - $name - $mapping - $type - $test";
118 # There are two classes of multi-char folds that need more work. For
120 # ":ß:" =~ /:[_s]{2}:/i
121 # ":ss:" =~ /:[_ß]:/i
123 # Some of the old tests for the second case happened to pass somewhat
124 # coincidentally. But none would pass if changed to this.
125 # ":SS:" =~ /:[_ß]:/i
127 # As the capital SS doesn't get folded. When those pass, it means
128 # that the code has been changed to take into account folding in the
129 # string, and all should pass, capitalized or not (this wouldn't be
130 # true for [^complemented character classes], for which the fold case
131 # is better, but these aren't used in this .t currently. So, what is
132 # done is to essentially upper-case the string for this class (but use
133 # the reverse fold not uc(), as that is more correct)
135 for my $i (0 .. $f_length - 1) {
136 my $cur_char = substr($f, $i, 1);
137 $u .= $reverse_fold{$cur_char} || $cur_char;
141 # A multi-char fold should not match just one char;
142 # e.g., ":ß:" !~ /:[_s]:/i
143 $test = qq[":$c:" !~ /:[_$f]:/i];
144 ok eval $test, "$code - $name - $mapping - $type - $test";
146 TODO: { # e.g., ":ß:" =~ /:[_s]{2}:/i
147 local $TODO = 'Multi-char fold in [character class]';
149 $test = qq[":$c:" =~ /:[_$f]{$f_length}:/i];
150 ok eval $test, "$code - $name - $mapping - $type - $test";
153 # e.g., ":SS:" =~ /:[_ß]:/i now pass, so TODO has been removed, but
154 # since they use '$u', they are left out of the main loop
155 $test = qq[ my \$s = ":$u:"; utf8::upgrade(\$s); \$s =~ /:[_$c]:/i];
156 ok eval $test, "$code - $name - $mapping - $type - $test";
163 # These three come from the ICU project's test suite, more especifically
164 # http://icu.sourcearchive.com/documentation/4.4~rc1-1/strcase_8cpp-source.html
166 my $s = "A\N{U+00df}\N{U+00b5}\N{U+fb03}\N{U+1040C}\N{U+0130}\N{U+0131}";
167 #\N{LATIN CAPITAL LETTER A}\N{LATIN SMALL LETTER SHARP S}\N{MICRO SIGN}\N{LATIN SMALL LIGATURE FFI}\N{DESERET CAPITAL LETTER AY}\N{LATIN CAPITAL LETTER I WITH DOT ABOVE}\N{LATIN SMALL LETTER DOTLESS I}
169 my $f = "ass\N{U+03bc}ffi\N{U+10434}i\N{U+0307}\N{U+0131}";
170 #\N{LATIN SMALL LETTER A}\N{LATIN SMALL LETTER S}\N{LATIN SMALL LETTER S}\N{GREEK SMALL LETTER MU}\N{LATIN SMALL LETTER F}\N{LATIN SMALL LETTER F}\N{LATIN SMALL LETTER I}\N{DESERET SMALL LETTER AY}\N{LATIN SMALL LETTER I}\N{COMBINING DOT ABOVE}\N{LATIN SMALL LETTER DOTLESS I}
172 is(fc($s), $f, "ICU's casefold test passes");
173 is("\F$s", $f, "ICU's casefold test passes");
175 is( fc("aBİIıϐßffi"), "abi̇iıβssffi" );
176 is( "\FaBİIıϐßffi", "abi̇iıβssffi" );
178 # local $::TODO = "turkic special cases";
179 # is( fc "aBİIıϐßffi", "abiııβssffi" );
182 # The next batch come from http://www.devdaily.com/java/jwarehouse/lucene/contrib/icu/src/test/org/apache/lucene/analysis/icu/TestICUFoldingFilter.java.shtml
183 # Except the article got most casings wrong. Or maybe Lucene does.
185 is( fc("This is a test"), "this is a test" );
186 is( fc("Ruß"), "russ" );
187 is( fc("ΜΆΪΟΣ"), "μάϊοσ" );
188 is( fc("Μάϊος"), "μάϊοσ" );
190 is( fc("r" . uni_to_native("\xe9") . "sum" . uni_to_native("\xe9")),
191 "r" . uni_to_native("\xe9") . "sum" . uni_to_native("\xe9") );
192 is( fc("re\x{0301}sume\x{0301}"), "re\x{301}sume\x{301}" );
193 is( fc("ELİF"), "eli\x{307}f" );
194 is( fc("eli\x{307}f"), "eli\x{307}f");
196 # This batch comes from
197 # http://www.java2s.com/Open-Source/Java-Document/Internationalization-Localization/icu4j/com/ibm/icu/dev/test/lang/UCharacterCaseTest.java.htm
198 # Which uses ICU as the backend.
200 my @folding_mixed = (
201 uni_to_native("\x{61}\x{42}\x{130}\x{49}\x{131}\x{3d0}\x{df}\x{fb03}"),
202 "A" . uni_to_native("\x{df}\x{b5}\x{fb03}\x{1040C}\x{130}\x{131}"),
205 my @folding_default = (
206 uni_to_native("\x{61}\x{62}\x{69}\x{307}\x{69}\x{131}\x{3b2}\x{73}\x{73}\x{66}\x{66}\x{69}"),
207 "ass\x{3bc}ffi\x{10434}i\x{307}\x{131}"
210 my @folding_exclude_turkic = (
211 uni_to_native("\x{61}\x{62}\x{69}\x{131}\x{131}\x{3b2}\x{73}\x{73}\x{66}\x{66}\x{69}"),
212 "ass\x{3bc}ffi\x{10434}i\x{131}",
215 is( fc($folding_mixed[1]), $folding_default[1] );
217 is( fc($folding_mixed[0]), $folding_default[0] );
223 # Table stolen from tchrist's mail in
224 # http://bugs.python.org/file23051/casing-tests.py
225 # and http://98.245.80.27/tcpc/OSCON2011/case-test.python3
226 # For reference, it's a longer version of what he posted here:
227 # http://stackoverflow.com/questions/6991038/case-insensitive-storage-and-unicode-compatibility
229 #Couple of repeats because I'm lazy, not tchrist's fault.
231 #This should probably go in t/op/lc.t
234 # ORIG LC_SIMPLE TC_SIMPLE UC_SIMPLE LC_FULL TC_FULL UC_FULL FC_SIMPLE FC_TURKIC FC_FULL
235 [ 'þǽr rihtes', 'þǽr rihtes', 'Þǽr Rihtes', 'ÞǼR RIHTES', 'þǽr rihtes', 'Þǽr Rihtes', 'ÞǼR RIHTES', 'þǽr rihtes', 'þǽr rihtes', 'þǽr rihtes', ],
236 [ 'duȝeðlice', 'duȝeðlice', 'Duȝeðlice', 'DUȜEÐLICE', 'duȝeðlice', 'Duȝeðlice', 'DUȜEÐLICE', 'duȝeðlice', 'duȝeðlice', 'duȝeðlice', ],
237 [ 'Ævar Arnfjörð Bjarmason', 'ævar arnfjörð bjarmason', 'Ævar Arnfjörð Bjarmason', 'ÆVAR ARNFJÖRÐ BJARMASON', 'ævar arnfjörð bjarmason', 'Ævar Arnfjörð Bjarmason', 'ÆVAR ARNFJÖRÐ BJARMASON', 'ævar arnfjörð bjarmason', 'ævar arnfjörð bjarmason', 'ævar arnfjörð bjarmason', ],
238 [ 'Кириллица', 'кириллица', 'Кириллица', 'КИРИЛЛИЦА', 'кириллица', 'Кириллица', 'КИРИЛЛИЦА', 'кириллица', 'кириллица', 'кириллица', ],
239 [ 'ij', 'ij', 'IJ', 'IJ', 'ij', 'IJ', 'IJ', 'ij', 'ij', 'ij', ],
240 [ 'Van Dijke', 'van dijke', 'Van Dijke', 'VAN DIJKE', 'van dijke', 'Van Dijke', 'VAN DIJKE', 'van dijke', 'van dijke', 'van dijke', ],
241 [ 'VAN DIJKE', 'van dijke', 'Van Dijke', 'VAN DIJKE', 'van dijke', 'Van Dijke', 'VAN DIJKE', 'van dijke', 'van dijke', 'van dijke', ],
242 [ 'efficient', 'efficient', 'Efficient', 'EffiCIENT', 'efficient', 'Efficient', 'EFFICIENT', 'efficient', 'efficient', 'efficient', ],
243 [ 'flour', 'flour', 'flour', 'flOUR', 'flour', 'Flour', 'FLOUR', 'flour', 'flour', 'flour', ],
244 [ 'flour and water', 'flour and water', 'flour And Water', 'flOUR AND WATER', 'flour and water', 'Flour And Water', 'FLOUR AND WATER', 'flour and water', 'flour and water', 'flour and water', ],
245 [ 'dzur', 'dzur', 'Dzur', 'DZUR', 'dzur', 'Dzur', 'DZUR', 'dzur', 'dzur', 'dzur', ],
246 [ 'Dzur', 'dzur', 'Dzur', 'DZUR', 'dzur', 'Dzur', 'DZUR', 'dzur', 'dzur', 'dzur', ],
247 [ 'DZUR', 'dzur', 'Dzur', 'DZUR', 'dzur', 'Dzur', 'DZUR', 'dzur', 'dzur', 'dzur', ],
248 [ 'dzur mountain', 'dzur mountain', 'Dzur Mountain', 'DZUR MOUNTAIN', 'dzur mountain', 'Dzur Mountain', 'DZUR MOUNTAIN', 'dzur mountain', 'dzur mountain', 'dzur mountain', ],
249 [ 'Dzur Mountain', 'dzur mountain', 'Dzur Mountain', 'DZUR MOUNTAIN', 'dzur mountain', 'Dzur Mountain', 'DZUR MOUNTAIN', 'dzur mountain', 'dzur mountain', 'dzur mountain', ],
250 [ 'DZUR MOUNTAIN', 'dzur mountain', 'Dzur Mountain', 'DZUR MOUNTAIN', 'dzur mountain', 'Dzur Mountain', 'DZUR MOUNTAIN', 'dzur mountain', 'dzur mountaın', 'dzur mountain', ],
251 [ 'poſt', 'poſt', 'Poſt', 'POST', 'poſt', 'Poſt', 'POST', 'post', 'post', 'post', ],
252 [ 'poſt', 'poſt', 'Poſt', 'POſt', 'poſt', 'Poſt', 'POST', 'poſt', 'post', 'post', ],
253 [ 'ſtop', 'ſtop', 'ſtop', 'ſtOP', 'ſtop', 'Stop', 'STOP', 'ſtop', 'stop', 'stop', ],
254 [ 'tschüß', 'tschüß', 'Tschüß', 'TSCHÜß', 'tschüß', 'Tschüß', 'TSCHÜSS', 'tschüß', 'tschüss', 'tschüss', ],
255 [ 'TSCHÜẞ', 'tschüß', 'Tschüß', 'TSCHÜẞ', 'tschüß', 'Tschüß', 'TSCHÜẞ', 'tschüß', 'tschüss', 'tschüss', ],
256 [ 'weiß', 'weiß', 'Weiß', 'WEIß', 'weiß', 'Weiß', 'WEISS', 'weiß', 'weiss', 'weiss', ],
257 [ 'WEIẞ', 'weiß', 'Weiß', 'WEIẞ', 'weiß', 'Weiß', 'WEIẞ', 'weiß', 'weıss', 'weiss', ],
258 [ 'ẞIEW', 'ßiew', 'ẞiew', 'ẞIEW', 'ßiew', 'ẞiew', 'ẞIEW', 'ßiew', 'ssıew', 'ssiew', ],
259 [ 'ᾲ', 'ᾲ', 'Ὰͅ', 'ᾺΙ', 'ᾲ', 'Ὰͅ', 'ᾺΙ', 'ὰι', 'ὰι', 'ὰι', ],
260 [ 'Ὰι', 'ὰι', 'Ὰι', 'ᾺΙ', 'ὰι', 'Ὰι', 'ᾺΙ', 'ὰι', 'ὰι', 'ὰι', ],
261 [ 'ᾺΙ', 'ὰι', 'Ὰι', 'ᾺΙ', 'ὰι', 'Ὰι', 'ᾺΙ', 'ὰι', 'ὰι', 'ὰι', ],
262 [ 'ᾲ', 'ᾲ', 'ᾲ', 'ᾲ', 'ᾲ', 'Ὰͅ', 'ᾺΙ', 'ᾲ', 'ὰι', 'ὰι', ],
263 [ 'Ὰͅ', 'ᾲ', 'Ὰͅ', 'ᾺΙ', 'ᾲ', 'Ὰͅ', 'ᾺΙ', 'ὰι', 'ὰι', 'ὰι', ],
264 [ 'ᾺΙ', 'ὰι', 'Ὰι', 'ᾺΙ', 'ὰι', 'Ὰι', 'ᾺΙ', 'ὰι', 'ὰι', 'ὰι', ],
265 [ 'ᾲ στο διάολο', 'ᾲ στο διάολο', 'ᾲ Στο Διάολο', 'ᾲ ΣΤΟ ΔΙΆΟΛΟ', 'ᾲ στο διάολο', 'Ὰͅ Στο Διάολο', 'ᾺΙ ΣΤΟ ΔΙΆΟΛΟ', 'ᾲ στο διάολο', 'ὰι στο διάολο', 'ὰι στο διάολο', ],
266 [ 'ᾲ στο διάολο', 'ᾲ στο διάολο', 'Ὰͅ Στο Διάολο', 'ᾺΙ ΣΤΟ ΔΙΆΟΛΟ', 'ᾲ στο διάολο', 'Ὰͅ Στο Διάολο', 'ᾺΙ ΣΤΟ ΔΙΆΟΛΟ', 'ὰι στο διάολο', 'ὰι στο διάολο', 'ὰι στο διάολο', ],
267 [ '𐐼𐐯𐑅𐐨𐑉𐐯𐐻', '𐐼𐐯𐑅𐐨𐑉𐐯𐐻', '𐐔𐐯𐑅𐐨𐑉𐐯𐐻', '𐐔𐐇𐐝𐐀𐐡𐐇𐐓', '𐐼𐐯𐑅𐐨𐑉𐐯𐐻', '𐐔𐐯𐑅𐐨𐑉𐐯𐐻', '𐐔𐐇𐐝𐐀𐐡𐐇𐐓', '𐐼𐐯𐑅𐐨𐑉𐐯𐐻', '𐐼𐐯𐑅𐐨𐑉𐐯𐐻', '𐐼𐐯𐑅𐐨𐑉𐐯𐐻', ],
268 [ '𐐔𐐯𐑅𐐨𐑉𐐯𐐻', '𐐼𐐯𐑅𐐨𐑉𐐯𐐻', '𐐔𐐯𐑅𐐨𐑉𐐯𐐻', '𐐔𐐇𐐝𐐀𐐡𐐇𐐓', '𐐼𐐯𐑅𐐨𐑉𐐯𐐻', '𐐔𐐯𐑅𐐨𐑉𐐯𐐻', '𐐔𐐇𐐝𐐀𐐡𐐇𐐓', '𐐼𐐯𐑅𐐨𐑉𐐯𐐻', '𐐼𐐯𐑅𐐨𐑉𐐯𐐻', '𐐼𐐯𐑅𐐨𐑉𐐯𐐻', ],
269 [ '𐐔𐐇𐐝𐐀𐐡𐐇𐐓', '𐐼𐐯𐑅𐐨𐑉𐐯𐐻', '𐐔𐐯𐑅𐐨𐑉𐐯𐐻', '𐐔𐐇𐐝𐐀𐐡𐐇𐐓', '𐐼𐐯𐑅𐐨𐑉𐐯𐐻', '𐐔𐐯𐑅𐐨𐑉𐐯𐐻', '𐐔𐐇𐐝𐐀𐐡𐐇𐐓', '𐐼𐐯𐑅𐐨𐑉𐐯𐐻', '𐐼𐐯𐑅𐐨𐑉𐐯𐐻', '𐐼𐐯𐑅𐐨𐑉𐐯𐐻', ],
270 [ 'henry ⅷ', 'henry ⅷ', 'Henry Ⅷ', 'HENRY Ⅷ', 'henry ⅷ', 'Henry Ⅷ', 'HENRY Ⅷ', 'henry ⅷ', 'henry ⅷ', 'henry ⅷ', ],
271 [ 'Henry Ⅷ', 'henry ⅷ', 'Henry Ⅷ', 'HENRY Ⅷ', 'henry ⅷ', 'Henry Ⅷ', 'HENRY Ⅷ', 'henry ⅷ', 'henry ⅷ', 'henry ⅷ', ],
272 [ 'HENRY Ⅷ', 'henry ⅷ', 'Henry Ⅷ', 'HENRY Ⅷ', 'henry ⅷ', 'Henry Ⅷ', 'HENRY Ⅷ', 'henry ⅷ', 'henry ⅷ', 'henry ⅷ', ],
273 [ 'i work at ⓚ', 'i work at ⓚ', 'I Work At Ⓚ', 'I WORK AT Ⓚ', 'i work at ⓚ', 'I Work At Ⓚ', 'I WORK AT Ⓚ', 'i work at ⓚ', 'i work at ⓚ', 'i work at ⓚ', ],
274 [ 'I Work At Ⓚ', 'i work at ⓚ', 'I Work At Ⓚ', 'I WORK AT Ⓚ', 'i work at ⓚ', 'I Work At Ⓚ', 'I WORK AT Ⓚ', 'i work at ⓚ', 'ı work at ⓚ', 'i work at ⓚ', ],
275 [ 'I WORK AT Ⓚ', 'i work at ⓚ', 'I Work At Ⓚ', 'I WORK AT Ⓚ', 'i work at ⓚ', 'I Work At Ⓚ', 'I WORK AT Ⓚ', 'i work at ⓚ', 'ı work at ⓚ', 'i work at ⓚ', ],
276 [ 'istambul', 'istambul', 'Istambul', 'ISTAMBUL', 'istambul', 'Istambul', 'ISTAMBUL', 'istambul', 'istambul', 'istambul', ],
277 [ 'i̇stanbul', 'i̇stanbul', 'İstanbul', 'İSTANBUL', 'i̇stanbul', 'İstanbul', 'İSTANBUL', 'i̇stanbul', 'i̇stanbul', 'i̇stanbul', ],
278 [ 'İstanbul', 'i̇stanbul', 'İstanbul', 'İSTANBUL', 'i̇stanbul', 'İstanbul', 'İSTANBUL', 'i̇stanbul', 'ı̇stanbul', 'i̇stanbul', ],
279 [ 'İSTANBUL', 'istanbul', 'İstanbul', 'İSTANBUL', 'i̇stanbul', 'İstanbul', 'İSTANBUL', 'İstanbul', 'istanbul', 'i̇stanbul', ],
280 [ 'στιγμας', 'στιγμας', 'Στιγμας', 'ΣΤΙΓΜΑΣ', 'στιγμας', 'Στιγμας', 'ΣΤΙΓΜΑΣ', 'στιγμασ', 'στιγμασ', 'στιγμασ', ],
281 [ 'στιγμασ', 'στιγμασ', 'Στιγμασ', 'ΣΤΙΓΜΑΣ', 'στιγμασ', 'Στιγμασ', 'ΣΤΙΓΜΑΣ', 'στιγμασ', 'στιγμασ', 'στιγμασ', ],
282 [ 'ΣΤΙΓΜΑΣ', 'στιγμασ', 'Στιγμασ', 'ΣΤΙΓΜΑΣ', 'στιγμασ', 'Στιγμασ', 'ΣΤΙΓΜΑΣ', 'στιγμασ', 'στιγμασ', 'στιγμασ', ],
283 [ 'ʀᴀʀᴇ', 'ʀᴀʀᴇ', 'Ʀᴀʀᴇ', 'ƦᴀƦᴇ', 'ʀᴀʀᴇ', 'Ʀᴀʀᴇ', 'ƦᴀƦᴇ', 'ʀᴀʀᴇ', 'ʀᴀʀᴇ', 'ʀᴀʀᴇ', ],
284 [ 'Ʀᴀʀᴇ', 'ʀᴀʀᴇ', 'Ʀᴀʀᴇ', 'ƦᴀƦᴇ', 'ʀᴀʀᴇ', 'Ʀᴀʀᴇ', 'ƦᴀƦᴇ', 'ʀᴀʀᴇ', 'ʀᴀʀᴇ', 'ʀᴀʀᴇ', ],
285 [ 'ƦᴀƦᴇ', 'ʀᴀʀᴇ', 'Ʀᴀʀᴇ', 'ƦᴀƦᴇ', 'ʀᴀʀᴇ', 'Ʀᴀʀᴇ', 'ƦᴀƦᴇ', 'ʀᴀʀᴇ', 'ʀᴀʀᴇ', 'ʀᴀʀᴇ', ],
286 [ 'Ԧԧ', 'ԧԧ', 'Ԧԧ', 'ԦԦ', 'ԧԧ', 'Ԧԧ', 'ԦԦ', 'ԧԧ', 'ԧԧ', 'ԧԧ', ],
287 [ 'ԧԧ', 'ԧԧ', 'Ԧԧ', 'ԦԦ', 'ԧԧ', 'Ԧԧ', 'ԦԦ', 'ԧԧ', 'ԧԧ', 'ԧԧ', ],
288 [ 'Ԧԧ', 'ԧԧ', 'Ԧԧ', 'ԦԦ', 'ԧԧ', 'Ԧԧ', 'ԦԦ', 'ԧԧ', 'ԧԧ', 'ԧԧ', ],
289 [ 'ԦԦ', 'ԧԧ', 'Ԧԧ', 'ԦԦ', 'ԧԧ', 'Ԧԧ', 'ԦԦ', 'ԧԧ', 'ԧԧ', 'ԧԧ', ],
290 [ "þǽr rihtes", "þǽr rihtes", "Þǽr Rihtes", "ÞǼR RIHTES", "þǽr rihtes", "Þǽr Rihtes", "ÞǼR RIHTES", "þǽr rihtes", "þǽr rihtes", "þǽr rihtes", ],
291 [ "duȝeðlice", "duȝeðlice", "Duȝeðlice", "DUȜEÐLICE", "duȝeðlice", "Duȝeðlice", "DUȜEÐLICE", "duȝeðlice", "duȝeðlice", "duȝeðlice", ],
292 [ "Van Dijke", "van dijke", "Van Dijke", "VAN DIJKE", "van dijke", "Van Dijke", "VAN DIJKE", "van dijke", "van dijke", "van dijke", ],
293 [ "fi", "fi", "fi", "fi", "fi", "Fi", "FI", "fi", "fi", "fi", ],
294 [ "filesystem", "filesystem", "filesystem", "fiLESYSTEM", "filesystem", "Filesystem", "FILESYSTEM", "filesystem", "filesystem", "filesystem", ],
295 [ "efficient", "efficient", "Efficient", "EffiCIENT", "efficient", "Efficient", "EFFICIENT", "efficient", "efficient", "efficient", ],
296 [ "flour and water", "flour and water", "flour And Water", "flOUR AND WATER", "flour and water", "Flour And Water", "FLOUR AND WATER", "flour and water", "flour and water", "flour and water", ],
297 [ "dz", "dz", "Dz", "DZ", "dz", "Dz", "DZ", "dz", "dz", "dz", ],
298 [ "dzur mountain", "dzur mountain", "Dzur Mountain", "DZUR MOUNTAIN", "dzur mountain", "Dzur Mountain", "DZUR MOUNTAIN", "dzur mountain", "dzur mountain", "dzur mountain", ],
299 [ "poſt", "poſt", "Poſt", "POST", "poſt", "Poſt", "POST", "post", "post", "post", ],
300 [ "poſt", "poſt", "Poſt", "POſt", "poſt", "Poſt", "POST", "poſt", "post", "post", ],
301 [ "ſtop", "ſtop", "ſtop", "ſtOP", "ſtop", "Stop", "STOP", "ſtop", "stop", "stop", ],
302 [ "tschüß", "tschüß", "Tschüß", "TSCHÜß", "tschüß", "Tschüß", "TSCHÜSS", "tschüß", "tschüss", "tschüss", ],
303 [ "TSCHÜẞ", "tschüß", "Tschüß", "TSCHÜẞ", "tschüß", "Tschüß", "TSCHÜẞ", "tschüß", "tschüss", "tschüss", ],
304 [ "rußland", "rußland", "Rußland", "RUßLAND", "rußland", "Rußland", "RUSSLAND", "rußland", "russland", "russland", ],
305 [ "RUẞLAND", "rußland", "Rußland", "RUẞLAND", "rußland", "Rußland", "RUẞLAND", "rußland", "russland", "russland", ],
306 [ "weiß", "weiß", "Weiß", "WEIß", "weiß", "Weiß", "WEISS", "weiß", "weiss", "weiss", ],
307 [ "WEIẞ", "weiß", "Weiß", "WEIẞ", "weiß", "Weiß", "WEIẞ", "weiß", "weıss", "weiss", ],
308 [ "ẞIEW", "ßiew", "ẞiew", "ẞIEW", "ßiew", "ẞiew", "ẞIEW", "ßiew", "ssıew", "ssiew", ],
309 [ "ͅ", "ͅ", "Ι", "Ι", "ͅ", "Ι", "Ι", "ι", "ι", "ι", ],
310 [ "ᾲ", "ᾲ", "Ὰͅ", "ᾺΙ", "ᾲ", "Ὰͅ", "ᾺΙ", "ὰι", "ὰι", "ὰι", ],
311 [ "Ὰι", "ὰι", "Ὰι", "ᾺΙ", "ὰι", "Ὰι", "ᾺΙ", "ὰι", "ὰι", "ὰι", ],
312 [ "ᾺΙ", "ὰι", "Ὰι", "ᾺΙ", "ὰι", "Ὰι", "ᾺΙ", "ὰι", "ὰι", "ὰι", ],
313 [ "ᾲ", "ᾲ", "ᾲ", "ᾲ", "ᾲ", "Ὰͅ", "ᾺΙ", "ᾲ", "ὰι", "ὰι", ],
314 [ "Ὰͅ", "ᾲ", "Ὰͅ", "ᾺΙ", "ᾲ", "Ὰͅ", "ᾺΙ", "ὰι", "ὰι", "ὰι", ],
315 [ "ᾺΙ", "ὰι", "Ὰι", "ᾺΙ", "ὰι", "Ὰι", "ᾺΙ", "ὰι", "ὰι", "ὰι", ],
316 [ "ᾲ στο διάολο", "ᾲ στο διάολο", "ᾲ Στο Διάολο", "ᾲ ΣΤΟ ΔΙΆΟΛΟ", "ᾲ στο διάολο", "Ὰͅ Στο Διάολο", "ᾺΙ ΣΤΟ ΔΙΆΟΛΟ", "ᾲ στο διάολο", "ὰι στο διάολο", "ὰι στο διάολο", ],
317 [ "ᾲ στο διάολο", "ᾲ στο διάολο", "Ὰͅ Στο Διάολο", "ᾺΙ ΣΤΟ ΔΙΆΟΛΟ", "ᾲ στο διάολο", "Ὰͅ Στο Διάολο", "ᾺΙ ΣΤΟ ΔΙΆΟΛΟ", "ὰι στο διάολο", "ὰι στο διάολο", "ὰι στο διάολο", ],
318 [ "ⅷ", "ⅷ", "Ⅷ", "Ⅷ", "ⅷ", "Ⅷ", "Ⅷ", "ⅷ", "ⅷ", "ⅷ", ],
319 [ "henry ⅷ", "henry ⅷ", "Henry Ⅷ", "HENRY Ⅷ", "henry ⅷ", "Henry Ⅷ", "HENRY Ⅷ", "henry ⅷ", "henry ⅷ", "henry ⅷ", ],
320 [ "ⓚ", "ⓚ", "Ⓚ", "Ⓚ", "ⓚ", "Ⓚ", "Ⓚ", "ⓚ", "ⓚ", "ⓚ", ],
321 [ "i work at ⓚ", "i work at ⓚ", "I Work At Ⓚ", "I WORK AT Ⓚ", "i work at ⓚ", "I Work At Ⓚ", "I WORK AT Ⓚ", "i work at ⓚ", "i work at ⓚ", "i work at ⓚ", ],
322 [ "istambul", "istambul", "Istambul", "ISTAMBUL", "istambul", "Istambul", "ISTAMBUL", "istambul", "istambul", "istambul", ],
323 [ "i̇stanbul", "i̇stanbul", "İstanbul", "İSTANBUL", "i̇stanbul", "İstanbul", "İSTANBUL", "i̇stanbul", "i̇stanbul", "i̇stanbul", ],
324 [ "İstanbul", "i̇stanbul", "İstanbul", "İSTANBUL", "i̇stanbul", "İstanbul", "İSTANBUL", "i̇stanbul", "ı̇stanbul", "i̇stanbul", ],
325 [ "İSTANBUL", "istanbul", "İstanbul", "İSTANBUL", "i̇stanbul", "İstanbul", "İSTANBUL", "İstanbul", "istanbul", "i̇stanbul", ],
326 [ "στιγμας", "στιγμας", "Στιγμας", "ΣΤΙΓΜΑΣ", "στιγμας", "Στιγμας", "ΣΤΙΓΜΑΣ", "στιγμασ", "στιγμασ", "στιγμασ", ],
327 [ "στιγμασ", "στιγμασ", "Στιγμασ", "ΣΤΙΓΜΑΣ", "στιγμασ", "Στιγμασ", "ΣΤΙΓΜΑΣ", "στιγμασ", "στιγμασ", "στιγμασ", ],
328 [ "ΣΤΙΓΜΑΣ", "στιγμασ", "Στιγμασ", "ΣΤΙΓΜΑΣ", "στιγμασ", "Στιγμασ", "ΣΤΙΓΜΑΣ", "στιγμασ", "στιγμασ", "στιγμασ", ],
329 [ "ʀᴀʀᴇ", "ʀᴀʀᴇ", "Ʀᴀʀᴇ", "ƦᴀƦᴇ", "ʀᴀʀᴇ", "Ʀᴀʀᴇ", "ƦᴀƦᴇ", "ʀᴀʀᴇ", "ʀᴀʀᴇ", "ʀᴀʀᴇ", ],
330 [ "𐐼𐐯𐑅𐐨𐑉𐐯𐐻", "𐐼𐐯𐑅𐐨𐑉𐐯𐐻", "𐐔𐐯𐑅𐐨𐑉𐐯𐐻", "𐐔𐐇𐐝𐐀𐐡𐐇𐐓", "𐐼𐐯𐑅𐐨𐑉𐐯𐐻", "𐐔𐐯𐑅𐐨𐑉𐐯𐐻", "𐐔𐐇𐐝𐐀𐐡𐐇𐐓", "𐐼𐐯𐑅𐐨𐑉𐐯𐐻", "𐐼𐐯𐑅𐐨𐑉𐐯𐐻", "𐐼𐐯𐑅𐐨𐑉𐐯𐐻", ],
331 [ "Ԧԧ", "ԧԧ", "Ԧԧ", "ԦԦ", "ԧԧ", "Ԧԧ", "ԦԦ", "ԧԧ", "ԧԧ", "ԧԧ", ],
332 [ "ﬓﬔﬕﬖﬗ", "ﬓﬔﬕﬖﬗ", "ﬓﬔﬕﬖﬗ", "ﬓﬔﬕﬖﬗ", "ﬓﬔﬕﬖﬗ", "Մնﬔﬕﬖﬗ", "ՄՆՄԵՄԻՎՆՄԽ", "ﬓﬔﬕﬖﬗ", "մնմեմիվնմխ", "մնմեմիվնմխ", ],
333 [ "ʼn groot", "ʼn groot", "ʼn Groot", "ʼn GROOT", "ʼn groot", "ʼN Groot", "ʼN GROOT", "ʼn groot", "ʼn groot", "ʼn groot", ],
334 [ "ẚ", "ẚ", "ẚ", "ẚ", "ẚ", "Aʾ", "Aʾ", "ẚ", "aʾ", "aʾ", ],
335 [ "ff", "ff", "ff", "ff", "ff", "Ff", "FF", "ff", "ff", "ff", ],
336 [ "ǰ", "ǰ", "ǰ", "ǰ", "ǰ", "J̌", "J̌", "ǰ", "ǰ", "ǰ", ],
337 [ "550 nm or Å", "550 nm or å", "550 Nm Or Å", "550 NM OR Å", "550 nm or å", "550 Nm Or Å", "550 NM OR Å", "550 nm or å", "550 nm or å", "550 nm or å", ],
343 my ($simple_lc, $simple_tc, $simple_uc, $simple_fc) = @{$_}[1, 2, 3, 7];
344 my ($orig, $lower, $titlecase, $upper, $fc_turkic, $fc_full) = @{$_}[0,4,5,6,8,9];
346 if ($orig =~ /(\P{Assigned})/) { # So can fail gracefully in earlier
348 fail(sprintf "because U+%04X is unassigned", ord($1));
351 is( fc($orig), $fc_full, "fc('$orig') returns '$fc_full'" );
352 is( "\F$orig", $fc_full, '\F works' );
353 is( lc($orig), $lower, "lc('$orig') returns '$lower'" );
354 is( "\L$orig", $lower, '\L works' );
355 is( uc($orig), $upper, "uc('$orig') returns '$upper'" );
356 is( "\U$orig", $upper, '\U works' );
362 package Eeyup { use overload q{""} => sub { main::uni_to_native("\x{df}") }, fallback => 1 }
363 package Uunope { use overload q{""} => sub { "\x{30cb}" }, fallback => 1 }
364 package Undef { use overload q{""} => sub { undef }, fallback => 1 }
366 my $obj = bless {}, "Eeyup";
367 is(fc($obj), "ss", "fc() works on overloaded objects returning latin-1");
368 $obj = bless {}, "Eeyup";
369 is("\F$obj", "ss", '\F works on overloaded objects returning latin-1');
371 $obj = bless {}, "Uunope";
372 is(fc($obj), "\x{30cb}", "fc() works on overloaded objects returning UTF-8");
373 $obj = bless {}, "Uunope";
374 is("\F$obj", "\x{30cb}", '\F works on overloaded objects returning UTF-8');
376 $obj = bless {}, "Undef";
380 use warnings "uninitialized";
381 local $SIG{__WARN__} = sub { $warnings++; like(shift, qr/Use of uninitialized value (?:\$obj )?in fc/) };
385 is( $warnings, 2, "correct number of warnings" );
388 package Derpy { sub TIESCALAR { bless {}, shift } sub FETCH { $fetched++; main::uni_to_native("\x{df}") } }
392 is( fc($x), "ss", "fc() works on tied values" );
393 is( $fetched, 1, "and only calls the magic once" );
398 use feature qw( fc );
399 my $troublesome1 = uni_to_native("\xdf") x 11; #SvLEN should be 12, SvCUR should be 11
400 #So this should force fc() to grow the string.
402 is( fc($troublesome1), "ss" x 11, "fc() grows the string" );
404 my $troublesome2 = "abcdef:" . uni_to_native("\x{df}")
405 . ":fjksjs"; #SvLEN should be 16, SvCUR should be 15
406 is( fc($troublesome2), "abcdef:ss:fjksjs", "fc() expands \\x{DF} in the middle of a string that needs to grow" );
408 my $troublesome3 = ":" . uni_to_native("\x{df}") . ":";
409 is( fc($troublesome3), ":ss:", "fc() expands \\x{DF} in the middle of a string" );
412 my $troublesome4 = uni_to_native("\x{B5}"); #\N{MICRON SIGN} is latin-1, but its foldcase is in UTF-8
414 is( fc($troublesome4), "\x{3BC}", "fc() for a latin-1 \x{B5} returns UTF-8" );
415 ok( !utf8::is_utf8($troublesome4), "fc() doesn't upgrade the original string" );
418 my $troublesome5 = uni_to_native("\x{C9}") . "abda"
419 . uni_to_native("\x{B5}") . "aaf"
420 . uni_to_native("\x{C8}"); # Up until foldcasing \x{B5}, the string
421 # was in Latin-1. This tests that the
422 # results don't have illegal UTF-8
423 # (i.e. leftover latin-1) in them
425 is( fc($troublesome5), uni_to_native("\x{E9}") . "abda\x{3BC}aaf"
426 . uni_to_native("\x{E8}") );
431 use feature qw( fc unicode_strings );
433 eval { require POSIX; import POSIX 'locale_h'; };
434 unless (defined &POSIX::LC_ALL) {
435 skip "no POSIX (or no Fcntl, or no dynamic loading)", 256;
438 setlocale(&POSIX::LC_ALL, "C") if $Config{d_setlocale};
440 # This tests both code paths in pp_fc
445 utf8::downgrade($latin1); #No-op, but doesn't hurt
446 utf8::upgrade($utf8);
447 is(fc($latin1), fc($utf8), "fc() gives the same results for \\x{$_} in Latin-1 and UTF-8 under unicode_strings");
449 skip 'Locales not available', 2 unless locales_enabled('LC_CTYPE');
451 is(fc($latin1), lc($latin1), "use locale; fc(qq{\\x{$_}}), lc(qq{\\x{$_}}) when qq{\\x{$_}} is in latin-1");
452 is(fc($utf8), lc($utf8), "use locale; fc(qq{\\x{$_}}), lc(qq{\\x{$_}}) when qq{\\x{$_}} is in latin-1");
455 no feature 'unicode_strings';
456 is(fc($latin1), lc($latin1), "under nothing, fc() for <256 is the same as lc");
461 my $utf8_locale = find_utf8_ctype_locale();
464 use feature qw( fc );
466 no warnings 'locale'; # Would otherwise warn
467 is(fc("\x{1E9E}"), fc("\x{17F}\x{17F}"), 'fc("\x{1E9E}") eq fc("\x{17F}\x{17F}")');
468 use warnings 'locale';
470 skip 'Can\'t find a UTF-8 locale', 1 unless defined $utf8_locale;
471 setlocale(&LC_CTYPE, $utf8_locale);
472 is(fc("\x{1E9E}"), "ss", 'fc("\x{1E9E}") eq "ss" in a UTF-8 locale)');
477 skip 'Can\'t find a UTF-8 locale', 256 unless defined $utf8_locale;
479 use feature qw( fc unicode_strings );
481 # Get the official fc values outside locale.
485 push @unicode_fc, fc(chr);
488 # These should match the UTF-8 locale values
489 setlocale(&LC_CTYPE, $utf8_locale);
492 is(fc(chr), $unicode_fc[$_], "In a UTF-8 locale, fc(chr $_) is the same as official Unicode");
497 my $num_tests = curr_test() - 1;