From 18674c0237bfe7d37a2e27fb4fd3c8903ede2437 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Wed, 26 Feb 2025 13:19:35 +0900 Subject: [PATCH] test/module.rb: add visibility tests; ref #1835 --- test/t/module.rb | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/test/t/module.rb b/test/t/module.rb index c5d26df8a..7a6b895c8 100644 --- a/test/t/module.rb +++ b/test/t/module.rb @@ -786,6 +786,47 @@ assert('clone Module') do assert_true(B.new.foo) end +assert('method visibility') do + class CallTypeTest + def test_private(&block) + func(&block) + end + def test_protected(&block) + self.func(&block) + end + private + def func + yield + end + end + + v = CallTypeTest.new + + assert_raise(NoMethodError) { v.func { :test } } + assert_equal :test, v.test_private { :test } + + class CallTypeTest + protected :func + end + + assert_raise(NoMethodError) { v.func { :test } } + assert_equal :test, v.test_protected { :test } + assert_equal :test, v.test_private { :test } + + class CallTypeTest + public def public_func + :test + end + + public :func + end + + assert_equal :test, v.public_func + assert_equal :test, v.func { :test } + assert_equal :test, v.test_protected { :test } + assert_equal :test, v.test_private { :test } +end + assert('Module#module_function') do module M def modfunc; end