diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-06-10 12:54:25 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-06-10 12:54:25 +0000 |
commit | 3255225ead1a643d5b8f4e68c66897fd67b97220 (patch) | |
tree | 4f47c71d71cfa638ddefa441d033ed3e3a78a889 /test | |
parent | 7d03b4ed3edf324c27820fd13a568e4283d7dd4b (diff) | |
download | ruby-3255225ead1a643d5b8f4e68c66897fd67b97220.tar.gz |
forwardable.rb: fix for non-module objects
* lib/forwardable.rb (Forwardable._delegator_method): extract
method generator and deal with non-module objects.
[ruby-dev:49656] [Bug #12478]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55366 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/test_forwardable.rb | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/test/test_forwardable.rb b/test/test_forwardable.rb index 550280de19..f678ca4fc7 100644 --- a/test/test_forwardable.rb +++ b/test/test_forwardable.rb @@ -144,7 +144,7 @@ class TestForwardable < Test::Unit::TestCase end end - def test_def_single_delegator + def test_class_single_delegator %i[def_delegator def_single_delegator].each do |m| cls = single_forwardable_class do __send__ m, :@receiver, :delegated1 @@ -154,7 +154,7 @@ class TestForwardable < Test::Unit::TestCase end end - def test_def_single_delegators + def test_class_single_delegators %i[def_delegators def_single_delegators].each do |m| cls = single_forwardable_class do __send__ m, :@receiver, :delegated1, :delegated2 @@ -165,7 +165,7 @@ class TestForwardable < Test::Unit::TestCase end end - def test_single_delegate + def test_class_single_delegate %i[delegate single_delegate].each do |m| cls = single_forwardable_class do __send__ m, delegated1: :@receiver, delegated2: :@receiver @@ -183,6 +183,45 @@ class TestForwardable < Test::Unit::TestCase end end + def test_obj_single_delegator + %i[def_delegator def_single_delegator].each do |m| + obj = single_forwardable_object do + __send__ m, :@receiver, :delegated1 + end + + assert_same RETURNED1, obj.delegated1 + end + end + + def test_obj_single_delegators + %i[def_delegators def_single_delegators].each do |m| + obj = single_forwardable_object do + __send__ m, :@receiver, :delegated1, :delegated2 + end + + assert_same RETURNED1, obj.delegated1 + assert_same RETURNED2, obj.delegated2 + end + end + + def test_obj_single_delegate + %i[delegate single_delegate].each do |m| + obj = single_forwardable_object do + __send__ m, delegated1: :@receiver, delegated2: :@receiver + end + + assert_same RETURNED1, obj.delegated1 + assert_same RETURNED2, obj.delegated2 + + obj = single_forwardable_object do + __send__ m, %i[delegated1 delegated2] => :@receiver + end + + assert_same RETURNED1, obj.delegated1 + assert_same RETURNED2, obj.delegated2 + end + end + class Foo extend Forwardable @@ -247,4 +286,11 @@ class TestForwardable < Test::Unit::TestCase class_exec(&block) end end + + def single_forwardable_object(&block) + obj = Object.new.extend SingleForwardable + obj.instance_variable_set(:@receiver, RECEIVER) + obj.instance_eval(&block) + obj + end end |