1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/ruby/test_enumerator.rb
ko1 977d66ec99 * cont.c: separate Continuation and Fiber from core.
* ext/continuation/*, ext/fiber/*: ditto.
* include/ruby/ruby.h: remove rb_cFiber.
* include/ruby/intern.h: add the rb_fiber_new() declaration.
* enumerator.c (next_init): fix to use rb_fiber_new().
* test/ruby/test_enumerator.rb: remove next? tests.
* test/ruby/test_continuation.rb: add a require 'continuation'.
* test/ruby/test_fiber.rb: add a require 'fiber'.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13259 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-25 02:03:44 +00:00

47 lines
894 B
Ruby

require 'test/unit'
class TestEnumerator < Test::Unit::TestCase
def enum_test obj
i = 0
obj.map{|e|
e
}.sort
end
def test_iterators
assert_equal [0, 1, 2], enum_test(3.times)
assert_equal [:x, :y, :z], enum_test([:x, :y, :z].each)
assert_equal [[:x, 1], [:y, 2]], enum_test({:x=>1, :y=>2})
end
## Enumerator as Iterator
def test_next
e = 3.times
3.times{|i|
assert_equal i, e.next
}
assert_raise(StopIteration){e.next}
end
def test_loop
e = 3.times
i = 0
loop{
assert_equal(i, e.next)
i += 1
}
end
def test_nested_itaration
def (o = Object.new).each
yield :ok1
yield [:ok2, :x].each.next
end
e = o.to_enum
assert_equal :ok1, e.next
assert_equal :ok2, e.next
assert_raise(StopIteration){e.next}
end
end