summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-10 16:01:25 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-10 16:01:25 +0000
commit094a3b116243a91b7be47025cc81766bd3a8146c (patch)
tree5c16f5556eefb714902d887ed008f1a908d6b023
parentbbb01a4b54bbe650531e6523be4bb5e6819658a4 (diff)
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
-rw-r--r--test/test_forwardable.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/test_forwardable.rb b/test/test_forwardable.rb
index f678ca4fc71..b948fddac02 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(