6 set_up_inc( qw(../lib .) );
7 require Config; import Config;
8 require "./loc_tools.pl";
13 if ($Config{ebcdic} eq 'define') {
14 $_ = join "", map chr($_), 129..233;
16 # 105 characters - 52 letters = 53 backslashes
17 # 105 characters + 53 backslashes = 158 characters
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;
25 # 96 characters - 52 letters - 10 digits - 1 underscore = 33 backslashes
26 # 96 characters + 33 backslashes = 129 characters
28 is(length($_), 129, "quotemeta string");
29 # 95 non-backslash characters
30 is(tr/\\//cd, 95, "tr count non-backslashed");
33 is(length(quotemeta ""), 0, "quotemeta empty string");
35 is("aA\UbB\LcC\EdD", "aABBccdD", 'aA\UbB\LcC\EdD');
36 is("aA\LbB\UcC\EdD", "aAbbCCdD", 'aA\LbB\UcC\EdD');
37 is("\L\upERL", "Perl", '\L\upERL');
38 is("\u\LpERL", "Perl", '\u\LpERL');
39 is("\U\lPerl", "pERL", '\U\lPerl');
40 is("\l\UPerl", "pERL", '\l\UPerl');
41 is("\u\LpE\Q#X#\ER\EL", "Pe\\#x\\#rL", '\u\LpE\Q#X#\ER\EL');
42 is("\l\UPe\Q!x!\Er\El", "pE\\!X\\!Rl", '\l\UPe\Q!x!\Er\El');
43 is("\Q\u\LpE.X.R\EL\E.", "Pe\\.x\\.rL.", '\Q\u\LpE.X.R\EL\E.');
44 is("\Q\l\UPe*x*r\El\E*", "pE\\*X\\*Rl*", '\Q\l\UPe*x*r\El\E*');
45 is("\U\lPerl\E\E\E\E", "pERL", '\U\lPerl\E\E\E\E');
46 is("\l\UPerl\E\E\E\E", "pERL", '\l\UPerl\E\E\E\E');
48 is(quotemeta("\x{263a}"), "\\\x{263a}", "quotemeta Unicode quoted");
49 is(length(quotemeta("\x{263a}")), 2, "quotemeta Unicode quoted length");
50 is(quotemeta("\x{100}"), "\x{100}", "quotemeta Unicode nonquoted");
51 is(length(quotemeta("\x{100}")), 1, "quotemeta Unicode nonquoted length");
55 is(quotemeta($char), "\\$char", "quotemeta '$char' in UTF-8");
56 is(length(quotemeta($char)), 2, "quotemeta '$char' in UTF-8 length");
60 is(quotemeta($char), "$char", "quotemeta '$char' in UTF-8");
61 is(length(quotemeta($char)), 1, "quotemeta '$char' in UTF-8 length");
63 my $char = "\N{U+D7}";
65 is(quotemeta($char), "\\$char", "quotemeta '\\N{U+D7}' in UTF-8");
66 is(length(quotemeta($char)), 2, "quotemeta '\\N{U+D7}' in UTF-8 length");
70 is(quotemeta($char), "$char", "quotemeta '\\N{U+DF}' in UTF-8");
71 is(length(quotemeta($char)), 1, "quotemeta '\\N{U+DF}' in UTF-8 length");
74 no feature 'unicode_strings';
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");
84 skip 'Locales not available', 8 unless locales_enabled('LC_CTYPE');
88 is(quotemeta($char), "\\$char", "quotemeta '$char' locale");
89 is(length(quotemeta($char)), 2, "quotemeta '$char' locale");
93 is(quotemeta($char), "$char", "quotemeta '$char' locale");
94 is(length(quotemeta($char)), 1, "quotemeta '$char' locale");
97 is(quotemeta($char), "\\$char", "quotemeta '\\x{BF}' locale");
98 is(length(quotemeta($char)), 2, "quotemeta '\\x{BF}' locale length");
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");
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");
113 skip 'Locales not available', 12 unless locales_enabled('LC_CTYPE');
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");
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");
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");
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");
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");
144 is("a\Q\Ec$a", "acfoo|bar", '\Q\E');
145 is("a\L\Ec$a", "acfoo|bar", '\L\E');
146 is("a\l\Ec$a", "acfoo|bar", '\l\E');
147 is("a\U\Ec$a", "acfoo|bar", '\U\E');
148 is("a\u\Ec$a", "acfoo|bar", '\u\E');