summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-hash-ext/test
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2014-04-27 03:03:27 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2014-04-27 03:03:27 +0900
commit7e175d8130bf329d44368a057587a9e4b3133589 (patch)
tree05bcc28852e18a4369b8fdaa45368bcad7227a29 /mrbgems/mruby-hash-ext/test
parent855a3f599188ef0e3c86f95410317d7f212e6ceb (diff)
downloadmruby-7e175d8130bf329d44368a057587a9e4b3133589.tar.gz
mruby-7e175d8130bf329d44368a057587a9e4b3133589.zip
add Hash#fetch; close #2134
Diffstat (limited to 'mrbgems/mruby-hash-ext/test')
-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 cdf00173a..661da3af3 100644
--- a/mrbgems/mruby-hash-ext/test/hash.rb
+++ b/mrbgems/mruby-hash-ext/test/hash.rb
@@ -27,3 +27,15 @@ assert('Hash#values_at') do
h = Hash.new { |hash,k| hash[k] = k }
assert_equal keys, h.values_at(*keys)
end
+
+assert('Hash#fetch') do
+ h = { "cat" => "feline", "dog" => "canine", "cow" => "bovine" }
+ assert_equal "feline", h.fetch("cat")
+ assert_equal "mickey", h.fetch("mouse", "mickey")
+ assert_equal "minny", h.fetch("mouse"){"minny"}
+ begin
+ h.fetch("gnu")
+ rescue => e
+ assert_kind_of(StandardError, e);
+ end
+end