diff options
author | Kenichi Kamiya <[email protected]> | 2021-03-27 12:55:46 +0900 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-27 12:55:46 +0900 |
commit | aceb8c0b4bf37a65c78f09eaf835db72c7a47c48 (patch) | |
tree | 02baafb15b9aa9fb1c45670932a25e1138a006f9 /test/ruby/test_enum.rb | |
parent | 785c77d7827677b547fa233deef0b65ec10ecf6b (diff) |
Fix Enumerable#tally with some arguments pattern [Feature #17744]
* Add test cases for Enumerable#tally with hash argument
* Add ruby/spec for Enumerable#tally with hash argument
* Fix Enumerable#tally does not update given frozen hash
* Add test cases for Enumerable#tally with hash convertible arguments
* Fix SEGV when Enumerable#tally takes non Hash convertible
* FIx cosmetic damage enum.c
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/4327
Merged-By: nobu <[email protected]>
Diffstat (limited to 'test/ruby/test_enum.rb')
-rw-r--r-- | test/ruby/test_enum.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/ruby/test_enum.rb b/test/ruby/test_enum.rb index b6d96f1379..4674f984ff 100644 --- a/test/ruby/test_enum.rb +++ b/test/ruby/test_enum.rb @@ -403,6 +403,34 @@ class TestEnumerable < Test::Unit::TestCase end h = {1 => 2, 2 => 2, 3 => 1} + assert_same(h, @obj.tally(h)) + + h = {1 => 2, 2 => 2, 3 => 1}.freeze + assert_raise(FrozenError) do + @obj.tally(h) + end + assert_equal({1 => 2, 2 => 2, 3 => 1}, h) + + hash_convertible = Object.new + def hash_convertible.to_hash + {1 => 3, 4 => "x"} + end + assert_equal({1 => 5, 2 => 2, 3 => 1, 4 => "x"}, @obj.tally(hash_convertible)) + + hash_convertible = Object.new + def hash_convertible.to_hash + {1 => 3, 4 => "x"}.freeze + end + assert_raise(FrozenError) do + @obj.tally(hash_convertible) + end + assert_equal({1 => 3, 4 => "x"}, hash_convertible.to_hash) + + assert_raise(TypeError) do + @obj.tally(BasicObject.new) + end + + h = {1 => 2, 2 => 2, 3 => 1} assert_equal(h, @obj.tally(Hash.new(100))) assert_equal(h, @obj.tally(Hash.new {100})) end |