diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/test_forwardable.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/test_forwardable.rb b/test/test_forwardable.rb index f678ca4fc7..b948fddac0 100644 --- a/test/test_forwardable.rb +++ b/test/test_forwardable.rb @@ -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( |