diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-08-08 07:07:03 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-08-08 07:07:03 +0000 |
commit | 7c9129e35d7b55e5fe2607f087fde36f5b4cc48f (patch) | |
tree | 03303e152f40736509c468d6e97fef014cbf47c1 /test/ruby | |
parent | e7e009f725d3a721430d2c968882ff4ec6ff961f (diff) | |
download | ruby-7c9129e35d7b55e5fe2607f087fde36f5b4cc48f.tar.gz ruby-7c9129e35d7b55e5fe2607f087fde36f5b4cc48f.tar.xz ruby-7c9129e35d7b55e5fe2607f087fde36f5b4cc48f.zip |
* enumerator.c (enumerator_next_p): should check correctly even when
e.next has not been called before.
* enumerator.c (enumerator_next): raise StopIteration (name taken
from Python) instead of IndexError.
* enum.c (enum_zip): catch StopIteration exception.
* enumerator.c (enumerator_with_index): return Enumerator if no
block is given.
* test/ruby/test_iterator.rb (TestIterator::test_enumerator): add
test for enumerators.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@12905 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_iterator.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/test/ruby/test_iterator.rb b/test/ruby/test_iterator.rb index e63823713..45f145262 100644 --- a/test/ruby/test_iterator.rb +++ b/test/ruby/test_iterator.rb @@ -488,4 +488,23 @@ class TestIterator < Test::Unit::TestCase def test_block_given_within_iterator assert_equal(["b"], ["a", "b", "c"].grep(IterString.new("b")) {|s| s}) end + + def test_enumerator + [1,2,3].each.with_index {|x,i| + assert_equal(x, i+1) + } + + e = [1,2,3].each + assert_equal(1, e.next) + assert_equal(true, e.next?) + assert_equal(2, e.next) + assert_equal(3, e.next) + assert_raises(StopIteration){e.next} + e.rewind + assert_equal(true, e.next?) + assert_equal(1, e.next) + + assert_equal([[1, 8, 10], [2, 6, 11], [3, 4, 12]], + (1..10).zip([8,6,4],(10..100)).to_a) + end end |