Skip to content

Commit

Permalink
Fix Enumerable#tally with some arguments pattern [Feature #17744]
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
kachick authored and eregon committed Mar 27, 2021
1 parent dbe1906 commit 085270e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions core/enumerable/tally_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,25 @@
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}
Expand Down

0 comments on commit 085270e

Please sign in to comment.