Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 137 lines (110 sloc) 4.795 kb
58135b3 [t/spec] changed 'use v6-alpha;' to 'use v6;'
moritz authored
1 use v6;
4739122 Converted quotemeta.t to unix format (?)
cosimo authored
2 # vim: filetype=perl6 :
3
4 # NOTES ON PORTING quotemeta.t FROM Perl 5.9.3
5 #
6 # 1. The original test suite did include may tests to exercise the
c84935c Added named arguments to string tests
frew authored
7 # behaviour in double-quotes interpolation with \Q and \E, and their
4739122 Converted quotemeta.t to unix format (?)
cosimo authored
8 # interaction with other modification like \L and \U. These
9 # interpolating sequences no longer exist.
10 #
11 # 2. The original test suite did not exercise the quotemeta function
12 # for the whole 0-255 Unicode character set. Extending that test
13 # suite to include all of these characters basically yields the
14 # modified tests included here FOR THE ASCII VARIANT ONLY.
15 # Tests for EBCDIC have not been (yet) extended, this is most
16 # due to the fact that the Config.pm mechanism is not available
17 # to date.
18 #
19 # 3. The original test suite used tr/// to count backslashes, here
20 # we use a combination of split and grep to count non-backslashes,
21 # which should be more intuitive.
22
23 use Test;
24
25
85d2267 @moritz [S32] more unfossiling
moritz authored
26 plan 11;
4739122 Converted quotemeta.t to unix format (?)
cosimo authored
27
28 # For the moment I don't know how to handle the lack of Config.pm...
29 # Sorry for ebcdic users!
30 my %Config; # Empty means there's no 'ebcdic' key defined...
31
f60ff61 [fudge] more sub counting tweaks
lwall authored
32 #?pugs todo 'Test Config.pm availability'
4739122 Converted quotemeta.t to unix format (?)
cosimo authored
33 is('Config.pm', 'available', 'Config.pm availability');
34
db6b784 [t/spec] fix smartlinks in S32-str
moritz authored
35 # L<S32::Str/Str/quotemeta>
4739122 Converted quotemeta.t to unix format (?)
cosimo authored
36
37 is(quotemeta("HeLLo World-72_1"), "HeLLo\\ World\\-72_1", "simple quotemeta test");
38 is(quotemeta(""), "", "empty string");
39
c84935c Added named arguments to string tests
frew authored
40 $_ = "HeLLo World-72_1";
4739122 Converted quotemeta.t to unix format (?)
cosimo authored
41 my $x = .quotemeta;
42 is($x, "HeLLo\\ World\\-72_1", 'quotemeta uses $_ as default');
43
44 { # test invocant syntax for quotemeta
45 my $x = "HeLLo World-72_1";
46 is($x.quotemeta, "HeLLo\\ World\\-72_1", '$x.quotemeta works');
47 is("HeLLo World-72_1".quotemeta, "HeLLo\\ World\\-72_1", '"HeLLo World-72_1".quotemeta works');
48 }
49
50
51 if (%Config<ebcdic> eq 'define') {
49d046f .join now defaults to ''
lwall authored
52 $_ = (129 .. 233).map({ chr($_); }).join;
4739122 Converted quotemeta.t to unix format (?)
cosimo authored
53 is($_.chars, 96, "quotemeta starting string");
c84935c Added named arguments to string tests
frew authored
54
4739122 Converted quotemeta.t to unix format (?)
cosimo authored
55 # 105 characters - 52 letters = 53 backslashes
56 # 105 characters + 53 backslashes = 158 characters
57 $_ = quotemeta $_;
58 is($_.chars, 158, "quotemeta string");
59 # 53 backslashed characters + 1 "original" backslash
60 is($_.split('').grep({ $_ eq "\x5c" }).elems, 54, "count backslashes");
61 }
62 else {
49d046f .join now defaults to ''
lwall authored
63 $_ = (0 .. 255).map({ chr($_); }).join;
4739122 Converted quotemeta.t to unix format (?)
cosimo authored
64 is($_.chars, 256, "quotemeta starting string");
c84935c Added named arguments to string tests
frew authored
65
4739122 Converted quotemeta.t to unix format (?)
cosimo authored
66 # Original test in Perl 5.9.3:
67 # 96 characters - 52 letters - 10 digits - 1 underscore = 33 backslashes
68 # 96 characters + 33 backslashes = 129 characters
c84935c Added named arguments to string tests
frew authored
69 #
4739122 Converted quotemeta.t to unix format (?)
cosimo authored
70 # Then added remaining 32 + 128, all escaped:
71 # 129 + (32 + 128) * 2 = 449
72 #
73 # Total backslashed chars are 33 + 32 + 128 = 193
74 # Total backslashes are 1 + 193 = 194
75 $_ = quotemeta $_;
76 is($_.chars, 449, "quotemeta string");
77 # 33 backslashed characters + 1 "original" backslash
78 is($_.split('').grep({ $_ eq "\x5c" }).elems, 194, "count backslashes");
79 }
80
81 # Current quotemeta implementation mimics that for Perl 5, avoiding
82 # to escape Unicode characters beyond 256th
83 is(quotemeta("\x[263a]"), "\x[263a]", "quotemeta Unicode");
84 is(quotemeta("\x[263a]").chars, 1, "quotemeta Unicode length");
85
86 =begin from_perl5
87
88
89 plan tests => 22;
90
91 if ($Config{ebcdic} eq 'define') {
92 $_ = join "", map chr($_), 129..233;
93
94 # 105 characters - 52 letters = 53 backslashes
95 # 105 characters + 53 backslashes = 158 characters
96 $_ = quotemeta $_;
97 is(length($_), 158, "quotemeta string");
98 # 104 non-backslash characters
99 is(tr/\\//cd, 104, "tr count non-backslashed");
100 } else { # some ASCII descendant, then.
101 $_ = join "", map chr($_), 32..127;
102
103 # 96 characters - 52 letters - 10 digits - 1 underscore = 33 backslashes
104 # 96 characters + 33 backslashes = 129 characters
105 $_ = quotemeta $_;
106 is(length($_), 129, "quotemeta string");
107 # 95 non-backslash characters
108 is(tr/\\//cd, 95, "tr count non-backslashed");
109 }
110
111 is(length(quotemeta ""), 0, "quotemeta empty string");
112
113 is("aA\UbB\LcC\EdD", "aABBccdD", 'aA\UbB\LcC\EdD');
114 is("aA\LbB\UcC\EdD", "aAbbCCdD", 'aA\LbB\UcC\EdD');
115 is("\L\upERL", "Perl", '\L\upERL');
116 is("\u\LpERL", "Perl", '\u\LpERL');
117 is("\U\lPerl", "pERL", '\U\lPerl');
118 is("\l\UPerl", "pERL", '\l\UPerl');
119 is("\u\LpE\Q#X#\ER\EL", "Pe\\#x\\#rL", '\u\LpE\Q#X#\ER\EL');
120 is("\l\UPe\Q!x!\Er\El", "pE\\!X\\!Rl", '\l\UPe\Q!x!\Er\El');
121 is("\Q\u\LpE.X.R\EL\E.", "Pe\\.x\\.rL.", '\Q\u\LpE.X.R\EL\E.');
122 is("\Q\l\UPe*x*r\El\E*", "pE\\*X\\*Rl*", '\Q\l\UPe*x*r\El\E*');
123 is("\U\lPerl\E\E\E\E", "pERL", '\U\lPerl\E\E\E\E');
124 is("\l\UPerl\E\E\E\E", "pERL", '\l\UPerl\E\E\E\E');
125
126 is(quotemeta("\x{263a}"), "\x{263a}", "quotemeta Unicode");
127 is(length(quotemeta("\x{263a}")), 1, "quotemeta Unicode length");
128
129 $a = "foo|bar";
130 is("a\Q\Ec$a", "acfoo|bar", '\Q\E');
131 is("a\L\Ec$a", "acfoo|bar", '\L\E');
132 is("a\l\Ec$a", "acfoo|bar", '\l\E');
133 is("a\U\Ec$a", "acfoo|bar", '\U\E');
134 is("a\u\Ec$a", "acfoo|bar", '\u\E');
135
136 =end from_perl5
Something went wrong with that request. Please try again.