зеркало из https://github.com/github/ruby.git
test_forwardable.rb: operators
* test/test_forwardable.rb: add tests for operators. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55369 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
bbb01a4b54
Коммит
094a3b1162
|
@ -253,6 +253,35 @@ class TestForwardable < Test::Unit::TestCase
|
|||
}
|
||||
end
|
||||
|
||||
def test_aref
|
||||
obj = Object.new.extend SingleForwardable
|
||||
obj.instance_variable_set("@h", {foo: 42})
|
||||
obj.def_delegator("@h", :[])
|
||||
assert_equal(42, obj[:foo])
|
||||
end
|
||||
|
||||
def test_aset
|
||||
obj = Object.new.extend SingleForwardable
|
||||
obj.instance_variable_set("@h", h = {foo: 0})
|
||||
obj.def_delegator("@h", :[]=)
|
||||
obj[:foo] = 42
|
||||
assert_equal(42, h[:foo])
|
||||
end
|
||||
|
||||
def test_binop
|
||||
obj = Object.new.extend SingleForwardable
|
||||
obj.instance_variable_set("@h", 40)
|
||||
obj.def_delegator("@h", :+)
|
||||
assert_equal(42, obj+2)
|
||||
end
|
||||
|
||||
def test_uniop
|
||||
obj = Object.new.extend SingleForwardable
|
||||
obj.instance_variable_set("@h", -42)
|
||||
obj.def_delegator("@h", :-@)
|
||||
assert_equal(42, -obj)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def forwardable_class(
|
||||
|
|
Загрузка…
Ссылка в новой задаче