summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2020-12-11 11:54:50 +0900
committerKoichi Sasada <ko1@atdot.net>2020-12-11 11:57:25 +0900
commitb53ccb9c69abd24e3bdad66cbe4c7e7480eaef16 (patch)
treed8b5ab834dcbaf999de8ac5ad612924cdb5c914b /test
parentad6573163f4a7b7eedb904f2f6f730c3cd2669e3 (diff)
show deprecation warning correctly for lambda(&b)
lambda(&b) where b is given block of method (like: def foo(&b)) should warn correctly. [Feature #17361] Also labmda(&labmda_block) or lambda(&:to_s) (Symbol#to_proc) should not warn (but I'm not sure who cares about it).
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_proc.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb
index c1f17a003a..ca690dce0d 100644
--- a/test/ruby/test_proc.rb
+++ b/test/ruby/test_proc.rb
@@ -291,6 +291,45 @@ class TestProc < Test::Unit::TestCase
assert_equal(true, Proc.new(&l).lambda?)
end
+ def self.helper_test_warn_lamda_with_passed_block &b
+ lambda(&b)
+ end
+
+ def self.def_lambda_warning name, warn
+ define_method(name, proc do
+ prev = Warning[:deprecated]
+ assert_warn warn do
+ Warning[:deprecated] = true
+ yield
+ end
+ ensure
+ Warning[:deprecated] = prev
+ end)
+ end
+
+ def_lambda_warning 'test_lambda_warning_normal', '' do
+ lambda{}
+ end
+
+ def_lambda_warning 'test_lambda_warning_pass_lambda', '' do
+ b = lambda{}
+ lambda(&b)
+ end
+
+ def_lambda_warning 'test_lambda_warning_pass_proc', /deprecated/ do
+ b = proc{}
+ lambda(&b)
+ end
+
+ def_lambda_warning 'test_lambda_warning_pass_proc', /deprecated/ do
+ helper_test_warn_lamda_with_passed_block{}
+ end
+
+ def_lambda_warning 'test_lambda_warning_pass_proc', '' do
+ # Symbol#to_proc returns lambda
+ helper_test_warn_lamda_with_passed_block(&:to_s)
+ end
+
def test_curry_ski_fib
s = proc {|f, g, x| f[x][g[x]] }.curry
k = proc {|x, y| x }.curry