diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-06-12 08:34:17 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-06-12 08:34:17 +0000 |
commit | 86eaa24570a7a062cf8f08606256e0cd23d2b980 (patch) | |
tree | 740126dbac52681afc6d8355f64fe67ae40a8c35 /test | |
parent | c54fb9ec8b7d7dc90e2083aada6dc9e472f21679 (diff) | |
download | ruby-86eaa24570a7a062cf8f08606256e0cd23d2b980.tar.gz |
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
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_hash.rb | 15 |
1 files changed, 15 insertions, 0 deletions
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 |