summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2022-02-09 18:24:17 +0900
committerYusuke Endoh <mame@ruby-lang.org>2022-02-10 00:14:27 +0900
commit496591de96b261b8789332c7f8b2bfbd17658955 (patch)
tree4bfeafcfd1086faa26c1cb2893790cebec404328 /test
parent8013250136b61e0ae5a8d27a4ec73936cd7647eb (diff)
st.c: Do not clear entries_bound when calling Hash#shift for empty hash
tab->entries_bound is used to check if the bins are full in rebuild_table_if_necessary. Hash#shift against an empty hash assigned 0 to tab->entries_bound, but didn't clear the bins. Thus, the table is not rebuilt even when the bins are full. Attempting to add a new element into full-bin hash gets stuck. This change stops clearing tab->entries_bound in Hash#shift. [Bug #18578]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5539
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_hash.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb
index 39376524fa..073a0dabe8 100644
--- a/test/ruby/test_hash.rb
+++ b/test/ruby/test_hash.rb
@@ -1069,6 +1069,19 @@ class TestHash < Test::Unit::TestCase
assert_nil(h.shift)
end
+ def test_shift_for_empty_hash
+ # [ruby-dev:51159]
+ h = @cls[]
+ 100.times{|n|
+ while h.size < n
+ k = Random.rand 0..1<<30
+ h[k] = 1
+ end
+ 0 while h.shift
+ assert_equal({}, h)
+ }
+ end
+
def test_reject_bang2
assert_equal({1=>2}, @cls[1=>2,3=>4].reject! {|k, v| k + v == 7 })
assert_nil(@cls[1=>2,3=>4].reject! {|k, v| k == 5 })