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:
nobu 2016-06-10 16:01:25 +00:00
Родитель bbb01a4b54
Коммит 094a3b1162
1 изменённых файлов: 29 добавлений и 0 удалений

Просмотреть файл

@ -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(