From e72e50b5d57d4ad003da8a1531263f7795c27db5 Mon Sep 17 00:00:00 2001 From: Kouhei Sutou Date: Tue, 21 Mar 2017 16:42:25 +0900 Subject: Hash sub class creates new sub class objects instead of Hash --- mrbgems/mruby-hash-ext/test/hash.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'mrbgems/mruby-hash-ext/test') diff --git a/mrbgems/mruby-hash-ext/test/hash.rb b/mrbgems/mruby-hash-ext/test/hash.rb index b43541b7f..6e70953f5 100644 --- a/mrbgems/mruby-hash-ext/test/hash.rb +++ b/mrbgems/mruby-hash-ext/test/hash.rb @@ -39,6 +39,12 @@ assert('Hash.[] "c_key", "c_value"') do end end +assert('Hash.[] for sub class') do + sub_hash_class = Class.new(Hash) + sub_hash = sub_hash_class[] + assert_equal(sub_hash_class, sub_hash.class) +end + assert('Hash.try_convert') do assert_nil Hash.try_convert(nil) assert_nil Hash.try_convert("{1=>2}") @@ -143,6 +149,12 @@ assert("Hash#invert") do assert_equal('b', h[2]) end +assert("Hash#invert with sub class") do + sub_hash_class = Class.new(Hash) + sub_hash = sub_hash_class.new + assert_equal(sub_hash_class, sub_hash.invert.class) +end + assert("Hash#keep_if") do h = { 1 => 2, 3 => 4, 5 => 6 } assert_equal({3=>4,5=>6}, h.keep_if {|k, v| k + v >= 7 }) -- cgit v1.2.3