summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorKouhei Sutou <[email protected]>2014-12-23 21:16:01 +0900
committerKouhei Sutou <[email protected]>2014-12-23 21:16:01 +0900
commit5ec676aa37b1c6e345b29ffa02ea8210b7a94da5 (patch)
treeb2b7cd63cba1d80fbb9226aeacb10ae54e4f7b0a /test
parente618438882606c8318bcc4eae2c47ce8ab82d6aa (diff)
downloadmruby-5ec676aa37b1c6e345b29ffa02ea8210b7a94da5.tar.gz
mruby-5ec676aa37b1c6e345b29ffa02ea8210b7a94da5.zip
Fix splat and multiple assignments
Case1: From variable Code: a = [1, 2, 3, 4, 5] b, c, *d = a p [a, b, c, d] Before: [[1, 2, 3, 4, 5], 1, 2, []] After: [[1, 2, 3, 4, 5], 1, 2, [3, 4, 5]] Ruby: [[1, 2, 3, 4, 5], 1, 2, [3, 4, 5]] Case2: From variables Code: a = [1, 2, 3] b = [4, 5, 6, 7] c, d, *e, f, g = *a, *b p [a, b, c, d, e, f, g] Before: [[1, 2, 3], [4, 5, 6, 7], 1, 2, [], 6, 7] After: [[1, 2, 3], [4, 5, 6, 7], 1, 2, [3, 4, 5], 6, 7] Ruby: [[1, 2, 3], [4, 5, 6, 7], 1, 2, [3, 4, 5], 6, 7] Case 3: "for" Code: a = [1, 2, 3, 4, 5, 6, 7] for b, c, *d, e, f in [a] do p [a, b, c, d, e, f] end Before: [[1, 2, 3, 4, 5, 6, 7], 1, 2, [], nil, nil] After: [[1, 2, 3, 4, 5, 6, 7], 1, 2, [3, 4, 5], 6, 7] Ruby: [[1, 2, 3, 4, 5, 6, 7], 1, 2, [3, 4, 5], 6, 7]
Diffstat (limited to 'test')
-rw-r--r--test/t/syntax.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/t/syntax.rb b/test/t/syntax.rb
index e7a962441..7ec6272fe 100644
--- a/test/t/syntax.rb
+++ b/test/t/syntax.rb
@@ -181,6 +181,38 @@ assert('Splat and multiple assignment') do
assert_equal [1,nil,2], [a,b,c]
end
+assert('Splat and multiple assignment from variable') do
+ a = [1, 2, 3]
+ b, *c = a
+
+ assert_equal 1, b
+ assert_equal [2, 3], c
+end
+
+assert('Splat and multiple assignment from variables') do
+ a = [1, 2, 3]
+ b = [4, 5, 6, 7]
+ c, d, *e, f, g = *a, *b
+
+ assert_equal 1, c
+ assert_equal 2, d
+ assert_equal [3, 4, 5], e
+ assert_equal 6, f
+ assert_equal 7, g
+end
+
+assert('Splat and multiple assignment in for') do
+ a = [1, 2, 3, 4, 5, 6, 7]
+ for b, c, *d, e, f in [a] do
+ end
+
+ assert_equal 1, b
+ assert_equal 2, c
+ assert_equal [3, 4, 5], d
+ assert_equal 6, e
+ assert_equal 7, f
+end
+
assert('Return values of case statements') do
a = [] << case 1
when 3 then 2