diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-12-30 02:26:15 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-12-30 02:26:15 +0000 |
commit | d8eb5ade4f9bbc083b1cf93717fe97098411bec7 (patch) | |
tree | 2a4d956fc0236f9f21712f74f779a690d5ff666f /test | |
parent | 986fb559613c6bd6a76424e08f0847a7e9cd90de (diff) | |
download | ruby-d8eb5ade4f9bbc083b1cf93717fe97098411bec7.tar.gz |
fix commit miss
* test/test_forwardable.rb: add tests for r53381.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53382 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/test_forwardable.rb | 104 |
1 files changed, 101 insertions, 3 deletions
diff --git a/test/test_forwardable.rb b/test/test_forwardable.rb index a3d03f438b..a474e4ad76 100644 --- a/test/test_forwardable.rb +++ b/test/test_forwardable.rb @@ -27,6 +27,34 @@ class TestForwardable < Test::Unit::TestCase end end + def test_def_instance_delegator_using_args_method_as_receiver + %i[def_delegator def_instance_delegator].each do |m| + cls = forwardable_class( + receiver_name: :args, + type: :method, + visibility: :private + ) do + __send__ m, :args, :delegated1 + end + + assert_same RETURNED1, cls.new.delegated1 + end + end + + def test_def_instance_delegator_using_block_method_as_receiver + %i[def_delegator def_instance_delegator].each do |m| + cls = forwardable_class( + receiver_name: :block, + type: :method, + visibility: :private + ) do + __send__ m, :block, :delegated1 + end + + assert_same RETURNED1, cls.new.delegated1 + end + end + def test_def_instance_delegators %i[def_delegators def_instance_delegators].each do |m| cls = forwardable_class do @@ -38,6 +66,36 @@ class TestForwardable < Test::Unit::TestCase end end + def test_def_instance_delegators_using_args_method_as_receiver + %i[def_delegators def_instance_delegators].each do |m| + cls = forwardable_class( + receiver_name: :args, + type: :method, + visibility: :private + ) do + __send__ m, :args, :delegated1, :delegated2 + end + + assert_same RETURNED1, cls.new.delegated1 + assert_same RETURNED2, cls.new.delegated2 + end + end + + def test_def_instance_delegators_using_block_method_as_receiver + %i[def_delegators def_instance_delegators].each do |m| + cls = forwardable_class( + receiver_name: :block, + type: :method, + visibility: :private + ) do + __send__ m, :block, :delegated1, :delegated2 + end + + assert_same RETURNED1, cls.new.delegated1 + assert_same RETURNED2, cls.new.delegated2 + end + end + def test_instance_delegate %i[delegate instance_delegate].each do |m| cls = forwardable_class do @@ -56,6 +114,36 @@ class TestForwardable < Test::Unit::TestCase end end + def test_def_instance_delegate_using_args_method_as_receiver + %i[delegate instance_delegate].each do |m| + cls = forwardable_class( + receiver_name: :args, + type: :method, + visibility: :private + ) do + __send__ m, delegated1: :args, delegated2: :args + end + + assert_same RETURNED1, cls.new.delegated1 + assert_same RETURNED2, cls.new.delegated2 + end + end + + def test_def_instance_delegate_using_block_method_as_receiver + %i[delegate instance_delegate].each do |m| + cls = forwardable_class( + receiver_name: :block, + type: :method, + visibility: :private + ) do + __send__ m, delegated1: :block, delegated2: :block + end + + assert_same RETURNED1, cls.new.delegated1 + assert_same RETURNED2, cls.new.delegated2 + end + end + def test_def_single_delegator %i[def_delegator def_single_delegator].each do |m| cls = single_forwardable_class do @@ -126,12 +214,22 @@ class TestForwardable < Test::Unit::TestCase private - def forwardable_class(&block) + def forwardable_class( + receiver_name: :receiver, + type: :ivar, + visibility: :public, + &block + ) Class.new do extend Forwardable - def initialize - @receiver = RECEIVER + define_method(:initialize) do + instance_variable_set("@#{receiver_name}", RECEIVER) + end + + if type == :method + attr_reader(receiver_name) + __send__(visibility, receiver_name) end class_exec(&block) |