xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/t/op/lc.t (revision 0:68f95e015346)
1*0Sstevel@tonic-gate#!./perl
2*0Sstevel@tonic-gate
3*0Sstevel@tonic-gateBEGIN {
4*0Sstevel@tonic-gate    chdir 't';
5*0Sstevel@tonic-gate    @INC = '../lib';
6*0Sstevel@tonic-gate    require './test.pl';
7*0Sstevel@tonic-gate}
8*0Sstevel@tonic-gate
9*0Sstevel@tonic-gateplan tests => 59;
10*0Sstevel@tonic-gate
11*0Sstevel@tonic-gate$a = "HELLO.* world";
12*0Sstevel@tonic-gate$b = "hello.* WORLD";
13*0Sstevel@tonic-gate
14*0Sstevel@tonic-gateis("\Q$a\E."      , "HELLO\\.\\*\\ world.", '\Q\E HELLO.* world');
15*0Sstevel@tonic-gateis("\u$a"         , "HELLO\.\* world",      '\u');
16*0Sstevel@tonic-gateis("\l$a"         , "hELLO\.\* world",      '\l');
17*0Sstevel@tonic-gateis("\U$a"         , "HELLO\.\* WORLD",      '\U');
18*0Sstevel@tonic-gateis("\L$a"         , "hello\.\* world",      '\L');
19*0Sstevel@tonic-gate
20*0Sstevel@tonic-gateis(quotemeta($a)  , "HELLO\\.\\*\\ world",  'quotemeta');
21*0Sstevel@tonic-gateis(ucfirst($a)    , "HELLO\.\* world",      'ucfirst');
22*0Sstevel@tonic-gateis(lcfirst($a)    , "hELLO\.\* world",      'lcfirst');
23*0Sstevel@tonic-gateis(uc($a)         , "HELLO\.\* WORLD",      'uc');
24*0Sstevel@tonic-gateis(lc($a)         , "hello\.\* world",      'lc');
25*0Sstevel@tonic-gate
26*0Sstevel@tonic-gateis("\Q$b\E."      , "hello\\.\\*\\ WORLD.", '\Q\E hello.* WORLD');
27*0Sstevel@tonic-gateis("\u$b"         , "Hello\.\* WORLD",      '\u');
28*0Sstevel@tonic-gateis("\l$b"         , "hello\.\* WORLD",      '\l');
29*0Sstevel@tonic-gateis("\U$b"         , "HELLO\.\* WORLD",      '\U');
30*0Sstevel@tonic-gateis("\L$b"         , "hello\.\* world",      '\L');
31*0Sstevel@tonic-gate
32*0Sstevel@tonic-gateis(quotemeta($b)  , "hello\\.\\*\\ WORLD",  'quotemeta');
33*0Sstevel@tonic-gateis(ucfirst($b)    , "Hello\.\* WORLD",      'ucfirst');
34*0Sstevel@tonic-gateis(lcfirst($b)    , "hello\.\* WORLD",      'lcfirst');
35*0Sstevel@tonic-gateis(uc($b)         , "HELLO\.\* WORLD",      'uc');
36*0Sstevel@tonic-gateis(lc($b)         , "hello\.\* world",      'lc');
37*0Sstevel@tonic-gate
38*0Sstevel@tonic-gate# \x{100} is LATIN CAPITAL LETTER A WITH MACRON; its bijective lowercase is
39*0Sstevel@tonic-gate# \x{101}, LATIN SMALL LETTER A WITH MACRON.
40*0Sstevel@tonic-gate
41*0Sstevel@tonic-gate$a = "\x{100}\x{101}Aa";
42*0Sstevel@tonic-gate$b = "\x{101}\x{100}aA";
43*0Sstevel@tonic-gate
44*0Sstevel@tonic-gateis("\Q$a\E."      , "\x{100}\x{101}Aa.", '\Q\E \x{100}\x{101}Aa');
45*0Sstevel@tonic-gateis("\u$a"         , "\x{100}\x{101}Aa",  '\u');
46*0Sstevel@tonic-gateis("\l$a"         , "\x{101}\x{101}Aa",  '\l');
47*0Sstevel@tonic-gateis("\U$a"         , "\x{100}\x{100}AA",  '\U');
48*0Sstevel@tonic-gateis("\L$a"         , "\x{101}\x{101}aa",  '\L');
49*0Sstevel@tonic-gate
50*0Sstevel@tonic-gateis(quotemeta($a)  , "\x{100}\x{101}Aa",  'quotemeta');
51*0Sstevel@tonic-gateis(ucfirst($a)    , "\x{100}\x{101}Aa",  'ucfirst');
52*0Sstevel@tonic-gateis(lcfirst($a)    , "\x{101}\x{101}Aa",  'lcfirst');
53*0Sstevel@tonic-gateis(uc($a)         , "\x{100}\x{100}AA",  'uc');
54*0Sstevel@tonic-gateis(lc($a)         , "\x{101}\x{101}aa",  'lc');
55*0Sstevel@tonic-gate
56*0Sstevel@tonic-gateis("\Q$b\E."      , "\x{101}\x{100}aA.", '\Q\E \x{101}\x{100}aA');
57*0Sstevel@tonic-gateis("\u$b"         , "\x{100}\x{100}aA",  '\u');
58*0Sstevel@tonic-gateis("\l$b"         , "\x{101}\x{100}aA",  '\l');
59*0Sstevel@tonic-gateis("\U$b"         , "\x{100}\x{100}AA",  '\U');
60*0Sstevel@tonic-gateis("\L$b"         , "\x{101}\x{101}aa",  '\L');
61*0Sstevel@tonic-gate
62*0Sstevel@tonic-gateis(quotemeta($b)  , "\x{101}\x{100}aA",  'quotemeta');
63*0Sstevel@tonic-gateis(ucfirst($b)    , "\x{100}\x{100}aA",  'ucfirst');
64*0Sstevel@tonic-gateis(lcfirst($b)    , "\x{101}\x{100}aA",  'lcfirst');
65*0Sstevel@tonic-gateis(uc($b)         , "\x{100}\x{100}AA",  'uc');
66*0Sstevel@tonic-gateis(lc($b)         , "\x{101}\x{101}aa",  'lc');
67*0Sstevel@tonic-gate
68*0Sstevel@tonic-gate# \x{DF} is LATIN SMALL LETTER SHARP S, its uppercase is SS or \x{53}\x{53};
69*0Sstevel@tonic-gate# \x{149} is LATIN SMALL LETTER N PRECEDED BY APOSTROPHE, its uppercase is
70*0Sstevel@tonic-gate# \x{2BC}\x{E4} or MODIFIER LETTER APOSTROPHE and N.
71*0Sstevel@tonic-gate
72*0Sstevel@tonic-gate# In EBCDIC \x{DF} is LATIN SMALL LETTER Y WITH DIAERESIS,
73*0Sstevel@tonic-gate# and it's uppercase is \x{178}, LATIN CAPITAL LETTER Y WITH DIAERESIS.
74*0Sstevel@tonic-gate
75*0Sstevel@tonic-gateif (ord("A") == 193) { # EBCDIC
76*0Sstevel@tonic-gate    is("\U\x{DF}aB\x{149}cD" , "\x{178}AB\x{2BC}NCD",
77*0Sstevel@tonic-gate       "multicharacter uppercase");
78*0Sstevel@tonic-gate} elsif (ord("A") == 65) {
79*0Sstevel@tonic-gate    is("\U\x{DF}aB\x{149}cD" , "SSAB\x{2BC}NCD",
80*0Sstevel@tonic-gate       "multicharacter uppercase");
81*0Sstevel@tonic-gate} else {
82*0Sstevel@tonic-gate    fail("what is your encoding?");
83*0Sstevel@tonic-gate}
84*0Sstevel@tonic-gate
85*0Sstevel@tonic-gate# The \x{DF} is its own lowercase, ditto for \x{149}.
86*0Sstevel@tonic-gate# There are no single character -> multiple characters lowercase mappings.
87*0Sstevel@tonic-gate
88*0Sstevel@tonic-gateif (ord("A") == 193) { # EBCDIC
89*0Sstevel@tonic-gate    is("\LaB\x{149}cD" , "ab\x{149}cd",
90*0Sstevel@tonic-gate       "multicharacter lowercase");
91*0Sstevel@tonic-gate} elsif (ord("A") == 65) {
92*0Sstevel@tonic-gate    is("\L\x{DF}aB\x{149}cD" , "\x{DF}ab\x{149}cd",
93*0Sstevel@tonic-gate       "multicharacter lowercase");
94*0Sstevel@tonic-gate} else {
95*0Sstevel@tonic-gate    fail("what is your encoding?");
96*0Sstevel@tonic-gate}
97*0Sstevel@tonic-gate
98*0Sstevel@tonic-gate# titlecase is used for \u / ucfirst.
99*0Sstevel@tonic-gate
100*0Sstevel@tonic-gate# \x{587} is ARMENIAN SMALL LIGATURE ECH YIWN and its titlecase is
101*0Sstevel@tonic-gate# \x{535}\x{582} ARMENIAN CAPITAL LETTER ECH + ARMENIAN SMALL LETTER YIWN
102*0Sstevel@tonic-gate# while its lowercase is
103*0Sstevel@tonic-gate# \x{587} itself
104*0Sstevel@tonic-gate# and its uppercase is
105*0Sstevel@tonic-gate# \x{535}\x{552} ARMENIAN CAPITAL LETTER ECH + ARMENIAN CAPITAL LETTER YIWN
106*0Sstevel@tonic-gate
107*0Sstevel@tonic-gate$a = "\x{587}";
108*0Sstevel@tonic-gate
109*0Sstevel@tonic-gateis("\L\x{587}" , "\x{587}",        "ligature lowercase");
110*0Sstevel@tonic-gateis("\u\x{587}" , "\x{535}\x{582}", "ligature titlecase");
111*0Sstevel@tonic-gateis("\U\x{587}" , "\x{535}\x{552}", "ligature uppercase");
112*0Sstevel@tonic-gate
113*0Sstevel@tonic-gate# mktables had problems where many-to-one case mappings didn't work right.
114*0Sstevel@tonic-gate# The lib/unifold.t should give the fourth folding, "casefolding", a good
115*0Sstevel@tonic-gate# workout.
116*0Sstevel@tonic-gate# \x{01C4} is LATIN CAPITAL LETTER DZ WITH CARON
117*0Sstevel@tonic-gate# \x{01C5} is LATIN CAPITAL LETTER D WITH SMALL LETTER Z WITH CARON
118*0Sstevel@tonic-gate# \x{01C6} is LATIN SMALL LETTER DZ WITH CARON
119*0Sstevel@tonic-gate# \x{03A3} is GREEK CAPITAL LETTER SIGMA
120*0Sstevel@tonic-gate# \x{03C2} is GREEK SMALL LETTER FINAL SIGMA
121*0Sstevel@tonic-gate# \x{03C3} is GREEK SMALL LETTER SIGMA
122*0Sstevel@tonic-gate
123*0Sstevel@tonic-gateis(lc("\x{1C4}") , "\x{1C6}",      "U+01C4 lc is U+01C6");
124*0Sstevel@tonic-gateis(lc("\x{1C5}") , "\x{1C6}",      "U+01C5 lc is U+01C6, too");
125*0Sstevel@tonic-gate
126*0Sstevel@tonic-gateis(ucfirst("\x{3C2}") , "\x{3A3}", "U+03C2 ucfirst is U+03A3");
127*0Sstevel@tonic-gateis(ucfirst("\x{3C3}") , "\x{3A3}", "U+03C3 ucfirst is U+03A3, too");
128*0Sstevel@tonic-gate
129*0Sstevel@tonic-gateis(uc("\x{1C5}") , "\x{1C4}",      "U+01C5 uc is U+01C4");
130*0Sstevel@tonic-gateis(uc("\x{1C6}") , "\x{1C4}",      "U+01C6 uc is U+01C4, too");
131*0Sstevel@tonic-gate
132*0Sstevel@tonic-gate# #18107: A host of bugs involving [ul]c{,first}. AMS 20021106
133*0Sstevel@tonic-gate$a = "\x{3c3}foo.bar"; # \x{3c3} == GREEK SMALL LETTER SIGMA.
134*0Sstevel@tonic-gate$b = "\x{3a3}FOO.BAR"; # \x{3a3} == GREEK CAPITAL LETTER SIGMA.
135*0Sstevel@tonic-gate
136*0Sstevel@tonic-gate($c = $b) =~ s/(\w+)/lc($1)/ge;
137*0Sstevel@tonic-gateis($c , $a, "Using s///e to change case.");
138*0Sstevel@tonic-gate
139*0Sstevel@tonic-gate($c = $a) =~ s/(\w+)/uc($1)/ge;
140*0Sstevel@tonic-gateis($c , $b, "Using s///e to change case.");
141*0Sstevel@tonic-gate
142*0Sstevel@tonic-gate($c = $b) =~ s/(\w+)/lcfirst($1)/ge;
143*0Sstevel@tonic-gateis($c , "\x{3c3}FOO.bAR", "Using s///e to change case.");
144*0Sstevel@tonic-gate
145*0Sstevel@tonic-gate($c = $a) =~ s/(\w+)/ucfirst($1)/ge;
146*0Sstevel@tonic-gateis($c , "\x{3a3}foo.Bar", "Using s///e to change case.");
147*0Sstevel@tonic-gate
148*0Sstevel@tonic-gate# #18931: perl5.8.0 bug in \U..\E processing
149*0Sstevel@tonic-gate# Test case from Nick Clark.
150*0Sstevel@tonic-gatefor my $a (0,1) {
151*0Sstevel@tonic-gate    $_ = 'abcdefgh';
152*0Sstevel@tonic-gate    $_ .= chr 256;
153*0Sstevel@tonic-gate    chop;
154*0Sstevel@tonic-gate    /(.*)/;
155*0Sstevel@tonic-gate    is(uc($1), "ABCDEFGH", "[perl #18931]");
156*0Sstevel@tonic-gate}
157*0Sstevel@tonic-gate
158*0Sstevel@tonic-gate{
159*0Sstevel@tonic-gate    foreach (0, 1) {
160*0Sstevel@tonic-gate	$a = v10.v257;
161*0Sstevel@tonic-gate	chop $a;
162*0Sstevel@tonic-gate	$a =~ s/^(\s*)(\w*)/$1\u$2/;
163*0Sstevel@tonic-gate	is($a, v10, "[perl #18857]");
164*0Sstevel@tonic-gate	$test++;
165*0Sstevel@tonic-gate    }
166*0Sstevel@tonic-gate}
167