Skip to content

Commit

Permalink
Merge pull request #879 from nobu/underscore-methods
Browse files Browse the repository at this point in the history
Allow cross references to methods including underscores
  • Loading branch information
nobu committed Apr 14, 2022
2 parents bf519a6 + db58bb5 commit 573fa92
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
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

0 comments on commit 573fa92

Please sign in to comment.