mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Added missing tests for public, private, protected and alias_method
This commit is contained in:
parent
d40d95296d
commit
5616f2ee93
1 changed files with 73 additions and 0 deletions
|
@ -828,6 +828,67 @@ class TestModule < Test::Unit::TestCase
|
|||
assert_equal([:bClass1], BClass.public_instance_methods(false))
|
||||
end
|
||||
|
||||
def test_s_public
|
||||
o = (c = Class.new(AClass)).new
|
||||
assert_raise(NoMethodError, /private method/) {o.aClass1}
|
||||
assert_raise(NoMethodError, /protected method/) {o.aClass2}
|
||||
c.class_eval {public :aClass1}
|
||||
assert_equal(:aClass1, o.aClass1)
|
||||
|
||||
o = (c = Class.new(AClass)).new
|
||||
c.class_eval {public :aClass1, :aClass2}
|
||||
assert_equal(:aClass1, o.aClass1)
|
||||
assert_equal(:aClass2, o.aClass2)
|
||||
|
||||
o = AClass.new
|
||||
assert_equal(:aClass, o.aClass)
|
||||
assert_raise(NoMethodError, /private method/) {o.aClass1}
|
||||
assert_raise(NoMethodError, /protected method/) {o.aClass2}
|
||||
end
|
||||
|
||||
def test_s_private
|
||||
o = (c = Class.new(AClass)).new
|
||||
assert_equal(:aClass, o.aClass)
|
||||
c.class_eval {private :aClass}
|
||||
assert_raise(NoMethodError, /private method/) {o.aClass}
|
||||
|
||||
o = (c = Class.new(AClass)).new
|
||||
c.class_eval {private :aClass, :aClass2}
|
||||
assert_raise(NoMethodError, /private method/) {o.aClass}
|
||||
assert_raise(NoMethodError, /private method/) {o.aClass2}
|
||||
|
||||
o = AClass.new
|
||||
assert_equal(:aClass, o.aClass)
|
||||
assert_raise(NoMethodError, /private method/) {o.aClass1}
|
||||
assert_raise(NoMethodError, /protected method/) {o.aClass2}
|
||||
end
|
||||
|
||||
def test_s_protected
|
||||
aclass = Class.new(AClass) do
|
||||
def _aClass(o) o.aClass; end
|
||||
def _aClass1(o) o.aClass1; end
|
||||
def _aClass2(o) o.aClass2; end
|
||||
end
|
||||
|
||||
o = (c = Class.new(aclass)).new
|
||||
assert_equal(:aClass, o.aClass)
|
||||
c.class_eval {protected :aClass}
|
||||
assert_raise(NoMethodError, /protected method/) {o.aClass}
|
||||
assert_equal(:aClass, c.new._aClass(o))
|
||||
|
||||
o = (c = Class.new(aclass)).new
|
||||
c.class_eval {protected :aClass, :aClass1}
|
||||
assert_raise(NoMethodError, /protected method/) {o.aClass}
|
||||
assert_raise(NoMethodError, /protected method/) {o.aClass1}
|
||||
assert_equal(:aClass, c.new._aClass(o))
|
||||
assert_equal(:aClass1, c.new._aClass1(o))
|
||||
|
||||
o = AClass.new
|
||||
assert_equal(:aClass, o.aClass)
|
||||
assert_raise(NoMethodError, /private method/) {o.aClass1}
|
||||
assert_raise(NoMethodError, /protected method/) {o.aClass2}
|
||||
end
|
||||
|
||||
def test_s_constants
|
||||
c1 = Module.constants
|
||||
Object.module_eval "WALTER = 99"
|
||||
|
@ -1165,6 +1226,18 @@ class TestModule < Test::Unit::TestCase
|
|||
assert_equal([:h, :h=, :i, :i=], c.class_eval { attr_accessor :h, :i })
|
||||
end
|
||||
|
||||
def test_alias_method
|
||||
c = Class.new do
|
||||
def foo; :foo end
|
||||
end
|
||||
o = c.new
|
||||
assert_respond_to(o, :foo)
|
||||
assert_not_respond_to(o, :bar)
|
||||
c.class_eval {alias_method :bar, :foo}
|
||||
assert_respond_to(o, :bar)
|
||||
assert_equal(:foo, o.bar)
|
||||
end
|
||||
|
||||
def test_undef
|
||||
c = Class.new
|
||||
assert_raise(NameError) do
|
||||
|
|
Loading…
Add table
Reference in a new issue