Skip to content

Commit

Permalink
Fix call-seq for aliased method with similar names
Browse files Browse the repository at this point in the history
deduplicate_call_seq has a bug that skips call-seq for methods where the
alias is a prefix of the method name. For example, if the alias name is
"each" and the current method name is "each_line", then
deduplicate_call_seq will skip all call-seq for "each_line" since it
will believe that it is for the alias.
  • Loading branch information
peterzhu2118 committed Jul 15, 2022
1 parent 92c04ce commit 1148988
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rdoc/any_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,12 @@ def deduplicate_call_seq(call_seq)
ignore << is_alias_for.name
ignore.concat is_alias_for.aliases.map(&:name)
end
ignore.map! { |n| n =~ /\A\[/ ? n[0, 1] : n}
ignore.map! { |n| n =~ /\A\[/ ? /\[.*\]/ : n}
ignore.delete(method_name)
ignore = Regexp.union(ignore)

matching = entries.reject do |entry|
entry =~ /^\w*\.?#{ignore}/ or
entry =~ /^\w*\.?#{ignore}[$\(\s]/ or
entry =~ /\s#{ignore}\s/
end

Expand Down
14 changes: 14 additions & 0 deletions test/rdoc/test_rdoc_any_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ def test_call_seq_equals
assert_equal 'foo', m.call_seq
end

def test_call_seq_alias_for
a = RDoc::AnyMethod.new nil, "each"
m = RDoc::AnyMethod.new nil, "each_line"

a.call_seq = <<-CALLSEQ
each(foo)
each_line(foo)
CALLSEQ

m.is_alias_for = a

assert_equal "each_line(foo)", m.call_seq
end

def test_full_name
assert_equal 'C1::m', @c1.method_list.first.full_name
end
Expand Down

0 comments on commit 1148988

Please sign in to comment.