Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: alias to a method with call-seq should render properly if the call-seq does not specify the alias #840

Merged
merged 1 commit into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rdoc/any_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,6 @@ def deduplicate_call_seq(call_seq)
entry =~ /\s#{ignore}\s/
end

matching.join "\n"
matching.empty? ? nil : matching.join("\n")
end
end
48 changes: 48 additions & 0 deletions test/rdoc/test_rdoc_any_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,54 @@ def test_is_alias_for
assert_nil m1.is_alias_for, 'missing alias'
end

def test_call_seq_handles_aliases
# see 0ead786
@store.path = Dir.tmpdir
top_level = @store.add_file 'file.rb'
cm = top_level.add_class RDoc::ClassModule, 'Klass'

method_with_call_seq = RDoc::AnyMethod.new(nil, "method_with_call_seq")
method_with_call_seq.call_seq = <<~SEQ
method_with_call_seq(a)
method_with_call_seq(a, b)
alias_to_method(a)
alias_to_method(a, b)
SEQ
cm.add_method(method_with_call_seq)

alias_to_method = method_with_call_seq.add_alias(
RDoc::Alias.new(nil, "method_with_call_seq", "alias_to_method", "comment"),
cm
)

assert_equal("method_with_call_seq(a)\nmethod_with_call_seq(a, b)",
method_with_call_seq.call_seq)
assert_equal("alias_to_method(a)\nalias_to_method(a, b)",
alias_to_method.call_seq)
end

def test_call_seq_returns_nil_if_alias_is_missing_from_call_seq
@store.path = Dir.tmpdir
top_level = @store.add_file 'file.rb'
cm = top_level.add_class RDoc::ClassModule, 'Klass'

method_with_call_seq = RDoc::AnyMethod.new(nil, "method_with_call_seq")
method_with_call_seq.call_seq = <<~SEQ
method_with_call_seq(a)
method_with_call_seq(a, b)
SEQ
cm.add_method(method_with_call_seq)

alias_to_method = method_with_call_seq.add_alias(
RDoc::Alias.new(nil, "method_with_call_seq", "alias_to_method", "comment"),
cm
)

assert_equal("method_with_call_seq(a)\nmethod_with_call_seq(a, b)",
method_with_call_seq.call_seq)
assert_nil(alias_to_method.call_seq)
end

def test_markup_code
tokens = [
{ :line_no => 0, :char_no => 0, :kind => :on_const, :text => 'CONSTANT' },
Expand Down