summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-09 08:54:15 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-09 08:54:15 +0000
commitea5184b939ec3dbdcbd7013da350b8dcb6ca6107 (patch)
treee4e0e60e4b59d9f33a8f05a9864ffd0ff660b2fb /test
parentcb18d4ba462e50149d2d9a5066ecdbac44d32905 (diff)
hash.c: implement Hash#map_v and Hash#map_v!
* hash.c (rb_hash_map_v, rb_hash_map_v_bang): impelement Hash#map_v and Hash#map_v! [Feature #12512] [ruby-core:76095] * test/ruby/test_hash.rb: add tests for above change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55847 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_hash.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb
index 6a8e7f0423..2b2f154803 100644
--- a/test/ruby/test_hash.rb
+++ b/test/ruby/test_hash.rb
@@ -1415,6 +1415,27 @@ class TestHash < Test::Unit::TestCase
assert_equal([10, 20, 30], [1, 2, 3].map(&h))
end
+ def test_map_v
+ x = @cls[a: 1, b: 2, c: 3]
+ y = x.map_v {|v| v ** 2 }
+ assert_equal([1, 4, 9], y.values_at(:a, :b, :c))
+ assert_not_same(x, y)
+
+ y = x.map_v.with_index {|v, i| "#{v}.#{i}" }
+ assert_equal(%w(1.0 2.1 3.2), y.values_at(:a, :b, :c))
+ end
+
+ def test_map_v_bang
+ x = @cls[a: 1, b: 2, c: 3]
+ y = x.map_v! {|v| v ** 2 }
+ assert_equal([1, 4, 9], y.values_at(:a, :b, :c))
+ assert_same(x, y)
+
+ x = @cls[a: 1, b: 2, c: 3]
+ y = x.map_v!.with_index {|v, i| "#{v}.#{i}" }
+ assert_equal(%w(1.0 2.1 3.2), y.values_at(:a, :b, :c))
+ end
+
class TestSubHash < TestHash
class SubHash < Hash
def reject(*)