1#!./perl 2 3BEGIN { 4 chdir 't' if -d 't'; 5 require "./test.pl"; 6 set_up_inc( qw(../lib .) ); 7 require Config; Config->import; 8 require "./loc_tools.pl"; 9} 10 11plan tests => 60; 12 13if ($Config{ebcdic} eq 'define') { 14 $_ = join "", map chr($_), 129..233; 15 16 # 105 characters - 52 letters = 53 backslashes 17 # 105 characters + 53 backslashes = 158 characters 18 $_ = quotemeta $_; 19 is(length($_), 158, "quotemeta string"); 20 # 104 non-backslash characters 21 is(tr/\\//cd, 104, "tr count non-backslashed"); 22} else { # some ASCII descendant, then. 23 $_ = join "", map chr(utf8::unicode_to_native($_)), 32..127; 24 25 # 96 characters - 52 letters - 10 digits - 1 underscore = 33 backslashes 26 # 96 characters + 33 backslashes = 129 characters 27 $_ = quotemeta $_; 28 is(length($_), 129, "quotemeta string"); 29 # 95 non-backslash characters 30 is(tr/\\//cd, 95, "tr count non-backslashed"); 31} 32 33is(length(quotemeta ""), 0, "quotemeta empty string"); 34 35is("aA\UbB\LcC\EdD", "aABBccdD", 'aA\UbB\LcC\EdD'); 36is("aA\LbB\UcC\EdD", "aAbbCCdD", 'aA\LbB\UcC\EdD'); 37is("\L\upERL", "Perl", '\L\upERL'); 38is("\u\LpERL", "Perl", '\u\LpERL'); 39is("\U\lPerl", "pERL", '\U\lPerl'); 40is("\l\UPerl", "pERL", '\l\UPerl'); 41is("\u\LpE\Q#X#\ER\EL", "Pe\\#x\\#rL", '\u\LpE\Q#X#\ER\EL'); 42is("\l\UPe\Q!x!\Er\El", "pE\\!X\\!Rl", '\l\UPe\Q!x!\Er\El'); 43is("\Q\u\LpE.X.R\EL\E.", "Pe\\.x\\.rL.", '\Q\u\LpE.X.R\EL\E.'); 44is("\Q\l\UPe*x*r\El\E*", "pE\\*X\\*Rl*", '\Q\l\UPe*x*r\El\E*'); 45is("\U\lPerl\E\E\E\E", "pERL", '\U\lPerl\E\E\E\E'); 46is("\l\UPerl\E\E\E\E", "pERL", '\l\UPerl\E\E\E\E'); 47 48is(quotemeta("\x{263a}"), "\\\x{263a}", "quotemeta Unicode quoted"); 49is(length(quotemeta("\x{263a}")), 2, "quotemeta Unicode quoted length"); 50is(quotemeta("\x{100}"), "\x{100}", "quotemeta Unicode nonquoted"); 51is(length(quotemeta("\x{100}")), 1, "quotemeta Unicode nonquoted length"); 52 53my $char = ":"; 54utf8::upgrade($char); 55is(quotemeta($char), "\\$char", "quotemeta '$char' in UTF-8"); 56is(length(quotemeta($char)), 2, "quotemeta '$char' in UTF-8 length"); 57 58$char = "M"; 59utf8::upgrade($char); 60is(quotemeta($char), "$char", "quotemeta '$char' in UTF-8"); 61is(length(quotemeta($char)), 1, "quotemeta '$char' in UTF-8 length"); 62 63my $char = "\N{U+D7}"; 64utf8::upgrade($char); 65is(quotemeta($char), "\\$char", "quotemeta '\\N{U+D7}' in UTF-8"); 66is(length(quotemeta($char)), 2, "quotemeta '\\N{U+D7}' in UTF-8 length"); 67 68$char = "\N{U+DF}"; 69utf8::upgrade($char); 70is(quotemeta($char), "$char", "quotemeta '\\N{U+DF}' in UTF-8"); 71is(length(quotemeta($char)), 1, "quotemeta '\\N{U+DF}' in UTF-8 length"); 72 73{ 74 no feature 'unicode_strings'; 75 76 # BF is chosen because it is NOt alphanumeric in both Latin1 and EBCDIC 77 # DF is chosen because it IS alphanumeric in both Latin1 and EBCDIC 78 is(quotemeta("\x{bf}"), "\\\x{bf}", "quotemeta Latin1 no unicode_strings quoted"); 79 is(length(quotemeta("\x{bf}")), 2, "quotemeta Latin1 no unicode_strings quoted length"); 80 is(quotemeta("\x{df}"), "\\\x{df}", "quotemeta Latin1 no unicode_strings quoted"); 81 is(length(quotemeta("\x{df}")), 2, "quotemeta Latin1 no unicode_strings quoted length"); 82 83 SKIP: { 84 skip 'Locales not available', 8 unless locales_enabled('LC_CTYPE'); 85 use locale; 86 87 my $char = ":"; 88 is(quotemeta($char), "\\$char", "quotemeta '$char' locale"); 89 is(length(quotemeta($char)), 2, "quotemeta '$char' locale"); 90 91 $char = "M"; 92 utf8::upgrade($char); 93 is(quotemeta($char), "$char", "quotemeta '$char' locale"); 94 is(length(quotemeta($char)), 1, "quotemeta '$char' locale"); 95 96 my $char = "\x{BF}"; 97 is(quotemeta($char), "\\$char", "quotemeta '\\x{BF}' locale"); 98 is(length(quotemeta($char)), 2, "quotemeta '\\x{BF}' locale length"); 99 100 $char = "\x{DF}"; # Every non-ASCII Latin1 is quoted in locale. 101 is(quotemeta($char), "\\$char", "quotemeta '\\x{DF}' locale"); 102 is(length(quotemeta($char)), 2, "quotemeta '\\x{DF}' locale length"); 103 } 104} 105{ 106 use feature 'unicode_strings'; 107 is(quotemeta("\x{bf}"), "\\\x{bf}", "quotemeta Latin1 unicode_strings quoted"); 108 is(length(quotemeta("\x{bf}")), 2, "quotemeta Latin1 unicode_strings quoted length"); 109 is(quotemeta("\x{df}"), "\x{df}", "quotemeta Latin1 unicode_strings nonquoted"); 110 is(length(quotemeta("\x{df}")), 1, "quotemeta Latin1 unicode_strings nonquoted length"); 111 112 SKIP: { 113 skip 'Locales not available', 12 unless locales_enabled('LC_CTYPE'); 114 use locale; 115 116 my $char = ":"; 117 utf8::upgrade($char); 118 is(quotemeta($char), "\\$char", "quotemeta '$char' locale in UTF-8"); 119 is(length(quotemeta($char)), 2, "quotemeta '$char' locale in UTF-8 length"); 120 121 $char = "M"; 122 utf8::upgrade($char); 123 is(quotemeta($char), "$char", "quotemeta '$char' locale in UTF-8"); 124 is(length(quotemeta($char)), 1, "quotemeta '$char' locale in UTF-8 length"); 125 126 my $char = "\N{U+D7}"; 127 utf8::upgrade($char); 128 is(quotemeta($char), "\\$char", "quotemeta '\\N{U+D7}' locale in UTF-8"); 129 is(length(quotemeta($char)), 2, "quotemeta '\\N{U+D7}' locale in UTF-8 length"); 130 131 $char = "\N{U+DF}"; # Every non-ASCII Latin1 is quoted in locale. 132 utf8::upgrade($char); 133 is(quotemeta($char), "\\$char", "quotemeta '\\N{U+DF}' locale in UTF-8"); 134 is(length(quotemeta($char)), 2, "quotemeta '\\N{U+DF}' locale in UTF-8 length"); 135 136 is(quotemeta("\x{263a}"), "\\\x{263a}", "quotemeta locale Unicode quoted"); 137 is(length(quotemeta("\x{263a}")), 2, "quotemeta locale Unicode quoted length"); 138 is(quotemeta("\x{100}"), "\x{100}", "quotemeta locale Unicode nonquoted"); 139 is(length(quotemeta("\x{100}")), 1, "quotemeta locale Unicode nonquoted length"); 140 } 141} 142 143$a = "foo|bar"; 144is("a\Q\Ec$a", "acfoo|bar", '\Q\E'); 145is("a\L\Ec$a", "acfoo|bar", '\L\E'); 146is("a\l\Ec$a", "acfoo|bar", '\l\E'); 147is("a\U\Ec$a", "acfoo|bar", '\U\E'); 148is("a\u\Ec$a", "acfoo|bar", '\u\E'); 149