From 2772c80ce01d097df86336ce27b30610d6bfcc29 Mon Sep 17 00:00:00 2001 From: akr Date: Tue, 18 Aug 2009 12:02:53 +0000 Subject: * 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 --- test/ruby/test_enumerator.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test') diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb index 8a2417c5d5..f8a3b3e32a 100644 --- a/test/ruby/test_enumerator.rb +++ b/test/ruby/test_enumerator.rb @@ -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 -- cgit v1.2.3