5 #P = start of string Q = start of substr R = end of substr S = end of string
14 $SIG{__WARN__} = sub {
15 if ($_[0] =~ /^substr outside of string/) {
17 } elsif ($_[0] =~ /^Attempt to use reference as lvalue in substr/) {
19 } elsif ($_[0] =~ /^Use of uninitialized value/) {
26 sub ok { print (($_[1] ? "" : "not ") . "ok $_[0]\n") }
28 $FATAL_MSG = '^substr outside of string' ;
30 ok 1, substr($a,0,3) eq 'abc'; # P=Q R S
31 ok 2, substr($a,3,3) eq 'def'; # P Q R S
32 ok 3, substr($a,6,999) eq 'xyz'; # P Q S R
33 $b = substr($a,999,999) ; # warn # P R Q S
35 eval{substr($a,999,999) = "" ; };# P R Q S
36 ok 5, $@ =~ /$FATAL_MSG/;
37 ok 6, substr($a,0,-6) eq 'abc'; # P=Q R S
38 ok 7, substr($a,-3,1) eq 'x'; # P Q R S
42 ok 8, substr($a,1,3) eq 'abc' ; # P=Q R S
43 ok 9, substr($a,4,3) eq 'def' ; # P Q R S
44 ok 10, substr($a,7,999) eq 'xyz';# P Q S R
45 $b = substr($a,999,999) ; # warn # P R Q S
47 eval{substr($a,999,999) = "" ; } ; # P R Q S
48 ok 12, $@ =~ /$FATAL_MSG/;
49 ok 13, substr($a,1,-6) eq 'abc' ;# P=Q R S
50 ok 14, substr($a,-3,1) eq 'x' ; # P Q R S
54 substr($a,3,3) = 'XYZ';
55 ok 15, $a eq 'abcXYZxyz' ;
57 ok 16, $a eq 'cXYZxyz' ;
58 substr($a,0,0) = 'ab';
59 ok 17, $a eq 'abcXYZxyz' ;
60 substr($a,0,0) = '12345678';
61 ok 18, $a eq '12345678abcXYZxyz' ;
62 substr($a,-3,3) = 'def';
63 ok 19, $a eq '12345678abcXYZdef';
64 substr($a,-3,3) = '<';
65 ok 20, $a eq '12345678abcXYZ<' ;
66 substr($a,-1,1) = '12345678';
67 ok 21, $a eq '12345678abcXYZ12345678' ;
71 ok 22, substr($a,6) eq 'xyz' ; # P Q R=S
72 ok 23, substr($a,-3) eq 'xyz' ; # P Q R=S
73 $b = substr($a,999,999) ; # warning # P R=S Q
75 eval{substr($a,999,999) = "" ; } ; # P R=S Q
76 ok 25, $@ =~ /$FATAL_MSG/;
77 ok 26, substr($a,0) eq 'abcdefxyz' ; # P=Q R=S
78 ok 27, substr($a,9) eq '' ; # P Q=R=S
79 ok 28, substr($a,-11) eq 'abcdefxyz'; # Q P R=S
80 ok 29, substr($a,-9) eq 'abcdefxyz'; # P=Q R=S
84 $b = substr($a,-7, 1) ; # warn # Q R P S
86 eval{substr($a,-7, 1) = "" ; }; # Q R P S
87 ok 31, $@ =~ /$FATAL_MSG/;
88 $b = substr($a,-7,-6) ; # warn # Q R P S
90 eval{substr($a,-7,-6) = "" ; }; # Q R P S
91 ok 33, $@ =~ /$FATAL_MSG/;
92 ok 34, substr($a,-5,-7) eq ''; # R P=Q S
93 ok 35, substr($a, 2,-7) eq ''; # R P Q S
94 ok 36, substr($a,-3,-7) eq ''; # R P Q S
95 ok 37, substr($a, 2,-5) eq ''; # P=R Q S
96 ok 38, substr($a,-3,-5) eq ''; # P=R Q S
97 ok 39, substr($a, 2,-4) eq ''; # P R Q S
98 ok 40, substr($a,-3,-4) eq ''; # P R Q S
99 ok 41, substr($a, 5,-6) eq ''; # R P Q=S
100 ok 42, substr($a, 5,-5) eq ''; # P=R Q S
101 ok 43, substr($a, 5,-3) eq ''; # P R Q=S
102 $b = substr($a, 7,-7) ; # warn # R P S Q
104 eval{substr($a, 7,-7) = "" ; }; # R P S Q
105 ok 45, $@ =~ /$FATAL_MSG/;
106 $b = substr($a, 7,-5) ; # warn # P=R S Q
108 eval{substr($a, 7,-5) = "" ; }; # P=R S Q
109 ok 47, $@ =~ /$FATAL_MSG/;
110 $b = substr($a, 7,-3) ; # warn # P Q S Q
112 eval{substr($a, 7,-3) = "" ; }; # P Q S Q
113 ok 49, $@ =~ /$FATAL_MSG/;
114 $b = substr($a, 7, 0) ; # warn # P S Q=R
116 eval{substr($a, 7, 0) = "" ; }; # P S Q=R
117 ok 51, $@ =~ /$FATAL_MSG/;
119 ok 52, substr($a,-7,2) eq ''; # Q P=R S
120 ok 53, substr($a,-7,4) eq '54'; # Q P R S
121 ok 54, substr($a,-7,7) eq '54321';# Q P R=S
122 ok 55, substr($a,-7,9) eq '54321';# Q P S R
123 ok 56, substr($a,-5,0) eq ''; # P=Q=R S
124 ok 57, substr($a,-5,3) eq '543';# P=Q R S
125 ok 58, substr($a,-5,5) eq '54321';# P=Q R=S
126 ok 59, substr($a,-5,7) eq '54321';# P=Q S R
127 ok 60, substr($a,-3,0) eq ''; # P Q=R S
128 ok 61, substr($a,-3,3) eq '321';# P Q R=S
129 ok 62, substr($a,-2,3) eq '21'; # P Q S R
130 ok 63, substr($a,0,-5) eq ''; # P=Q=R S
131 ok 64, substr($a,2,-3) eq ''; # P Q=R S
132 ok 65, substr($a,0,0) eq ''; # P=Q=R S
133 ok 66, substr($a,0,5) eq '54321';# P=Q R=S
134 ok 67, substr($a,0,7) eq '54321';# P=Q S R
135 ok 68, substr($a,2,0) eq ''; # P Q=R S
136 ok 69, substr($a,2,3) eq '321'; # P Q R=S
137 ok 70, substr($a,5,0) eq ''; # P Q=R=S
138 ok 71, substr($a,5,2) eq ''; # P Q=S R
139 ok 72, substr($a,-7,-5) eq ''; # Q P=R S
140 ok 73, substr($a,-7,-2) eq '543';# Q P R S
141 ok 74, substr($a,-5,-5) eq ''; # P=Q=R S
142 ok 75, substr($a,-5,-2) eq '543';# P=Q R S
143 ok 76, substr($a,-3,-3) eq ''; # P Q=R S
144 ok 77, substr($a,-3,-1) eq '32';# P Q R S
148 ok 78, substr($a,-2,2) eq ''; # Q P=R=S
149 ok 79, substr($a,0,0) eq ''; # P=Q=R=S
150 ok 80, substr($a,0,1) eq ''; # P=Q=S R
151 ok 81, substr($a,-2,3) eq ''; # Q P=S R
152 ok 82, substr($a,-2) eq ''; # Q P=R=S
153 ok 83, substr($a,0) eq ''; # P=Q=R=S
156 ok 84, substr($a,0,-1) eq ''; # R P=Q=S
157 $b = substr($a,-2, 0) ; # warn # Q=R P=S
159 eval{substr($a,-2, 0) = "" ; }; # Q=R P=S
160 ok 86, $@ =~ /$FATAL_MSG/;
162 $b = substr($a,-2, 1) ; # warn # Q R P=S
164 eval{substr($a,-2, 1) = "" ; }; # Q R P=S
165 ok 88, $@ =~ /$FATAL_MSG/;
167 $b = substr($a,-2,-1) ; # warn # Q R P=S
169 eval{substr($a,-2,-1) = "" ; }; # Q R P=S
170 ok 90, $@ =~ /$FATAL_MSG/;
172 $b = substr($a,-2,-2) ; # warn # Q=R P=S
174 eval{substr($a,-2,-2) = "" ; }; # Q=R P=S
175 ok 92, $@ =~ /$FATAL_MSG/;
177 $b = substr($a, 1,-2) ; # warn # R P=S Q
179 eval{substr($a, 1,-2) = "" ; }; # R P=S Q
180 ok 94, $@ =~ /$FATAL_MSG/;
182 $b = substr($a, 1, 1) ; # warn # P=S Q R
184 eval{substr($a, 1, 1) = "" ; }; # P=S Q R
185 ok 96, $@ =~ /$FATAL_MSG/;
187 $b = substr($a, 1, 0) ;# warn # P=S Q=R
189 eval{substr($a, 1, 0) = "" ; }; # P=S Q=R
190 ok 98, $@ =~ /$FATAL_MSG/;
192 $b = substr($a,1) ; # warning # P=R=S Q
194 eval{substr($a,1) = "" ; }; # P=R=S Q
195 ok 100, $@ =~ /$FATAL_MSG/;
199 ok 101, $a eq 'zxcvbnm';
201 ok 102, $a eq 'zxcvbnm';
203 ok 103, $a eq 'zxcvbnm';
204 substr($a,0,2) = 'pq';
205 ok 104, $a eq 'pqcvbnm';
206 substr($a,2,0) = 'r';
207 ok 105, $a eq 'pqrcvbnm';
208 substr($a,8,0) = 'asd';
209 ok 106, $a eq 'pqrcvbnmasd';
210 substr($a,0,2) = 'iop';
211 ok 107, $a eq 'ioprcvbnmasd';
212 substr($a,0,5) = 'fgh';
213 ok 108, $a eq 'fghvbnmasd';
214 substr($a,3,5) = 'jkl';
215 ok 109, $a eq 'fghjklsd';
216 substr($a,3,2) = '1234';
217 ok 110, $a eq 'fgh1234lsd';
220 # with lexicals (and in re-entered scopes)
225 substr($txt, -1) = "X";
226 ok 111, $txt eq "FoX";
229 substr($txt, 0, 1) = "X";
235 # coercion of references
238 substr($s, 0, 1) = 'Foo';
239 ok 113, substr($s,0,7) eq "FooRRAY" && !($w-=2);
242 # check no spurious warnings
245 # check new 4 arg replacement syntax
248 ok 115, substr($a, 0, 3, "") eq "abc" && $a eq "xyz";
249 ok 116, substr($a, 0, 0, "abc") eq "" && $a eq "abcxyz";
250 ok 117, substr($a, 3, -1, "") eq "xy" && $a eq "abcz";
252 ok 118, substr($a, 3, undef, "xy") eq "" && $a eq "abcxyz"
257 ok 119, substr($a, 3, 9999999, "") eq "xyz" && $a eq "abc";
258 eval{substr($a, -99, 0, "") };
259 ok 120, $@ =~ /$FATAL_MSG/;
260 eval{substr($a, 99, 3, "") };
261 ok 121, $@ =~ /$FATAL_MSG/;
263 substr($a, 0, length($a), "foo");
264 ok 122, $a eq "foo" && !$w;
266 # using 4 arg substr as lvalue is a compile time error
267 eval 'substr($a,0,0,"") = "abc"';
268 ok 123, $@ && $@ =~ /Can't modify substr/ && $a eq "foo";
271 ok 124, sub { shift }->(substr($a, 0, 4, "xxxx")) eq 'abcd';
272 ok 125, $a eq 'xxxxefgh';
282 my $x = substr("a\x{263a}b",0);
283 ok 127, length($x) == 3;
285 ok 128, $x eq "\x{263a}";
287 ok 129, length($x) == 2;
288 substr($x,0,1) = "abcd";
289 ok 130, $x eq "abcd\x{263a}";
290 ok 131, length($x) == 5;
292 ok 132, length($x) == 5;
293 ok 133, $x eq "\x{263a}dcba";
296 $z = "21\x{263a}" . $z;
297 ok 134, length($z) == 5;
298 ok 135, $z eq "21\x{263a}10";
301 # replacement should work on magical values
304 tie $data{'a'}, 'Tie::StdScalar'; # makes $data{'a'} magical
305 $data{a} = "firstlast";
306 ok 136, substr($data{'a'}, 0, 5, "") eq "first" && $data{'a'} eq "last";
310 # The following two originally from Ignasi Roca.
313 substr($x, 0, 1) = "\x{100}"; # Ignasi had \x{FF}
314 ok 137, length($x) == 3 &&
315 $x eq "\x{100}\xF2\xF3" &&
316 substr($x, 0, 1) eq "\x{100}" &&
317 substr($x, 1, 1) eq "\x{F2}" &&
318 substr($x, 2, 1) eq "\x{F3}";
321 substr($x, 0, 1) = "\x{100}\x{FF}"; # Ignasi had \x{FF}
322 ok 138, length($x) == 4 &&
323 $x eq "\x{100}\x{FF}\xF2\xF3" &&
324 substr($x, 0, 1) eq "\x{100}" &&
325 substr($x, 1, 1) eq "\x{FF}" &&
326 substr($x, 2, 1) eq "\x{F2}" &&
327 substr($x, 3, 1) eq "\x{F3}";
329 # more utf8 lval exercise
332 substr($x, 0, 2) = "\x{100}\xFF";
333 ok 139, length($x) == 3 &&
334 $x eq "\x{100}\xFF\xF3" &&
335 substr($x, 0, 1) eq "\x{100}" &&
336 substr($x, 1, 1) eq "\x{FF}" &&
337 substr($x, 2, 1) eq "\x{F3}";
340 substr($x, 1, 1) = "\x{100}\xFF";
341 ok 140, length($x) == 4 &&
342 $x eq "\xF1\x{100}\xFF\xF3" &&
343 substr($x, 0, 1) eq "\x{F1}" &&
344 substr($x, 1, 1) eq "\x{100}" &&
345 substr($x, 2, 1) eq "\x{FF}" &&
346 substr($x, 3, 1) eq "\x{F3}";
349 substr($x, 2, 1) = "\x{100}\xFF";
350 ok 141, length($x) == 4 &&
351 $x eq "\xF1\xF2\x{100}\xFF" &&
352 substr($x, 0, 1) eq "\x{F1}" &&
353 substr($x, 1, 1) eq "\x{F2}" &&
354 substr($x, 2, 1) eq "\x{100}" &&
355 substr($x, 3, 1) eq "\x{FF}";
358 substr($x, 3, 1) = "\x{100}\xFF";
359 ok 142, length($x) == 5 &&
360 $x eq "\xF1\xF2\xF3\x{100}\xFF" &&
361 substr($x, 0, 1) eq "\x{F1}" &&
362 substr($x, 1, 1) eq "\x{F2}" &&
363 substr($x, 2, 1) eq "\x{F3}" &&
364 substr($x, 3, 1) eq "\x{100}" &&
365 substr($x, 4, 1) eq "\x{FF}";
368 substr($x, -1, 1) = "\x{100}\xFF";
369 ok 143, length($x) == 4 &&
370 $x eq "\xF1\xF2\x{100}\xFF" &&
371 substr($x, 0, 1) eq "\x{F1}" &&
372 substr($x, 1, 1) eq "\x{F2}" &&
373 substr($x, 2, 1) eq "\x{100}" &&
374 substr($x, 3, 1) eq "\x{FF}";
377 substr($x, -1, 0) = "\x{100}\xFF";
378 ok 144, length($x) == 5 &&
379 $x eq "\xF1\xF2\x{100}\xFF\xF3" &&
380 substr($x, 0, 1) eq "\x{F1}" &&
381 substr($x, 1, 1) eq "\x{F2}" &&
382 substr($x, 2, 1) eq "\x{100}" &&
383 substr($x, 3, 1) eq "\x{FF}" &&
384 substr($x, 4, 1) eq "\x{F3}";
387 substr($x, 0, -1) = "\x{100}\xFF";
388 ok 145, length($x) == 3 &&
389 $x eq "\x{100}\xFF\xF3" &&
390 substr($x, 0, 1) eq "\x{100}" &&
391 substr($x, 1, 1) eq "\x{FF}" &&
392 substr($x, 2, 1) eq "\x{F3}";
395 substr($x, 0, -2) = "\x{100}\xFF";
396 ok 146, length($x) == 4 &&
397 $x eq "\x{100}\xFF\xF2\xF3" &&
398 substr($x, 0, 1) eq "\x{100}" &&
399 substr($x, 1, 1) eq "\x{FF}" &&
400 substr($x, 2, 1) eq "\x{F2}" &&
401 substr($x, 3, 1) eq "\x{F3}";
404 substr($x, 0, -3) = "\x{100}\xFF";
405 ok 147, length($x) == 5 &&
406 $x eq "\x{100}\xFF\xF1\xF2\xF3" &&
407 substr($x, 0, 1) eq "\x{100}" &&
408 substr($x, 1, 1) eq "\x{FF}" &&
409 substr($x, 2, 1) eq "\x{F1}" &&
410 substr($x, 3, 1) eq "\x{F2}" &&
411 substr($x, 4, 1) eq "\x{F3}";
414 substr($x, 1, -1) = "\x{100}\xFF";
415 ok 148, length($x) == 4 &&
416 $x eq "\xF1\x{100}\xFF\xF3" &&
417 substr($x, 0, 1) eq "\x{F1}" &&
418 substr($x, 1, 1) eq "\x{100}" &&
419 substr($x, 2, 1) eq "\x{FF}" &&
420 substr($x, 3, 1) eq "\x{F3}";
423 substr($x, -1, -1) = "\x{100}\xFF";
424 ok 149, length($x) == 5 &&
425 $x eq "\xF1\xF2\x{100}\xFF\xF3" &&
426 substr($x, 0, 1) eq "\x{F1}" &&
427 substr($x, 1, 1) eq "\x{F2}" &&
428 substr($x, 2, 1) eq "\x{100}" &&
429 substr($x, 3, 1) eq "\x{FF}" &&
430 substr($x, 4, 1) eq "\x{F3}";
432 # And tests for already-UTF8 one
434 $x = "\x{101}\x{F2}\x{F3}";
435 substr($x, 0, 1) = "\x{100}";
436 ok 150, length($x) == 3 &&
437 $x eq "\x{100}\xF2\xF3" &&
438 substr($x, 0, 1) eq "\x{100}" &&
439 substr($x, 1, 1) eq "\x{F2}" &&
440 substr($x, 2, 1) eq "\x{F3}";
442 $x = "\x{101}\x{F2}\x{F3}";
443 substr($x, 0, 1) = "\x{100}\x{FF}";
444 ok 151, length($x) == 4 &&
445 $x eq "\x{100}\x{FF}\xF2\xF3" &&
446 substr($x, 0, 1) eq "\x{100}" &&
447 substr($x, 1, 1) eq "\x{FF}" &&
448 substr($x, 2, 1) eq "\x{F2}" &&
449 substr($x, 3, 1) eq "\x{F3}";
451 $x = "\x{101}\x{F2}\x{F3}";
452 substr($x, 0, 2) = "\x{100}\xFF";
453 ok 152, length($x) == 3 &&
454 $x eq "\x{100}\xFF\xF3" &&
455 substr($x, 0, 1) eq "\x{100}" &&
456 substr($x, 1, 1) eq "\x{FF}" &&
457 substr($x, 2, 1) eq "\x{F3}";
459 $x = "\x{101}\x{F2}\x{F3}";
460 substr($x, 1, 1) = "\x{100}\xFF";
461 ok 153, length($x) == 4 &&
462 $x eq "\x{101}\x{100}\xFF\xF3" &&
463 substr($x, 0, 1) eq "\x{101}" &&
464 substr($x, 1, 1) eq "\x{100}" &&
465 substr($x, 2, 1) eq "\x{FF}" &&
466 substr($x, 3, 1) eq "\x{F3}";
468 $x = "\x{101}\x{F2}\x{F3}";
469 substr($x, 2, 1) = "\x{100}\xFF";
470 ok 154, length($x) == 4 &&
471 $x eq "\x{101}\xF2\x{100}\xFF" &&
472 substr($x, 0, 1) eq "\x{101}" &&
473 substr($x, 1, 1) eq "\x{F2}" &&
474 substr($x, 2, 1) eq "\x{100}" &&
475 substr($x, 3, 1) eq "\x{FF}";
477 $x = "\x{101}\x{F2}\x{F3}";
478 substr($x, 3, 1) = "\x{100}\xFF";
479 ok 155, length($x) == 5 &&
480 $x eq "\x{101}\x{F2}\x{F3}\x{100}\xFF" &&
481 substr($x, 0, 1) eq "\x{101}" &&
482 substr($x, 1, 1) eq "\x{F2}" &&
483 substr($x, 2, 1) eq "\x{F3}" &&
484 substr($x, 3, 1) eq "\x{100}" &&
485 substr($x, 4, 1) eq "\x{FF}";
487 $x = "\x{101}\x{F2}\x{F3}";
488 substr($x, -1, 1) = "\x{100}\xFF";
489 ok 156, length($x) == 4 &&
490 $x eq "\x{101}\xF2\x{100}\xFF" &&
491 substr($x, 0, 1) eq "\x{101}" &&
492 substr($x, 1, 1) eq "\x{F2}" &&
493 substr($x, 2, 1) eq "\x{100}" &&
494 substr($x, 3, 1) eq "\x{FF}";
496 $x = "\x{101}\x{F2}\x{F3}";
497 substr($x, -1, 0) = "\x{100}\xFF";
498 ok 157, length($x) == 5 &&
499 $x eq "\x{101}\xF2\x{100}\xFF\xF3" &&
500 substr($x, 0, 1) eq "\x{101}" &&
501 substr($x, 1, 1) eq "\x{F2}" &&
502 substr($x, 2, 1) eq "\x{100}" &&
503 substr($x, 3, 1) eq "\x{FF}" &&
504 substr($x, 4, 1) eq "\x{F3}";
506 $x = "\x{101}\x{F2}\x{F3}";
507 substr($x, 0, -1) = "\x{100}\xFF";
508 ok 158, length($x) == 3 &&
509 $x eq "\x{100}\xFF\xF3" &&
510 substr($x, 0, 1) eq "\x{100}" &&
511 substr($x, 1, 1) eq "\x{FF}" &&
512 substr($x, 2, 1) eq "\x{F3}";
514 $x = "\x{101}\x{F2}\x{F3}";
515 substr($x, 0, -2) = "\x{100}\xFF";
516 ok 159, length($x) == 4 &&
517 $x eq "\x{100}\xFF\xF2\xF3" &&
518 substr($x, 0, 1) eq "\x{100}" &&
519 substr($x, 1, 1) eq "\x{FF}" &&
520 substr($x, 2, 1) eq "\x{F2}" &&
521 substr($x, 3, 1) eq "\x{F3}";
523 $x = "\x{101}\x{F2}\x{F3}";
524 substr($x, 0, -3) = "\x{100}\xFF";
525 ok 160, length($x) == 5 &&
526 $x eq "\x{100}\xFF\x{101}\x{F2}\x{F3}" &&
527 substr($x, 0, 1) eq "\x{100}" &&
528 substr($x, 1, 1) eq "\x{FF}" &&
529 substr($x, 2, 1) eq "\x{101}" &&
530 substr($x, 3, 1) eq "\x{F2}" &&
531 substr($x, 4, 1) eq "\x{F3}";
533 $x = "\x{101}\x{F2}\x{F3}";
534 substr($x, 1, -1) = "\x{100}\xFF";
535 ok 161, length($x) == 4 &&
536 $x eq "\x{101}\x{100}\xFF\xF3" &&
537 substr($x, 0, 1) eq "\x{101}" &&
538 substr($x, 1, 1) eq "\x{100}" &&
539 substr($x, 2, 1) eq "\x{FF}" &&
540 substr($x, 3, 1) eq "\x{F3}";
542 $x = "\x{101}\x{F2}\x{F3}";
543 substr($x, -1, -1) = "\x{100}\xFF";
544 ok 162, length($x) == 5 &&
545 $x eq "\x{101}\xF2\x{100}\xFF\xF3" &&
546 substr($x, 0, 1) eq "\x{101}" &&
547 substr($x, 1, 1) eq "\x{F2}" &&
548 substr($x, 2, 1) eq "\x{100}" &&
549 substr($x, 3, 1) eq "\x{FF}" &&
550 substr($x, 4, 1) eq "\x{F3}";
552 substr($x = "ab", 0, 0, "\x{100}\x{200}");
553 ok 163, $x eq "\x{100}\x{200}ab";
555 substr($x = "\x{100}\x{200}", 0, 0, "ab");
556 ok 164, $x eq "ab\x{100}\x{200}";
558 substr($x = "ab", 1, 0, "\x{100}\x{200}");
559 ok 165, $x eq "a\x{100}\x{200}b";
561 substr($x = "\x{100}\x{200}", 1, 0, "ab");
562 ok 166, $x eq "\x{100}ab\x{200}";
564 substr($x = "ab", 2, 0, "\x{100}\x{200}");
565 ok 167, $x eq "ab\x{100}\x{200}";
567 substr($x = "\x{100}\x{200}", 2, 0, "ab");
568 ok 168, $x eq "\x{100}\x{200}ab";
570 substr($x = "\xFFb", 0, 0, "\x{100}\x{200}");
571 ok 169, $x eq "\x{100}\x{200}\xFFb";
573 substr($x = "\x{100}\x{200}", 0, 0, "\xFFb");
574 ok 170, $x eq "\xFFb\x{100}\x{200}";
576 substr($x = "\xFFb", 1, 0, "\x{100}\x{200}");
577 ok 171, $x eq "\xFF\x{100}\x{200}b";
579 substr($x = "\x{100}\x{200}", 1, 0, "\xFFb");
580 ok 172, $x eq "\x{100}\xFFb\x{200}";
582 substr($x = "\xFFb", 2, 0, "\x{100}\x{200}");
583 ok 173, $x eq "\xFFb\x{100}\x{200}";
585 substr($x = "\x{100}\x{200}", 2, 0, "\xFFb");
586 ok 174, $x eq "\x{100}\x{200}\xFFb";
592 $r[$_] = \ substr $s, $_, 1 for (0, 1);
593 ok 175, join("", map { $$_ } @r) eq "ab";