mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* enumerator.c (lazy_take_func, lazy_take): multiple calls of
force/to_a method to Enumerator::Lazy#take should return same results. [ruby-dev:45634] [Bug #6428] * test/ruby/test_lazy_enumerator.rb (test_take_recycle): add test for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35638 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
526a853d6d
commit
4007da1792
3 changed files with 19 additions and 1 deletions
|
@ -1,3 +1,12 @@
|
|||
Mon May 14 00:14:24 2012 CHIKANAGA Tomoyuki <nagachika@ruby-lang.org>
|
||||
|
||||
* enumerator.c (lazy_take_func, lazy_take): multiple calls of
|
||||
force/to_a method to Enumerator::Lazy#take should return same
|
||||
results. [ruby-dev:45634] [Bug #6428]
|
||||
|
||||
* test/ruby/test_lazy_enumerator.rb (test_take_recycle): add test for
|
||||
above.
|
||||
|
||||
Sun May 13 23:38:31 2012 CHIKANAGA Tomoyuki <nagachika@ruby-lang.org>
|
||||
|
||||
* test/ruby/test_io.rb (test_flush_in_finalizer1): don't use IO.for_fd
|
||||
|
|
|
@ -1533,6 +1533,7 @@ lazy_take_func(VALUE val, VALUE args, int argc, VALUE *argv)
|
|||
|
||||
rb_funcall2(argv[0], id_yield, argc - 1, argv + 1);
|
||||
if (--memo->u3.cnt == 0) {
|
||||
memo->u3.cnt = memo->u2.argc;
|
||||
return Qundef;
|
||||
}
|
||||
else {
|
||||
|
@ -1557,7 +1558,7 @@ lazy_take(VALUE obj, VALUE n)
|
|||
argv[2] = INT2NUM(0);
|
||||
argc = 3;
|
||||
}
|
||||
memo = NEW_MEMO(0, 0, len);
|
||||
memo = NEW_MEMO(0, len, len);
|
||||
return lazy_set_method(rb_block_call(rb_cLazy, id_new, argc, argv,
|
||||
lazy_take_func, (VALUE) memo),
|
||||
rb_ary_new3(1, n));
|
||||
|
|
|
@ -229,6 +229,14 @@ class TestLazyEnumerator < Test::Unit::TestCase
|
|||
assert_equal(nil, a.current)
|
||||
end
|
||||
|
||||
def test_take_recycle
|
||||
bug6428 = '[ruby-dev:45634]'
|
||||
a = Step.new(1..10)
|
||||
take5 = a.lazy.take(5)
|
||||
assert_equal((1..5).to_a, take5.force, bug6428)
|
||||
assert_equal((1..5).to_a, take5.force, bug6428)
|
||||
end
|
||||
|
||||
def test_take_while
|
||||
a = Step.new(1..10)
|
||||
assert_equal(1, a.take_while {|i| i < 5}.first)
|
||||
|
|
Loading…
Add table
Reference in a new issue