aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-09 05:14:42 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-09 05:14:42 +0000
commitcccfe4774c1f01e334a1b8d4fe2e74a7f3e82aeb (patch)
tree6031f357843cc2787be721cdb2543d088adc3c50 /test/ruby
parentd000891e435637dcc74a7018755dde4f558735fc (diff)
downloadruby-cccfe4774c1f01e334a1b8d4fe2e74a7f3e82aeb.tar.gz
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54051 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_hash.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb
index e08235ec1c..99231c73b2 100644
--- a/test/ruby/test_hash.rb
+++ b/test/ruby/test_hash.rb
@@ -742,6 +742,28 @@ class TestHash < Test::Unit::TestCase
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)