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.rb109
1 files changed, 106 insertions, 3 deletions
diff --git a/test/ruby/test_lambda.rb b/test/ruby/test_lambda.rb
index 75362e2796..9949fab8c7 100644
--- a/test/ruby/test_lambda.rb
+++ b/test/ruby/test_lambda.rb
@@ -74,10 +74,107 @@ class TestLambdaParameters < Test::Unit::TestCase
assert_raise(ArgumentError, bug9605) {proc(&plus).call [1,2]}
end
- def test_warning_for_non_literal_blocks
- assert_warn(/lambda without a literal block/, '[ruby-core:93482] [Feature #15973]') do
- lambda(&:symbol)
+ def test_proc_inside_lambda_inside_method_return_inside_lambda_inside_method
+ def self.a
+ -> do
+ p = Proc.new{return :a}
+ p.call
+ end.call
end
+ assert_equal(:a, a)
+
+ def self.b
+ lambda do
+ p = Proc.new{return :b}
+ p.call
+ end.call
+ end
+ assert_equal(:b, b)
+ end
+
+ def test_proc_inside_lambda_inside_method_return_inside_lambda_outside_method
+ def self.a
+ -> do
+ p = Proc.new{return :a}
+ p.call
+ end
+ end
+ assert_equal(:a, a.call)
+
+ def self.b
+ lambda do
+ p = Proc.new{return :b}
+ p.call
+ end
+ end
+ assert_equal(:b, b.call)
+ end
+
+ def test_proc_inside_lambda_inside_method_return_outside_lambda_inside_method
+ def self.a
+ -> do
+ Proc.new{return :a}
+ end.call.call
+ end
+ assert_raise(LocalJumpError) {a}
+
+ def self.b
+ lambda do
+ Proc.new{return :b}
+ end.call.call
+ end
+ assert_raise(LocalJumpError) {b}
+ end
+
+ def test_proc_inside_lambda_inside_method_return_outside_lambda_outside_method
+ def self.a
+ -> do
+ Proc.new{return :a}
+ end
+ end
+ assert_raise(LocalJumpError) {a.call.call}
+
+ def self.b
+ lambda do
+ Proc.new{return :b}
+ end
+ end
+ assert_raise(LocalJumpError) {b.call.call}
+ end
+
+ def test_proc_inside_lambda2_inside_method_return_outside_lambda1_inside_method
+ def self.a
+ -> do
+ -> do
+ Proc.new{return :a}
+ end.call.call
+ end.call
+ end
+ assert_raise(LocalJumpError) {a}
+
+ def self.b
+ lambda do
+ lambda do
+ Proc.new{return :a}
+ end.call.call
+ end.call
+ end
+ assert_raise(LocalJumpError) {b}
+ end
+
+ def test_proc_inside_lambda_toplevel
+ assert_separately [], <<~RUBY
+ lambda{
+ $g = proc{ return :pr }
+ }.call
+ begin
+ $g.call
+ rescue LocalJumpError
+ # OK!
+ else
+ raise
+ end
+ RUBY
end
def pass_along(&block)
@@ -89,15 +186,21 @@ class TestLambdaParameters < Test::Unit::TestCase
end
def test_create_non_lambda_for_proc_one_level
+ prev_warning, Warning[:deprecated] = Warning[:deprecated], false
f = pass_along {}
refute_predicate(f, :lambda?, '[Bug #15620]')
assert_nothing_raised(ArgumentError) { f.call(:extra_arg) }
+ ensure
+ Warning[:deprecated] = prev_warning
end
def test_create_non_lambda_for_proc_two_levels
+ prev_warning, Warning[:deprecated] = Warning[:deprecated], false
f = pass_along2 {}
refute_predicate(f, :lambda?, '[Bug #15620]')
assert_nothing_raised(ArgumentError) { f.call(:extra_arg) }
+ ensure
+ Warning[:deprecated] = prev_warning
end
def test_instance_exec