2007-05-28 21:59:53 -04:00
|
|
|
require 'test/unit'
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2007-05-30 01:56:13 -04:00
|
|
|
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
|
|
|
|
|
2007-05-28 21:59:53 -04:00
|
|
|
def test_error
|
|
|
|
cont = callcc{|c| c}
|
|
|
|
assert_raise(RuntimeError){
|
|
|
|
Thread.new{cont.call}.join
|
|
|
|
}
|
|
|
|
assert_raise(LocalJumpError){
|
|
|
|
callcc
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|