Skip to content

Commit 828ea27

Browse files
committed
join: tests from GH #21458
1 parent 922e8c4 commit 828ea27

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

t/op/join.t

+52-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ BEGIN {
66
set_up_inc('../lib');
77
}
88

9-
plan tests => 29;
9+
plan tests => 41;
1010

1111
@x = (1, 2, 3);
1212
is( join(':',@x), '1:2:3', 'join an array with character');
@@ -128,3 +128,54 @@ package o { use overload q|""| => sub { ${$_[0]}++ } }
128128
for(1,2) { push @_, \join "x", 1 }
129129
isnt $_[1], $_[0],
130130
'join(const, const) still returns a new scalar each time';
131+
132+
# tests from GH #21458
133+
# simple tied variable
134+
{
135+
package S;
136+
our $fetched;
137+
sub TIESCALAR { my $x = '-'; $fetched = 0; bless \$x }
138+
sub FETCH { my $y = shift; $fetched++; $$y }
139+
140+
package main;
141+
my $t;
142+
143+
tie $t, 'S';
144+
is( join( $t, a .. c ), 'a-b-c', 'tied separator' );
145+
is( $S::fetched, 1, 'FETCH called once' );
146+
147+
tie $t, 'S';
148+
is( join( $t, 'a' ), 'a', 'tied separator on single item join' );
149+
is( $S::fetched, 0, 'FETCH not called' );
150+
151+
tie $t, 'S';
152+
is( join( $t, 'a', $t, 'b', $t, 'c' ),
153+
'a---b---c', 'tied separator also in the join arguments' );
154+
is( $S::fetched, 3, 'FETCH called 1 + 2 times' );
155+
}
156+
# self-modifying tied variable
157+
{
158+
159+
package SM;
160+
our $fetched;
161+
sub TIESCALAR { my $x = "1"; $fetched = 0; bless \$x }
162+
sub FETCH { my $y = shift; $fetched++; $$y += 3 }
163+
164+
package main;
165+
my $t;
166+
167+
tie $t, "SM";
168+
is( join( $t, a .. c ), 'a4b4c', 'tied separator' );
169+
is( $SM::fetched, 1, 'FETCH called once' );
170+
171+
tie $t, "SM";
172+
is( join( $t, 'a' ), 'a', 'tied separator on single item join' );
173+
is( $SM::fetched, 0, 'FETCH not called' );
174+
175+
tie $t, "SM";
176+
{ local $TODO = "separator keeps being FETCHed";
177+
is( join( $t, "a", $t, "b", $t, "c" ),
178+
'a474b4104c', 'tied separator also in the join arguments' );
179+
}
180+
is( $SM::fetched, 3, 'FETCH called 1 + 2 times' );
181+
}

0 commit comments

Comments
 (0)