[前][次][番号順一覧][スレッド一覧]

ruby-changes:41310

From: nobu <ko1@a...>
Date: Wed, 30 Dec 2015 11:26:20 +0900 (JST)
Subject: [ruby-changes:41310] nobu:r53382 (trunk): fix commit miss

nobu	2015-12-30 11:26:15 +0900 (Wed, 30 Dec 2015)

  New Revision: 53382

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=53382

  Log:
    fix commit miss
    
    * test/test_forwardable.rb: add tests for r53381.

  Modified files:
    trunk/test/test_forwardable.rb
Index: test/test_forwardable.rb
===================================================================
--- test/test_forwardable.rb	(revision 53381)
+++ test/test_forwardable.rb	(revision 53382)
@@ -27,6 +27,34 @@ class TestForwardable < Test::Unit::Test https://github.com/ruby/ruby/blob/trunk/test/test_forwardable.rb#L27
     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::Test https://github.com/ruby/ruby/blob/trunk/test/test_forwardable.rb#L66
     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::Test https://github.com/ruby/ruby/blob/trunk/test/test_forwardable.rb#L114
     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::Test https://github.com/ruby/ruby/blob/trunk/test/test_forwardable.rb#L214
 
   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)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]