diff options
author | Kenichi Kamiya <kachick1@gmail.com> | 2021-03-21 01:57:46 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-03-21 09:38:35 +0900 |
commit | d319eb602d3fe9dbc5dab55cb85974a7c22742e5 (patch) | |
tree | b40843fde44d2847be176129f0355f6e4bbc7e94 /test | |
parent | 54bfa0570d8dd2da0dbf8c8fc75b34b4cf6831a6 (diff) |
Add Hash#{update, merge!} test to ensure receiver modifiable in block
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/4299
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_hash.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index 849fd3a772..afce9fd6d3 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -1232,6 +1232,14 @@ class TestHash < Test::Unit::TestCase assert_equal({1=>8, 2=>4, 3=>4, 5=>7}, h1) end + def test_update5 + h = @cls[a: 1, b: 2, c: 3] + assert_raise(FrozenError) do + h.update({a: 10, b: 20}){ |key, v1, v2| key == :b && h.freeze; v2 } + end + assert_equal(@cls[a: 10, b: 2, c: 3], h) + end + def test_merge h1 = @cls[1=>2, 3=>4] h2 = {1=>3, 5=>7} @@ -1243,6 +1251,14 @@ class TestHash < Test::Unit::TestCase assert_equal({1=>8, 2=>4, 3=>4, 5=>7}, h1.merge(h2, h3) {|k, v1, v2| k + v1 + v2 }) end + def test_merge! + h = @cls[a: 1, b: 2, c: 3] + assert_raise(FrozenError) do + h.merge!({a: 10, b: 20}){ |key, v1, v2| key == :b && h.freeze; v2 } + end + assert_equal(@cls[a: 10, b: 2, c: 3], h) + end + def test_assoc assert_equal([3,4], @cls[1=>2, 3=>4, 5=>6].assoc(3)) assert_nil(@cls[1=>2, 3=>4, 5=>6].assoc(4)) |