[ruby/rdoc] Allow cross references to methods including underscores

As underscores are masked to "protect" from the conversion, consider
also `PROTECT_ATTR` as a word character.

https://github.com/ruby/rdoc/commit/db58bb5170
This commit is contained in:
Nobuyoshi Nakada 2022-02-10 08:13:57 +09:00 committed by git
parent 5d45afdbbf
commit e06100d969
2 changed files with 15 additions and 7 deletions

View File

@ -1,4 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
require_relative 'markup/attribute_manager' # for PROTECT_ATTR
## ##
# RDoc::CrossReference is a reusable way to create cross references for names. # RDoc::CrossReference is a reusable way to create cross references for names.
@ -29,7 +32,10 @@ class RDoc::CrossReference
# #
# See CLASS_REGEXP_STR # 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 # Regular expressions matching text that should potentially have

View File

@ -2,7 +2,9 @@
require_relative 'xref_test_case' require_relative 'xref_test_case'
class TestRDocCrossReference < XrefTestCase class TestRDocCrossReference < XrefTestCase
OPERATOR_METHODS = %w'== === != =~ !~ < > <= >= <=> [] []= << >> -@ +@ ! - + * / % ** !@ ` | & ^ ~' EXAMPLE_METHODS = %w'== === != =~ !~ < > <= >= <=> [] []= << >>
-@ +@ ! - + * / % ** !@ ` | & ^ ~ __id__
'
def setup def setup
super super
@ -21,7 +23,7 @@ class TestRDocCrossReference < XrefTestCase
def test_METHOD_REGEXP_STR def test_METHOD_REGEXP_STR
re = /\A(?:#{RDoc::CrossReference::METHOD_REGEXP_STR})\z/ re = /\A(?:#{RDoc::CrossReference::METHOD_REGEXP_STR})\z/
OPERATOR_METHODS.each do |x| EXAMPLE_METHODS.each do |x|
re =~ x re =~ x
assert_equal x, $& assert_equal x, $&
end end
@ -170,7 +172,7 @@ class TestRDocCrossReference < XrefTestCase
assert_ref page, 'README' assert_ref page, 'README'
end end
def assert_resolve_oeprator(x) def assert_resolve_method(x)
@c1.methods_hash.clear @c1.methods_hash.clear
i_op = RDoc::AnyMethod.new nil, x i_op = RDoc::AnyMethod.new nil, x
@ -189,9 +191,9 @@ class TestRDocCrossReference < XrefTestCase
assert_ref c_op, "C1::#{x}" assert_ref c_op, "C1::#{x}"
end end
OPERATOR_METHODS.each do |x| EXAMPLE_METHODS.each do |x|
define_method("test_resolve_operator:#{x}") do define_method("test_resolve_method:#{x}") do
assert_resolve_oeprator(x) assert_resolve_method(x)
end end
end end