aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_hash.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-04-24 03:46:55 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-04-24 03:46:55 +0000
commit770ddcdfe069f8654a07e0fcc758aea591cdd17d (patch)
tree36c7009eeab34ae5c08ac62d6005c9ee145b46a3 /test/ruby/test_hash.rb
parentb05c95d93f39b95c6c743282ce4d9e674453f12f (diff)
downloadruby-770ddcdfe069f8654a07e0fcc758aea591cdd17d.tar.gz
* hash.c, object.c, struct.c, lib/ostruct.rb: add to_h methods.
[Feature #6276] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35452 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_hash.rb')
-rw-r--r--test/ruby/test_hash.rb26
1 files changed, 25 insertions, 1 deletions
diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb
index e3c92125c5..0c03bf4726 100644
--- a/test/ruby/test_hash.rb
+++ b/test/ruby/test_hash.rb
@@ -77,7 +77,7 @@ class TestHash < Test::Unit::TestCase
# From rubicon
def setup
- @cls = Hash
+ @cls ||= Hash
@h = @cls[
1 => 'one', 2 => 'two', 3 => 'three',
self => 'self', true => 'true', nil => 'nil',
@@ -631,6 +631,20 @@ class TestHash < Test::Unit::TestCase
def test_to_hash
h = @h.to_hash
assert_equal(@h, h)
+ assert_instance_of(@cls, h)
+ end
+
+ def test_to_h
+ h = @h.to_h
+ assert_equal(@h, h)
+ assert_instance_of(Hash, h)
+ end
+
+ def test_nil_to_h
+ h = nil.to_h
+ assert_equal({}, h)
+ assert_nil(h.default)
+ assert_nil(h.default_proc)
end
def test_to_s
@@ -932,4 +946,14 @@ class TestHash < Test::Unit::TestCase
assert_not_equal(h.hash, h.invert.hash, feature4262)
end
end
+
+ class TestSubHash < TestHash
+ class SubHash < Hash
+ end
+
+ def setup
+ @cls = SubHash
+ super
+ end
+ end
end