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_continuation.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

54 lines
972 B
Ruby

require 'test/unit'
require 'continuation'
require 'fiber'
class TestContinuation < Test::Unit::TestCase
def test_create
assert_equal(:ok, callcc{:ok})
assert_equal(:ok, callcc{|c| c.call :ok})
end
def test_call
assert_equal(:ok, callcc{|c| c.call :ok})
ary = []
ary << callcc{|c|
@cont = c
:a
}
@cont.call :b if ary.length < 3
assert_equal([:a, :b, :b], ary)
end
def test_check_localvars
vv = 0
@v = 0
@ary = []
[1, 2, 3].each{|i|
callcc {|k| @k = k}
@v += 1
vv += 1
}
@ary << [vv, @v]
@k.call if @v < 10
assert_equal((3..10).map{|e| [e, e]}, @ary)
end
def test_error
cont = callcc{|c| c}
assert_raise(RuntimeError){
Thread.new{cont.call}.join
}
assert_raise(LocalJumpError){
callcc
}
assert_raise(RuntimeError){
c = nil
Fiber.new do
callcc {|c2| c = c2 }
end.yield
c.call
}
end
end