mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* test/test_forwardable.rb: Write basic tests for lib/forwardable.
[fix GH-1035] Patch by @kachick git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51959 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
eb47de3005
commit
d92470bbc2
2 changed files with 125 additions and 0 deletions
|
@ -1,3 +1,8 @@
|
|||
Mon Sep 28 10:31:12 2015 SHIBATA Hiroshi <hsbt@ruby-lang.org>
|
||||
|
||||
* test/test_forwardable.rb: Write basic tests for lib/forwardable.
|
||||
[fix GH-1035] Patch by @kachick
|
||||
|
||||
Sun Sep 27 23:32:46 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* class.c (rb_define_class, rb_define_class_id_under): refine
|
||||
|
|
120
test/test_forwardable.rb
Normal file
120
test/test_forwardable.rb
Normal file
|
@ -0,0 +1,120 @@
|
|||
require 'test/unit'
|
||||
require 'forwardable'
|
||||
|
||||
class TestForwardable < Test::Unit::TestCase
|
||||
RECEIVER = BasicObject.new
|
||||
RETURNED1 = BasicObject.new
|
||||
RETURNED2 = BasicObject.new
|
||||
|
||||
class << RECEIVER
|
||||
def delegated1
|
||||
RETURNED1
|
||||
end
|
||||
|
||||
def delegated2
|
||||
RETURNED2
|
||||
end
|
||||
end
|
||||
|
||||
def test_def_instance_delegator
|
||||
%i[def_delegator def_instance_delegator].each do |m|
|
||||
cls = forwardable_class do
|
||||
__send__ m, :@receiver, :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
|
||||
__send__ m, :@receiver, :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
|
||||
__send__ m, delegated1: :@receiver, delegated2: :@receiver
|
||||
end
|
||||
|
||||
assert_same RETURNED1, cls.new.delegated1
|
||||
assert_same RETURNED2, cls.new.delegated2
|
||||
|
||||
cls = forwardable_class do
|
||||
__send__ m, %i[delegated1 delegated2] => :@receiver
|
||||
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
|
||||
__send__ m, :@receiver, :delegated1
|
||||
end
|
||||
|
||||
assert_same RETURNED1, cls.delegated1
|
||||
end
|
||||
end
|
||||
|
||||
def test_def_single_delegators
|
||||
%i[def_delegators def_single_delegators].each do |m|
|
||||
cls = single_forwardable_class do
|
||||
__send__ m, :@receiver, :delegated1, :delegated2
|
||||
end
|
||||
|
||||
assert_same RETURNED1, cls.delegated1
|
||||
assert_same RETURNED2, cls.delegated2
|
||||
end
|
||||
end
|
||||
|
||||
def test_single_delegate
|
||||
%i[delegate single_delegate].each do |m|
|
||||
cls = single_forwardable_class do
|
||||
__send__ m, delegated1: :@receiver, delegated2: :@receiver
|
||||
end
|
||||
|
||||
assert_same RETURNED1, cls.delegated1
|
||||
assert_same RETURNED2, cls.delegated2
|
||||
|
||||
cls = single_forwardable_class do
|
||||
__send__ m, %i[delegated1 delegated2] => :@receiver
|
||||
end
|
||||
|
||||
assert_same RETURNED1, cls.delegated1
|
||||
assert_same RETURNED2, cls.delegated2
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def forwardable_class(&block)
|
||||
Class.new do
|
||||
extend Forwardable
|
||||
|
||||
def initialize
|
||||
@receiver = RECEIVER
|
||||
end
|
||||
|
||||
class_exec(&block)
|
||||
end
|
||||
end
|
||||
|
||||
def single_forwardable_class(&block)
|
||||
Class.new do
|
||||
extend SingleForwardable
|
||||
|
||||
@receiver = RECEIVER
|
||||
|
||||
class_exec(&block)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue