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

ruby-changes:41977

From: nobu <ko1@a...>
Date: Wed, 9 Mar 2016 14:14:47 +0900 (JST)
Subject: [ruby-changes:41977] nobu:r54051 (trunk): test_hash.rb: tests for to_h

nobu	2016-03-09 14:14:42 +0900 (Wed, 09 Mar 2016)

  New Revision: 54051

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

  Log:
    test_hash.rb: tests for to_h
    
    * test/ruby/test_hash.rb: add tests for Hash#to_h, which copies
      default value/proc but not instance variables.

  Modified files:
    trunk/test/ruby/test_hash.rb
Index: test/ruby/test_hash.rb
===================================================================
--- test/ruby/test_hash.rb	(revision 54050)
+++ test/ruby/test_hash.rb	(revision 54051)
@@ -742,6 +742,28 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_hash.rb#L742
     assert_instance_of(Hash, h)
   end
 
+  def test_to_h_instance_variable
+    @h.instance_variable_set(:@x, 42)
+    h = @h.to_h
+    if @cls == Hash
+      assert_equal(42, h.instance_variable_get(:@x))
+    else
+      assert_not_send([h, :instance_variable_defined?, :@x])
+    end
+  end
+
+  def test_to_h_default_value
+    @h.default = :foo
+    h = @h.to_h
+    assert_equal(:foo, h.default)
+  end
+
+  def test_to_h_default_proc
+    @h.default_proc = ->(_,k) {"nope#{k}"}
+    h = @h.to_h
+    assert_equal("nope42", h[42])
+  end
+
   def test_nil_to_h
     h = nil.to_h
     assert_equal({}, h)

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

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