6 require Config; import Config;
12 if ($Config{ebcdic} eq 'define') {
13 $_ = join "", map chr($_), 129..233;
15 # 105 characters - 52 letters = 53 backslashes
16 # 105 characters + 53 backslashes = 158 characters
18 is(length($_), 158, "quotemeta string");
19 # 104 non-backslash characters
20 is(tr/\\//cd, 104, "tr count non-backslashed");
21 } else { # some ASCII descendant, then.
22 $_ = join "", map chr($_), 32..127;
24 # 96 characters - 52 letters - 10 digits - 1 underscore = 33 backslashes
25 # 96 characters + 33 backslashes = 129 characters
27 is(length($_), 129, "quotemeta string");
28 # 95 non-backslash characters
29 is(tr/\\//cd, 95, "tr count non-backslashed");
32 is(length(quotemeta ""), 0, "quotemeta empty string");
34 is("aA\UbB\LcC\EdD", "aABBccdD", 'aA\UbB\LcC\EdD');
35 is("aA\LbB\UcC\EdD", "aAbbCCdD", 'aA\LbB\UcC\EdD');
36 is("\L\upERL", "Perl", '\L\upERL');
37 is("\u\LpERL", "Perl", '\u\LpERL');
38 is("\U\lPerl", "pERL", '\U\lPerl');
39 is("\l\UPerl", "pERL", '\l\UPerl');
40 is("\u\LpE\Q#X#\ER\EL", "Pe\\#x\\#rL", '\u\LpE\Q#X#\ER\EL');
41 is("\l\UPe\Q!x!\Er\El", "pE\\!X\\!Rl", '\l\UPe\Q!x!\Er\El');
42 is("\Q\u\LpE.X.R\EL\E.", "Pe\\.x\\.rL.", '\Q\u\LpE.X.R\EL\E.');
43 is("\Q\l\UPe*x*r\El\E*", "pE\\*X\\*Rl*", '\Q\l\UPe*x*r\El\E*');
44 is("\U\lPerl\E\E\E\E", "pERL", '\U\lPerl\E\E\E\E');
45 is("\l\UPerl\E\E\E\E", "pERL", '\l\UPerl\E\E\E\E');
47 is(quotemeta("\x{263a}"), "\\\x{263a}", "quotemeta Unicode quoted");
48 is(length(quotemeta("\x{263a}")), 2, "quotemeta Unicode quoted length");
49 is(quotemeta("\x{100}"), "\x{100}", "quotemeta Unicode nonquoted");
50 is(length(quotemeta("\x{100}")), 1, "quotemeta Unicode nonquoted length");
54 is(quotemeta($char), "\\$char", "quotemeta '$char' in UTF-8");
55 is(length(quotemeta($char)), 2, "quotemeta '$char' in UTF-8 length");
59 is(quotemeta($char), "$char", "quotemeta '$char' in UTF-8");
60 is(length(quotemeta($char)), 1, "quotemeta '$char' in UTF-8 length");
62 my $char = "\N{U+D7}";
64 is(quotemeta($char), "\\$char", "quotemeta '\\N{U+D7}' in UTF-8");
65 is(length(quotemeta($char)), 2, "quotemeta '\\N{U+D7}' in UTF-8 length");
69 is(quotemeta($char), "$char", "quotemeta '\\N{U+D8}' in UTF-8");
70 is(length(quotemeta($char)), 1, "quotemeta '\\N{U+D8}' in UTF-8 length");
73 no feature 'unicode_strings';
74 is(quotemeta("\x{d7}"), "\\\x{d7}", "quotemeta Latin1 no unicode_strings quoted");
75 is(length(quotemeta("\x{d7}")), 2, "quotemeta Latin1 no unicode_strings quoted length");
76 is(quotemeta("\x{d8}"), "\\\x{d8}", "quotemeta Latin1 no unicode_strings quoted");
77 is(length(quotemeta("\x{d8}")), 2, "quotemeta Latin1 no unicode_strings quoted length");
80 skip 'No locale testing without d_setlocale', 8 if(!$Config{d_setlocale});
84 is(quotemeta($char), "\\$char", "quotemeta '$char' locale");
85 is(length(quotemeta($char)), 2, "quotemeta '$char' locale");
89 is(quotemeta($char), "$char", "quotemeta '$char' locale");
90 is(length(quotemeta($char)), 1, "quotemeta '$char' locale");
93 is(quotemeta($char), "\\$char", "quotemeta '\\x{D7}' locale");
94 is(length(quotemeta($char)), 2, "quotemeta '\\x{D7}' locale length");
96 $char = "\x{D8}"; # Every non-ASCII Latin1 is quoted in locale.
97 is(quotemeta($char), "\\$char", "quotemeta '\\x{D8}' locale");
98 is(length(quotemeta($char)), 2, "quotemeta '\\x{D8}' locale length");
102 use feature 'unicode_strings';
103 is(quotemeta("\x{d7}"), "\\\x{d7}", "quotemeta Latin1 unicode_strings quoted");
104 is(length(quotemeta("\x{d7}")), 2, "quotemeta Latin1 unicode_strings quoted length");
105 is(quotemeta("\x{d8}"), "\x{d8}", "quotemeta Latin1 unicode_strings nonquoted");
106 is(length(quotemeta("\x{d8}")), 1, "quotemeta Latin1 unicode_strings nonquoted length");
109 skip 'No locale testing without d_setlocale', 12 if(!$Config{d_setlocale});
113 utf8::upgrade($char);
114 is(quotemeta($char), "\\$char", "quotemeta '$char' locale in UTF-8");
115 is(length(quotemeta($char)), 2, "quotemeta '$char' locale in UTF-8 length");
118 utf8::upgrade($char);
119 is(quotemeta($char), "$char", "quotemeta '$char' locale in UTF-8");
120 is(length(quotemeta($char)), 1, "quotemeta '$char' locale in UTF-8 length");
122 my $char = "\N{U+D7}";
123 utf8::upgrade($char);
124 is(quotemeta($char), "\\$char", "quotemeta '\\N{U+D7}' locale in UTF-8");
125 is(length(quotemeta($char)), 2, "quotemeta '\\N{U+D7}' locale in UTF-8 length");
127 $char = "\N{U+D8}"; # Every non-ASCII Latin1 is quoted in locale.
128 utf8::upgrade($char);
129 is(quotemeta($char), "\\$char", "quotemeta '\\N{U+D8}' locale in UTF-8");
130 is(length(quotemeta($char)), 2, "quotemeta '\\N{U+D8}' locale in UTF-8 length");
132 is(quotemeta("\x{263a}"), "\\\x{263a}", "quotemeta locale Unicode quoted");
133 is(length(quotemeta("\x{263a}")), 2, "quotemeta locale Unicode quoted length");
134 is(quotemeta("\x{100}"), "\x{100}", "quotemeta locale Unicode nonquoted");
135 is(length(quotemeta("\x{100}")), 1, "quotemeta locale Unicode nonquoted length");
140 is("a\Q\Ec$a", "acfoo|bar", '\Q\E');
141 is("a\L\Ec$a", "acfoo|bar", '\L\E');
142 is("a\l\Ec$a", "acfoo|bar", '\l\E');
143 is("a\U\Ec$a", "acfoo|bar", '\U\E');
144 is("a\u\Ec$a", "acfoo|bar", '\u\E');