diff options
Diffstat (limited to 'test/ruby/test_hash.rb')
-rw-r--r-- | test/ruby/test_hash.rb | 21 |
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(*) |