Permalink
Browse files

MethodAttr equality is now based on full_name

This fixes a test that would occasionally fail on ruby 1.8.7 due to hash
ordering.  MethodAttr equality is not ordinarily used outside tests.

superclass_method looks up superclass methods based on name, not
equality, due to this change.

Added aliases to RDoc::Store tests for extra coverage.
  • Loading branch information...
1 parent dabcab8 commit 0eb1dd78098ef55f298479fc5265458bdd36a6c3 @drbrain drbrain committed Nov 18, 2012
View
@@ -249,7 +249,7 @@ def superclass_method
return @superclass_method if @superclass_method
parent.each_ancestor do |ancestor|
- if method = ancestor.method_list.find { |m| m == self } then
+ if method = ancestor.method_list.find { |m| m.name == @name } then
@superclass_method = method
break
end
View
@@ -98,7 +98,12 @@ def initialize text, name
# Order by #singleton then #name
def <=>(other)
- [@singleton ? 0 : 1, name] <=> [other.singleton ? 0 : 1, other.name]
+ [ @singleton ? 0 : 1, name] <=>
+ [other.singleton ? 0 : 1, other.name]
+ end
+
+ def == other # :nodoc:
+ super or self.class == other.class and full_name == other.full_name
end
##
@@ -86,7 +86,7 @@ def test_marshal_dump
assert_equal m, loaded
- assert_equal [al_m], loaded.aliases
+ assert_equal [al_m.name], loaded.aliases.map { |alas| alas.name }
assert_equal 'some_block', loaded.block_params
assert_equal 'call_seq', loaded.call_seq
assert_equal comment, loaded.comment
@@ -151,7 +151,7 @@ def test_marshal_load_version_0
assert_equal m, loaded
- assert_equal [al_m], loaded.aliases
+ assert_equal [al_m.name], loaded.aliases.map { |alas| alas.name }
assert_equal 'some_block', loaded.block_params
assert_equal 'call_seq', loaded.call_seq
assert_equal comment, loaded.comment
@@ -866,14 +866,15 @@ def test_merge_methods
tl1 = @store.add_file 'one.rb'
tl2 = @store.add_file 'two.rb'
- cm1 = RDoc::ClassModule.new 'Klass'
+ cm1 = tl1.add_class RDoc::NormalClass, 'Klass'
meth = cm1.add_method RDoc::AnyMethod.new(nil, 'm1')
meth.record_location tl1
meth = cm1.add_method RDoc::AnyMethod.new(nil, 'm3')
meth.record_location tl1
cm2 = RDoc::ClassModule.new 'Klass'
+ cm2.store = @store
cm2.instance_variable_set :@comment, @RM::Document.new
meth = cm2.add_method RDoc::AnyMethod.new(nil, 'm2')
@@ -899,14 +900,15 @@ def test_merge_methods
def test_merge_methods_version_0
tl1 = @store.add_file 'one.rb'
- cm1 = RDoc::ClassModule.new 'Klass'
+ cm1 = tl1.add_class RDoc::NormalClass, 'Klass'
meth = cm1.add_method RDoc::AnyMethod.new(nil, 'm1')
meth.record_location tl1
meth = cm1.add_method RDoc::AnyMethod.new(nil, 'm3')
meth.record_location tl1
cm2 = RDoc::ClassModule.new 'Klass'
+ cm2.store = @store
cm2.instance_variable_set :@comment, @RM::Document.new
meth = cm2.add_method RDoc::AnyMethod.new(nil, 'm2')
@@ -140,6 +140,11 @@ def test_search_record
assert_equal expected, @c1_m.search_record
end
+ def test_equals2
+ assert_equal @c1_m, @c1_m
+ refute_equal @c1_m, @parent_m
+ end
+
def test_to_s
assert_equal 'RDoc::AnyMethod: C1#m', @c1_m.to_s
assert_equal 'RDoc::AnyMethod: C2#b', @c2_b.to_s
View
@@ -33,6 +33,11 @@ def setup
@meth_bang = RDoc::AnyMethod.new nil, 'method!'
@meth_bang.record_location @top_level
+ @meth_bang_alias = RDoc::Alias.new nil, 'method!', 'method_bang', ''
+ @meth_bang_alias.record_location @top_level
+
+ @meth_bang.add_alias @meth_bang_alias, @klass
+
@attr_comment = RDoc::Comment.new 'attribute comment'
@attr_comment.location = @top_level
@@ -74,7 +79,7 @@ def mu_pp obj
def assert_cache imethods, cmethods, attrs, modules,
ancestors = {}, pages = [], main = nil, title = nil
- imethods ||= { 'Object' => %w[method method!] }
+ imethods ||= { 'Object' => %w[method method! method_bang] }
cmethods ||= { 'Object' => %w[cmethod] }
attrs ||= { 'Object' => ['attr_accessor attr'] }
@@ -287,11 +292,17 @@ def test_load_all
mod.method_list
end.flatten.sort
- assert_equal [@cmeth, @meth, @nest_meth, @meth_bang], methods.sort
+ _meth_bang_alias = RDoc::AnyMethod.new nil, 'method_bang'
+ _meth_bang_alias.parent = @klass
+
+ assert_equal [@cmeth, @meth, @nest_meth, @meth_bang, _meth_bang_alias],
+ methods
method = methods.find { |m| m == @meth }
assert_equal @meth_comment.parse, method.comment
+ assert_equal @klass, methods.last.parent
+
attributes = s.all_classes_and_modules.map do |mod|
mod.attributes
end.flatten.sort
@@ -441,9 +452,9 @@ def test_load_method_legacy
end
meth = @s.load_method('Object', '#method')
- assert_equal @meth, meth
- assert_equal @klass, meth.parent
- assert_equal @s, meth.store
+ assert_equal 'Klass#method', meth.full_name
+ assert_equal @klass, meth.parent
+ assert_equal @s, meth.store
end
def test_load_page
@@ -509,7 +520,7 @@ def test_save
:attributes => { 'Object' => ['attr_accessor attr'] },
:class_methods => { 'Object' => %w[cmethod] },
:instance_methods => {
- 'Object' => %w[attr method method!],
+ 'Object' => %w[attr method method! method_bang],
'Object::SubClass' => %w[method],
},
:main => nil,
@@ -549,7 +560,7 @@ def test_save_cache
:attributes => { 'Object' => ['attr_accessor attr'] },
:class_methods => { 'Object' => %w[cmethod] },
:instance_methods => {
- 'Object' => %w[method method!],
+ 'Object' => %w[method method! method_bang],
'Object::SubClass' => %w[method],
},
:main => @page.full_name,

0 comments on commit 0eb1dd7

Please sign in to comment.