summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-01-24 04:02:30 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-01-24 04:02:30 +0000
commit498838c6627c82befd3c6dcd5c5d6870b38db5e7 (patch)
tree0a404b6870169df73a240e80766ccb51e926f18a /test
parentac2683c80978dabb24ec367141427c62f1dc5a20 (diff)
* object.c (rb_Hash): add Kernel#Hash conversion method like
Array() or Float(). a patch from Run Paint Run Run. Fix #3131 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34367 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_object.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb
index b05375ebba..15e7b72e35 100644
--- a/test/ruby/test_object.rb
+++ b/test/ruby/test_object.rb
@@ -197,6 +197,19 @@ class TestObject < Test::Unit::TestCase
assert_equal([o], Array(o))
end
+ def test_convert_hash
+ assert_equal(Hash(nil), {})
+ assert_equal(Hash([]), {})
+ assert_equal(Hash(key: :value), {key: :value})
+ assert_raise(TypeError) { Hash([1,2]) }
+ assert_raise(TypeError) { Hash(Object.new) }
+ o = Object.new
+ def o.to_hash; {a: 1, b: 2}; end
+ assert_equal(Hash(o), {a: 1, b: 2})
+ def o.to_hash; 9; end
+ assert_raise(TypeError) { Hash(o) }
+ end
+
def test_to_integer
o = Object.new
def o.to_i; nil; end