Skip to content

Commit 611222a

Browse files
committed
Add a test for multi-assignment in for-loop
ruby/prism#4156
1 parent 6465bba commit 611222a

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

language/for_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,26 @@
4040
end
4141
end
4242

43+
it "iterates over a list of arrays and destructures with a multi-assignment" do
44+
for (i, j, k) in [[1,2,3]]
45+
[i, j, k].should == [1, 2, 3]
46+
end
47+
48+
for i, (j, k) in [[1,[2,3]]]
49+
[i, j, k].should == [1, 2, 3]
50+
end
51+
52+
# Prism-related bug
53+
# https://github.com/ruby/prism/pull/4156
54+
ruby_version_is "4.1" do
55+
eval <<~RUBY
56+
for (i, j), k in [[[1,2],3]]
57+
[i, j, k].should == [1, 2, 3]
58+
end
59+
RUBY
60+
end
61+
end
62+
4363
it "iterates over an Hash passing each key-value pair to the block" do
4464
k = 0
4565
l = 0

0 commit comments

Comments
 (0)