1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* enumerator.c (next_init): don't clear feedvalue.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24588 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2009-08-19 17:32:56 +00:00
parent 3b4949ffa8
commit 0c0f754400
3 changed files with 38 additions and 1 deletions

View file

@ -1,3 +1,7 @@
Thu Aug 20 02:32:08 2009 Tanaka Akira <akr@fsij.org>
* enumerator.c (next_init): don't clear feedvalue.
Thu Aug 20 01:28:42 2009 Tanaka Akira <akr@fsij.org>
* enumerator.c: implement Enumerator#{next_values,peek_values,feed}

View file

@ -592,7 +592,6 @@ next_init(VALUE obj, struct enumerator *e)
e->dst = curr;
e->fib = rb_fiber_new(next_i, obj);
e->lookahead = Qundef;
e->feedvalue = Qundef;
}
/*

View file

@ -266,6 +266,40 @@ class TestEnumerator < Test::Unit::TestCase
assert_raise(TypeError) { e.feed 2 }
end
def test_feed_before_first_next
o = Object.new
def o.each(ary)
ary << yield
ary << yield
ary << yield
end
ary = []
e = o.to_enum(:each, ary)
e.feed 1
e.next
e.next
assert_equal([1], ary)
end
def test_rewind_clear_feed
o = Object.new
def o.each(ary)
ary << yield
ary << yield
ary << yield
end
ary = []
e = o.to_enum(:each, ary)
e.next
e.feed 1
e.next
e.feed 2
e.rewind
e.next
e.next
assert_equal([1,nil], ary)
end
def test_feed_yielder
x = nil
e = Enumerator.new {|y| x = y.yield; 10 }