diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-08-18 12:02:53 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-08-18 12:02:53 +0000 |
commit | 2772c80ce01d097df86336ce27b30610d6bfcc29 (patch) | |
tree | d97deebedbedd94781971ec3c84aff3dacceb18e /test/ruby/test_enumerator.rb | |
parent | ec490ab2c49260f1238e64f1a3db526f00745559 (diff) | |
download | ruby-2772c80ce01d097df86336ce27b30610d6bfcc29.tar.gz |
* 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
Diffstat (limited to 'test/ruby/test_enumerator.rb')
-rw-r--r-- | test/ruby/test_enumerator.rb | 22 |
1 files changed, 22 insertions, 0 deletions
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 |