summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2021-03-21 09:42:29 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-03-21 10:07:24 +0900
commitd36ac283d188ba6d923c905a85341761fa1305c3 (patch)
treed09d2dcaecf2c3de1df323e562f05a016a085ded /test
parentd319eb602d3fe9dbc5dab55cb85974a7c22742e5 (diff)
Ensure the receiver hash modifiable before updating [Bug #17736]
Close https://github.com/ruby/ruby/pull/4298
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4299
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_hash.rb12
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