diff options
author | Yusuke Endoh <mame@ruby-lang.org> | 2019-09-04 01:32:42 +0900 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2019-09-05 17:47:12 -0700 |
commit | ce04392d8d4f8cf14c70bbf1ad3544c7db4e1671 (patch) | |
tree | d7fa8f17c71b0590e56c42f8cd5497cb0a635ef8 /test | |
parent | 3754e155309ed430250781c616a6e52b54ef511d (diff) | |
download | ruby-ce04392d8d4f8cf14c70bbf1ad3544c7db4e1671.tar.gz |
Propagate kw_splat information
The kw_splat flag is whether the original call passes keyword or not.
Some types of methods (e.g., bmethod and sym_proc) drops the
information. This change tries to propagate the flag to the final
callee, as far as I can.
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_keyword.rb | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb index c3ad7b9a97..b8d8736c5f 100644 --- a/test/ruby/test_keyword.rb +++ b/test/ruby/test_keyword.rb @@ -522,6 +522,81 @@ class TestKeywordArguments < Test::Unit::TestCase assert_equal([1, h3], c.send(:m, **h3)) end + def test_define_method_kwsplat + kw = {} + h = {'a'=>1} + h2 = {'a'=>1} + h3 = {'a'=>1, :a=>1} + + c = Object.new + class << c + define_method(:m) { } + end + assert_nil(c.m(**{})) + assert_nil(c.m(**kw)) + assert_raise(ArgumentError) { c.m(**h) } + assert_raise(ArgumentError) { c.m(**h2) } + assert_raise(ArgumentError) { c.m(**h3) } + + c = Object.new + class << c + define_method(:m) {|arg| } + end + assert_raise(ArgumentError) { c.m(**{}) } + assert_raise(ArgumentError) { c.m(**kw) } + assert_nil(c.m(**h)) + assert_nil(c.m(**h2)) + assert_nil(c.m(**h3)) + + c = Object.new + class << c + define_method(:m) {|*args| } + end + assert_nil(c.m(**{})) + assert_nil(c.m(**kw)) + assert_nil(c.m(**h)) + assert_nil(c.m(**h2)) + assert_nil(c.m(**h3)) + + c = Object.new + class << c + define_method(:m) {|**opt| } + end + assert_nil(c.m(**{})) + assert_nil(c.m(**kw)) + assert_nil(c.m(**h)) + assert_nil(c.m(**h2)) + assert_nil(c.m(**h3)) + + c = Object.new + class << c + define_method(:m) {|arg, **opt| [arg, opt] } + end + assert_raise(ArgumentError) { c.m(**{}) } + assert_warn(/The keyword argument is passed as the last hash parameter/m) do + assert_equal([kw, kw], c.m(**kw)) + end + assert_warn(/The keyword argument is passed as the last hash parameter/m) do + assert_equal([h, kw], c.m(**h)) + end + assert_warn(/The keyword argument is passed as the last hash parameter/m) do + assert_equal([h2, kw], c.m(**h2)) + end + assert_warn(/The keyword argument is passed as the last hash parameter/m) do + assert_equal([h3, kw], c.m(**h3)) + end + + c = Object.new + class << c + define_method(:m) {|arg=1, **opt| } + end + assert_nil(c.m(**{})) + assert_nil(c.m(**kw)) + assert_nil(c.m(**h)) + assert_nil(c.m(**h2)) + assert_nil(c.m(**h3)) + end + def p1 Proc.new do |str: "foo", num: 424242| [str, num] |