From d4413ca1770431b04291741e543a02c294ddf4cc Mon Sep 17 00:00:00 2001 From: ko1 Date: Tue, 5 Jun 2007 17:26:00 +0000 Subject: * parse.y (new_yield), compile.c (iseq_compile_each): fix passing parameter. * eval.c, eval_jump.h: simplify rb_yield*. * proc.c (proc_mark): fix to mark proc->block.proc. * proc.c (Init_Proc): add Proc#lambda? * test/ruby/test_lambda.rb: add some tests. * vm.c (invoke_block): fix to check lambda block or not. * vm.c (th_yield_setup_args): fix to check arguments size when lambda block. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@12441 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_lambda.rb | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'test') diff --git a/test/ruby/test_lambda.rb b/test/ruby/test_lambda.rb index 6105f5d12..bb0861ab5 100644 --- a/test/ruby/test_lambda.rb +++ b/test/ruby/test_lambda.rb @@ -1,9 +1,19 @@ require 'test/unit' -__END__ - class TestLambdaParameters < Test::Unit::TestCase + + def test_exact_parameter + assert_raise(ArgumentError){(1..3).each(&lambda{})} + end + def test_call_simple + assert_equal(1, lambda{|a| a}.call(1)) + assert_equal([1,2], lambda{|a, b| [a,b]}.call(1,2)) + assert_raises(ArgumentError) { lambda{|a|}.call(1,2) } + assert_raises(ArgumentError) { lambda{|a|}.call() } + assert_raises(ArgumentError) { lambda{}.call(1) } + assert_raises(ArgumentError) { lambda{|a, b|}.call(1,2,3) } + assert_equal(1, ->(a){ a }.call(1)) assert_equal([1,2], ->(a,b){ [a,b] }.call(1,2)) assert_raises(ArgumentError) { ->(a){ }.call(1,2) } @@ -12,20 +22,15 @@ class TestLambdaParameters < Test::Unit::TestCase assert_raises(ArgumentError) { ->(a,b){ }.call(1,2,3) } end +end + +__END__ def test_lambda_as_iterator a = 0 2.times(&->(_){ a += 1 }) assert_equal(a, 2) end - def test_message - flunk("YARV doesn't support some argument types for Proc object created by '->' syntax") - end -end - -__END__ - -class TestLambdaParameters def test_call_rest_args assert_equal([1,2], ->(*a){ a }.call(1,2)) assert_equal([1,2,[]], ->(a,b,*c){ [a,b,c] }.call(1,2)) -- cgit