ruby-changes:48551
From: marcandre <ko1@a...>
Date: Mon, 6 Nov 2017 07:14:30 +0900 (JST)
Subject: [ruby-changes:48551] marcandRe: r60666 (trunk): Fix size on Enumerable#cycle when the size is 0 [Bug #14082].
marcandre 2017-11-06 07:14:25 +0900 (Mon, 06 Nov 2017) New Revision: 60666 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60666 Log: Fix size on Enumerable#cycle when the size is 0 [Bug #14082]. Patch by Kenichi Kamiya Modified files: trunk/enum.c trunk/test/ruby/test_enumerator.rb Index: enum.c =================================================================== --- enum.c (revision 60665) +++ enum.c (revision 60666) @@ -2845,6 +2845,7 @@ enum_cycle_size(VALUE self, VALUE args, https://github.com/ruby/ruby/blob/trunk/enum.c#L2845 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); Index: test/ruby/test_enumerator.rb =================================================================== --- test/ruby/test_enumerator.rb (revision 60665) +++ test/ruby/test_enumerator.rb (revision 60666) @@ -576,13 +576,20 @@ class TestEnumerator < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_enumerator.rb#L576 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/