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

Allow cross references to methods including underscores #879

Merged
merged 1 commit into from
Apr 14, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/rdoc/cross_reference.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# frozen_string_literal: true

require_relative 'markup/attribute_manager' # for PROTECT_ATTR

##
# RDoc::CrossReference is a reusable way to create cross references for names.

Expand Down Expand Up @@ -29,7 +32,10 @@ class RDoc::CrossReference
#
# See CLASS_REGEXP_STR

METHOD_REGEXP_STR = /([A-Za-z]\w*[!?=]?|%|=(?:==?|~)|![=~]|\[\]=?|<(?:<|=>?)?|>[>=]?|[-+!]@?|\*\*?|[\/%`|&^~])#{METHOD_ARGS_REGEXP_STR}/.source
METHOD_REGEXP_STR = /(
(?!\d)[\w#{RDoc::Markup::AttributeManager::PROTECT_ATTR}]+[!?=]?|
%|=(?:==?|~)|![=~]|\[\]=?|<(?:<|=>?)?|>[>=]?|[-+!]@?|\*\*?|[\/%\`|&^~]
)#{METHOD_ARGS_REGEXP_STR}/.source.delete("\n ").freeze

##
# Regular expressions matching text that should potentially have
Expand Down
14 changes: 8 additions & 6 deletions test/rdoc/test_rdoc_cross_reference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
require_relative 'xref_test_case'

class TestRDocCrossReference < XrefTestCase
OPERATOR_METHODS = %w'== === != =~ !~ < > <= >= <=> [] []= << >> -@ +@ ! - + * / % ** !@ ` | & ^ ~'
EXAMPLE_METHODS = %w'== === != =~ !~ < > <= >= <=> [] []= << >>
-@ +@ ! - + * / % ** !@ ` | & ^ ~ __id__
'

def setup
super
Expand All @@ -21,7 +23,7 @@ def refute_ref name
def test_METHOD_REGEXP_STR
re = /\A(?:#{RDoc::CrossReference::METHOD_REGEXP_STR})\z/

OPERATOR_METHODS.each do |x|
EXAMPLE_METHODS.each do |x|
re =~ x
assert_equal x, $&
end
Expand Down Expand Up @@ -170,7 +172,7 @@ def test_resolve_page
assert_ref page, 'README'
end

def assert_resolve_oeprator(x)
def assert_resolve_method(x)
@c1.methods_hash.clear

i_op = RDoc::AnyMethod.new nil, x
Expand All @@ -189,9 +191,9 @@ def assert_resolve_oeprator(x)
assert_ref c_op, "C1::#{x}"
end

OPERATOR_METHODS.each do |x|
define_method("test_resolve_operator:#{x}") do
assert_resolve_oeprator(x)
EXAMPLE_METHODS.each do |x|
define_method("test_resolve_method:#{x}") do
assert_resolve_method(x)
end
end

Expand Down