mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
test/module.rb: add visibility tests; ref #1835
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user