summaryrefslogtreecommitdiff
path: root/spec/ruby
diff options
context:
space:
mode:
authorKenichi Kamiya <kachick1@gmail.com>2021-03-27 12:55:46 +0900
committerGitHub <noreply@github.com>2021-03-27 12:55:46 +0900
commitaceb8c0b4bf37a65c78f09eaf835db72c7a47c48 (patch)
tree02baafb15b9aa9fb1c45670932a25e1138a006f9 /spec/ruby
parent785c77d7827677b547fa233deef0b65ec10ecf6b (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 <nobu@ruby-lang.org>
Diffstat (limited to 'spec/ruby')
-rw-r--r--spec/ruby/core/enumerable/tally_spec.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/spec/ruby/core/enumerable/tally_spec.rb b/spec/ruby/core/enumerable/tally_spec.rb
index 1367453f44..c23ea11697 100644
--- a/spec/ruby/core/enumerable/tally_spec.rb
+++ b/spec/ruby/core/enumerable/tally_spec.rb
@@ -45,6 +45,25 @@ ruby_version_is "3.1" do
enum.tally({ 'foo' => 1 }).should == { 'foo' => 3, 'bar' => 1, 'baz' => 1}
end
+ it "returns the given hash" do
+ enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz')
+ hash = { 'foo' => 1 }
+ enum.tally(hash).should equal(hash)
+ end
+
+ it "raises a FrozenError and does not udpate the given hash when the hash is frozen" do
+ enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz')
+ hash = { 'foo' => 1 }.freeze
+ -> { enum.tally(hash) }.should raise_error(FrozenError)
+ hash.should == { 'foo' => 1 }
+ end
+
+ it "does not call given block" do
+ enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz')
+ enum.tally({ 'foo' => 1 }) { |v| ScratchPad << v }
+ ScratchPad.recorded.should == []
+ end
+
it "ignores the default value" do
enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz')
enum.tally(Hash.new(100)).should == { 'foo' => 2, 'bar' => 1, 'baz' => 1}