зеркало из https://github.com/github/ruby.git
* test/ruby/test_module.rb (TestModule#test_method_{undefined,removed}):
tests for method_undefined and method_removed. Bug#5015 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32567 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
6349c7bf4d
Коммит
1297cc615c
|
@ -866,6 +866,64 @@ class TestModule < Test::Unit::TestCase
|
|||
assert_equal mod.instance_method(:a=), memo.shift
|
||||
end
|
||||
|
||||
def test_method_undefined
|
||||
added = []
|
||||
undefed = []
|
||||
removed = []
|
||||
mod = Module.new do
|
||||
mod = self
|
||||
def f
|
||||
end
|
||||
(class << self ; self ; end).class_eval do
|
||||
define_method :method_added do |sym|
|
||||
added << sym
|
||||
end
|
||||
define_method :method_undefined do |sym|
|
||||
undefed << sym
|
||||
end
|
||||
define_method :method_removed do |sym|
|
||||
removed << sym
|
||||
end
|
||||
end
|
||||
end
|
||||
assert_method_defined?(mod, :f)
|
||||
mod.module_eval do
|
||||
undef :f
|
||||
end
|
||||
assert_equal [], added
|
||||
assert_equal [:f], undefed
|
||||
assert_equal [], removed
|
||||
end
|
||||
|
||||
def test_method_removed
|
||||
added = []
|
||||
undefed = []
|
||||
removed = []
|
||||
mod = Module.new do
|
||||
mod = self
|
||||
def f
|
||||
end
|
||||
(class << self ; self ; end).class_eval do
|
||||
define_method :method_added do |sym|
|
||||
added << sym
|
||||
end
|
||||
define_method :method_undefined do |sym|
|
||||
undefed << sym
|
||||
end
|
||||
define_method :method_removed do |sym|
|
||||
removed << sym
|
||||
end
|
||||
end
|
||||
end
|
||||
assert_method_defined?(mod, :f)
|
||||
mod.module_eval do
|
||||
remove_method :f
|
||||
end
|
||||
assert_equal [], added
|
||||
assert_equal [], undefed
|
||||
assert_equal [:f], removed
|
||||
end
|
||||
|
||||
def test_method_redefinition
|
||||
feature2155 = '[ruby-dev:39400]'
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче