mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Add test for #<< and #>> for Proc and Method class
This commit is contained in:
@@ -371,6 +371,25 @@ assert "Method#initialize_copy" do
|
||||
assert_equal(m1, m2)
|
||||
end
|
||||
|
||||
assert "Method#<< and Method#>>" do
|
||||
obj = Object.new
|
||||
class << obj
|
||||
def mul2(n); n * 2; end
|
||||
def add3(n); n + 3; end
|
||||
end
|
||||
|
||||
f = obj.method(:mul2)
|
||||
g = obj.method(:add3)
|
||||
|
||||
m1 = f << g
|
||||
assert_kind_of Proc, m1
|
||||
assert_equal 16, m1.call(5)
|
||||
|
||||
m2 = f >> g
|
||||
assert_kind_of Proc, m2
|
||||
assert_equal 13, m2.call(5)
|
||||
end
|
||||
|
||||
assert 'UnboundMethod#arity' do
|
||||
c = Class.new {
|
||||
def foo(a, b)
|
||||
|
||||
@@ -77,6 +77,19 @@ assert('Kernel#proc') do
|
||||
end
|
||||
end
|
||||
|
||||
assert "Proc#<< and Proc#>>" do
|
||||
add3 = ->(n) { n + 3 }
|
||||
mul2 = ->(n) { n * 2 }
|
||||
|
||||
f1 = mul2 << add3
|
||||
assert_kind_of Proc, f1
|
||||
assert_equal 16, f1.call(5)
|
||||
|
||||
f2 = mul2 >> add3
|
||||
assert_kind_of Proc, f2
|
||||
assert_equal 13, f2.call(5)
|
||||
end
|
||||
|
||||
assert('mrb_proc_new_cfunc_with_env') do
|
||||
ProcExtTest.mrb_proc_new_cfunc_with_env(:test)
|
||||
ProcExtTest.mrb_proc_new_cfunc_with_env(:mruby)
|
||||
|
||||
Reference in New Issue
Block a user