diff options
author | Yusuke Endoh <mame@ruby-lang.org> | 2019-09-05 18:52:22 +0900 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2019-09-05 17:47:12 -0700 |
commit | 4615886c76c0e906a349440ac7e232ad0ba5ce30 (patch) | |
tree | f19d2ec6daf2ed69c7cbcf556d7f48c9158aadee /test | |
parent | acee6302419f02792ec331d384f430c5fc6bdb70 (diff) | |
download | ruby-4615886c76c0e906a349440ac7e232ad0ba5ce30.tar.gz |
test_method_missing_kwsplat should call the target directly
not via Object#send which uses a fast path vm_call_opt_send.
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_keyword.rb | 85 |
1 files changed, 44 insertions, 41 deletions
diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb index 04d3b247ae..974a14fbcf 100644 --- a/test/ruby/test_keyword.rb +++ b/test/ruby/test_keyword.rb @@ -594,80 +594,83 @@ class TestKeywordArguments < Test::Unit::TestCase def c.method_missing(_, *args) args end - assert_equal([], c.send(:m, **{})) - assert_equal([], c.send(:m, **kw)) - assert_equal([h], c.send(:m, **h)) - assert_equal([h], c.send(:m, a: 1)) - assert_equal([h2], c.send(:m, **h2)) - assert_equal([h3], c.send(:m, **h3)) - assert_equal([h3], c.send(:m, a: 1, **h2)) + assert_equal([], c.m(**{})) + assert_equal([], c.m(**kw)) + assert_equal([h], c.m(**h)) + assert_equal([h], c.m(a: 1)) + assert_equal([h2], c.m(**h2)) + assert_equal([h3], c.m(**h3)) + assert_equal([h3], c.m(a: 1, **h2)) c.singleton_class.remove_method(:method_missing) def c.method_missing(_); end - assert_nil(c.send(:m, **{})) - assert_nil(c.send(:m, **kw)) - assert_raise(ArgumentError) { c.send(:m, **h) } - assert_raise(ArgumentError) { c.send(:m, a: 1) } - assert_raise(ArgumentError) { c.send(:m, **h2) } - assert_raise(ArgumentError) { c.send(:m, **h3) } - assert_raise(ArgumentError) { c.send(:m, a: 1, **h2) } + assert_nil(c.m(**{})) + assert_nil(c.m(**kw)) + assert_raise(ArgumentError) { c.m(**h) } + assert_raise(ArgumentError) { c.m(a: 1) } + assert_raise(ArgumentError) { c.m(**h2) } + assert_raise(ArgumentError) { c.m(**h3) } + assert_raise(ArgumentError) { c.m(a: 1, **h2) } c.singleton_class.remove_method(:method_missing) def c.method_missing(_, args) args end - assert_raise(ArgumentError) { c.send(:m, **{}) } - assert_raise(ArgumentError) { c.send(:m, **kw) } - assert_equal(h, c.send(:m, **h)) - assert_equal(h, c.send(:m, a: 1)) - assert_equal(h2, c.send(:m, **h2)) - assert_equal(h3, c.send(:m, **h3)) - assert_equal(h3, c.send(:m, a: 1, **h2)) + assert_raise(ArgumentError) { c.m(**{}) } + assert_raise(ArgumentError) { c.m(**kw) } + assert_equal(h, c.m(**h)) + assert_equal(h, c.m(a: 1)) + assert_equal(h2, c.m(**h2)) + assert_equal(h3, c.m(**h3)) + assert_equal(h3, c.m(a: 1, **h2)) c.singleton_class.remove_method(:method_missing) def c.method_missing(_, **args) args end - assert_equal(kw, c.send(:m, **{})) - assert_equal(kw, c.send(:m, **kw)) - assert_equal(h, c.send(:m, **h)) - assert_equal(h, c.send(:m, a: 1)) - assert_equal(h2, c.send(:m, **h2)) - assert_equal(h3, c.send(:m, a: 1, **h2)) + assert_equal(kw, c.m(**{})) + assert_equal(kw, c.m(**kw)) + assert_equal(h, c.m(**h)) + assert_equal(h, c.m(a: 1)) + assert_equal(h2, c.m(**h2)) + assert_equal(h3, c.m(a: 1, **h2)) c.singleton_class.remove_method(:method_missing) def c.method_missing(_, arg, **args) [arg, args] end - assert_raise(ArgumentError) { c.send(:m, **{}) } - assert_raise(ArgumentError) { c.send(:m, **kw) } + assert_raise(ArgumentError) { c.m(**{}) } + assert_raise(ArgumentError) { c.send(:m, **kw) } # XXX: fix it after the commit assert_warn(/The keyword argument is passed as the last hash parameter.* for `method_missing'/m) do - assert_equal([h, kw], c.send(:m, **h)) + assert_equal([kw, kw], c.m(**kw)) end assert_warn(/The keyword argument is passed as the last hash parameter.* for `method_missing'/m) do - assert_equal([h, kw], c.send(:m, a: 1)) + assert_equal([h, kw], c.m(**h)) end assert_warn(/The keyword argument is passed as the last hash parameter.* for `method_missing'/m) do - assert_equal([h2, kw], c.send(:m, **h2)) + assert_equal([h, kw], c.m(a: 1)) end assert_warn(/The keyword argument is passed as the last hash parameter.* for `method_missing'/m) do - assert_equal([h3, kw], c.send(:m, **h3)) + assert_equal([h2, kw], c.m(**h2)) end assert_warn(/The keyword argument is passed as the last hash parameter.* for `method_missing'/m) do - assert_equal([h3, kw], c.send(:m, a: 1, **h2)) + assert_equal([h3, kw], c.m(**h3)) + end + assert_warn(/The keyword argument is passed as the last hash parameter.* for `method_missing'/m) do + assert_equal([h3, kw], c.m(a: 1, **h2)) end c.singleton_class.remove_method(:method_missing) def c.method_missing(_, arg=1, **args) [arg=1, args] end - assert_equal([1, kw], c.send(:m, **{})) - assert_equal([1, kw], c.send(:m, **kw)) - assert_equal([1, h], c.send(:m, **h)) - assert_equal([1, h], c.send(:m, a: 1)) - assert_equal([1, h2], c.send(:m, **h2)) - assert_equal([1, h3], c.send(:m, **h3)) - assert_equal([1, h3], c.send(:m, a: 1, **h2)) + assert_equal([1, kw], c.m(**{})) + assert_equal([1, kw], c.m(**kw)) + assert_equal([1, h], c.m(**h)) + assert_equal([1, h], c.m(a: 1)) + assert_equal([1, h2], c.m(**h2)) + assert_equal([1, h3], c.m(**h3)) + assert_equal([1, h3], c.m(a: 1, **h2)) end def test_define_method_kwsplat |