mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Fix size on Enumerable#cycle when the size is 0 [Bug #14082].
Patch by Kenichi Kamiya git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60666 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3280f54168
commit
dcb8a22f26
2 changed files with 8 additions and 0 deletions
1
enum.c
1
enum.c
|
@ -2845,6 +2845,7 @@ enum_cycle_size(VALUE self, VALUE args, VALUE eobj)
|
|||
VALUE size = enum_size(self, args, 0);
|
||||
|
||||
if (size == Qnil) return Qnil;
|
||||
if (FIXNUM_ZERO_P(size)) return size;
|
||||
|
||||
if (args && (RARRAY_LEN(args) > 0)) {
|
||||
n = RARRAY_AREF(args, 0);
|
||||
|
|
|
@ -576,13 +576,20 @@ class TestEnumerator < Test::Unit::TestCase
|
|||
assert_equal Float::INFINITY, [:foo].cycle.size
|
||||
assert_equal 10, [:foo, :bar].cycle(5).size
|
||||
assert_equal 0, [:foo, :bar].cycle(-10).size
|
||||
assert_equal Float::INFINITY, {foo: 1}.cycle.size
|
||||
assert_equal 10, {foo: 1, bar: 2}.cycle(5).size
|
||||
assert_equal 0, {foo: 1, bar: 2}.cycle(-10).size
|
||||
assert_equal 0, [].cycle.size
|
||||
assert_equal 0, [].cycle(5).size
|
||||
assert_equal 0, {}.cycle.size
|
||||
assert_equal 0, {}.cycle(5).size
|
||||
|
||||
assert_equal nil, @obj.cycle.size
|
||||
assert_equal nil, @obj.cycle(5).size
|
||||
assert_equal Float::INFINITY, @sized.cycle.size
|
||||
assert_equal 126, @sized.cycle(3).size
|
||||
assert_equal Float::INFINITY, [].to_enum { 42 }.cycle.size
|
||||
assert_equal 0, [].to_enum { 0 }.cycle.size
|
||||
end
|
||||
|
||||
def test_size_for_loops
|
||||
|
|
Loading…
Add table
Reference in a new issue