diff options
author | Yusuke Endoh <mame@ruby-lang.org> | 2019-09-05 17:03:38 +0900 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2019-09-05 17:47:12 -0700 |
commit | 0bfe3bf4d1a2cf6659a99c7466c733cf922ee0e0 (patch) | |
tree | 758d94cc9602d676d9a2535ea10dee757b187a07 /test | |
parent | 437ff408790d5426e0ee03a4b22171bf745471a7 (diff) | |
download | ruby-0bfe3bf4d1a2cf6659a99c7466c733cf922ee0e0.tar.gz |
Ignore an empty keyword splat for attr_reader/writer methods
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_keyword.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb index 5945a3b87e..04d3b247ae 100644 --- a/test/ruby/test_keyword.rb +++ b/test/ruby/test_keyword.rb @@ -759,6 +759,52 @@ class TestKeywordArguments < Test::Unit::TestCase assert_equal([1, h3], c.m(a: 1, **h2)) end + def test_attr_reader_kwsplat + kw = {} + h = {:a=>1} + h2 = {'a'=>1} + h3 = {'a'=>1, :a=>1} + + c = Object.new + class << c + attr_reader :m + end + 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) } + end + + def test_attr_writer_kwsplat + kw = {} + h = {:a=>1} + h2 = {'a'=>1} + h3 = {'a'=>1, :a=>1} + + c = Object.new + class << c + attr_writer :m + 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_equal(42, c.send(:m=, 42, **{})) + assert_equal(42, c.send(:m=, 42, **kw)) + assert_raise(ArgumentError) { c.send(:m=, 42, **h) } + assert_raise(ArgumentError) { c.send(:m=, 42, a: 1) } + assert_raise(ArgumentError) { c.send(:m=, 42, **h2) } + assert_raise(ArgumentError) { c.send(:m=, 42, **h3) } + assert_raise(ArgumentError) { c.send(:m=, 42, a: 1, **h2) } + end + def p1 Proc.new do |str: "foo", num: 424242| [str, num] |