xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/t/op/substr.t (revision 0:68f95e015346)
1*0Sstevel@tonic-gate#!./perl
2*0Sstevel@tonic-gate
3*0Sstevel@tonic-gateprint "1..180\n";
4*0Sstevel@tonic-gate
5*0Sstevel@tonic-gate#P = start of string  Q = start of substr  R = end of substr  S = end of string
6*0Sstevel@tonic-gate
7*0Sstevel@tonic-gateBEGIN {
8*0Sstevel@tonic-gate    chdir 't' if -d 't';
9*0Sstevel@tonic-gate    @INC = '../lib';
10*0Sstevel@tonic-gate}
11*0Sstevel@tonic-gateuse warnings ;
12*0Sstevel@tonic-gate
13*0Sstevel@tonic-gate$a = 'abcdefxyz';
14*0Sstevel@tonic-gate$SIG{__WARN__} = sub {
15*0Sstevel@tonic-gate     if ($_[0] =~ /^substr outside of string/) {
16*0Sstevel@tonic-gate          $w++;
17*0Sstevel@tonic-gate     } elsif ($_[0] =~ /^Attempt to use reference as lvalue in substr/) {
18*0Sstevel@tonic-gate          $w += 2;
19*0Sstevel@tonic-gate     } elsif ($_[0] =~ /^Use of uninitialized value/) {
20*0Sstevel@tonic-gate          $w += 3;
21*0Sstevel@tonic-gate     } else {
22*0Sstevel@tonic-gate          warn $_[0];
23*0Sstevel@tonic-gate     }
24*0Sstevel@tonic-gate};
25*0Sstevel@tonic-gate
26*0Sstevel@tonic-gatesub ok { print (($_[1] ? "" : "not ") . "ok $_[0]\n") }
27*0Sstevel@tonic-gate
28*0Sstevel@tonic-gate$FATAL_MSG = '^substr outside of string' ;
29*0Sstevel@tonic-gate
30*0Sstevel@tonic-gateok 1, substr($a,0,3) eq 'abc';   # P=Q R S
31*0Sstevel@tonic-gateok 2, substr($a,3,3) eq 'def';   # P Q R S
32*0Sstevel@tonic-gateok 3, substr($a,6,999) eq 'xyz'; # P Q S R
33*0Sstevel@tonic-gate$b = substr($a,999,999) ; # warn # P R Q S
34*0Sstevel@tonic-gateok 4, $w-- == 1 ;
35*0Sstevel@tonic-gateeval{substr($a,999,999) = "" ; };# P R Q S
36*0Sstevel@tonic-gateok 5, $@ =~ /$FATAL_MSG/;
37*0Sstevel@tonic-gateok 6, substr($a,0,-6) eq 'abc';  # P=Q R S
38*0Sstevel@tonic-gateok 7, substr($a,-3,1) eq 'x';    # P Q R S
39*0Sstevel@tonic-gate
40*0Sstevel@tonic-gate$[ = 1;
41*0Sstevel@tonic-gate
42*0Sstevel@tonic-gateok 8, substr($a,1,3) eq 'abc' ;  # P=Q R S
43*0Sstevel@tonic-gateok 9, substr($a,4,3) eq 'def' ;  # P Q R S
44*0Sstevel@tonic-gateok 10, substr($a,7,999) eq 'xyz';# P Q S R
45*0Sstevel@tonic-gate$b = substr($a,999,999) ; # warn # P R Q S
46*0Sstevel@tonic-gateok 11, $w-- == 1 ;
47*0Sstevel@tonic-gateeval{substr($a,999,999) = "" ; } ; # P R Q S
48*0Sstevel@tonic-gateok 12, $@ =~ /$FATAL_MSG/;
49*0Sstevel@tonic-gateok 13, substr($a,1,-6) eq 'abc' ;# P=Q R S
50*0Sstevel@tonic-gateok 14, substr($a,-3,1) eq 'x' ;  # P Q R S
51*0Sstevel@tonic-gate
52*0Sstevel@tonic-gate$[ = 0;
53*0Sstevel@tonic-gate
54*0Sstevel@tonic-gatesubstr($a,3,3) = 'XYZ';
55*0Sstevel@tonic-gateok 15, $a eq 'abcXYZxyz' ;
56*0Sstevel@tonic-gatesubstr($a,0,2) = '';
57*0Sstevel@tonic-gateok 16, $a eq 'cXYZxyz' ;
58*0Sstevel@tonic-gatesubstr($a,0,0) = 'ab';
59*0Sstevel@tonic-gateok 17, $a eq 'abcXYZxyz' ;
60*0Sstevel@tonic-gatesubstr($a,0,0) = '12345678';
61*0Sstevel@tonic-gateok 18, $a eq '12345678abcXYZxyz' ;
62*0Sstevel@tonic-gatesubstr($a,-3,3) = 'def';
63*0Sstevel@tonic-gateok 19, $a eq '12345678abcXYZdef';
64*0Sstevel@tonic-gatesubstr($a,-3,3) = '<';
65*0Sstevel@tonic-gateok 20, $a eq '12345678abcXYZ<' ;
66*0Sstevel@tonic-gatesubstr($a,-1,1) = '12345678';
67*0Sstevel@tonic-gateok 21, $a eq '12345678abcXYZ12345678' ;
68*0Sstevel@tonic-gate
69*0Sstevel@tonic-gate$a = 'abcdefxyz';
70*0Sstevel@tonic-gate
71*0Sstevel@tonic-gateok 22, substr($a,6) eq 'xyz' ;        # P Q R=S
72*0Sstevel@tonic-gateok 23, substr($a,-3) eq 'xyz' ;       # P Q R=S
73*0Sstevel@tonic-gate$b = substr($a,999,999) ; # warning   # P R=S Q
74*0Sstevel@tonic-gateok 24, $w-- == 1 ;
75*0Sstevel@tonic-gateeval{substr($a,999,999) = "" ; } ;    # P R=S Q
76*0Sstevel@tonic-gateok 25, $@ =~ /$FATAL_MSG/;
77*0Sstevel@tonic-gateok 26, substr($a,0) eq 'abcdefxyz' ;  # P=Q R=S
78*0Sstevel@tonic-gateok 27, substr($a,9) eq '' ;           # P Q=R=S
79*0Sstevel@tonic-gateok 28, substr($a,-11) eq 'abcdefxyz'; # Q P R=S
80*0Sstevel@tonic-gateok 29, substr($a,-9) eq 'abcdefxyz';  # P=Q R=S
81*0Sstevel@tonic-gate
82*0Sstevel@tonic-gate$a = '54321';
83*0Sstevel@tonic-gate
84*0Sstevel@tonic-gate$b = substr($a,-7, 1) ; # warn  # Q R P S
85*0Sstevel@tonic-gateok 30, $w-- == 1 ;
86*0Sstevel@tonic-gateeval{substr($a,-7, 1) = "" ; }; # Q R P S
87*0Sstevel@tonic-gateok 31, $@ =~ /$FATAL_MSG/;
88*0Sstevel@tonic-gate$b = substr($a,-7,-6) ; # warn  # Q R P S
89*0Sstevel@tonic-gateok 32, $w-- == 1 ;
90*0Sstevel@tonic-gateeval{substr($a,-7,-6) = "" ; }; # Q R P S
91*0Sstevel@tonic-gateok 33, $@ =~ /$FATAL_MSG/;
92*0Sstevel@tonic-gateok 34, substr($a,-5,-7) eq '';  # R P=Q S
93*0Sstevel@tonic-gateok 35, substr($a, 2,-7) eq '';  # R P Q S
94*0Sstevel@tonic-gateok 36, substr($a,-3,-7) eq '';  # R P Q S
95*0Sstevel@tonic-gateok 37, substr($a, 2,-5) eq '';  # P=R Q S
96*0Sstevel@tonic-gateok 38, substr($a,-3,-5) eq '';  # P=R Q S
97*0Sstevel@tonic-gateok 39, substr($a, 2,-4) eq '';  # P R Q S
98*0Sstevel@tonic-gateok 40, substr($a,-3,-4) eq '';  # P R Q S
99*0Sstevel@tonic-gateok 41, substr($a, 5,-6) eq '';  # R P Q=S
100*0Sstevel@tonic-gateok 42, substr($a, 5,-5) eq '';  # P=R Q S
101*0Sstevel@tonic-gateok 43, substr($a, 5,-3) eq '';  # P R Q=S
102*0Sstevel@tonic-gate$b = substr($a, 7,-7) ; # warn  # R P S Q
103*0Sstevel@tonic-gateok 44, $w-- == 1 ;
104*0Sstevel@tonic-gateeval{substr($a, 7,-7) = "" ; }; # R P S Q
105*0Sstevel@tonic-gateok 45, $@ =~ /$FATAL_MSG/;
106*0Sstevel@tonic-gate$b = substr($a, 7,-5) ; # warn  # P=R S Q
107*0Sstevel@tonic-gateok 46, $w-- == 1 ;
108*0Sstevel@tonic-gateeval{substr($a, 7,-5) = "" ; }; # P=R S Q
109*0Sstevel@tonic-gateok 47, $@ =~ /$FATAL_MSG/;
110*0Sstevel@tonic-gate$b = substr($a, 7,-3) ; # warn  # P Q S Q
111*0Sstevel@tonic-gateok 48, $w-- == 1 ;
112*0Sstevel@tonic-gateeval{substr($a, 7,-3) = "" ; }; # P Q S Q
113*0Sstevel@tonic-gateok 49, $@ =~ /$FATAL_MSG/;
114*0Sstevel@tonic-gate$b = substr($a, 7, 0) ; # warn  # P S Q=R
115*0Sstevel@tonic-gateok 50, $w-- == 1 ;
116*0Sstevel@tonic-gateeval{substr($a, 7, 0) = "" ; }; # P S Q=R
117*0Sstevel@tonic-gateok 51, $@ =~ /$FATAL_MSG/;
118*0Sstevel@tonic-gate
119*0Sstevel@tonic-gateok 52, substr($a,-7,2) eq '';   # Q P=R S
120*0Sstevel@tonic-gateok 53, substr($a,-7,4) eq '54'; # Q P R S
121*0Sstevel@tonic-gateok 54, substr($a,-7,7) eq '54321';# Q P R=S
122*0Sstevel@tonic-gateok 55, substr($a,-7,9) eq '54321';# Q P S R
123*0Sstevel@tonic-gateok 56, substr($a,-5,0) eq '';   # P=Q=R S
124*0Sstevel@tonic-gateok 57, substr($a,-5,3) eq '543';# P=Q R S
125*0Sstevel@tonic-gateok 58, substr($a,-5,5) eq '54321';# P=Q R=S
126*0Sstevel@tonic-gateok 59, substr($a,-5,7) eq '54321';# P=Q S R
127*0Sstevel@tonic-gateok 60, substr($a,-3,0) eq '';   # P Q=R S
128*0Sstevel@tonic-gateok 61, substr($a,-3,3) eq '321';# P Q R=S
129*0Sstevel@tonic-gateok 62, substr($a,-2,3) eq '21'; # P Q S R
130*0Sstevel@tonic-gateok 63, substr($a,0,-5) eq '';   # P=Q=R S
131*0Sstevel@tonic-gateok 64, substr($a,2,-3) eq '';   # P Q=R S
132*0Sstevel@tonic-gateok 65, substr($a,0,0) eq '';    # P=Q=R S
133*0Sstevel@tonic-gateok 66, substr($a,0,5) eq '54321';# P=Q R=S
134*0Sstevel@tonic-gateok 67, substr($a,0,7) eq '54321';# P=Q S R
135*0Sstevel@tonic-gateok 68, substr($a,2,0) eq '';    # P Q=R S
136*0Sstevel@tonic-gateok 69, substr($a,2,3) eq '321'; # P Q R=S
137*0Sstevel@tonic-gateok 70, substr($a,5,0) eq '';    # P Q=R=S
138*0Sstevel@tonic-gateok 71, substr($a,5,2) eq '';    # P Q=S R
139*0Sstevel@tonic-gateok 72, substr($a,-7,-5) eq '';  # Q P=R S
140*0Sstevel@tonic-gateok 73, substr($a,-7,-2) eq '543';# Q P R S
141*0Sstevel@tonic-gateok 74, substr($a,-5,-5) eq '';  # P=Q=R S
142*0Sstevel@tonic-gateok 75, substr($a,-5,-2) eq '543';# P=Q R S
143*0Sstevel@tonic-gateok 76, substr($a,-3,-3) eq '';  # P Q=R S
144*0Sstevel@tonic-gateok 77, substr($a,-3,-1) eq '32';# P Q R S
145*0Sstevel@tonic-gate
146*0Sstevel@tonic-gate$a = '';
147*0Sstevel@tonic-gate
148*0Sstevel@tonic-gateok 78, substr($a,-2,2) eq '';   # Q P=R=S
149*0Sstevel@tonic-gateok 79, substr($a,0,0) eq '';    # P=Q=R=S
150*0Sstevel@tonic-gateok 80, substr($a,0,1) eq '';    # P=Q=S R
151*0Sstevel@tonic-gateok 81, substr($a,-2,3) eq '';   # Q P=S R
152*0Sstevel@tonic-gateok 82, substr($a,-2) eq '';     # Q P=R=S
153*0Sstevel@tonic-gateok 83, substr($a,0) eq '';      # P=Q=R=S
154*0Sstevel@tonic-gate
155*0Sstevel@tonic-gate
156*0Sstevel@tonic-gateok 84, substr($a,0,-1) eq '';   # R P=Q=S
157*0Sstevel@tonic-gate$b = substr($a,-2, 0) ; # warn  # Q=R P=S
158*0Sstevel@tonic-gateok 85, $w-- == 1 ;
159*0Sstevel@tonic-gateeval{substr($a,-2, 0) = "" ; }; # Q=R P=S
160*0Sstevel@tonic-gateok 86, $@ =~ /$FATAL_MSG/;
161*0Sstevel@tonic-gate
162*0Sstevel@tonic-gate$b = substr($a,-2, 1) ; # warn  # Q R P=S
163*0Sstevel@tonic-gateok 87, $w-- == 1 ;
164*0Sstevel@tonic-gateeval{substr($a,-2, 1) = "" ; }; # Q R P=S
165*0Sstevel@tonic-gateok 88, $@ =~ /$FATAL_MSG/;
166*0Sstevel@tonic-gate
167*0Sstevel@tonic-gate$b = substr($a,-2,-1) ; # warn  # Q R P=S
168*0Sstevel@tonic-gateok 89, $w-- == 1 ;
169*0Sstevel@tonic-gateeval{substr($a,-2,-1) = "" ; }; # Q R P=S
170*0Sstevel@tonic-gateok 90, $@ =~ /$FATAL_MSG/;
171*0Sstevel@tonic-gate
172*0Sstevel@tonic-gate$b = substr($a,-2,-2) ; # warn  # Q=R P=S
173*0Sstevel@tonic-gateok 91, $w-- == 1 ;
174*0Sstevel@tonic-gateeval{substr($a,-2,-2) = "" ; }; # Q=R P=S
175*0Sstevel@tonic-gateok 92, $@ =~ /$FATAL_MSG/;
176*0Sstevel@tonic-gate
177*0Sstevel@tonic-gate$b = substr($a, 1,-2) ; # warn  # R P=S Q
178*0Sstevel@tonic-gateok 93, $w-- == 1 ;
179*0Sstevel@tonic-gateeval{substr($a, 1,-2) = "" ; }; # R P=S Q
180*0Sstevel@tonic-gateok 94, $@ =~ /$FATAL_MSG/;
181*0Sstevel@tonic-gate
182*0Sstevel@tonic-gate$b = substr($a, 1, 1) ; # warn  # P=S Q R
183*0Sstevel@tonic-gateok 95, $w-- == 1 ;
184*0Sstevel@tonic-gateeval{substr($a, 1, 1) = "" ; }; # P=S Q R
185*0Sstevel@tonic-gateok 96, $@ =~ /$FATAL_MSG/;
186*0Sstevel@tonic-gate
187*0Sstevel@tonic-gate$b = substr($a, 1, 0) ;# warn   # P=S Q=R
188*0Sstevel@tonic-gateok 97, $w-- == 1 ;
189*0Sstevel@tonic-gateeval{substr($a, 1, 0) = "" ; }; # P=S Q=R
190*0Sstevel@tonic-gateok 98, $@ =~ /$FATAL_MSG/;
191*0Sstevel@tonic-gate
192*0Sstevel@tonic-gate$b = substr($a,1) ; # warning   # P=R=S Q
193*0Sstevel@tonic-gateok 99, $w-- == 1 ;
194*0Sstevel@tonic-gateeval{substr($a,1) = "" ; };     # P=R=S Q
195*0Sstevel@tonic-gateok 100, $@ =~ /$FATAL_MSG/;
196*0Sstevel@tonic-gate
197*0Sstevel@tonic-gatemy $a = 'zxcvbnm';
198*0Sstevel@tonic-gatesubstr($a,2,0) = '';
199*0Sstevel@tonic-gateok 101, $a eq 'zxcvbnm';
200*0Sstevel@tonic-gatesubstr($a,7,0) = '';
201*0Sstevel@tonic-gateok 102, $a eq 'zxcvbnm';
202*0Sstevel@tonic-gatesubstr($a,5,0) = '';
203*0Sstevel@tonic-gateok 103, $a eq 'zxcvbnm';
204*0Sstevel@tonic-gatesubstr($a,0,2) = 'pq';
205*0Sstevel@tonic-gateok 104, $a eq 'pqcvbnm';
206*0Sstevel@tonic-gatesubstr($a,2,0) = 'r';
207*0Sstevel@tonic-gateok 105, $a eq 'pqrcvbnm';
208*0Sstevel@tonic-gatesubstr($a,8,0) = 'asd';
209*0Sstevel@tonic-gateok 106, $a eq 'pqrcvbnmasd';
210*0Sstevel@tonic-gatesubstr($a,0,2) = 'iop';
211*0Sstevel@tonic-gateok 107, $a eq 'ioprcvbnmasd';
212*0Sstevel@tonic-gatesubstr($a,0,5) = 'fgh';
213*0Sstevel@tonic-gateok 108, $a eq 'fghvbnmasd';
214*0Sstevel@tonic-gatesubstr($a,3,5) = 'jkl';
215*0Sstevel@tonic-gateok 109, $a eq 'fghjklsd';
216*0Sstevel@tonic-gatesubstr($a,3,2) = '1234';
217*0Sstevel@tonic-gateok 110, $a eq 'fgh1234lsd';
218*0Sstevel@tonic-gate
219*0Sstevel@tonic-gate
220*0Sstevel@tonic-gate# with lexicals (and in re-entered scopes)
221*0Sstevel@tonic-gatefor (0,1) {
222*0Sstevel@tonic-gate  my $txt;
223*0Sstevel@tonic-gate  unless ($_) {
224*0Sstevel@tonic-gate    $txt = "Foo";
225*0Sstevel@tonic-gate    substr($txt, -1) = "X";
226*0Sstevel@tonic-gate    ok 111, $txt eq "FoX";
227*0Sstevel@tonic-gate  }
228*0Sstevel@tonic-gate  else {
229*0Sstevel@tonic-gate    substr($txt, 0, 1) = "X";
230*0Sstevel@tonic-gate    ok 112, $txt eq "X";
231*0Sstevel@tonic-gate  }
232*0Sstevel@tonic-gate}
233*0Sstevel@tonic-gate
234*0Sstevel@tonic-gate$w = 0 ;
235*0Sstevel@tonic-gate# coercion of references
236*0Sstevel@tonic-gate{
237*0Sstevel@tonic-gate  my $s = [];
238*0Sstevel@tonic-gate  substr($s, 0, 1) = 'Foo';
239*0Sstevel@tonic-gate  ok 113, substr($s,0,7) eq "FooRRAY" && !($w-=2);
240*0Sstevel@tonic-gate}
241*0Sstevel@tonic-gate
242*0Sstevel@tonic-gate# check no spurious warnings
243*0Sstevel@tonic-gateok 114, $w == 0;
244*0Sstevel@tonic-gate
245*0Sstevel@tonic-gate# check new 4 arg replacement syntax
246*0Sstevel@tonic-gate$a = "abcxyz";
247*0Sstevel@tonic-gate$w = 0;
248*0Sstevel@tonic-gateok 115, substr($a, 0, 3, "") eq "abc" && $a eq "xyz";
249*0Sstevel@tonic-gateok 116, substr($a, 0, 0, "abc") eq "" && $a eq "abcxyz";
250*0Sstevel@tonic-gateok 117, substr($a, 3, -1, "") eq "xy" && $a eq "abcz";
251*0Sstevel@tonic-gate
252*0Sstevel@tonic-gateok 118, substr($a, 3, undef, "xy") eq "" && $a eq "abcxyz"
253*0Sstevel@tonic-gate                 && $w == 3;
254*0Sstevel@tonic-gate
255*0Sstevel@tonic-gate$w = 0;
256*0Sstevel@tonic-gate
257*0Sstevel@tonic-gateok 119, substr($a, 3, 9999999, "") eq "xyz" && $a eq "abc";
258*0Sstevel@tonic-gateeval{substr($a, -99, 0, "") };
259*0Sstevel@tonic-gateok 120, $@ =~ /$FATAL_MSG/;
260*0Sstevel@tonic-gateeval{substr($a, 99, 3, "") };
261*0Sstevel@tonic-gateok 121, $@ =~ /$FATAL_MSG/;
262*0Sstevel@tonic-gate
263*0Sstevel@tonic-gatesubstr($a, 0, length($a), "foo");
264*0Sstevel@tonic-gateok 122, $a eq "foo" && !$w;
265*0Sstevel@tonic-gate
266*0Sstevel@tonic-gate# using 4 arg substr as lvalue is a compile time error
267*0Sstevel@tonic-gateeval 'substr($a,0,0,"") = "abc"';
268*0Sstevel@tonic-gateok 123, $@ && $@ =~ /Can't modify substr/ && $a eq "foo";
269*0Sstevel@tonic-gate
270*0Sstevel@tonic-gate$a = "abcdefgh";
271*0Sstevel@tonic-gateok 124, sub { shift }->(substr($a, 0, 4, "xxxx")) eq 'abcd';
272*0Sstevel@tonic-gateok 125, $a eq 'xxxxefgh';
273*0Sstevel@tonic-gate
274*0Sstevel@tonic-gate{
275*0Sstevel@tonic-gate    my $y = 10;
276*0Sstevel@tonic-gate    $y = "2" . $y;
277*0Sstevel@tonic-gate    ok 126, $y+0 == 210;
278*0Sstevel@tonic-gate}
279*0Sstevel@tonic-gate
280*0Sstevel@tonic-gate# utf8 sanity
281*0Sstevel@tonic-gate{
282*0Sstevel@tonic-gate    my $x = substr("a\x{263a}b",0);
283*0Sstevel@tonic-gate    ok 127, length($x) == 3;
284*0Sstevel@tonic-gate    $x = substr($x,1,1);
285*0Sstevel@tonic-gate    ok 128, $x eq "\x{263a}";
286*0Sstevel@tonic-gate    $x = $x x 2;
287*0Sstevel@tonic-gate    ok 129, length($x) == 2;
288*0Sstevel@tonic-gate    substr($x,0,1) = "abcd";
289*0Sstevel@tonic-gate    ok 130, $x eq "abcd\x{263a}";
290*0Sstevel@tonic-gate    ok 131, length($x) == 5;
291*0Sstevel@tonic-gate    $x = reverse $x;
292*0Sstevel@tonic-gate    ok 132, length($x) == 5;
293*0Sstevel@tonic-gate    ok 133, $x eq "\x{263a}dcba";
294*0Sstevel@tonic-gate
295*0Sstevel@tonic-gate    my $z = 10;
296*0Sstevel@tonic-gate    $z = "21\x{263a}" . $z;
297*0Sstevel@tonic-gate    ok 134, length($z) == 5;
298*0Sstevel@tonic-gate    ok 135, $z eq "21\x{263a}10";
299*0Sstevel@tonic-gate}
300*0Sstevel@tonic-gate
301*0Sstevel@tonic-gate# replacement should work on magical values
302*0Sstevel@tonic-gaterequire Tie::Scalar;
303*0Sstevel@tonic-gatemy %data;
304*0Sstevel@tonic-gatetie $data{'a'}, 'Tie::StdScalar';  # makes $data{'a'} magical
305*0Sstevel@tonic-gate$data{a} = "firstlast";
306*0Sstevel@tonic-gateok 136, substr($data{'a'}, 0, 5, "") eq "first" && $data{'a'} eq "last";
307*0Sstevel@tonic-gate
308*0Sstevel@tonic-gate# more utf8
309*0Sstevel@tonic-gate
310*0Sstevel@tonic-gate# The following two originally from Ignasi Roca.
311*0Sstevel@tonic-gate
312*0Sstevel@tonic-gate$x = "\xF1\xF2\xF3";
313*0Sstevel@tonic-gatesubstr($x, 0, 1) = "\x{100}"; # Ignasi had \x{FF}
314*0Sstevel@tonic-gateok 137, length($x) == 3 &&
315*0Sstevel@tonic-gate        $x eq "\x{100}\xF2\xF3" &&
316*0Sstevel@tonic-gate        substr($x, 0, 1) eq "\x{100}" &&
317*0Sstevel@tonic-gate        substr($x, 1, 1) eq "\x{F2}" &&
318*0Sstevel@tonic-gate        substr($x, 2, 1) eq "\x{F3}";
319*0Sstevel@tonic-gate
320*0Sstevel@tonic-gate$x = "\xF1\xF2\xF3";
321*0Sstevel@tonic-gatesubstr($x, 0, 1) = "\x{100}\x{FF}"; # Ignasi had \x{FF}
322*0Sstevel@tonic-gateok 138, length($x) == 4 &&
323*0Sstevel@tonic-gate        $x eq "\x{100}\x{FF}\xF2\xF3" &&
324*0Sstevel@tonic-gate        substr($x, 0, 1) eq "\x{100}" &&
325*0Sstevel@tonic-gate        substr($x, 1, 1) eq "\x{FF}" &&
326*0Sstevel@tonic-gate        substr($x, 2, 1) eq "\x{F2}" &&
327*0Sstevel@tonic-gate        substr($x, 3, 1) eq "\x{F3}";
328*0Sstevel@tonic-gate
329*0Sstevel@tonic-gate# more utf8 lval exercise
330*0Sstevel@tonic-gate
331*0Sstevel@tonic-gate$x = "\xF1\xF2\xF3";
332*0Sstevel@tonic-gatesubstr($x, 0, 2) = "\x{100}\xFF";
333*0Sstevel@tonic-gateok 139, length($x) == 3 &&
334*0Sstevel@tonic-gate        $x eq "\x{100}\xFF\xF3" &&
335*0Sstevel@tonic-gate        substr($x, 0, 1) eq "\x{100}" &&
336*0Sstevel@tonic-gate        substr($x, 1, 1) eq "\x{FF}" &&
337*0Sstevel@tonic-gate        substr($x, 2, 1) eq "\x{F3}";
338*0Sstevel@tonic-gate
339*0Sstevel@tonic-gate$x = "\xF1\xF2\xF3";
340*0Sstevel@tonic-gatesubstr($x, 1, 1) = "\x{100}\xFF";
341*0Sstevel@tonic-gateok 140, length($x) == 4 &&
342*0Sstevel@tonic-gate        $x eq "\xF1\x{100}\xFF\xF3" &&
343*0Sstevel@tonic-gate        substr($x, 0, 1) eq "\x{F1}" &&
344*0Sstevel@tonic-gate        substr($x, 1, 1) eq "\x{100}" &&
345*0Sstevel@tonic-gate        substr($x, 2, 1) eq "\x{FF}" &&
346*0Sstevel@tonic-gate        substr($x, 3, 1) eq "\x{F3}";
347*0Sstevel@tonic-gate
348*0Sstevel@tonic-gate$x = "\xF1\xF2\xF3";
349*0Sstevel@tonic-gatesubstr($x, 2, 1) = "\x{100}\xFF";
350*0Sstevel@tonic-gateok 141, length($x) == 4 &&
351*0Sstevel@tonic-gate        $x eq "\xF1\xF2\x{100}\xFF" &&
352*0Sstevel@tonic-gate        substr($x, 0, 1) eq "\x{F1}" &&
353*0Sstevel@tonic-gate        substr($x, 1, 1) eq "\x{F2}" &&
354*0Sstevel@tonic-gate        substr($x, 2, 1) eq "\x{100}" &&
355*0Sstevel@tonic-gate        substr($x, 3, 1) eq "\x{FF}";
356*0Sstevel@tonic-gate
357*0Sstevel@tonic-gate$x = "\xF1\xF2\xF3";
358*0Sstevel@tonic-gatesubstr($x, 3, 1) = "\x{100}\xFF";
359*0Sstevel@tonic-gateok 142, length($x) == 5 &&
360*0Sstevel@tonic-gate        $x eq "\xF1\xF2\xF3\x{100}\xFF" &&
361*0Sstevel@tonic-gate        substr($x, 0, 1) eq "\x{F1}" &&
362*0Sstevel@tonic-gate        substr($x, 1, 1) eq "\x{F2}" &&
363*0Sstevel@tonic-gate        substr($x, 2, 1) eq "\x{F3}" &&
364*0Sstevel@tonic-gate        substr($x, 3, 1) eq "\x{100}" &&
365*0Sstevel@tonic-gate        substr($x, 4, 1) eq "\x{FF}";
366*0Sstevel@tonic-gate
367*0Sstevel@tonic-gate$x = "\xF1\xF2\xF3";
368*0Sstevel@tonic-gatesubstr($x, -1, 1) = "\x{100}\xFF";
369*0Sstevel@tonic-gateok 143, length($x) == 4 &&
370*0Sstevel@tonic-gate        $x eq "\xF1\xF2\x{100}\xFF" &&
371*0Sstevel@tonic-gate        substr($x, 0, 1) eq "\x{F1}" &&
372*0Sstevel@tonic-gate        substr($x, 1, 1) eq "\x{F2}" &&
373*0Sstevel@tonic-gate        substr($x, 2, 1) eq "\x{100}" &&
374*0Sstevel@tonic-gate        substr($x, 3, 1) eq "\x{FF}";
375*0Sstevel@tonic-gate
376*0Sstevel@tonic-gate$x = "\xF1\xF2\xF3";
377*0Sstevel@tonic-gatesubstr($x, -1, 0) = "\x{100}\xFF";
378*0Sstevel@tonic-gateok 144, length($x) == 5 &&
379*0Sstevel@tonic-gate        $x eq "\xF1\xF2\x{100}\xFF\xF3" &&
380*0Sstevel@tonic-gate        substr($x, 0, 1) eq "\x{F1}" &&
381*0Sstevel@tonic-gate        substr($x, 1, 1) eq "\x{F2}" &&
382*0Sstevel@tonic-gate        substr($x, 2, 1) eq "\x{100}" &&
383*0Sstevel@tonic-gate        substr($x, 3, 1) eq "\x{FF}" &&
384*0Sstevel@tonic-gate        substr($x, 4, 1) eq "\x{F3}";
385*0Sstevel@tonic-gate
386*0Sstevel@tonic-gate$x = "\xF1\xF2\xF3";
387*0Sstevel@tonic-gatesubstr($x, 0, -1) = "\x{100}\xFF";
388*0Sstevel@tonic-gateok 145, length($x) == 3 &&
389*0Sstevel@tonic-gate        $x eq "\x{100}\xFF\xF3" &&
390*0Sstevel@tonic-gate        substr($x, 0, 1) eq "\x{100}" &&
391*0Sstevel@tonic-gate        substr($x, 1, 1) eq "\x{FF}" &&
392*0Sstevel@tonic-gate        substr($x, 2, 1) eq "\x{F3}";
393*0Sstevel@tonic-gate
394*0Sstevel@tonic-gate$x = "\xF1\xF2\xF3";
395*0Sstevel@tonic-gatesubstr($x, 0, -2) = "\x{100}\xFF";
396*0Sstevel@tonic-gateok 146, length($x) == 4 &&
397*0Sstevel@tonic-gate        $x eq "\x{100}\xFF\xF2\xF3" &&
398*0Sstevel@tonic-gate        substr($x, 0, 1) eq "\x{100}" &&
399*0Sstevel@tonic-gate        substr($x, 1, 1) eq "\x{FF}" &&
400*0Sstevel@tonic-gate        substr($x, 2, 1) eq "\x{F2}" &&
401*0Sstevel@tonic-gate        substr($x, 3, 1) eq "\x{F3}";
402*0Sstevel@tonic-gate
403*0Sstevel@tonic-gate$x = "\xF1\xF2\xF3";
404*0Sstevel@tonic-gatesubstr($x, 0, -3) = "\x{100}\xFF";
405*0Sstevel@tonic-gateok 147, length($x) == 5 &&
406*0Sstevel@tonic-gate        $x eq "\x{100}\xFF\xF1\xF2\xF3" &&
407*0Sstevel@tonic-gate        substr($x, 0, 1) eq "\x{100}" &&
408*0Sstevel@tonic-gate        substr($x, 1, 1) eq "\x{FF}" &&
409*0Sstevel@tonic-gate        substr($x, 2, 1) eq "\x{F1}" &&
410*0Sstevel@tonic-gate        substr($x, 3, 1) eq "\x{F2}" &&
411*0Sstevel@tonic-gate        substr($x, 4, 1) eq "\x{F3}";
412*0Sstevel@tonic-gate
413*0Sstevel@tonic-gate$x = "\xF1\xF2\xF3";
414*0Sstevel@tonic-gatesubstr($x, 1, -1) = "\x{100}\xFF";
415*0Sstevel@tonic-gateok 148, length($x) == 4 &&
416*0Sstevel@tonic-gate        $x eq "\xF1\x{100}\xFF\xF3" &&
417*0Sstevel@tonic-gate        substr($x, 0, 1) eq "\x{F1}" &&
418*0Sstevel@tonic-gate        substr($x, 1, 1) eq "\x{100}" &&
419*0Sstevel@tonic-gate        substr($x, 2, 1) eq "\x{FF}" &&
420*0Sstevel@tonic-gate        substr($x, 3, 1) eq "\x{F3}";
421*0Sstevel@tonic-gate
422*0Sstevel@tonic-gate$x = "\xF1\xF2\xF3";
423*0Sstevel@tonic-gatesubstr($x, -1, -1) = "\x{100}\xFF";
424*0Sstevel@tonic-gateok 149, length($x) == 5 &&
425*0Sstevel@tonic-gate        $x eq "\xF1\xF2\x{100}\xFF\xF3" &&
426*0Sstevel@tonic-gate        substr($x, 0, 1) eq "\x{F1}" &&
427*0Sstevel@tonic-gate        substr($x, 1, 1) eq "\x{F2}" &&
428*0Sstevel@tonic-gate        substr($x, 2, 1) eq "\x{100}" &&
429*0Sstevel@tonic-gate        substr($x, 3, 1) eq "\x{FF}" &&
430*0Sstevel@tonic-gate        substr($x, 4, 1) eq "\x{F3}";
431*0Sstevel@tonic-gate
432*0Sstevel@tonic-gate# And tests for already-UTF8 one
433*0Sstevel@tonic-gate
434*0Sstevel@tonic-gate$x = "\x{101}\x{F2}\x{F3}";
435*0Sstevel@tonic-gatesubstr($x, 0, 1) = "\x{100}";
436*0Sstevel@tonic-gateok 150, length($x) == 3 &&
437*0Sstevel@tonic-gate        $x eq "\x{100}\xF2\xF3" &&
438*0Sstevel@tonic-gate        substr($x, 0, 1) eq "\x{100}" &&
439*0Sstevel@tonic-gate        substr($x, 1, 1) eq "\x{F2}" &&
440*0Sstevel@tonic-gate        substr($x, 2, 1) eq "\x{F3}";
441*0Sstevel@tonic-gate
442*0Sstevel@tonic-gate$x = "\x{101}\x{F2}\x{F3}";
443*0Sstevel@tonic-gatesubstr($x, 0, 1) = "\x{100}\x{FF}";
444*0Sstevel@tonic-gateok 151, length($x) == 4 &&
445*0Sstevel@tonic-gate        $x eq "\x{100}\x{FF}\xF2\xF3" &&
446*0Sstevel@tonic-gate        substr($x, 0, 1) eq "\x{100}" &&
447*0Sstevel@tonic-gate        substr($x, 1, 1) eq "\x{FF}" &&
448*0Sstevel@tonic-gate        substr($x, 2, 1) eq "\x{F2}" &&
449*0Sstevel@tonic-gate        substr($x, 3, 1) eq "\x{F3}";
450*0Sstevel@tonic-gate
451*0Sstevel@tonic-gate$x = "\x{101}\x{F2}\x{F3}";
452*0Sstevel@tonic-gatesubstr($x, 0, 2) = "\x{100}\xFF";
453*0Sstevel@tonic-gateok 152, length($x) == 3 &&
454*0Sstevel@tonic-gate        $x eq "\x{100}\xFF\xF3" &&
455*0Sstevel@tonic-gate        substr($x, 0, 1) eq "\x{100}" &&
456*0Sstevel@tonic-gate        substr($x, 1, 1) eq "\x{FF}" &&
457*0Sstevel@tonic-gate        substr($x, 2, 1) eq "\x{F3}";
458*0Sstevel@tonic-gate
459*0Sstevel@tonic-gate$x = "\x{101}\x{F2}\x{F3}";
460*0Sstevel@tonic-gatesubstr($x, 1, 1) = "\x{100}\xFF";
461*0Sstevel@tonic-gateok 153, length($x) == 4 &&
462*0Sstevel@tonic-gate        $x eq "\x{101}\x{100}\xFF\xF3" &&
463*0Sstevel@tonic-gate        substr($x, 0, 1) eq "\x{101}" &&
464*0Sstevel@tonic-gate        substr($x, 1, 1) eq "\x{100}" &&
465*0Sstevel@tonic-gate        substr($x, 2, 1) eq "\x{FF}" &&
466*0Sstevel@tonic-gate        substr($x, 3, 1) eq "\x{F3}";
467*0Sstevel@tonic-gate
468*0Sstevel@tonic-gate$x = "\x{101}\x{F2}\x{F3}";
469*0Sstevel@tonic-gatesubstr($x, 2, 1) = "\x{100}\xFF";
470*0Sstevel@tonic-gateok 154, length($x) == 4 &&
471*0Sstevel@tonic-gate        $x eq "\x{101}\xF2\x{100}\xFF" &&
472*0Sstevel@tonic-gate        substr($x, 0, 1) eq "\x{101}" &&
473*0Sstevel@tonic-gate        substr($x, 1, 1) eq "\x{F2}" &&
474*0Sstevel@tonic-gate        substr($x, 2, 1) eq "\x{100}" &&
475*0Sstevel@tonic-gate        substr($x, 3, 1) eq "\x{FF}";
476*0Sstevel@tonic-gate
477*0Sstevel@tonic-gate$x = "\x{101}\x{F2}\x{F3}";
478*0Sstevel@tonic-gatesubstr($x, 3, 1) = "\x{100}\xFF";
479*0Sstevel@tonic-gateok 155, length($x) == 5 &&
480*0Sstevel@tonic-gate        $x eq "\x{101}\x{F2}\x{F3}\x{100}\xFF" &&
481*0Sstevel@tonic-gate        substr($x, 0, 1) eq "\x{101}" &&
482*0Sstevel@tonic-gate        substr($x, 1, 1) eq "\x{F2}" &&
483*0Sstevel@tonic-gate        substr($x, 2, 1) eq "\x{F3}" &&
484*0Sstevel@tonic-gate        substr($x, 3, 1) eq "\x{100}" &&
485*0Sstevel@tonic-gate        substr($x, 4, 1) eq "\x{FF}";
486*0Sstevel@tonic-gate
487*0Sstevel@tonic-gate$x = "\x{101}\x{F2}\x{F3}";
488*0Sstevel@tonic-gatesubstr($x, -1, 1) = "\x{100}\xFF";
489*0Sstevel@tonic-gateok 156, length($x) == 4 &&
490*0Sstevel@tonic-gate        $x eq "\x{101}\xF2\x{100}\xFF" &&
491*0Sstevel@tonic-gate        substr($x, 0, 1) eq "\x{101}" &&
492*0Sstevel@tonic-gate        substr($x, 1, 1) eq "\x{F2}" &&
493*0Sstevel@tonic-gate        substr($x, 2, 1) eq "\x{100}" &&
494*0Sstevel@tonic-gate        substr($x, 3, 1) eq "\x{FF}";
495*0Sstevel@tonic-gate
496*0Sstevel@tonic-gate$x = "\x{101}\x{F2}\x{F3}";
497*0Sstevel@tonic-gatesubstr($x, -1, 0) = "\x{100}\xFF";
498*0Sstevel@tonic-gateok 157, length($x) == 5 &&
499*0Sstevel@tonic-gate        $x eq "\x{101}\xF2\x{100}\xFF\xF3" &&
500*0Sstevel@tonic-gate        substr($x, 0, 1) eq "\x{101}" &&
501*0Sstevel@tonic-gate        substr($x, 1, 1) eq "\x{F2}" &&
502*0Sstevel@tonic-gate        substr($x, 2, 1) eq "\x{100}" &&
503*0Sstevel@tonic-gate        substr($x, 3, 1) eq "\x{FF}" &&
504*0Sstevel@tonic-gate        substr($x, 4, 1) eq "\x{F3}";
505*0Sstevel@tonic-gate
506*0Sstevel@tonic-gate$x = "\x{101}\x{F2}\x{F3}";
507*0Sstevel@tonic-gatesubstr($x, 0, -1) = "\x{100}\xFF";
508*0Sstevel@tonic-gateok 158, length($x) == 3 &&
509*0Sstevel@tonic-gate        $x eq "\x{100}\xFF\xF3" &&
510*0Sstevel@tonic-gate        substr($x, 0, 1) eq "\x{100}" &&
511*0Sstevel@tonic-gate        substr($x, 1, 1) eq "\x{FF}" &&
512*0Sstevel@tonic-gate        substr($x, 2, 1) eq "\x{F3}";
513*0Sstevel@tonic-gate
514*0Sstevel@tonic-gate$x = "\x{101}\x{F2}\x{F3}";
515*0Sstevel@tonic-gatesubstr($x, 0, -2) = "\x{100}\xFF";
516*0Sstevel@tonic-gateok 159, length($x) == 4 &&
517*0Sstevel@tonic-gate        $x eq "\x{100}\xFF\xF2\xF3" &&
518*0Sstevel@tonic-gate        substr($x, 0, 1) eq "\x{100}" &&
519*0Sstevel@tonic-gate        substr($x, 1, 1) eq "\x{FF}" &&
520*0Sstevel@tonic-gate        substr($x, 2, 1) eq "\x{F2}" &&
521*0Sstevel@tonic-gate        substr($x, 3, 1) eq "\x{F3}";
522*0Sstevel@tonic-gate
523*0Sstevel@tonic-gate$x = "\x{101}\x{F2}\x{F3}";
524*0Sstevel@tonic-gatesubstr($x, 0, -3) = "\x{100}\xFF";
525*0Sstevel@tonic-gateok 160, length($x) == 5 &&
526*0Sstevel@tonic-gate        $x eq "\x{100}\xFF\x{101}\x{F2}\x{F3}" &&
527*0Sstevel@tonic-gate        substr($x, 0, 1) eq "\x{100}" &&
528*0Sstevel@tonic-gate        substr($x, 1, 1) eq "\x{FF}" &&
529*0Sstevel@tonic-gate        substr($x, 2, 1) eq "\x{101}" &&
530*0Sstevel@tonic-gate        substr($x, 3, 1) eq "\x{F2}" &&
531*0Sstevel@tonic-gate        substr($x, 4, 1) eq "\x{F3}";
532*0Sstevel@tonic-gate
533*0Sstevel@tonic-gate$x = "\x{101}\x{F2}\x{F3}";
534*0Sstevel@tonic-gatesubstr($x, 1, -1) = "\x{100}\xFF";
535*0Sstevel@tonic-gateok 161, length($x) == 4 &&
536*0Sstevel@tonic-gate        $x eq "\x{101}\x{100}\xFF\xF3" &&
537*0Sstevel@tonic-gate        substr($x, 0, 1) eq "\x{101}" &&
538*0Sstevel@tonic-gate        substr($x, 1, 1) eq "\x{100}" &&
539*0Sstevel@tonic-gate        substr($x, 2, 1) eq "\x{FF}" &&
540*0Sstevel@tonic-gate        substr($x, 3, 1) eq "\x{F3}";
541*0Sstevel@tonic-gate
542*0Sstevel@tonic-gate$x = "\x{101}\x{F2}\x{F3}";
543*0Sstevel@tonic-gatesubstr($x, -1, -1) = "\x{100}\xFF";
544*0Sstevel@tonic-gateok 162, length($x) == 5 &&
545*0Sstevel@tonic-gate        $x eq "\x{101}\xF2\x{100}\xFF\xF3" &&
546*0Sstevel@tonic-gate        substr($x, 0, 1) eq "\x{101}" &&
547*0Sstevel@tonic-gate        substr($x, 1, 1) eq "\x{F2}" &&
548*0Sstevel@tonic-gate        substr($x, 2, 1) eq "\x{100}" &&
549*0Sstevel@tonic-gate        substr($x, 3, 1) eq "\x{FF}" &&
550*0Sstevel@tonic-gate        substr($x, 4, 1) eq "\x{F3}";
551*0Sstevel@tonic-gate
552*0Sstevel@tonic-gatesubstr($x = "ab", 0, 0, "\x{100}\x{200}");
553*0Sstevel@tonic-gateok 163, $x eq "\x{100}\x{200}ab";
554*0Sstevel@tonic-gate
555*0Sstevel@tonic-gatesubstr($x = "\x{100}\x{200}", 0, 0, "ab");
556*0Sstevel@tonic-gateok 164, $x eq "ab\x{100}\x{200}";
557*0Sstevel@tonic-gate
558*0Sstevel@tonic-gatesubstr($x = "ab", 1, 0, "\x{100}\x{200}");
559*0Sstevel@tonic-gateok 165, $x eq "a\x{100}\x{200}b";
560*0Sstevel@tonic-gate
561*0Sstevel@tonic-gatesubstr($x = "\x{100}\x{200}", 1, 0, "ab");
562*0Sstevel@tonic-gateok 166, $x eq "\x{100}ab\x{200}";
563*0Sstevel@tonic-gate
564*0Sstevel@tonic-gatesubstr($x = "ab", 2, 0, "\x{100}\x{200}");
565*0Sstevel@tonic-gateok 167, $x eq "ab\x{100}\x{200}";
566*0Sstevel@tonic-gate
567*0Sstevel@tonic-gatesubstr($x = "\x{100}\x{200}", 2, 0, "ab");
568*0Sstevel@tonic-gateok 168, $x eq "\x{100}\x{200}ab";
569*0Sstevel@tonic-gate
570*0Sstevel@tonic-gatesubstr($x = "\xFFb", 0, 0, "\x{100}\x{200}");
571*0Sstevel@tonic-gateok 169, $x eq "\x{100}\x{200}\xFFb";
572*0Sstevel@tonic-gate
573*0Sstevel@tonic-gatesubstr($x = "\x{100}\x{200}", 0, 0, "\xFFb");
574*0Sstevel@tonic-gateok 170, $x eq "\xFFb\x{100}\x{200}";
575*0Sstevel@tonic-gate
576*0Sstevel@tonic-gatesubstr($x = "\xFFb", 1, 0, "\x{100}\x{200}");
577*0Sstevel@tonic-gateok 171, $x eq "\xFF\x{100}\x{200}b";
578*0Sstevel@tonic-gate
579*0Sstevel@tonic-gatesubstr($x = "\x{100}\x{200}", 1, 0, "\xFFb");
580*0Sstevel@tonic-gateok 172, $x eq "\x{100}\xFFb\x{200}";
581*0Sstevel@tonic-gate
582*0Sstevel@tonic-gatesubstr($x = "\xFFb", 2, 0, "\x{100}\x{200}");
583*0Sstevel@tonic-gateok 173, $x eq "\xFFb\x{100}\x{200}";
584*0Sstevel@tonic-gate
585*0Sstevel@tonic-gatesubstr($x = "\x{100}\x{200}", 2, 0, "\xFFb");
586*0Sstevel@tonic-gateok 174, $x eq "\x{100}\x{200}\xFFb";
587*0Sstevel@tonic-gate
588*0Sstevel@tonic-gate# [perl #20933]
589*0Sstevel@tonic-gate{
590*0Sstevel@tonic-gate    my $s = "ab";
591*0Sstevel@tonic-gate    my @r;
592*0Sstevel@tonic-gate    $r[$_] = \ substr $s, $_, 1 for (0, 1);
593*0Sstevel@tonic-gate    ok 175, join("", map { $$_ } @r) eq "ab";
594*0Sstevel@tonic-gate}
595*0Sstevel@tonic-gate
596*0Sstevel@tonic-gate# [perl #23207]
597*0Sstevel@tonic-gate{
598*0Sstevel@tonic-gate    sub ss {
599*0Sstevel@tonic-gate	substr($_[0],0,1) ^= substr($_[0],1,1) ^=
600*0Sstevel@tonic-gate	substr($_[0],0,1) ^= substr($_[0],1,1);
601*0Sstevel@tonic-gate    }
602*0Sstevel@tonic-gate    my $x = my $y = 'AB'; ss $x; ss $y;
603*0Sstevel@tonic-gate    ok 176, $x eq $y;
604*0Sstevel@tonic-gate}
605*0Sstevel@tonic-gate
606*0Sstevel@tonic-gate# [perl #24605]
607*0Sstevel@tonic-gate{
608*0Sstevel@tonic-gate    my $x = "0123456789\x{500}";
609*0Sstevel@tonic-gate    my $y = substr $x, 4;
610*0Sstevel@tonic-gate    ok 177, substr($x, 7, 1) eq "7";
611*0Sstevel@tonic-gate}
612*0Sstevel@tonic-gate
613*0Sstevel@tonic-gate# [perl #24200] string corruption with lvalue sub
614*0Sstevel@tonic-gate
615*0Sstevel@tonic-gate{
616*0Sstevel@tonic-gate    my $foo = "a";
617*0Sstevel@tonic-gate    sub bar: lvalue { substr $foo, 0 }
618*0Sstevel@tonic-gate    bar = "XXX";
619*0Sstevel@tonic-gate    ok 178, bar eq 'XXX';
620*0Sstevel@tonic-gate    $foo = '123456789';
621*0Sstevel@tonic-gate    ok 179, bar eq '123456789';
622*0Sstevel@tonic-gate}
623*0Sstevel@tonic-gate
624*0Sstevel@tonic-gate# [perl #29149]
625*0Sstevel@tonic-gate{
626*0Sstevel@tonic-gate    my $text  = "0123456789\xED ";
627*0Sstevel@tonic-gate    utf8::upgrade($text);
628*0Sstevel@tonic-gate    my $pos = 5;
629*0Sstevel@tonic-gate    pos($text) = $pos;
630*0Sstevel@tonic-gate    my $a = substr($text, $pos, $pos);
631*0Sstevel@tonic-gate    ok 180, substr($text,$pos,1) eq $pos;
632*0Sstevel@tonic-gate}
633