mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* compile.c (iseq_compile_each, set_block_local_tbl) :
support NODE_LAMBDA (partly). * sample/test.rb : restore test of NODE_LAMBDA * test/ruby/test_lambda.rb : ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11477 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f189294d04
commit
c5bd0c8e3b
4 changed files with 97 additions and 52 deletions
|
@ -1,14 +1,6 @@
|
|||
require 'test/unit'
|
||||
|
||||
class TestLambdaParameters < Test::Unit::TestCase
|
||||
def test_not_supported
|
||||
flunk("YARV doesn't support NODE_LAMBDA")
|
||||
end
|
||||
end
|
||||
|
||||
__END__
|
||||
|
||||
class TestLambdaParametersBackup
|
||||
def test_call_simple
|
||||
assert_equal(1, ->(a){ a }.call(1))
|
||||
assert_equal([1,2], ->(a,b){ [a,b] }.call(1,2))
|
||||
|
@ -18,6 +10,20 @@ class TestLambdaParametersBackup
|
|||
assert_raises(ArgumentError) { ->(a,b){ }.call(1,2,3) }
|
||||
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))
|
||||
|
@ -52,10 +58,4 @@ class TestLambdaParametersBackup
|
|||
def foo
|
||||
assert_equal(nil, ->(&b){ b }.call)
|
||||
end
|
||||
|
||||
def test_lambda_as_iterator
|
||||
a = 0
|
||||
2.times(&->(_){ a += 1 })
|
||||
assert_equal(a, 2)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue