diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-03-21 09:42:29 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-03-21 10:07:24 +0900 |
commit | d36ac283d188ba6d923c905a85341761fa1305c3 (patch) | |
tree | d09d2dcaecf2c3de1df323e562f05a016a085ded /test/ruby/test_hash.rb | |
parent | d319eb602d3fe9dbc5dab55cb85974a7c22742e5 (diff) | |
download | ruby-d36ac283d188ba6d923c905a85341761fa1305c3.tar.gz |
Ensure the receiver hash modifiable before updating [Bug #17736]
Close https://github.com/ruby/ruby/pull/4298
Diffstat (limited to 'test/ruby/test_hash.rb')
-rw-r--r-- | test/ruby/test_hash.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index afce9fd6d3..a6acbc6054 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -1238,6 +1238,12 @@ class TestHash < Test::Unit::TestCase 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) + + h = @cls[a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9, j: 10] + 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, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9, j: 10], h) end def test_merge @@ -1257,6 +1263,12 @@ class TestHash < Test::Unit::TestCase 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) + + h = @cls[a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9, j: 10] + 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, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9, j: 10], h) end def test_assoc |