From 86eaa24570a7a062cf8f08606256e0cd23d2b980 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 12 Jun 2015 08:34:17 +0000 Subject: hash.c: fetch_values * hash.c (rb_hash_fetch_values): add `Hash#fetch_values`. [Feature #10017] [Fix GH-776] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50845 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_hash.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test') diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index 86305ee958..f6046cb428 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -498,6 +498,21 @@ class TestHash < Test::Unit::TestCase assert_equal ['three', nil, 'one', 'nil'], res end + def test_fetch_values + res = @h.fetch_values + assert_equal(0, res.length) + + res = @h.fetch_values(3, 2, 1, nil) + assert_equal(4, res.length) + assert_equal %w( three two one nil ), res + + assert_raises KeyError do + @h.fetch_values(3, 'invalid') + end + + res = @h.fetch_values(3, 'invalid') { |k| k.upcase } + assert_equal %w( three INVALID ), res + end def test_invert h = @h.invert -- cgit v1.2.3