diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-25 15:02:05 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-25 15:02:05 +0000 |
commit | 0dc342de848a642ecce8db697b8fecd83a63e117 (patch) | |
tree | 2b7ed4724aff1f86073e4740134bda9c4aac1a39 /trunk/test/ruby/test_continuation.rb | |
parent | ef70cf7138ab8034b5b806f466e4b484b24f0f88 (diff) |
added tag v1_9_0_4
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_9_0_4@18845 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'trunk/test/ruby/test_continuation.rb')
-rw-r--r-- | trunk/test/ruby/test_continuation.rb | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/trunk/test/ruby/test_continuation.rb b/trunk/test/ruby/test_continuation.rb new file mode 100644 index 0000000000..c719db8c35 --- /dev/null +++ b/trunk/test/ruby/test_continuation.rb @@ -0,0 +1,81 @@ +require 'test/unit' +require 'continuation' +require 'fiber' +require_relative 'envutil' + +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.resume + c.call + } + end + + def test_ary_flatten + assert_normal_exit %q{ + require 'continuation' + n = 0 + o = Object.new + def o.to_ary() callcc {|k| $k = k; [1,2,3]} end + [10,20,o,30,o,40].flatten.inspect + n += 1 + $k.call if n < 100 + }, '[ruby-dev:34798]' + end + + def test_marshal_dump + assert_normal_exit %q{ + require 'continuation' + n = 0 + o = Object.new + def o.marshal_dump() callcc {|k| $k = k }; "fofof" end + a = [1,2,3,o,4,5,6] + Marshal.dump(a).inspect + n += 1 + $k.call if n < 100 + }, '[ruby-dev:34802]' + end + +end + |