mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* enumerator.c (enumerator_peek): new method Enumerator#peek.
(enumerator_next): don't rewind at end. [ruby-dev:38932] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24578 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ec490ab2c4
commit
2772c80ce0
3 changed files with 74 additions and 3 deletions
|
@ -130,5 +130,27 @@ class TestEnumerator < Test::Unit::TestCase
|
|||
assert_equal(3, e.next)
|
||||
assert_raise(StopIteration) { e.next }
|
||||
end
|
||||
|
||||
def test_peek
|
||||
a = [1]
|
||||
e = a.each
|
||||
assert_equal(1, e.peek)
|
||||
assert_equal(1, e.peek)
|
||||
assert_equal(1, e.next)
|
||||
assert_raise(StopIteration) { e.peek }
|
||||
assert_raise(StopIteration) { e.peek }
|
||||
end
|
||||
|
||||
def test_next_after_stopiteration
|
||||
a = [1]
|
||||
e = a.each
|
||||
assert_equal(1, e.next)
|
||||
assert_raise(StopIteration) { e.next }
|
||||
assert_raise(StopIteration) { e.next }
|
||||
e.rewind
|
||||
assert_equal(1, e.next)
|
||||
assert_raise(StopIteration) { e.next }
|
||||
assert_raise(StopIteration) { e.next }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue