Small optimisations, by Brandon Black
[p5sagit/p5-mst-13.2.git] / t / op / subst.t
CommitLineData
25aae3a7 1#!./perl -w
d9d8d8de 2
a1a0e61e 3BEGIN {
4 chdir 't' if -d 't';
20822f61 5 @INC = '../lib';
a1a0e61e 6 require Config; import Config;
7}
344462d3 8
e8ebd21b 9require './test.pl';
3be69782 10plan( tests => 136 );
d9d8d8de 11
12$x = 'foo';
13$_ = "x";
14s/x/\$x/;
e8ebd21b 15ok( $_ eq '$x', ":$_: eq :\$x:" );
d9d8d8de 16
17$_ = "x";
18s/x/$x/;
e8ebd21b 19ok( $_ eq 'foo', ":$_: eq :foo:" );
d9d8d8de 20
21$_ = "x";
22s/x/\$x $x/;
e8ebd21b 23ok( $_ eq '$x foo', ":$_: eq :\$x foo:" );
d9d8d8de 24
25$b = 'cd';
79072805 26($a = 'abcdef') =~ s<(b${b}e)>'\n$1';
e8ebd21b 27ok( $1 eq 'bcde' && $a eq 'a\n$1f', ":$1: eq :bcde: ; :$a: eq :a\\n\$1f:" );
d9d8d8de 28
29$a = 'abacada';
e8ebd21b 30ok( ($a =~ s/a/x/g) == 4 && $a eq 'xbxcxdx' );
d9d8d8de 31
e8ebd21b 32ok( ($a =~ s/a/y/g) == 0 && $a eq 'xbxcxdx' );
d9d8d8de 33
e8ebd21b 34ok( ($a =~ s/b/y/g) == 1 && $a eq 'xyxcxdx' );
d9d8d8de 35
36$_ = 'ABACADA';
e8ebd21b 37ok( /a/i && s///gi && $_ eq 'BCD' );
d9d8d8de 38
39$_ = '\\' x 4;
e8ebd21b 40ok( length($_) == 4 );
41$snum = s/\\/\\\\/g;
42ok( $_ eq '\\' x 8 && $snum == 4 );
d9d8d8de 43
44$_ = '\/' x 4;
e8ebd21b 45ok( length($_) == 8 );
46$snum = s/\//\/\//g;
47ok( $_ eq '\\//' x 4 && $snum == 4 );
48ok( length($_) == 12 );
d9d8d8de 49
50$_ = 'aaaXXXXbbb';
51s/^a//;
e8ebd21b 52ok( $_ eq 'aaXXXXbbb' );
d9d8d8de 53
54$_ = 'aaaXXXXbbb';
55s/a//;
e8ebd21b 56ok( $_ eq 'aaXXXXbbb' );
d9d8d8de 57
58$_ = 'aaaXXXXbbb';
59s/^a/b/;
e8ebd21b 60ok( $_ eq 'baaXXXXbbb' );
d9d8d8de 61
62$_ = 'aaaXXXXbbb';
63s/a/b/;
e8ebd21b 64ok( $_ eq 'baaXXXXbbb' );
d9d8d8de 65
66$_ = 'aaaXXXXbbb';
67s/aa//;
e8ebd21b 68ok( $_ eq 'aXXXXbbb' );
d9d8d8de 69
70$_ = 'aaaXXXXbbb';
71s/aa/b/;
e8ebd21b 72ok( $_ eq 'baXXXXbbb' );
d9d8d8de 73
74$_ = 'aaaXXXXbbb';
75s/b$//;
e8ebd21b 76ok( $_ eq 'aaaXXXXbb' );
d9d8d8de 77
78$_ = 'aaaXXXXbbb';
79s/b//;
e8ebd21b 80ok( $_ eq 'aaaXXXXbb' );
d9d8d8de 81
82$_ = 'aaaXXXXbbb';
83s/bb//;
e8ebd21b 84ok( $_ eq 'aaaXXXXb' );
d9d8d8de 85
86$_ = 'aaaXXXXbbb';
87s/aX/y/;
e8ebd21b 88ok( $_ eq 'aayXXXbbb' );
d9d8d8de 89
90$_ = 'aaaXXXXbbb';
91s/Xb/z/;
e8ebd21b 92ok( $_ eq 'aaaXXXzbb' );
d9d8d8de 93
94$_ = 'aaaXXXXbbb';
95s/aaX.*Xbb//;
e8ebd21b 96ok( $_ eq 'ab' );
d9d8d8de 97
98$_ = 'aaaXXXXbbb';
99s/bb/x/;
e8ebd21b 100ok( $_ eq 'aaaXXXXxb' );
d9d8d8de 101
102# now for some unoptimized versions of the same.
103
104$_ = 'aaaXXXXbbb';
105$x ne $x || s/^a//;
e8ebd21b 106ok( $_ eq 'aaXXXXbbb' );
d9d8d8de 107
108$_ = 'aaaXXXXbbb';
109$x ne $x || s/a//;
e8ebd21b 110ok( $_ eq 'aaXXXXbbb' );
d9d8d8de 111
112$_ = 'aaaXXXXbbb';
113$x ne $x || s/^a/b/;
e8ebd21b 114ok( $_ eq 'baaXXXXbbb' );
d9d8d8de 115
116$_ = 'aaaXXXXbbb';
117$x ne $x || s/a/b/;
e8ebd21b 118ok( $_ eq 'baaXXXXbbb' );
d9d8d8de 119
120$_ = 'aaaXXXXbbb';
121$x ne $x || s/aa//;
e8ebd21b 122ok( $_ eq 'aXXXXbbb' );
d9d8d8de 123
124$_ = 'aaaXXXXbbb';
125$x ne $x || s/aa/b/;
e8ebd21b 126ok( $_ eq 'baXXXXbbb' );
d9d8d8de 127
128$_ = 'aaaXXXXbbb';
129$x ne $x || s/b$//;
e8ebd21b 130ok( $_ eq 'aaaXXXXbb' );
d9d8d8de 131
132$_ = 'aaaXXXXbbb';
133$x ne $x || s/b//;
e8ebd21b 134ok( $_ eq 'aaaXXXXbb' );
d9d8d8de 135
136$_ = 'aaaXXXXbbb';
137$x ne $x || s/bb//;
e8ebd21b 138ok( $_ eq 'aaaXXXXb' );
d9d8d8de 139
140$_ = 'aaaXXXXbbb';
141$x ne $x || s/aX/y/;
e8ebd21b 142ok( $_ eq 'aayXXXbbb' );
d9d8d8de 143
144$_ = 'aaaXXXXbbb';
145$x ne $x || s/Xb/z/;
e8ebd21b 146ok( $_ eq 'aaaXXXzbb' );
d9d8d8de 147
148$_ = 'aaaXXXXbbb';
149$x ne $x || s/aaX.*Xbb//;
e8ebd21b 150ok( $_ eq 'ab' );
d9d8d8de 151
152$_ = 'aaaXXXXbbb';
153$x ne $x || s/bb/x/;
e8ebd21b 154ok( $_ eq 'aaaXXXXxb' );
d9d8d8de 155
156$_ = 'abc123xyz';
c277df42 157s/(\d+)/$1*2/e; # yields 'abc246xyz'
e8ebd21b 158ok( $_ eq 'abc246xyz' );
c277df42 159s/(\d+)/sprintf("%5d",$1)/e; # yields 'abc 246xyz'
e8ebd21b 160ok( $_ eq 'abc 246xyz' );
c277df42 161s/(\w)/$1 x 2/eg; # yields 'aabbcc 224466xxyyzz'
e8ebd21b 162ok( $_ eq 'aabbcc 224466xxyyzz' );
d9d8d8de 163
164$_ = "aaaaa";
e8ebd21b 165ok( y/a/b/ == 5 );
166ok( y/a/b/ == 0 );
167ok( y/b// == 5 );
168ok( y/b/c/s == 5 );
169ok( y/c// == 1 );
170ok( y/c//d == 1 );
171ok( $_ eq "" );
d9d8d8de 172
173$_ = "Now is the %#*! time for all good men...";
e8ebd21b 174ok( ($x=(y/a-zA-Z //cd)) == 7 );
175ok( y/ / /s == 8 );
d9d8d8de 176
79072805 177$_ = 'abcdefghijklmnopqrstuvwxyz0123456789';
178tr/a-z/A-Z/;
179
e8ebd21b 180ok( $_ eq 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' );
79072805 181
182# same as tr/A-Z/a-z/;
e8ebd21b 183if (defined $Config{ebcdic} && $Config{ebcdic} eq 'define') { # EBCDIC.
6e68dac8 184 no utf8;
9d116dd7 185 y[\301-\351][\201-\251];
186} else { # Ye Olde ASCII. Or something like it.
187 y[\101-\132][\141-\172];
188}
79072805 189
e8ebd21b 190ok( $_ eq 'abcdefghijklmnopqrstuvwxyz0123456789' );
79072805 191
e8ebd21b 192SKIP: {
193 skip("not ASCII",1) unless (ord("+") == ord(",") - 1
194 && ord(",") == ord("-") - 1
195 && ord("a") == ord("b") - 1
196 && ord("b") == ord("c") - 1);
197 $_ = '+,-';
198 tr/+--/a-c/;
199 ok( $_ eq 'abc' );
9d116dd7 200}
79072805 201
202$_ = '+,-';
203tr/+\--/a\/c/;
e8ebd21b 204ok( $_ eq 'a,/' );
79072805 205
206$_ = '+,-';
207tr/-+,/ab\-/;
e8ebd21b 208ok( $_ eq 'b-a' );
843b4603 209
210
211# test recursive substitutions
212# code based on the recursive expansion of makefile variables
213
214my %MK = (
215 AAAAA => '$(B)', B=>'$(C)', C => 'D', # long->short
216 E => '$(F)', F=>'p $(G) q', G => 'HHHHH', # short->long
217 DIR => '$(UNDEFINEDNAME)/xxx',
218);
219sub var {
220 my($var,$level) = @_;
221 return "\$($var)" unless exists $MK{$var};
222 return exp_vars($MK{$var}, $level+1); # can recurse
223}
224sub exp_vars {
225 my($str,$level) = @_;
226 $str =~ s/\$\((\w+)\)/var($1, $level+1)/ge; # can recurse
227 #warn "exp_vars $level = '$str'\n";
228 $str;
229}
230
e8ebd21b 231ok( exp_vars('$(AAAAA)',0) eq 'D' );
232ok( exp_vars('$(E)',0) eq 'p HHHHH q' );
233ok( exp_vars('$(DIR)',0) eq '$(UNDEFINEDNAME)/xxx' );
234ok( exp_vars('foo $(DIR)/yyy bar',0) eq 'foo $(UNDEFINEDNAME)/xxx/yyy bar' );
3e3baf6d 235
236$_ = "abcd";
c277df42 237s/(..)/$x = $1, m#.#/eg;
e8ebd21b 238ok( $x eq "cd", 'a match nested in the RHS of a substitution' );
fb73857a 239
c277df42 240# Subst and lookbehind
241
242$_="ccccc";
e8ebd21b 243$snum = s/(?<!x)c/x/g;
244ok( $_ eq "xxxxx" && $snum == 5 );
c277df42 245
246$_="ccccc";
e8ebd21b 247$snum = s/(?<!x)(c)/x/g;
248ok( $_ eq "xxxxx" && $snum == 5 );
c277df42 249
250$_="foobbarfoobbar";
e8ebd21b 251$snum = s/(?<!r)foobbar/foobar/g;
252ok( $_ eq "foobarfoobbar" && $snum == 1 );
c277df42 253
254$_="foobbarfoobbar";
e8ebd21b 255$snum = s/(?<!ar)(foobbar)/foobar/g;
256ok( $_ eq "foobarfoobbar" && $snum == 1 );
c277df42 257
258$_="foobbarfoobbar";
e8ebd21b 259$snum = s/(?<!ar)foobbar/foobar/g;
260ok( $_ eq "foobarfoobbar" && $snum == 1 );
c277df42 261
fb73857a 262eval 's{foo} # this is a comment, not a delimiter
263 {bar};';
e8ebd21b 264ok( ! @?, 'parsing of split subst with comment' );
f3ea7b5e 265
f3ea7b5e 266$_="baacbaa";
e8ebd21b 267$snum = tr/a/b/s;
268ok( $_ eq "bbcbb" && $snum == 4,
269 'check if squashing works at the end of string' );
f3ea7b5e 270
2216f30a 271$_ = "ab";
e8ebd21b 272ok( s/a/b/ == 1 );
ce862d02 273
274$_ = <<'EOL';
275 $url = new URI::URL "http://www/"; die if $url eq "xXx";
276EOL
277$^R = 'junk';
278
279$foo = ' $@%#lowercase $@%# lowercase UPPERCASE$@%#UPPERCASE' .
280 ' $@%#lowercase$@%#lowercase$@%# lowercase lowercase $@%#lowercase' .
281 ' lowercase $@%#MiXeD$@%# ';
282
e8ebd21b 283$snum =
ce862d02 284s{ \d+ \b [,.;]? (?{ 'digits' })
285 |
286 [a-z]+ \b [,.;]? (?{ 'lowercase' })
287 |
288 [A-Z]+ \b [,.;]? (?{ 'UPPERCASE' })
289 |
290 [A-Z] [a-z]+ \b [,.;]? (?{ 'Capitalized' })
291 |
292 [A-Za-z]+ \b [,.;]? (?{ 'MiXeD' })
293 |
294 [A-Za-z0-9]+ \b [,.;]? (?{ 'alphanumeric' })
295 |
296 \s+ (?{ ' ' })
297 |
298 [^A-Za-z0-9\s]+ (?{ '$@%#' })
299}{$^R}xg;
e8ebd21b 300ok( $_ eq $foo );
8e5e9ebe 301ok( $snum == 31 );
302
303$_ = 'a' x 6;
304$snum = s/a(?{})//g;
305ok( $_ eq '' && $snum == 6 );
ce862d02 306
2beec16e 307$_ = 'x' x 20;
e8ebd21b 308$snum = s/(\d*|x)/<$1>/g;
2beec16e 309$foo = '<>' . ('<x><>' x 20) ;
e8ebd21b 310ok( $_ eq $foo && $snum == 41 );
ad94a511 311
312$t = 'aaaaaaaaa';
313
314$_ = $t;
315pos = 6;
e8ebd21b 316$snum = s/\Ga/xx/g;
317ok( $_ eq 'aaaaaaxxxxxx' && $snum == 3 );
ad94a511 318
319$_ = $t;
320pos = 6;
e8ebd21b 321$snum = s/\Ga/x/g;
322ok( $_ eq 'aaaaaaxxx' && $snum == 3 );
ad94a511 323
324$_ = $t;
325pos = 6;
326s/\Ga/xx/;
e8ebd21b 327ok( $_ eq 'aaaaaaxxaa' );
ad94a511 328
329$_ = $t;
330pos = 6;
331s/\Ga/x/;
e8ebd21b 332ok( $_ eq 'aaaaaaxaa' );
ad94a511 333
334$_ = $t;
e8ebd21b 335$snum = s/\Ga/xx/g;
336ok( $_ eq 'xxxxxxxxxxxxxxxxxx' && $snum == 9 );
ad94a511 337
338$_ = $t;
e8ebd21b 339$snum = s/\Ga/x/g;
340ok( $_ eq 'xxxxxxxxx' && $snum == 9 );
ad94a511 341
342$_ = $t;
343s/\Ga/xx/;
e8ebd21b 344ok( $_ eq 'xxaaaaaaaa' );
ad94a511 345
346$_ = $t;
347s/\Ga/x/;
e8ebd21b 348ok( $_ eq 'xaaaaaaaa' );
ad94a511 349
f5c9036e 350$_ = 'aaaa';
e8ebd21b 351$snum = s/\ba/./g;
352ok( $_ eq '.aaa' && $snum == 1 );
ad94a511 353
e9fa98b2 354eval q% s/a/"b"}/e %;
e8ebd21b 355ok( $@ =~ /Bad evalled substitution/ );
e9fa98b2 356eval q% ($_ = "x") =~ s/(.)/"$1 "/e %;
e8ebd21b 357ok( $_ eq "x " and !length $@ );
43a16006 358$x = $x = 'interp';
359eval q% ($_ = "x") =~ s/x(($x)*)/"$1"/e %;
e8ebd21b 360ok( $_ eq '' and !length $@ );
e9fa98b2 361
653099ff 362$_ = "C:/";
e8ebd21b 363ok( !s/^([a-z]:)/\u$1/ );
e9fa98b2 364
12d33761 365$_ = "Charles Bronson";
e8ebd21b 366$snum = s/\B\w//g;
367ok( $_ eq "C B" && $snum == 12 );
5b71a6a7 368
369{
370 use utf8;
371 my $s = "H\303\266he";
372 my $l = my $r = $s;
373 $l =~ s/[^\w]//g;
374 $r =~ s/[^\w\.]//g;
aefe6dfc 375 is($l, $r, "use utf8 \\w");
5b71a6a7 376}
89afcb60 377
378my $pv1 = my $pv2 = "Andreas J. K\303\266nig";
379$pv1 =~ s/A/\x{100}/;
380substr($pv2,0,1) = "\x{100}";
381is($pv1, $pv2);
aefe6dfc 382
8e9639e9 383SKIP: {
384 skip("EBCDIC", 3) if ord("A") == 193;
385
386 {
387 # Gregor Chrupala <gregor.chrupala@star-group.net>
388 use utf8;
389 $a = 'Espa&ntilde;a';
390 $a =~ s/&ntilde;/ñ/;
391 like($a, qr/ñ/, "use utf8 RHS");
392 }
393
394 {
395 use utf8;
396 $a = 'España España';
397 $a =~ s/ñ/&ntilde;/;
398 like($a, qr/ñ/, "use utf8 LHS");
399 }
400
401 {
402 use utf8;
403 $a = 'España';
404 $a =~ s/ñ/ñ/;
405 like($a, qr/ñ/, "use utf8 LHS and RHS");
406 }
aefe6dfc 407}
408
8514a05a 409{
410 # SADAHIRO Tomoyuki <bqw10602@nifty.com>
411
412 $a = "\x{100}\x{101}";
413 $a =~ s/\x{101}/\xFF/;
414 like($a, qr/\xFF/);
4a176938 415 is(length($a), 2, "SADAHIRO utf8 s///");
8514a05a 416
417 $a = "\x{100}\x{101}";
418 $a =~ s/\x{101}/"\xFF"/e;
419 like($a, qr/\xFF/);
420 is(length($a), 2);
421
422 $a = "\x{100}\x{101}";
423 $a =~ s/\x{101}/\xFF\xFF\xFF/;
424 like($a, qr/\xFF\xFF\xFF/);
425 is(length($a), 4);
426
427 $a = "\x{100}\x{101}";
428 $a =~ s/\x{101}/"\xFF\xFF\xFF"/e;
429 like($a, qr/\xFF\xFF\xFF/);
430 is(length($a), 4);
431
432 $a = "\xFF\x{101}";
433 $a =~ s/\xFF/\x{100}/;
434 like($a, qr/\x{100}/);
435 is(length($a), 2);
436
437 $a = "\xFF\x{101}";
438 $a =~ s/\xFF/"\x{100}"/e;
439 like($a, qr/\x{100}/);
440 is(length($a), 2);
441
442 $a = "\xFF";
443 $a =~ s/\xFF/\x{100}/;
444 like($a, qr/\x{100}/);
445 is(length($a), 1);
446
447 $a = "\xFF";
448 $a =~ s/\xFF/"\x{100}"/e;
449 like($a, qr/\x{100}/);
450 is(length($a), 1);
451}
d6d0e86e 452
453{
454 # subst with mixed utf8/non-utf8 type
455 my($ua, $ub, $uc, $ud) = ("\x{101}", "\x{102}", "\x{103}", "\x{104}");
456 my($na, $nb) = ("\x{ff}", "\x{fe}");
457 my $a = "$ua--$ub";
458 my $b;
459 ($b = $a) =~ s/--/$na/;
460 is($b, "$ua$na$ub", "s///: replace non-utf8 into utf8");
461 ($b = $a) =~ s/--/--$na--/;
462 is($b, "$ua--$na--$ub", "s///: replace long non-utf8 into utf8");
463 ($b = $a) =~ s/--/$uc/;
464 is($b, "$ua$uc$ub", "s///: replace utf8 into utf8");
465 ($b = $a) =~ s/--/--$uc--/;
466 is($b, "$ua--$uc--$ub", "s///: replace long utf8 into utf8");
467 $a = "$na--$nb";
468 ($b = $a) =~ s/--/$ua/;
469 is($b, "$na$ua$nb", "s///: replace utf8 into non-utf8");
470 ($b = $a) =~ s/--/--$ua--/;
471 is($b, "$na--$ua--$nb", "s///: replace long utf8 into non-utf8");
472
473 # now with utf8 pattern
474 $a = "$ua--$ub";
475 ($b = $a) =~ s/-($ud)?-/$na/;
476 is($b, "$ua$na$ub", "s///: replace non-utf8 into utf8 (utf8 pattern)");
477 ($b = $a) =~ s/-($ud)?-/--$na--/;
478 is($b, "$ua--$na--$ub", "s///: replace long non-utf8 into utf8 (utf8 pattern)");
479 ($b = $a) =~ s/-($ud)?-/$uc/;
480 is($b, "$ua$uc$ub", "s///: replace utf8 into utf8 (utf8 pattern)");
481 ($b = $a) =~ s/-($ud)?-/--$uc--/;
482 is($b, "$ua--$uc--$ub", "s///: replace long utf8 into utf8 (utf8 pattern)");
483 $a = "$na--$nb";
484 ($b = $a) =~ s/-($ud)?-/$ua/;
485 is($b, "$na$ua$nb", "s///: replace utf8 into non-utf8 (utf8 pattern)");
486 ($b = $a) =~ s/-($ud)?-/--$ua--/;
487 is($b, "$na--$ua--$nb", "s///: replace long utf8 into non-utf8 (utf8 pattern)");
488 ($b = $a) =~ s/-($ud)?-/$na/;
489 is($b, "$na$na$nb", "s///: replace non-utf8 into non-utf8 (utf8 pattern)");
490 ($b = $a) =~ s/-($ud)?-/--$na--/;
491 is($b, "$na--$na--$nb", "s///: replace long non-utf8 into non-utf8 (utf8 pattern)");
492}
493
6c8d78fb 494$_ = 'aaaa';
495$r = 'x';
496$s = s/a(?{})/$r/g;
f14c76ed 497is("<$_> <$s>", "<xxxx> <4>", "[perl #7806]");
6c8d78fb 498
499$_ = 'aaaa';
500$s = s/a(?{})//g;
f14c76ed 501is("<$_> <$s>", "<> <4>", "[perl #7806]");
6c8d78fb 502
f14c76ed 503# [perl #19048] Coredump in silly replacement
504{
505 local $^W = 0;
506 $_="abcdef\n";
507 s!.!!eg;
508 is($_, "\n", "[perl #19048]");
509}
510
4addbd3b 511# [perl #17757] interaction between saw_ampersand and study
512{
513 my $f = eval q{ $& };
514 $f = "xx";
515 study $f;
516 $f =~ s/x/y/g;
517 is($f, "yy", "[perl #17757]");
518}
22e13caa 519
520# [perl #20684] returned a zero count
521$_ = "1111";
522is(s/(??{1})/2/eg, 4, '#20684 s/// with (??{..}) inside');
523
83b43d92 524# [perl #20682] @- not visible in replacement
525$_ = "123";
526/(2)/; # seed @- with something else
527s/(1)(2)(3)/$#- (@-)/;
528is($_, "3 (0 0 1 2)", '#20682 @- not visible in replacement');
529
76ec6486 530# [perl #20682] $^N not visible in replacement
531$_ = "abc";
532/(a)/; s/(b)|(c)/-$^N/g;
533is($_,'a-b-c','#20682 $^N not visible in replacement');
7357df17 534
535# [perl #22351] perl bug with 'e' substitution modifier
536my $name = "chris";
537{
538 no warnings 'uninitialized';
539 $name =~ s/hr//e;
540}
541is($name, "cis", q[#22351 bug with 'e' substitution modifier]);
01b35787 542
543
544# [perl #34171] $1 didn't honour 'use bytes' in s//e
545{
546 my $s="\x{100}";
547 my $x;
548 {
549 use bytes;
550 $s=~ s/(..)/$x=$1/e
551 }
552 is(length($x), 2, '[perl #34171]');
553}
554
555
1749ea0d 556{ # [perl #27940] perlbug: [\x00-\x1f] works, [\c@-\c_] does not
557 my $c;
558
559 ($c = "\x20\c@\x30\cA\x40\cZ\x50\c_\x60") =~ s/[\c@-\c_]//g;
560 is($c, "\x20\x30\x40\x50\x60", "s/[\\c\@-\\c_]//g");
561
562 ($c = "\x20\x00\x30\x01\x40\x1A\x50\x1F\x60") =~ s/[\x00-\x1f]//g;
563 is($c, "\x20\x30\x40\x50\x60", "s/[\\x00-\\x1f]//g");
564}
3be69782 565{
f0852a51 566 $_ = "xy";
567 no warnings 'uninitialized';
568 /(((((((((x)))))))))(z)/; # clear $10
569 s/(((((((((x)))))))))(y)/${10}/;
570 is($_,"y","RT#6006: \$_ eq '$_'");
3be69782 571 $_ = "xr";
572 s/(((((((((x)))))))))(r)/fooba${10}/;
573 is($_,"foobar","RT#6006: \$_ eq '$_'");
f0852a51 574}
336b1602 575{
576 my $want=("\n" x 11).("B\n" x 11)."B";
577 $_="B";
578 our $i;
579 for $i(1..11){
580 s/^.*$/$&/gm;
581 $_="\n$_\n$&";
582 }
583 is($want,$_,"RT#17542");
584}
1749ea0d 585