Skip to content

Commit

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

pending "doesn't find sibling methods with fake receiver" do
it "doesn't find sibling methods with fake receiver" do
{base, base_foo}.each do |obj|
assert_code_link(obj, "wrong#bar")
assert_code_link(obj, "wrong.bar")
Expand Down Expand Up @@ -183,7 +183,7 @@ describe Doc::Markdown::DocRenderer do
end
end

pending "finds method of an absolute type" do
it "finds method of an absolute type" do
{base, base_foo}.each do |obj|
assert_code_link(obj, "::Base::Nested#foo", %(<a href="Base/Nested.html#foo-instance-method">::Base::Nested#foo</a>))
assert_code_link(obj, "::Base.baz", %(<a href="Base.html#baz-class-method">::Base.baz</a>))
Expand Down Expand Up @@ -250,7 +250,7 @@ describe Doc::Markdown::DocRenderer do
end
end

pending "doesn't find type not at word boundary" do
it "doesn't find type not at word boundary" do
{base, base_foo}.each do |obj|
assert_code_link(obj, "aBase")
end
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/crystal/tools/doc/markdown/doc_renderer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ class Crystal::Doc::Markdown::DocRenderer < Crystal::Doc::Markdown::HTMLRenderer
end

# Check Type#method(...) or Type or #method(...)
text.gsub %r(\b
((?:\:\:)?[A-Z]\w+(?:\:\:[A-Z]\w+)*[#\.][\w<=>+\-*\/\[\]&|?!^~]+[?!]?(?:\(.*?\))?)
text.gsub %r(
((?:\B\:\:)?\b[A-Z]\w+(?:\:\:[A-Z]\w+)*[#\.][\w<=>+\-*\/\[\]&|?!^~]+[?!]?(?:\(.*?\))?)
|
((?:\:\:)?[A-Z]\w+(?:\:\:[A-Z]\w+)*)
((?:\B\:\:)?\b[A-Z]\w+(?:\:\:[A-Z]\w+)*)
|
([#\.][\w<=>+\-*\/\[\]&|?!^~]+[?!]?(?:\(.*?\))?)
(\B[#\.][\w<=>+\-*\/\[\]&|?!^~]+[?!]?(?:\(.*?\))?)
)x do |match_text, match|
sharp_index = match_text.index('#')
dot_index = match_text.index('.')
Expand Down

0 comments on commit 757433a

Please sign in to comment.