This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
RT #75468: readline ignores <> overloading when arg is tied
[perl5.git] / t / op / quotemeta.t
CommitLineData
a0d0e21e 1#!./perl
9d116dd7 2
a1a0e61e
TD
3BEGIN {
4 chdir 't' if -d 't';
6e909404 5 @INC = qw(../lib .);
a1a0e61e 6 require Config; import Config;
6e909404 7 require "test.pl";
a1a0e61e
TD
8}
9
6e909404 10plan tests => 22;
a0d0e21e 11
a1a0e61e 12if ($Config{ebcdic} eq 'define') {
6e909404 13 $_ = join "", map chr($_), 129..233;
9d116dd7
JH
14
15 # 105 characters - 52 letters = 53 backslashes
16 # 105 characters + 53 backslashes = 158 characters
6e909404
JH
17 $_ = quotemeta $_;
18 is(length($_), 158, "quotemeta string");
9d116dd7 19 # 104 non-backslash characters
6e909404 20 is(tr/\\//cd, 104, "tr count non-backslashed");
9d116dd7 21} else { # some ASCII descendant, then.
6e909404 22 $_ = join "", map chr($_), 32..127;
a0d0e21e 23
9d116dd7
JH
24 # 96 characters - 52 letters - 10 digits - 1 underscore = 33 backslashes
25 # 96 characters + 33 backslashes = 129 characters
6e909404
JH
26 $_ = quotemeta $_;
27 is(length($_), 129, "quotemeta string");
9d116dd7 28 # 95 non-backslash characters
6e909404 29 is(tr/\\//cd, 95, "tr count non-backslashed");
9d116dd7 30}
a0d0e21e 31
6e909404
JH
32is(length(quotemeta ""), 0, "quotemeta empty string");
33
34is("aA\UbB\LcC\EdD", "aABBccdD", 'aA\UbB\LcC\EdD');
35is("aA\LbB\UcC\EdD", "aAbbCCdD", 'aA\LbB\UcC\EdD');
36is("\L\upERL", "Perl", '\L\upERL');
37is("\u\LpERL", "Perl", '\u\LpERL');
38is("\U\lPerl", "pERL", '\U\lPerl');
39is("\l\UPerl", "pERL", '\l\UPerl');
40is("\u\LpE\Q#X#\ER\EL", "Pe\\#x\\#rL", '\u\LpE\Q#X#\ER\EL');
41is("\l\UPe\Q!x!\Er\El", "pE\\!X\\!Rl", '\l\UPe\Q!x!\Er\El');
42is("\Q\u\LpE.X.R\EL\E.", "Pe\\.x\\.rL.", '\Q\u\LpE.X.R\EL\E.');
43is("\Q\l\UPe*x*r\El\E*", "pE\\*X\\*Rl*", '\Q\l\UPe*x*r\El\E*');
44is("\U\lPerl\E\E\E\E", "pERL", '\U\lPerl\E\E\E\E');
45is("\l\UPerl\E\E\E\E", "pERL", '\l\UPerl\E\E\E\E');
46
47is(quotemeta("\x{263a}"), "\x{263a}", "quotemeta Unicode");
48is(length(quotemeta("\x{263a}")), 1, "quotemeta Unicode length");
49
50$a = "foo|bar";
51is("a\Q\Ec$a", "acfoo|bar", '\Q\E');
52is("a\L\Ec$a", "acfoo|bar", '\L\E');
53is("a\l\Ec$a", "acfoo|bar", '\l\E');
54is("a\U\Ec$a", "acfoo|bar", '\U\E');
55is("a\u\Ec$a", "acfoo|bar", '\u\E');