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 | 226ec37b0312ba20adf9f219272fd2043956fdc6 (patch) | |
tree | 740126dbac52681afc6d8355f64fe67ae40a8c35 /test/ruby | |
parent | abc4b723bdcd0c4480427b74e052990cfd8f0065 (diff) | |
download | ruby-226ec37b0312ba20adf9f219272fd2043956fdc6.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/ruby')
-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 |