- Timestamp:
- Jul 9, 2020, 8:51:43 AM (4 years ago)
- Location:
- EcnlProtoTool/trunk/mruby-2.1.1
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/mruby-2.1.1/mrbgems/mruby-proc-ext/test/proc.rb
r331 r439 2 2 # Proc(Ext) Test 3 3 4 def enable_debug_info? 5 return @enable_debug_info unless @enable_debug_info == nil 6 begin 7 raise 8 rescue => e 9 @enable_debug_info = !e.backtrace.empty? 10 end 11 end 12 4 13 assert('Proc#source_location') do 5 loc = Proc.new {}.source_location6 next true if loc.nil?7 assert_equal loc[0][-7, 7], 'proc.rb'8 assert_equal loc[1], 514 skip unless enable_debug_info? 15 file, line = Proc.new{}.source_location 16 assert_equal __FILE__, file 17 assert_equal __LINE__ - 2, line 9 18 end 10 19 11 20 assert('Proc#inspect') do 12 21 ins = Proc.new{}.inspect 13 assert_kind_of String, ins 22 if enable_debug_info? 23 metas = %w(\\ * ? [ ] { }) 24 file = __FILE__.split("").map{|c| metas.include?(c) ? "\\#{c}" : c}.join 25 line = __LINE__ - 4 26 else 27 file = line = "-" 28 end 29 assert_match "#<Proc:0x*@#{file}:#{line}>", ins 30 end 31 32 assert('Proc#parameters') do 33 parameters = Proc.new{|x,y=42,*other|}.parameters 34 assert_equal [[:opt, :x], [:opt, :y], [:rest, :other]], parameters 14 35 end 15 36 … … 67 88 assert('Kernel#proc') do 68 89 assert_true !proc{|a|}.lambda? 90 91 assert_raise LocalJumpError do 92 proc{ break }.call 93 end 94 end 95 96 assert "Proc#<< and Proc#>>" do 97 add3 = ->(n) { n + 3 } 98 mul2 = ->(n) { n * 2 } 99 100 f1 = mul2 << add3 101 assert_kind_of Proc, f1 102 assert_equal 16, f1.call(5) 103 104 f2 = mul2 >> add3 105 assert_kind_of Proc, f2 106 assert_equal 13, f2.call(5) 69 107 end 70 108
Note:
See TracChangeset
for help on using the changeset viewer.