mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/rdoc] fix: alias to method with call-seq
This change fixes alias call-seq to return nil if the method's call-seq does not specify the alias. Previously, the alias's call-seq would be an empty string in this case which broke darkfish rendering. This change also backfills test coverage for 0ead786 which moved call-seq deduplication into AnyMethod. https://github.com/ruby/rdoc/commit/5ce2789b6f
This commit is contained in:
parent
5d975684da
commit
4ffc3fb019
2 changed files with 49 additions and 1 deletions
|
@ -359,6 +359,6 @@ class RDoc::AnyMethod < RDoc::MethodAttr
|
|||
entry =~ /\s#{ignore}\s/
|
||||
end
|
||||
|
||||
matching.join "\n"
|
||||
matching.empty? ? nil : matching.join("\n")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -72,6 +72,54 @@ method(a, b) { |c, d| ... }
|
|||
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' },
|
||||
|
|
Loading…
Add table
Reference in a new issue