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.rb60
1 files changed, 17 insertions, 43 deletions
diff --git a/test/ruby/test_lambda.rb b/test/ruby/test_lambda.rb
index 2c42b54edb..c1858a36dd 100644
--- a/test/ruby/test_lambda.rb
+++ b/test/ruby/test_lambda.rb
@@ -76,7 +76,7 @@ class TestLambdaParameters < Test::Unit::TestCase
def test_proc_inside_lambda_inside_method_return_inside_lambda_inside_method
def self.a
- r = -> do
+ -> do
p = Proc.new{return :a}
p.call
end.call
@@ -84,7 +84,7 @@ class TestLambdaParameters < Test::Unit::TestCase
assert_equal(:a, a)
def self.b
- r = lambda do
+ lambda do
p = Proc.new{return :b}
p.call
end.call
@@ -94,7 +94,7 @@ class TestLambdaParameters < Test::Unit::TestCase
def test_proc_inside_lambda_inside_method_return_inside_lambda_outside_method
def self.a
- r = -> do
+ -> do
p = Proc.new{return :a}
p.call
end
@@ -102,7 +102,7 @@ class TestLambdaParameters < Test::Unit::TestCase
assert_equal(:a, a.call)
def self.b
- r = lambda do
+ lambda do
p = Proc.new{return :b}
p.call
end
@@ -112,14 +112,14 @@ class TestLambdaParameters < Test::Unit::TestCase
def test_proc_inside_lambda_inside_method_return_outside_lambda_inside_method
def self.a
- r = -> do
+ -> do
Proc.new{return :a}
end.call.call
end
assert_raise(LocalJumpError) {a}
def self.b
- r = lambda do
+ lambda do
Proc.new{return :b}
end.call.call
end
@@ -128,14 +128,14 @@ class TestLambdaParameters < Test::Unit::TestCase
def test_proc_inside_lambda_inside_method_return_outside_lambda_outside_method
def self.a
- r = -> do
+ -> do
Proc.new{return :a}
end
end
assert_raise(LocalJumpError) {a.call.call}
def self.b
- r = lambda do
+ lambda do
Proc.new{return :b}
end
end
@@ -144,7 +144,7 @@ class TestLambdaParameters < Test::Unit::TestCase
def test_proc_inside_lambda2_inside_method_return_outside_lambda1_inside_method
def self.a
- r = -> do
+ -> do
-> do
Proc.new{return :a}
end.call.call
@@ -153,7 +153,7 @@ class TestLambdaParameters < Test::Unit::TestCase
assert_raise(LocalJumpError) {a}
def self.b
- r = lambda do
+ lambda do
lambda do
Proc.new{return :a}
end.call.call
@@ -163,7 +163,7 @@ class TestLambdaParameters < Test::Unit::TestCase
end
def test_proc_inside_lambda_toplevel
- assert_separately [], <<~RUBY
+ assert_ruby_status [], <<~RUBY
lambda{
$g = proc{ return :pr }
}.call
@@ -177,32 +177,6 @@ class TestLambdaParameters < Test::Unit::TestCase
RUBY
end
- def pass_along(&block)
- lambda(&block)
- end
-
- def pass_along2(&block)
- pass_along(&block)
- 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
bug12568 = '[ruby-core:76300] [Bug #12568]'
assert_nothing_raised(ArgumentError, bug12568) do
@@ -302,27 +276,27 @@ class TestLambdaParameters < Test::Unit::TestCase
end
def test_do_lambda_source_location
- exp_lineno = __LINE__ + 3
+ exp = [__LINE__ + 1, 10, __LINE__ + 5, 7]
lmd = ->(x,
y,
z) do
#
end
- file, lineno = lmd.source_location
+ file, *loc = lmd.source_location
assert_match(/^#{ Regexp.quote(__FILE__) }$/, file)
- assert_equal(exp_lineno, lineno, "must be at the beginning of the block")
+ assert_equal(exp, loc)
end
def test_brace_lambda_source_location
- exp_lineno = __LINE__ + 3
+ exp = [__LINE__ + 1, 10, __LINE__ + 5, 5]
lmd = ->(x,
y,
z) {
#
}
- file, lineno = lmd.source_location
+ file, *loc = lmd.source_location
assert_match(/^#{ Regexp.quote(__FILE__) }$/, file)
- assert_equal(exp_lineno, lineno, "must be at the beginning of the block")
+ assert_equal(exp, loc)
end
def test_not_orphan_return