3 # This file is intentionally encoded in latin-1.
15 is(lc(undef), "", "lc(undef) is ''");
16 is(lcfirst(undef), "", "lcfirst(undef) is ''");
17 is(uc(undef), "", "uc(undef) is ''");
18 is(ucfirst(undef), "", "ucfirst(undef) is ''");
22 is(CORE::fc(undef), "", "fc(undef) is ''");
23 is(CORE::fc(''), "", "fc('') is ''");
27 like($@, qr/Undefined subroutine &main::fc/, "fc() throws an exception,");
33 ok(!$@, "...but works after requesting the feature");
40 is("\Q$a\E." , "HELLO\\.\\*\\ world.", '\Q\E HELLO.* world');
41 is("\u$a" , "HELLO\.\* world", '\u');
42 is("\l$a" , "hELLO\.\* world", '\l');
43 is("\U$a" , "HELLO\.\* WORLD", '\U');
44 is("\L$a" , "hello\.\* world", '\L');
45 is("\F$a" , "hello\.\* world", '\F');
47 is(quotemeta($a) , "HELLO\\.\\*\\ world", 'quotemeta');
48 is(ucfirst($a) , "HELLO\.\* world", 'ucfirst');
49 is(lcfirst($a) , "hELLO\.\* world", 'lcfirst');
50 is(uc($a) , "HELLO\.\* WORLD", 'uc');
51 is(lc($a) , "hello\.\* world", 'lc');
52 is(fc($a) , "hello\.\* world", 'fc');
54 is("\Q$b\E." , "hello\\.\\*\\ WORLD.", '\Q\E hello.* WORLD');
55 is("\u$b" , "Hello\.\* WORLD", '\u');
56 is("\l$b" , "hello\.\* WORLD", '\l');
57 is("\U$b" , "HELLO\.\* WORLD", '\U');
58 is("\L$b" , "hello\.\* world", '\L');
59 is("\F$b" , "hello\.\* world", '\F');
61 is(quotemeta($b) , "hello\\.\\*\\ WORLD", 'quotemeta');
62 is(ucfirst($b) , "Hello\.\* WORLD", 'ucfirst');
63 is(lcfirst($b) , "hello\.\* WORLD", 'lcfirst');
64 is(uc($b) , "HELLO\.\* WORLD", 'uc');
65 is(lc($b) , "hello\.\* world", 'lc');
66 is(fc($b) , "hello\.\* world", 'fc');
68 # \x{100} is LATIN CAPITAL LETTER A WITH MACRON; its bijective lowercase is
69 # \x{101}, LATIN SMALL LETTER A WITH MACRON.
70 # Which is also its foldcase.
72 $a = "\x{100}\x{101}Aa";
73 $b = "\x{101}\x{100}aA";
75 is("\Q$a\E." , "\x{100}\x{101}Aa.", '\Q\E \x{100}\x{101}Aa');
76 is("\u$a" , "\x{100}\x{101}Aa", '\u');
77 is("\l$a" , "\x{101}\x{101}Aa", '\l');
78 is("\U$a" , "\x{100}\x{100}AA", '\U');
79 is("\L$a" , "\x{101}\x{101}aa", '\L');
80 is("\F$a" , "\x{101}\x{101}aa", '\F');
82 is(quotemeta($a) , "\x{100}\x{101}Aa", 'quotemeta');
83 is(ucfirst($a) , "\x{100}\x{101}Aa", 'ucfirst');
84 is(lcfirst($a) , "\x{101}\x{101}Aa", 'lcfirst');
85 is(uc($a) , "\x{100}\x{100}AA", 'uc');
86 is(lc($a) , "\x{101}\x{101}aa", 'lc');
87 is(fc($a) , "\x{101}\x{101}aa", 'fc');
89 is("\Q$b\E." , "\x{101}\x{100}aA.", '\Q\E \x{101}\x{100}aA');
90 is("\u$b" , "\x{100}\x{100}aA", '\u');
91 is("\l$b" , "\x{101}\x{100}aA", '\l');
92 is("\U$b" , "\x{100}\x{100}AA", '\U');
93 is("\L$b" , "\x{101}\x{101}aa", '\L');
94 is("\F$b" , "\x{101}\x{101}aa", '\F');
96 is(quotemeta($b) , "\x{101}\x{100}aA", 'quotemeta');
97 is(ucfirst($b) , "\x{100}\x{100}aA", 'ucfirst');
98 is(lcfirst($b) , "\x{101}\x{100}aA", 'lcfirst');
99 is(uc($b) , "\x{100}\x{100}AA", 'uc');
100 is(lc($b) , "\x{101}\x{101}aa", 'lc');
101 is(fc($b) , "\x{101}\x{101}aa", 'fc');
103 # \x{DF} is LATIN SMALL LETTER SHARP S, its uppercase is SS or \x{53}\x{53};
104 # \x{149} is LATIN SMALL LETTER N PRECEDED BY APOSTROPHE, its uppercase is
105 # \x{2BC}\x{E4} or MODIFIER LETTER APOSTROPHE and N.
107 is(latin1_to_native("\U\x{DF}aB\x{149}cD"), latin1_to_native("SSAB\x{2BC}NCD"),
108 "multicharacter uppercase");
110 # The \x{DF} is its own lowercase, ditto for \x{149}.
111 # There are no single character -> multiple characters lowercase mappings.
113 is(latin1_to_native("\L\x{DF}aB\x{149}cD"), latin1_to_native("\x{DF}ab\x{149}cd"),
114 "multicharacter lowercase");
116 # \x{DF} is LATIN SMALL LETTER SHARP S, its foldcase is ss or \x{73}\x{73};
117 # \x{149} is LATIN SMALL LETTER N PRECEDED BY APOSTROPHE, its foldcase is
118 # \x{2BC}\x{6E} or MODIFIER LETTER APOSTROPHE and n.
119 # Note that is this further tested in t/uni/fold.t
121 is(latin1_to_native("\F\x{DF}aB\x{149}cD"), latin1_to_native("ssab\x{2BC}ncd"),
122 "multicharacter foldcase");
125 # titlecase is used for \u / ucfirst.
127 # \x{587} is ARMENIAN SMALL LIGATURE ECH YIWN and its titlecase is
128 # \x{535}\x{582} ARMENIAN CAPITAL LETTER ECH + ARMENIAN SMALL LETTER YIWN
129 # while its lowercase is
131 # and its uppercase is
132 # \x{535}\x{552} ARMENIAN CAPITAL LETTER ECH + ARMENIAN CAPITAL LETTER YIWN
133 # The foldcase is \x{565}\x{582} ARMENIAN SMALL LETTER ECH + ARMENIAN SMALL LETTER YIWN
137 is("\L\x{587}" , "\x{587}", "ligature lowercase");
138 is("\u\x{587}" , "\x{535}\x{582}", "ligature titlecase");
139 is("\U\x{587}" , "\x{535}\x{552}", "ligature uppercase");
140 is("\F\x{587}" , "\x{565}\x{582}", "ligature foldcase");
142 # mktables had problems where many-to-one case mappings didn't work right.
143 # The lib/uni/fold.t should give the fourth folding, "casefolding", a good
145 # \x{01C4} is LATIN CAPITAL LETTER DZ WITH CARON
146 # \x{01C5} is LATIN CAPITAL LETTER D WITH SMALL LETTER Z WITH CARON
147 # \x{01C6} is LATIN SMALL LETTER DZ WITH CARON
148 # \x{03A3} is GREEK CAPITAL LETTER SIGMA
149 # \x{03C2} is GREEK SMALL LETTER FINAL SIGMA
150 # \x{03C3} is GREEK SMALL LETTER SIGMA
152 is(lc("\x{1C4}") , "\x{1C6}", "U+01C4 lc is U+01C6");
153 is(lc("\x{1C5}") , "\x{1C6}", "U+01C5 lc is U+01C6, too");
155 is(ucfirst("\x{3C2}") , "\x{3A3}", "U+03C2 ucfirst is U+03A3");
156 is(ucfirst("\x{3C3}") , "\x{3A3}", "U+03C3 ucfirst is U+03A3, too");
158 is(uc("\x{1C5}") , "\x{1C4}", "U+01C5 uc is U+01C4");
159 is(uc("\x{1C6}") , "\x{1C4}", "U+01C6 uc is U+01C4, too");
161 # #18107: A host of bugs involving [ul]c{,first}. AMS 20021106
162 $a = "\x{3c3}foo.bar"; # \x{3c3} == GREEK SMALL LETTER SIGMA.
163 $b = "\x{3a3}FOO.BAR"; # \x{3a3} == GREEK CAPITAL LETTER SIGMA.
165 ($c = $b) =~ s/(\w+)/lc($1)/ge;
166 is($c , $a, "Using s///e to change case.");
168 ($c = $a) =~ s/(\p{IsWord}+)/uc($1)/ge;
169 is($c , $b, "Using s///e to change case.");
171 ($c = $a) =~ s/(\p{IsWord}+)/fc($1)/ge;
172 is($c , $a, "Using s///e to foldcase.");
174 ($c = $b) =~ s/(\p{IsWord}+)/lcfirst($1)/ge;
175 is($c , "\x{3c3}FOO.bAR", "Using s///e to change case.");
177 ($c = $a) =~ s/(\p{IsWord}+)/ucfirst($1)/ge;
178 is($c , "\x{3a3}foo.Bar", "Using s///e to change case.");
180 # #18931: perl5.8.0 bug in \U..\E processing
181 # Test case from Nicholas Clark.
187 is(uc($1), "ABCDEFGH", "[perl #18931]");
194 $a =~ s/^(\s*)(\w*)/$1\u$2/;
195 is($a, v10, "[perl #18857]");
200 # [perl #38619] Bug in lc and uc (interaction between UTF-8, substr, and lc/uc)
202 for ("a\x{100}", "xyz\x{100}") {
203 is(substr(uc($_), 0), uc($_), "[perl #38619] uc");
205 for ("A\x{100}", "XYZ\x{100}") {
206 is(substr(lc($_), 0), lc($_), "[perl #38619] lc");
208 for ("a\x{100}", "ßyz\x{100}") { # ß to Ss (different length)
209 is(substr(ucfirst($_), 0), ucfirst($_), "[perl #38619] ucfirst");
212 #fc() didn't exist back then, but coverage is coverage.
213 for ("a\x{100}", "ßyz\x{100}", "xyz\x{100}", "XYZ\x{100}") { # ß to Ss (different length)
214 is(substr(fc($_), 0), fc($_), "[perl #38619] fc");
217 # Related to [perl #38619]
218 # the original report concerns PERL_MAGIC_utf8.
219 # these cases concern PERL_MAGIC_regex_global.
221 for (map { $_ } "a\x{100}", "abc\x{100}", "\x{100}") {
222 chop; # get ("a", "abc", "") in utf8
223 my $return = uc($_) =~ /\G(.?)/g;
224 my $result = $return ? $1 : "not";
225 my $expect = (uc($_) =~ /(.?)/g)[0];
226 is($return, 1, "[perl #38619]");
227 is($result, $expect, "[perl #38619]");
230 for (map { $_ } "A\x{100}", "ABC\x{100}", "\x{100}") {
231 chop; # get ("A", "ABC", "") in utf8
232 my $return = lc($_) =~ /\G(.?)/g;
233 my $result = $return ? $1 : "not";
234 my $expect = (lc($_) =~ /(.?)/g)[0];
235 is($return, 1, "[perl #38619]");
236 is($result, $expect, "[perl #38619]");
239 for (map { $_ } "A\x{100}", "ABC\x{100}", "\x{100}") {
240 chop; # get ("A", "ABC", "") in utf8
241 my $return = fc($_) =~ /\G(.?)/g;
242 my $result = $return ? $1 : "not";
243 my $expect = (fc($_) =~ /(.?)/g)[0];
244 is($return, 1, "[perl #38619]");
245 is($result, $expect, "[perl #38619]");
248 for (1, 4, 9, 16, 25) {
249 is(uc "\x{03B0}" x $_, "\x{3a5}\x{308}\x{301}" x $_,
250 'uc U+03B0 grows threefold');
252 is(lc "\x{0130}" x $_, "i\x{307}" x $_, 'lc U+0130 grows');
254 is(fc "\x{03B0}" x $_, "\x{3C5}\x{308}\x{301}" x $_,
255 'fc U+03B0 grows threefold');
272 # new in Unicode 5.1.0
273 is(lc("\x{1E9E}"), "\x{df}", "lc(LATIN CAPITAL LETTER SHARP S)");
276 use feature 'unicode_strings';
278 is(lc("\xc0"), "\xc0", "lc of above-ASCII Latin1 is itself under use bytes");
279 is(lcfirst("\xc0"), "\xc0", "lcfirst of above-ASCII Latin1 is itself under use bytes");
280 is(uc("\xe0"), "\xe0", "uc of above-ASCII Latin1 is itself under use bytes");
281 is(ucfirst("\xe0"), "\xe0", "ucfirst of above-ASCII Latin1 is itself under use bytes");
284 # Brought up in ticket #117855: Constant folding applied to uc() should use
285 # the right set of hints.
286 fresh_perl_like(<<'constantfolding', qr/^(\d+),\1\z/, {},
290 use feature 'unicode_strings';
291 print ord uc($char), ",",
292 ord eval "$function('$char')", "\n";
295 'folded uc() in string eval uses the right hints');