Skip to content

Commit c749f60

Browse files
authored
Merge pull request #840 from flavorjones/flavorjones/alias-call-seq-fix
fix: alias to a method with call-seq should render properly if the call-seq does not specify the alias
2 parents 6d98e9f + 5ce2789 commit c749f60

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

lib/rdoc/any_method.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,6 @@ def deduplicate_call_seq(call_seq)
359359
entry =~ /\s#{ignore}\s/
360360
end
361361

362-
matching.join "\n"
362+
matching.empty? ? nil : matching.join("\n")
363363
end
364364
end

test/rdoc/test_rdoc_any_method.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,54 @@ def test_is_alias_for
7272
assert_nil m1.is_alias_for, 'missing alias'
7373
end
7474

75+
def test_call_seq_handles_aliases
76+
# see 0ead786
77+
@store.path = Dir.tmpdir
78+
top_level = @store.add_file 'file.rb'
79+
cm = top_level.add_class RDoc::ClassModule, 'Klass'
80+
81+
method_with_call_seq = RDoc::AnyMethod.new(nil, "method_with_call_seq")
82+
method_with_call_seq.call_seq = <<~SEQ
83+
method_with_call_seq(a)
84+
method_with_call_seq(a, b)
85+
alias_to_method(a)
86+
alias_to_method(a, b)
87+
SEQ
88+
cm.add_method(method_with_call_seq)
89+
90+
alias_to_method = method_with_call_seq.add_alias(
91+
RDoc::Alias.new(nil, "method_with_call_seq", "alias_to_method", "comment"),
92+
cm
93+
)
94+
95+
assert_equal("method_with_call_seq(a)\nmethod_with_call_seq(a, b)",
96+
method_with_call_seq.call_seq)
97+
assert_equal("alias_to_method(a)\nalias_to_method(a, b)",
98+
alias_to_method.call_seq)
99+
end
100+
101+
def test_call_seq_returns_nil_if_alias_is_missing_from_call_seq
102+
@store.path = Dir.tmpdir
103+
top_level = @store.add_file 'file.rb'
104+
cm = top_level.add_class RDoc::ClassModule, 'Klass'
105+
106+
method_with_call_seq = RDoc::AnyMethod.new(nil, "method_with_call_seq")
107+
method_with_call_seq.call_seq = <<~SEQ
108+
method_with_call_seq(a)
109+
method_with_call_seq(a, b)
110+
SEQ
111+
cm.add_method(method_with_call_seq)
112+
113+
alias_to_method = method_with_call_seq.add_alias(
114+
RDoc::Alias.new(nil, "method_with_call_seq", "alias_to_method", "comment"),
115+
cm
116+
)
117+
118+
assert_equal("method_with_call_seq(a)\nmethod_with_call_seq(a, b)",
119+
method_with_call_seq.call_seq)
120+
assert_nil(alias_to_method.call_seq)
121+
end
122+
75123
def test_markup_code
76124
tokens = [
77125
{ :line_no => 0, :char_no => 0, :kind => :on_const, :text => 'CONSTANT' },

0 commit comments

Comments
 (0)