mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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:
parent
bbb01a4b54
commit
094a3b1162
1 changed files with 29 additions and 0 deletions
|
@ -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(
|
||||
|
|
Loading…
Add table
Reference in a new issue