Skip to content

Commit

Permalink
Fix handling of zero-arg calls
Browse files Browse the repository at this point in the history
  • Loading branch information
oprypin committed Oct 11, 2020
1 parent 227e486 commit ef0253e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions spec/compiler/crystal/tools/doc/doc_renderer_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe Doc::Markdown::DocRenderer do
end
end

pending "finds method with zero args" do
it "finds method with zero args" do
{base, base_foo}.each do |obj|
assert_code_link(obj, "bar()", %(<a href="Base.html#bar-instance-method">#bar()</a>))
assert_code_link(obj, "#bar()", %(<a href="Base.html#bar-instance-method">#bar()</a>))
Expand All @@ -128,7 +128,7 @@ describe Doc::Markdown::DocRenderer do
end
end

pending "doesn't find method with wrong number of args (zero)" do
it "doesn't find method with wrong number of args (zero)" do
{base, base_foo}.each do |obj|
assert_code_link(obj, "foo2()")
assert_code_link(obj, "#foo2()")
Expand Down
Binary file added spec/compiler/data/compiler_spec_output
Binary file not shown.
10 changes: 5 additions & 5 deletions src/compiler/crystal/tools/doc/markdown/doc_renderer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Crystal::Doc::Markdown::DocRenderer < Crystal::Doc::Markdown::HTMLRenderer

def detect_code_link(text : String) : String
# Check method reference (without #, but must be the whole text)
if text =~ /\A([\w<=>+\-*\/\[\]&|?!^~]+[?!]?)(\(.+?\))?\Z/
if text =~ /\A([\w<=>+\-*\/\[\]&|?!^~]+[?!]?)(\(.*?\))?\Z/
name = $1
args = $2? || ""

Expand All @@ -48,11 +48,11 @@ class Crystal::Doc::Markdown::DocRenderer < Crystal::Doc::Markdown::HTMLRenderer

# Check Type#method(...) or Type or #method(...)
text.gsub %r(\b
((?:\:\:)?[A-Z]\w+(?:\:\:[A-Z]\w+)*[#\.][\w<=>+\-*\/\[\]&|?!^~]+[?!]?(?:\(.+?\))?)
((?:\:\:)?[A-Z]\w+(?:\:\:[A-Z]\w+)*[#\.][\w<=>+\-*\/\[\]&|?!^~]+[?!]?(?:\(.*?\))?)
|
((?:\:\:)?[A-Z]\w+(?:\:\:[A-Z]\w+)*)
|
([#\.][\w<=>+\-*\/\[\]&|?!^~]+[?!]?(?:\(.+?\))?)
([#\.][\w<=>+\-*\/\[\]&|?!^~]+[?!]?(?:\(.*?\))?)
)x do |match_text, match|
sharp_index = match_text.index('#')
dot_index = match_text.index('.')
Expand All @@ -67,7 +67,7 @@ class Crystal::Doc::Markdown::DocRenderer < Crystal::Doc::Markdown::HTMLRenderer

if paren_index
method_name = match_text[separator_index + 1...paren_index]
method_args = match_text[paren_index + 1..-2]
method_args = match_text[paren_index..]
else
method_name = match_text[separator_index + 1..-1]
method_args = ""
Expand Down Expand Up @@ -96,7 +96,7 @@ class Crystal::Doc::Markdown::DocRenderer < Crystal::Doc::Markdown::HTMLRenderer

if paren_index
method_name = match_text[1...paren_index]
method_args = match_text[paren_index + 1..-2]
method_args = match_text[paren_index..]
else
method_name = match_text[1..-1]
method_args = ""
Expand Down

0 comments on commit ef0253e

Please sign in to comment.