X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fop%2Flc.t;h=6b7625b54aa8b137b305b7fa296b68575e931f03;hb=6ec5370cb0aeb185d92b8fd2bad21bb10f75b30e;hp=243b0c714be329b214ae091e732a429223f52548;hpb=3a2263fe90d1c0e6c8f9368f10e6672379a975a2;p=p5sagit%2Fp5-mst-13.2.git diff --git a/t/op/lc.t b/t/op/lc.t index 243b0c7..6b7625b 100644 --- a/t/op/lc.t +++ b/t/op/lc.t @@ -6,7 +6,12 @@ BEGIN { require './test.pl'; } -plan tests => 59; +plan tests => 93; + +is(lc(undef), "", "lc(undef) is ''"); +is(lcfirst(undef), "", "lcfirst(undef) is ''"); +is(uc(undef), "", "uc(undef) is ''"); +is(ucfirst(undef), "", "ucfirst(undef) is ''"); $a = "HELLO.* world"; $b = "hello.* WORLD"; @@ -111,8 +116,14 @@ is("\u\x{587}" , "\x{535}\x{582}", "ligature titlecase"); is("\U\x{587}" , "\x{535}\x{552}", "ligature uppercase"); # mktables had problems where many-to-one case mappings didn't work right. -# The lib/unifold.t should give the fourth folding, "casefolding", a good -# workout. +# The lib/uni/fold.t should give the fourth folding, "casefolding", a good +# workout (one cannot directly get that from Perl). +# \x{01C4} is LATIN CAPITAL LETTER DZ WITH CARON +# \x{01C5} is LATIN CAPITAL LETTER D WITH SMALL LETTER Z WITH CARON +# \x{01C6} is LATIN SMALL LETTER DZ WITH CARON +# \x{03A3} is GREEK CAPITAL LETTER SIGMA +# \x{03C2} is GREEK SMALL LETTER FINAL SIGMA +# \x{03C3} is GREEK SMALL LETTER SIGMA is(lc("\x{1C4}") , "\x{1C6}", "U+01C4 lc is U+01C6"); is(lc("\x{1C5}") , "\x{1C6}", "U+01C5 lc is U+01C6, too"); @@ -130,17 +141,17 @@ $b = "\x{3a3}FOO.BAR"; # \x{3a3} == GREEK CAPITAL LETTER SIGMA. ($c = $b) =~ s/(\w+)/lc($1)/ge; is($c , $a, "Using s///e to change case."); -($c = $a) =~ s/(\w+)/uc($1)/ge; +($c = $a) =~ s/(\p{IsWord}+)/uc($1)/ge; is($c , $b, "Using s///e to change case."); -($c = $b) =~ s/(\w+)/lcfirst($1)/ge; +($c = $b) =~ s/(\p{IsWord}+)/lcfirst($1)/ge; is($c , "\x{3c3}FOO.bAR", "Using s///e to change case."); -($c = $a) =~ s/(\w+)/ucfirst($1)/ge; +($c = $a) =~ s/(\p{IsWord}+)/ucfirst($1)/ge; is($c , "\x{3a3}foo.Bar", "Using s///e to change case."); # #18931: perl5.8.0 bug in \U..\E processing -# Test case from Nick Clark. +# Test case from Nicholas Clark. for my $a (0,1) { $_ = 'abcdefgh'; $_ .= chr 256; @@ -155,6 +166,57 @@ for my $a (0,1) { chop $a; $a =~ s/^(\s*)(\w*)/$1\u$2/; is($a, v10, "[perl #18857]"); - $test++; } } + + +# [perl #38619] Bug in lc and uc (interaction between UTF-8, substr, and lc/uc) + +for ("a\x{100}", "xyz\x{100}") { + is(substr(uc($_), 0), uc($_), "[perl #38619] uc"); +} +for ("A\x{100}", "XYZ\x{100}") { + is(substr(lc($_), 0), lc($_), "[perl #38619] lc"); +} +for ("a\x{100}", "ßyz\x{100}") { # ß to Ss (different length) + is(substr(ucfirst($_), 0), ucfirst($_), "[perl #38619] ucfirst"); +} + +# Related to [perl #38619] +# the original report concerns PERL_MAGIC_utf8. +# these cases concern PERL_MAGIC_regex_global. + +for (map { $_ } "a\x{100}", "abc\x{100}", "\x{100}") { + chop; # get ("a", "abc", "") in utf8 + my $return = uc($_) =~ /\G(.?)/g; + my $result = $return ? $1 : "not"; + my $expect = (uc($_) =~ /(.?)/g)[0]; + is($return, 1, "[perl #38619]"); + is($result, $expect, "[perl #38619]"); +} + +for (map { $_ } "A\x{100}", "ABC\x{100}", "\x{100}") { + chop; # get ("A", "ABC", "") in utf8 + my $return = lc($_) =~ /\G(.?)/g; + my $result = $return ? $1 : "not"; + my $expect = (lc($_) =~ /(.?)/g)[0]; + is($return, 1, "[perl #38619]"); + is($result, $expect, "[perl #38619]"); +} + +for (1, 4, 9, 16, 25) { + is(uc "\x{03B0}" x $_, "\x{3a5}\x{308}\x{301}" x $_, + 'uc U+03B0 grows threefold'); + + is(lc "\x{0130}" x $_, "i\x{307}" x $_, 'lc U+0130 grows'); +} + +# bug #43207 +my $temp = "Hello"; +for ("$temp") { + lc $_; + is($_, "Hello"); +} + +# new in Unicode 5.1.0 +is(lc("\x{1E9E}"), "\x{df}", "lc(LATIN CAPITAL LETTER SHARP S)");