test/module.rb: add visibility tests; ref #1835

This commit is contained in:
Yukihiro "Matz" Matsumoto
2025-02-26 13:19:35 +09:00
parent 384579fd21
commit 18674c0237
+41
View File
@@ -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