Commit | Line | Data |
---|---|---|
c8e3bb4c GS |
1 | # tr.t |
2 | ||
cb6d3474 KW |
3 | use utf8; |
4 | ||
f05dd7cc JH |
5 | BEGIN { |
6 | chdir 't' if -d 't'; | |
20822f61 | 7 | @INC = '../lib'; |
953ab6e5 | 8 | require './test.pl'; |
f05dd7cc | 9 | } |
a5095b95 | 10 | |
2203fb5a | 11 | plan tests => 132; |
953ab6e5 MS |
12 | |
13 | my $Is_EBCDIC = (ord('i') == 0x89 & ord('J') == 0xd1); | |
c8e3bb4c GS |
14 | |
15 | $_ = "abcdefghijklmnopqrstuvwxyz"; | |
16 | ||
17 | tr/a-z/A-Z/; | |
18 | ||
953ab6e5 | 19 | is($_, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 'uc'); |
c8e3bb4c GS |
20 | |
21 | tr/A-Z/a-z/; | |
22 | ||
953ab6e5 | 23 | is($_, "abcdefghijklmnopqrstuvwxyz", 'lc'); |
c8e3bb4c GS |
24 | |
25 | tr/b-y/B-Y/; | |
953ab6e5 | 26 | is($_, "aBCDEFGHIJKLMNOPQRSTUVWXYz", 'partial uc'); |
c8e3bb4c | 27 | |
c8e3bb4c GS |
28 | |
29 | # In EBCDIC 'I' is \xc9 and 'J' is \0xd1, 'i' is \x89 and 'j' is \x91. | |
30 | # Yes, discontinuities. Regardless, the \xca in the below should stay | |
31 | # untouched (and not became \x8a). | |
5e037136 GS |
32 | { |
33 | no utf8; | |
34 | $_ = "I\xcaJ"; | |
c8e3bb4c | 35 | |
5e037136 | 36 | tr/I-J/i-j/; |
c8e3bb4c | 37 | |
ff36f15d | 38 | is($_, "i\xcaj", 'EBCDIC discontinuity'); |
5e037136 | 39 | } |
c8e3bb4c | 40 | # |
2de7b02f | 41 | |
953ab6e5 | 42 | |
2de7b02f GS |
43 | ($x = 12) =~ tr/1/3/; |
44 | (my $y = 12) =~ tr/1/3/; | |
45 | ($f = 1.5) =~ tr/1/3/; | |
46 | (my $g = 1.5) =~ tr/1/3/; | |
953ab6e5 MS |
47 | is($x + $y + $f + $g, 71, 'tr cancels IOK and NOK'); |
48 | ||
bb16bae8 FC |
49 | # /r |
50 | $_ = 'adam'; | |
51 | is y/dam/ve/rd, 'eve', '/r'; | |
52 | is $_, 'adam', '/r leaves param alone'; | |
53 | $g = 'ruby'; | |
54 | is $g =~ y/bury/repl/r, 'perl', '/r with explicit param'; | |
55 | is $g, 'ruby', '/r leaves explicit param alone'; | |
56 | is "aaa" =~ y\a\b\r, 'bbb', '/r with constant param'; | |
57 | ok !eval '$_ !~ y///r', "!~ y///r is forbidden"; | |
58 | like $@, qr\^Using !~ with tr///r doesn't make sense\, | |
59 | "!~ y///r error message"; | |
60 | { | |
61 | my $w; | |
62 | my $wc; | |
63 | local $SIG{__WARN__} = sub { $w = shift; ++$wc }; | |
64 | local $^W = 1; | |
65 | eval 'y///r; 1'; | |
66 | like $w, qr '^Useless use of non-destructive transliteration \(tr///r\)', | |
67 | '/r warns in void context'; | |
68 | is $wc, 1, '/r warns just once'; | |
69 | } | |
2de7b02f | 70 | |
953ab6e5 | 71 | # perlbug [ID 20000511.005] |
2de7b02f GS |
72 | $_ = 'fred'; |
73 | /([a-z]{2})/; | |
74 | $1 =~ tr/A-Z//; | |
75 | s/^(\s*)f/$1F/; | |
953ab6e5 MS |
76 | is($_, 'Fred', 'harmless if explicitly not updating'); |
77 | ||
78 | ||
79 | # A variant of the above, added in 5.7.2 | |
80 | $_ = 'fred'; | |
81 | /([a-z]{2})/; | |
82 | eval '$1 =~ tr/A-Z/A-Z/;'; | |
83 | s/^(\s*)f/$1F/; | |
84 | is($_, 'Fred', 'harmless if implicitly not updating'); | |
85 | is($@, '', ' no error'); | |
86 | ||
2de7b02f GS |
87 | |
88 | # check tr handles UTF8 correctly | |
89 | ($x = 256.65.258) =~ tr/a/b/; | |
953ab6e5 MS |
90 | is($x, 256.65.258, 'handles UTF8'); |
91 | is(length $x, 3); | |
92 | ||
2de7b02f | 93 | $x =~ tr/A/B/; |
953ab6e5 | 94 | is(length $x, 3); |
67a17885 | 95 | if (ord("\t") == 9) { # ASCII |
953ab6e5 | 96 | is($x, 256.66.258); |
67a17885 PP |
97 | } |
98 | else { | |
953ab6e5 | 99 | is($x, 256.65.258); |
67a17885 | 100 | } |
953ab6e5 | 101 | |
cbe7f703 PP |
102 | # EBCDIC variants of the above tests |
103 | ($x = 256.193.258) =~ tr/a/b/; | |
953ab6e5 MS |
104 | is(length $x, 3); |
105 | is($x, 256.193.258); | |
106 | ||
cbe7f703 | 107 | $x =~ tr/A/B/; |
953ab6e5 | 108 | is(length $x, 3); |
cbe7f703 | 109 | if (ord("\t") == 9) { # ASCII |
953ab6e5 | 110 | is($x, 256.193.258); |
cbe7f703 PP |
111 | } |
112 | else { | |
953ab6e5 | 113 | is($x, 256.194.258); |
cbe7f703 | 114 | } |
953ab6e5 | 115 | |
036b4402 GS |
116 | |
117 | { | |
953ab6e5 MS |
118 | my $l = chr(300); my $r = chr(400); |
119 | $x = 200.300.400; | |
120 | $x =~ tr/\x{12c}/\x{190}/; | |
121 | is($x, 200.400.400, | |
122 | 'changing UTF8 chars in a UTF8 string, same length'); | |
123 | is(length $x, 3); | |
124 | ||
125 | $x = 200.300.400; | |
126 | $x =~ tr/\x{12c}/\x{be8}/; | |
127 | is($x, 200.3048.400, ' more bytes'); | |
128 | is(length $x, 3); | |
129 | ||
130 | $x = 100.125.60; | |
131 | $x =~ tr/\x{64}/\x{190}/; | |
132 | is($x, 400.125.60, 'Putting UT8 chars into a non-UTF8 string'); | |
133 | is(length $x, 3); | |
134 | ||
135 | $x = 400.125.60; | |
136 | $x =~ tr/\x{190}/\x{64}/; | |
137 | is($x, 100.125.60, 'Removing UTF8 chars from UTF8 string'); | |
138 | is(length $x, 3); | |
139 | ||
140 | $x = 400.125.60.400; | |
141 | $y = $x =~ tr/\x{190}/\x{190}/; | |
142 | is($y, 2, 'Counting UTF8 chars in UTF8 string'); | |
143 | ||
144 | $x = 60.400.125.60.400; | |
145 | $y = $x =~ tr/\x{3c}/\x{3c}/; | |
146 | is($y, 2, ' non-UTF8 chars in UTF8 string'); | |
147 | ||
148 | # 17 - counting UTF8 chars in non-UTF8 string | |
149 | $x = 200.125.60; | |
150 | $y = $x =~ tr/\x{190}/\x{190}/; | |
151 | is($y, 0, ' UTF8 chars in non-UTFs string'); | |
036b4402 | 152 | } |
c2e66d9e | 153 | |
c2e66d9e | 154 | $_ = "abcdefghijklmnopqrstuvwxyz"; |
953ab6e5 MS |
155 | eval 'tr/a-z-9/ /'; |
156 | like($@, qr/^Ambiguous range in transliteration operator/, 'tr/a-z-9//'); | |
c2e66d9e | 157 | |
cbe7f703 | 158 | # 19-21: Make sure leading and trailing hyphens still work |
c2e66d9e GS |
159 | $_ = "car-rot9"; |
160 | tr/-a-m/./; | |
953ab6e5 | 161 | is($_, '..r.rot9', 'hyphens, leading'); |
c2e66d9e GS |
162 | |
163 | $_ = "car-rot9"; | |
164 | tr/a-m-/./; | |
953ab6e5 | 165 | is($_, '..r.rot9', ' trailing'); |
c2e66d9e GS |
166 | |
167 | $_ = "car-rot9"; | |
168 | tr/-a-m-/./; | |
953ab6e5 | 169 | is($_, '..r.rot9', ' both'); |
c2e66d9e GS |
170 | |
171 | $_ = "abcdefghijklmnop"; | |
172 | tr/ae-hn/./; | |
953ab6e5 | 173 | is($_, '.bcd....ijklm.op'); |
c2e66d9e GS |
174 | |
175 | $_ = "abcdefghijklmnop"; | |
176 | tr/a-cf-kn-p/./; | |
953ab6e5 | 177 | is($_, '...de......lm...'); |
c2e66d9e GS |
178 | |
179 | $_ = "abcdefghijklmnop"; | |
180 | tr/a-ceg-ikm-o/./; | |
953ab6e5 MS |
181 | is($_, '...d.f...j.l...p'); |
182 | ||
c2e66d9e | 183 | |
c2e66d9e GS |
184 | # 20000705 MJD |
185 | eval "tr/m-d/ /"; | |
321ecc04 | 186 | like($@, qr/^Invalid range "m-d" in transliteration operator/, |
953ab6e5 | 187 | 'reversed range check'); |
c2e66d9e | 188 | |
d897a58d | 189 | 'abcdef' =~ /(bcd)/; |
953ab6e5 MS |
190 | is(eval '$1 =~ tr/abcd//', 3, 'explicit read-only count'); |
191 | is($@, '', ' no error'); | |
d897a58d | 192 | |
953ab6e5 MS |
193 | 'abcdef' =~ /(bcd)/; |
194 | is(eval '$1 =~ tr/abcd/abcd/', 3, 'implicit read-only count'); | |
195 | is($@, '', ' no error'); | |
196 | ||
197 | is(eval '"123" =~ tr/12//', 2, 'LHS of non-updating tr'); | |
d897a58d | 198 | |
94bfe852 | 199 | eval '"123" =~ tr/1/2/'; |
953ab6e5 MS |
200 | like($@, qr|^Can't modify constant item in transliteration \(tr///\)|, |
201 | 'LHS bad on updating tr'); | |
202 | ||
d897a58d | 203 | |
381d18bc JH |
204 | # v300 (0x12c) is UTF-8-encoded as 196 172 (0xc4 0xac) |
205 | # v400 (0x190) is UTF-8-encoded as 198 144 (0xc6 0x90) | |
206 | ||
207 | # Transliterate a byte to a byte, all four ways. | |
208 | ||
209 | ($a = v300.196.172.300.196.172) =~ tr/\xc4/\xc5/; | |
953ab6e5 | 210 | is($a, v300.197.172.300.197.172, 'byte2byte transliteration'); |
381d18bc JH |
211 | |
212 | ($a = v300.196.172.300.196.172) =~ tr/\xc4/\x{c5}/; | |
953ab6e5 | 213 | is($a, v300.197.172.300.197.172); |
381d18bc JH |
214 | |
215 | ($a = v300.196.172.300.196.172) =~ tr/\x{c4}/\xc5/; | |
953ab6e5 | 216 | is($a, v300.197.172.300.197.172); |
381d18bc JH |
217 | |
218 | ($a = v300.196.172.300.196.172) =~ tr/\x{c4}/\x{c5}/; | |
953ab6e5 | 219 | is($a, v300.197.172.300.197.172); |
381d18bc | 220 | |
381d18bc JH |
221 | |
222 | ($a = v300.196.172.300.196.172) =~ tr/\xc4/\x{12d}/; | |
953ab6e5 | 223 | is($a, v300.301.172.300.301.172, 'byte2wide transliteration'); |
381d18bc JH |
224 | |
225 | ($a = v300.196.172.300.196.172) =~ tr/\x{12c}/\xc3/; | |
953ab6e5 | 226 | is($a, v195.196.172.195.196.172, ' wide2byte'); |
381d18bc JH |
227 | |
228 | ($a = v300.196.172.300.196.172) =~ tr/\x{12c}/\x{12d}/; | |
953ab6e5 | 229 | is($a, v301.196.172.301.196.172, ' wide2wide'); |
381d18bc | 230 | |
381d18bc JH |
231 | |
232 | ($a = v300.196.172.300.196.172) =~ tr/\xc4\x{12c}/\x{12d}\xc3/; | |
953ab6e5 | 233 | is($a, v195.301.172.195.301.172, 'byte2wide & wide2byte'); |
381d18bc | 234 | |
381d18bc JH |
235 | |
236 | ($a = v300.196.172.300.196.172.400.198.144) =~ | |
237 | tr/\xac\xc4\x{12c}\x{190}/\xad\x{12d}\xc5\x{191}/; | |
953ab6e5 | 238 | is($a, v197.301.173.197.301.173.401.198.144, 'all together now!'); |
381d18bc | 239 | |
381d18bc | 240 | |
953ab6e5 MS |
241 | is((($a = v300.196.172.300.196.172) =~ tr/\xc4/\xc5/), 2, |
242 | 'transliterate and count'); | |
381d18bc | 243 | |
953ab6e5 | 244 | is((($a = v300.196.172.300.196.172) =~ tr/\x{12c}/\x{12d}/), 2); |
381d18bc | 245 | |
381d18bc JH |
246 | |
247 | ($a = v300.196.172.300.196.172) =~ tr/\xc4/\x{12d}/c; | |
953ab6e5 | 248 | is($a, v301.196.301.301.196.301, 'translit w/complement'); |
381d18bc JH |
249 | |
250 | ($a = v300.196.172.300.196.172) =~ tr/\x{12c}/\xc5/c; | |
953ab6e5 | 251 | is($a, v300.197.197.300.197.197); |
381d18bc | 252 | |
381d18bc JH |
253 | |
254 | ($a = v300.196.172.300.196.172) =~ tr/\xc4//d; | |
953ab6e5 | 255 | is($a, v300.172.300.172, 'translit w/deletion'); |
381d18bc JH |
256 | |
257 | ($a = v300.196.172.300.196.172) =~ tr/\x{12c}//d; | |
953ab6e5 | 258 | is($a, v196.172.196.172); |
381d18bc | 259 | |
381d18bc JH |
260 | |
261 | ($a = v196.196.172.300.300.196.172) =~ tr/\xc4/\xc5/s; | |
953ab6e5 | 262 | is($a, v197.172.300.300.197.172, 'translit w/squeeze'); |
381d18bc JH |
263 | |
264 | ($a = v196.172.300.300.196.172.172) =~ tr/\x{12c}/\x{12d}/s; | |
953ab6e5 | 265 | is($a, v196.172.301.196.172.172); |
381d18bc | 266 | |
a1874b66 | 267 | |
953ab6e5 | 268 | # Tricky cases (When Simon Cozens Attacks) |
a1874b66 | 269 | ($a = v196.172.200) =~ tr/\x{12c}/a/; |
953ab6e5 | 270 | is(sprintf("%vd", $a), '196.172.200'); |
a1874b66 JH |
271 | |
272 | ($a = v196.172.200) =~ tr/\x{12c}/\x{12c}/; | |
953ab6e5 | 273 | is(sprintf("%vd", $a), '196.172.200'); |
a1874b66 JH |
274 | |
275 | ($a = v196.172.200) =~ tr/\x{12c}//d; | |
953ab6e5 MS |
276 | is(sprintf("%vd", $a), '196.172.200'); |
277 | ||
a1874b66 | 278 | |
8973db79 | 279 | # UTF8 range tests from Inaba Hiroto |
f9a63242 | 280 | |
a26bfc40 | 281 | # Not working in EBCDIC as of 12674. |
f9a63242 | 282 | ($a = v300.196.172.302.197.172) =~ tr/\x{12c}-\x{130}/\xc0-\xc4/; |
953ab6e5 | 283 | is($a, v192.196.172.194.197.172, 'UTF range'); |
f9a63242 JH |
284 | |
285 | ($a = v300.196.172.302.197.172) =~ tr/\xc4-\xc8/\x{12c}-\x{130}/; | |
953ab6e5 MS |
286 | is($a, v300.300.172.302.301.172); |
287 | ||
8973db79 JH |
288 | |
289 | # UTF8 range tests from Karsten Sperling (patch #9008 required) | |
290 | ||
291 | ($a = "\x{0100}") =~ tr/\x00-\x{100}/X/; | |
953ab6e5 | 292 | is($a, "X"); |
8973db79 JH |
293 | |
294 | ($a = "\x{0100}") =~ tr/\x{0000}-\x{00ff}/X/c; | |
953ab6e5 | 295 | is($a, "X"); |
8973db79 JH |
296 | |
297 | ($a = "\x{0100}") =~ tr/\x{0000}-\x{00ff}\x{0101}/X/c; | |
953ab6e5 | 298 | is($a, "X"); |
8973db79 JH |
299 | |
300 | ($a = v256) =~ tr/\x{0000}-\x{00ff}\x{0101}/X/c; | |
953ab6e5 MS |
301 | is($a, "X"); |
302 | ||
8973db79 | 303 | |
94472101 JH |
304 | # UTF8 range tests from Inaba Hiroto |
305 | ||
306 | ($a = "\x{200}") =~ tr/\x00-\x{100}/X/c; | |
953ab6e5 | 307 | is($a, "X"); |
94472101 JH |
308 | |
309 | ($a = "\x{200}") =~ tr/\x00-\x{100}/X/cs; | |
953ab6e5 MS |
310 | is($a, "X"); |
311 | ||
94472101 | 312 | |
6b6bd37b JH |
313 | # Tricky on EBCDIC: while [a-z] [A-Z] must not match the gap characters, |
314 | # (i-j, r-s, I-J, R-S), [\x89-\x91] [\xc9-\xd1] has to match them, | |
315 | # from Karsten Sperling. | |
316 | ||
317 | $c = ($a = "\x89\x8a\x8b\x8c\x8d\x8f\x90\x91") =~ tr/\x89-\x91/X/; | |
953ab6e5 MS |
318 | is($c, 8); |
319 | is($a, "XXXXXXXX"); | |
4c3a8340 | 320 | |
6b6bd37b | 321 | $c = ($a = "\xc9\xca\xcb\xcc\xcd\xcf\xd0\xd1") =~ tr/\xc9-\xd1/X/; |
953ab6e5 MS |
322 | is($c, 8); |
323 | is($a, "XXXXXXXX"); | |
6b6bd37b | 324 | |
4c3a8340 | 325 | SKIP: { |
953ab6e5 MS |
326 | skip "not EBCDIC", 4 unless $Is_EBCDIC; |
327 | ||
328 | $c = ($a = "\x89\x8a\x8b\x8c\x8d\x8f\x90\x91") =~ tr/i-j/X/; | |
329 | is($c, 2); | |
330 | is($a, "X\x8a\x8b\x8c\x8d\x8f\x90X"); | |
331 | ||
332 | $c = ($a = "\xc9\xca\xcb\xcc\xcd\xcf\xd0\xd1") =~ tr/I-J/X/; | |
333 | is($c, 2); | |
334 | is($a, "X\xca\xcb\xcc\xcd\xcf\xd0X"); | |
6b6bd37b | 335 | } |
1ed601ec JH |
336 | |
337 | ($a = "\x{100}") =~ tr/\x00-\xff/X/c; | |
953ab6e5 | 338 | is(ord($a), ord("X")); |
1ed601ec JH |
339 | |
340 | ($a = "\x{100}") =~ tr/\x00-\xff/X/cs; | |
953ab6e5 | 341 | is(ord($a), ord("X")); |
1ed601ec JH |
342 | |
343 | ($a = "\x{100}\x{100}") =~ tr/\x{101}-\x{200}//c; | |
953ab6e5 | 344 | is($a, "\x{100}\x{100}"); |
1ed601ec JH |
345 | |
346 | ($a = "\x{100}\x{100}") =~ tr/\x{101}-\x{200}//cs; | |
953ab6e5 | 347 | is($a, "\x{100}"); |
1ed601ec | 348 | |
629b4584 | 349 | $a = "\xfe\xff"; $a =~ tr/\xfe\xff/\x{1ff}\x{1fe}/; |
953ab6e5 MS |
350 | is($a, "\x{1ff}\x{1fe}"); |
351 | ||
76ef7183 JH |
352 | |
353 | # From David Dyck | |
354 | ($a = "R0_001") =~ tr/R_//d; | |
953ab6e5 | 355 | is(hex($a), 1); |
76ef7183 | 356 | |
800b4dc4 JH |
357 | # From Inaba Hiroto |
358 | @a = (1,2); map { y/1/./ for $_ } @a; | |
953ab6e5 | 359 | is("@a", ". 2"); |
800b4dc4 JH |
360 | |
361 | @a = (1,2); map { y/1/./ for $_.'' } @a; | |
953ab6e5 MS |
362 | is("@a", "1 2"); |
363 | ||
800b4dc4 | 364 | |
bec89253 RH |
365 | # Additional test for Inaba Hiroto patch (robin@kitsite.com) |
366 | ($a = "\x{100}\x{102}\x{101}") =~ tr/\x00-\377/XYZ/c; | |
953ab6e5 MS |
367 | is($a, "XZY"); |
368 | ||
bec89253 | 369 | |
2233f375 NC |
370 | # Used to fail with "Modification of a read-only value attempted" |
371 | %a = (N=>1); | |
372 | foreach (keys %a) { | |
953ab6e5 MS |
373 | eval 'tr/N/n/'; |
374 | is($_, 'n', 'pp_trans needs to unshare shared hash keys'); | |
375 | is($@, '', ' no error'); | |
2233f375 | 376 | } |
94bfe852 | 377 | |
953ab6e5 | 378 | |
94bfe852 | 379 | $x = eval '"1213" =~ tr/1/1/'; |
953ab6e5 MS |
380 | is($x, 2, 'implicit count on constant'); |
381 | is($@, '', ' no error'); | |
382 | ||
383 | ||
384 | my @foo = (); | |
385 | eval '$foo[-1] =~ tr/N/N/'; | |
386 | is( $@, '', 'implicit count outside array bounds, index negative' ); | |
387 | is( scalar @foo, 0, " doesn't extend the array"); | |
388 | ||
389 | eval '$foo[1] =~ tr/N/N/'; | |
390 | is( $@, '', 'implicit count outside array bounds, index positive' ); | |
391 | is( scalar @foo, 0, " doesn't extend the array"); | |
392 | ||
393 | ||
394 | my %foo = (); | |
395 | eval '$foo{bar} =~ tr/N/N/'; | |
396 | is( $@, '', 'implicit count outside hash bounds' ); | |
397 | is( scalar keys %foo, 0, " doesn't extend the hash"); | |
d59e14db RGS |
398 | |
399 | $x = \"foo"; | |
400 | is( $x =~ tr/A/A/, 2, 'non-modifying tr/// on a scalar ref' ); | |
401 | is( ref $x, 'SCALAR', " doesn't stringify its argument" ); | |
0d65d7d5 MS |
402 | |
403 | # rt.perl.org 36622. Perl didn't like a y/// at end of file. No trailing | |
404 | # newline allowed. | |
405 | fresh_perl_is(q[$_ = "foo"; y/A-Z/a-z/], ''); | |
9f7f3913 TS |
406 | |
407 | ||
408 | { # [perl #38293] chr(65535) should be allowed in regexes | |
409 | no warnings 'utf8'; # to allow non-characters | |
410 | ||
411 | $s = "\x{d800}\x{ffff}"; | |
412 | $s =~ tr/\0/A/; | |
413 | is($s, "\x{d800}\x{ffff}", "do_trans_simple"); | |
414 | ||
415 | $s = "\x{d800}\x{ffff}"; | |
416 | $i = $s =~ tr/\0//; | |
417 | is($i, 0, "do_trans_count"); | |
418 | ||
419 | $s = "\x{d800}\x{ffff}"; | |
420 | $s =~ tr/\0/A/s; | |
421 | is($s, "\x{d800}\x{ffff}", "do_trans_complex, SQUASH"); | |
422 | ||
423 | $s = "\x{d800}\x{ffff}"; | |
424 | $s =~ tr/\0/A/c; | |
425 | is($s, "AA", "do_trans_complex, COMPLEMENT"); | |
426 | ||
427 | $s = "A\x{ffff}B"; | |
428 | $s =~ tr/\x{ffff}/\x{1ffff}/; | |
429 | is($s, "A\x{1ffff}B", "utf8, SEARCHLIST"); | |
430 | ||
431 | $s = "\x{fffd}\x{fffe}\x{ffff}"; | |
432 | $s =~ tr/\x{fffd}-\x{ffff}/ABC/; | |
433 | is($s, "ABC", "utf8, SEARCHLIST range"); | |
434 | ||
435 | $s = "ABC"; | |
436 | $s =~ tr/ABC/\x{ffff}/; | |
437 | is($s, "\x{ffff}"x3, "utf8, REPLACEMENTLIST"); | |
438 | ||
439 | $s = "ABC"; | |
440 | $s =~ tr/ABC/\x{fffd}-\x{ffff}/; | |
441 | is($s, "\x{fffd}\x{fffe}\x{ffff}", "utf8, REPLACEMENTLIST range"); | |
442 | ||
443 | $s = "A\x{ffff}B\x{100}\0\x{fffe}\x{ffff}"; | |
444 | $i = $s =~ tr/\x{ffff}//; | |
445 | is($i, 2, "utf8, count"); | |
446 | ||
447 | $s = "A\x{ffff}\x{ffff}C"; | |
448 | $s =~ tr/\x{ffff}/\x{100}/s; | |
449 | is($s, "A\x{100}C", "utf8, SQUASH"); | |
450 | ||
451 | $s = "A\x{ffff}\x{ffff}\x{fffe}\x{fffe}\x{fffe}C"; | |
452 | $s =~ tr/\x{fffe}\x{ffff}//s; | |
453 | is($s, "A\x{ffff}\x{fffe}C", "utf8, SQUASH"); | |
454 | ||
455 | $s = "xAABBBy"; | |
456 | $s =~ tr/AB/\x{ffff}/s; | |
457 | is($s, "x\x{ffff}y", "utf8, SQUASH"); | |
458 | ||
459 | $s = "xAABBBy"; | |
460 | $s =~ tr/AB/\x{fffe}\x{ffff}/s; | |
461 | is($s, "x\x{fffe}\x{ffff}y", "utf8, SQUASH"); | |
462 | ||
463 | $s = "A\x{ffff}B\x{fffe}C"; | |
464 | $s =~ tr/\x{fffe}\x{ffff}/x/c; | |
465 | is($s, "x\x{ffff}x\x{fffe}x", "utf8, COMPLEMENT"); | |
466 | ||
467 | $s = "A\x{10000}B\x{2abcd}C"; | |
468 | $s =~ tr/\0-\x{ffff}/x/c; | |
469 | is($s, "AxBxC", "utf8, COMPLEMENT range"); | |
470 | ||
471 | $s = "A\x{fffe}B\x{ffff}C"; | |
472 | $s =~ tr/\x{fffe}\x{ffff}/x/d; | |
473 | is($s, "AxBC", "utf8, DELETE"); | |
474 | ||
475 | } # non-characters end | |
476 | ||
1749ea0d TS |
477 | { # related to [perl #27940] |
478 | my $c; | |
479 | ||
480 | ($c = "\x20\c@\x30\cA\x40\cZ\x50\c_\x60") =~ tr/\c@-\c_//d; | |
481 | is($c, "\x20\x30\x40\x50\x60", "tr/\\c\@-\\c_//d"); | |
482 | ||
483 | ($c = "\x20\x00\x30\x01\x40\x1A\x50\x1F\x60") =~ tr/\x00-\x1f//d; | |
484 | is($c, "\x20\x30\x40\x50\x60", "tr/\\x00-\\x1f//d"); | |
485 | } | |
486 | ||
3788ef8f | 487 | ($s) = keys %{{pie => 3}}; |
3e89ba19 | 488 | SKIP: { |
2203fb5a | 489 | if (!eval { require B }) { skip "no B", 2 } |
3e89ba19 | 490 | my $wasro = B::svref_2object(\$s)->FLAGS & &B::SVf_READONLY; |
2203fb5a | 491 | ok $wasro, "have a COW"; |
3788ef8f | 492 | $s =~ tr/i//; |
3e89ba19 FC |
493 | ok( B::svref_2object(\$s)->FLAGS & &B::SVf_READONLY, |
494 | "count-only tr doesn't deCOW COWs" ); | |
3788ef8f | 495 | } |
a5446a64 DM |
496 | |
497 | # [ RT #61520 ] | |
498 | # | |
499 | # under threads, unicode tr within a cloned closure would SEGV or assert | |
500 | # fail, since the pointer in the pad to the swash was getting zeroed out | |
501 | # in the proto-CV | |
502 | ||
503 | { | |
504 | my $x = "\x{142}"; | |
505 | sub { | |
506 | $x =~ tr[\x{142}][\x{143}]; | |
507 | }->(); | |
508 | is($x,"\x{143}", "utf8 + closure"); | |
509 | } | |
510 | ||
9100eeb1 Z |
511 | # Freeing of trans ops prior to pmtrans() [perl #102858]. |
512 | eval q{ $a ~= tr/a/b/; }; | |
513 | ok 1; | |
514 | SKIP: { | |
515 | skip "no encoding", 1 unless eval { require encoding; 1 }; | |
516 | eval q{ use encoding "utf8"; $a ~= tr/a/b/; }; | |
517 | ok 1; | |
518 | } | |
a5446a64 | 519 | |
cb6d3474 KW |
520 | { # [perl #113584] |
521 | ||
522 | my $x = "Perlα"; | |
523 | $x =~ tr/αα/βγ/; | |
524 | note $x; | |
525 | is($x, "Perlβ", "Only first of multiple transliterations is used"); | |
526 | } | |
527 | ||
9100eeb1 | 528 | 1; |