Ignore:
Timestamp:
Jul 9, 2020, 8:51:43 AM (4 years ago)
Author:
coas-nagasima
Message:

mrubyを2.1.1に更新

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  
    22# Proc(Ext) Test
    33
     4def 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
     11end
     12
    413assert('Proc#source_location') do
    5   loc = Proc.new {}.source_location
    6   next true if loc.nil?
    7   assert_equal loc[0][-7, 7], 'proc.rb'
    8   assert_equal loc[1], 5
     14  skip unless enable_debug_info?
     15  file, line = Proc.new{}.source_location
     16  assert_equal __FILE__, file
     17  assert_equal __LINE__ - 2, line
    918end
    1019
    1120assert('Proc#inspect') do
    1221  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
     30end
     31
     32assert('Proc#parameters') do
     33  parameters = Proc.new{|x,y=42,*other|}.parameters
     34  assert_equal [[:opt, :x], [:opt, :y], [:rest, :other]], parameters
    1435end
    1536
     
    6788assert('Kernel#proc') do
    6889  assert_true !proc{|a|}.lambda?
     90
     91  assert_raise LocalJumpError do
     92    proc{ break }.call
     93  end
     94end
     95
     96assert "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)
    69107end
    70108
Note: See TracChangeset for help on using the changeset viewer.