summaryrefslogtreecommitdiff
path: root/test/ruby/test_proc.rb
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2020-01-24 12:13:41 -0800
committerJeremy Evans <code@jeremyevans.net>2020-01-24 13:04:14 -0800
commitc1d8829ef515ee51fadeadd7dd022b5c47a71cdd (patch)
tree19855350cd3319a95221c4726036e47d9fae3acc /test/ruby/test_proc.rb
parent9af7d048b6e2f5221dfb7bb757fd6cb5d5757124 (diff)
Do not autosplat when calling proc with empty keyword splat
With the removal of the splatted argument when using an empty keyword splat, the autosplat code considered an empty keyword splat the same as no argument at all. However, that results in autosplat behavior changing dependent on the content of the splatted hash, which is not what anyone would expect or want. This change always skips an autosplat if keywords were provided. Fixes [Bug #16560]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/2861
Diffstat (limited to 'test/ruby/test_proc.rb')
-rw-r--r--test/ruby/test_proc.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb
index af4cf11623..4177707ddd 100644
--- a/test/ruby/test_proc.rb
+++ b/test/ruby/test_proc.rb
@@ -1087,6 +1087,26 @@ class TestProc < Test::Unit::TestCase
assert_equal([1,2,[3],4,5], r, "[ruby-core:19485]")
end
+ def test_proc_autosplat
+ def self.a(arg, kw)
+ yield arg
+ yield arg, **kw
+ yield arg, kw
+ end
+
+ arr = []
+ a([1,2,3], {}) do |arg1, arg2=0|
+ arr << [arg1, arg2]
+ end
+ assert_equal([[1, 2], [[1, 2, 3], 0], [[1, 2, 3], {}]], arr)
+
+ arr = []
+ a([1,2,3], a: 1) do |arg1, arg2=0|
+ arr << [arg1, arg2]
+ end
+ assert_equal([[1, 2], [[1, 2, 3], {a: 1}], [[1, 2, 3], {a: 1}]], arr)
+ end
+
def test_proc_single_arg_with_keywords_accepted_and_yielded
def self.a
yield [], **{a: 1}