From d36ac283d188ba6d923c905a85341761fa1305c3 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sun, 21 Mar 2021 09:42:29 +0900 Subject: Ensure the receiver hash modifiable before updating [Bug #17736] Close https://github.com/ruby/ruby/pull/4298 --- test/ruby/test_hash.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/ruby/test_hash.rb') 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 -- cgit v1.2.3