source: EcnlProtoTool/trunk/mruby-1.2.0/mrbgems/mruby-error/test/exception.rb@ 321

Last change on this file since 321 was 321, checked in by coas-nagasima, 7 years ago

文字コードを設定

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-ruby;charset=UTF-8
File size: 1.4 KB
Line 
1assert 'mrb_protect' do
2 # no failure in protect returns [result, false]
3 assert_equal ['test', false] do
4 ExceptionTest.mrb_protect { 'test' }
5 end
6 # failure in protect returns [exception, true]
7 result = ExceptionTest.mrb_protect { raise 'test' }
8 assert_kind_of RuntimeError, result[0]
9 assert_true result[1]
10end
11
12assert 'mrb_ensure' do
13 a = false
14 assert_equal 'test' do
15 ExceptionTest.mrb_ensure Proc.new { 'test' }, Proc.new { a = true }
16 end
17 assert_true a
18
19 a = false
20 assert_raise RuntimeError do
21 ExceptionTest.mrb_ensure Proc.new { raise 'test' }, Proc.new { a = true }
22 end
23 assert_true a
24end
25
26assert 'mrb_rescue' do
27 assert_equal 'test' do
28 ExceptionTest.mrb_rescue Proc.new { 'test' }, Proc.new {}
29 end
30
31 class CustomExp < Exception
32 end
33
34 assert_raise CustomExp do
35 ExceptionTest.mrb_rescue Proc.new { raise CustomExp.new 'test' }, Proc.new { 'rescue' }
36 end
37
38 assert_equal 'rescue' do
39 ExceptionTest.mrb_rescue Proc.new { raise 'test' }, Proc.new { 'rescue' }
40 end
41end
42
43assert 'mrb_rescue_exceptions' do
44 assert_equal 'test' do
45 ExceptionTest.mrb_rescue_exceptions Proc.new { 'test' }, Proc.new {}
46 end
47
48 assert_raise RangeError do
49 ExceptionTest.mrb_rescue_exceptions Proc.new { raise RangeError.new 'test' }, Proc.new { 'rescue' }
50 end
51
52 assert_equal 'rescue' do
53 ExceptionTest.mrb_rescue_exceptions Proc.new { raise TypeError.new 'test' }, Proc.new { 'rescue' }
54 end
55end
Note: See TracBrowser for help on using the repository browser.