summaryrefslogtreecommitdiff
path: root/test/ruby/test_lambda.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_lambda.rb')
-rw-r--r--test/ruby/test_lambda.rb52
1 files changed, 27 insertions, 25 deletions
diff --git a/test/ruby/test_lambda.rb b/test/ruby/test_lambda.rb
index c65169ac27..3ac2e4cb98 100644
--- a/test/ruby/test_lambda.rb
+++ b/test/ruby/test_lambda.rb
@@ -31,8 +31,10 @@ class TestLambdaParameters < Test::Unit::TestCase
bug9605 = '[ruby-core:61468] [Bug #9605]'
assert_nothing_raised(ArgumentError, bug9605) {1.times(&->(n){ a += 1 })}
assert_equal(3, a, bug9605)
- assert_nothing_raised(ArgumentError, bug9605) {a = [[1, 2]].map(&->(x, y) {x+y})}
- assert_equal([3], a, bug9605)
+ assert_nothing_raised(ArgumentError, bug9605) {
+ a = %w(Hi there how are you).each_with_index.detect(&->(w, i) {w.length == 3})
+ }
+ assert_equal(["how", 2], a, bug9605)
end
def test_call_rest_args
@@ -79,29 +81,29 @@ class TestLambdaParameters < Test::Unit::TestCase
end
end
- def yield_1(arg)
- yield arg
- end
-
- tap do |;bug9605, expected, result|
- bug9605 = '[ruby-core:65887] [Bug #9605] arity check should be relaxed'
- expected = [1,2,3]
-
- [
- ["array", expected],
- ["to_ary", Struct.new(:to_ary).new(expected)],
- ].product \
- [
- ["proc", proc {|a, b, c| [a, b, c]}],
- ["lambda", lambda {|a, b, c| [a, b, c]}],
- ] do
- |(vtype, val), (btype, block)|
- define_method("test_yield_relaxed(#{vtype},&#{btype})") do
- result = assert_nothing_raised(ArgumentError, bug9605) {
- break yield_1(val, &block)
- }
- assert_equal(expected, result, bug9605)
- end
+ def test_instance_eval_return
+ bug13090 = '[ruby-core:78917] [Bug #13090] cannot return in lambdas'
+ x = :ng
+ assert_nothing_raised(LocalJumpError) do
+ x = instance_eval(&->(_){return :ok})
+ end
+ ensure
+ assert_equal(:ok, x, bug13090)
+ end
+
+ def test_instance_exec_return
+ bug13090 = '[ruby-core:78917] [Bug #13090] cannot return in lambdas'
+ x = :ng
+ assert_nothing_raised(LocalJumpError) do
+ x = instance_exec(&->(){return :ok})
+ end
+ ensure
+ assert_equal(:ok, x, bug13090)
+ end
+
+ def test_arity_error
+ assert_raise(ArgumentError, '[Bug #12705]') do
+ [1, 2].tap(&lambda {|a, b|})
end
end