summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-hash-ext/test/hash.rb
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2017-03-23 01:14:46 +0900
committerGitHub <[email protected]>2017-03-23 01:14:46 +0900
commit41f5c5b2c7e0411ae416bd7915e8772c569f3182 (patch)
treeb94ea6c03ed32c83683c16449751c185dc59e40f /mrbgems/mruby-hash-ext/test/hash.rb
parent8ca9823196f52a3a63006bef703247f0f982bb80 (diff)
parente72e50b5d57d4ad003da8a1531263f7795c27db5 (diff)
downloadmruby-41f5c5b2c7e0411ae416bd7915e8772c569f3182.tar.gz
mruby-41f5c5b2c7e0411ae416bd7915e8772c569f3182.zip
Merge pull request #3529 from kou/hash-ext-sub-class
Hash sub class creates new sub class objects instead of Hash
Diffstat (limited to 'mrbgems/mruby-hash-ext/test/hash.rb')
-rw-r--r--mrbgems/mruby-hash-ext/test/hash.rb12
1 files changed, 12 insertions, 0 deletions
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 })