Commit | Line | Data |
---|---|---|
a0d0e21e | 1 | #!./perl |
9d116dd7 | 2 | |
a1a0e61e TD |
3 | BEGIN { |
4 | chdir 't' if -d 't'; | |
6e909404 | 5 | @INC = qw(../lib .); |
a1a0e61e | 6 | require Config; import Config; |
1ae3d757 | 7 | require "./test.pl"; |
ef9d5242 | 8 | require "./loc_tools.pl"; |
a1a0e61e TD |
9 | } |
10 | ||
20adcf7c | 11 | plan tests => 60; |
a0d0e21e | 12 | |
a1a0e61e | 13 | if ($Config{ebcdic} eq 'define') { |
6e909404 | 14 | $_ = join "", map chr($_), 129..233; |
9d116dd7 JH |
15 | |
16 | # 105 characters - 52 letters = 53 backslashes | |
17 | # 105 characters + 53 backslashes = 158 characters | |
6e909404 JH |
18 | $_ = quotemeta $_; |
19 | is(length($_), 158, "quotemeta string"); | |
9d116dd7 | 20 | # 104 non-backslash characters |
6e909404 | 21 | is(tr/\\//cd, 104, "tr count non-backslashed"); |
9d116dd7 | 22 | } else { # some ASCII descendant, then. |
e2ebe053 | 23 | $_ = join "", map chr(utf8::unicode_to_native($_)), 32..127; |
a0d0e21e | 24 | |
9d116dd7 JH |
25 | # 96 characters - 52 letters - 10 digits - 1 underscore = 33 backslashes |
26 | # 96 characters + 33 backslashes = 129 characters | |
6e909404 JH |
27 | $_ = quotemeta $_; |
28 | is(length($_), 129, "quotemeta string"); | |
9d116dd7 | 29 | # 95 non-backslash characters |
6e909404 | 30 | is(tr/\\//cd, 95, "tr count non-backslashed"); |
9d116dd7 | 31 | } |
a0d0e21e | 32 | |
6e909404 JH |
33 | is(length(quotemeta ""), 0, "quotemeta empty string"); |
34 | ||
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'); | |
47 | ||
2e2b2571 KW |
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"); | |
52 | ||
53 | my $char = ":"; | |
54 | utf8::upgrade($char); | |
55 | is(quotemeta($char), "\\$char", "quotemeta '$char' in UTF-8"); | |
56 | is(length(quotemeta($char)), 2, "quotemeta '$char' in UTF-8 length"); | |
57 | ||
58 | $char = "M"; | |
59 | utf8::upgrade($char); | |
60 | is(quotemeta($char), "$char", "quotemeta '$char' in UTF-8"); | |
61 | is(length(quotemeta($char)), 1, "quotemeta '$char' in UTF-8 length"); | |
62 | ||
63 | my $char = "\N{U+D7}"; | |
64 | utf8::upgrade($char); | |
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"); | |
67 | ||
e2ebe053 | 68 | $char = "\N{U+DF}"; |
2e2b2571 | 69 | utf8::upgrade($char); |
e2ebe053 KW |
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"); | |
2e2b2571 KW |
72 | |
73 | { | |
74 | no feature 'unicode_strings'; | |
e2ebe053 KW |
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"); | |
20adcf7c | 82 | |
569f7fc5 | 83 | SKIP: { |
ef9d5242 | 84 | skip 'Locales not available', 8 unless locales_enabled('LC_CTYPE'); |
5f1269ab | 85 | use locale; |
20adcf7c KW |
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 | ||
e2ebe053 KW |
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"); | |
20adcf7c | 99 | |
e2ebe053 KW |
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"); | |
569f7fc5 | 103 | } |
2e2b2571 KW |
104 | } |
105 | { | |
106 | use feature 'unicode_strings'; | |
e2ebe053 KW |
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"); | |
20adcf7c | 111 | |
569f7fc5 | 112 | SKIP: { |
ef9d5242 | 113 | skip 'Locales not available', 12 unless locales_enabled('LC_CTYPE'); |
5f1269ab | 114 | use locale; |
20adcf7c KW |
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 | ||
e2ebe053 | 131 | $char = "\N{U+DF}"; # Every non-ASCII Latin1 is quoted in locale. |
20adcf7c | 132 | utf8::upgrade($char); |
e2ebe053 KW |
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"); | |
20adcf7c KW |
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"); | |
569f7fc5 | 140 | } |
2e2b2571 | 141 | } |
6e909404 JH |
142 | |
143 | $a = "foo|bar"; | |
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'); |