[前][次][番号順一覧][スレッド一覧]

ruby-changes:43296

From: nobu <ko1@a...>
Date: Sat, 11 Jun 2016 01:01:31 +0900 (JST)
Subject: [ruby-changes:43296] nobu:r55369 (trunk): test_forwardable.rb: operators

nobu	2016-06-11 01:01:25 +0900 (Sat, 11 Jun 2016)

  New Revision: 55369

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55369

  Log:
    test_forwardable.rb: operators
    
    * test/test_forwardable.rb: add tests for operators.

  Modified files:
    trunk/test/test_forwardable.rb
Index: test/test_forwardable.rb
===================================================================
--- test/test_forwardable.rb	(revision 55368)
+++ test/test_forwardable.rb	(revision 55369)
@@ -253,6 +253,35 @@ class TestForwardable < Test::Unit::Test https://github.com/ruby/ruby/blob/trunk/test/test_forwardable.rb#L253
     }
   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(

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]