aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_object.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_object.rb')
-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