[前][次][番号順一覧][スレッド一覧]

ruby-changes:71726

From: Nobuyoshi <ko1@a...>
Date: Thu, 14 Apr 2022 12:51:43 +0900 (JST)
Subject: [ruby-changes:71726] e06100d969 (master): [ruby/rdoc] Allow cross references to methods including underscores

https://git.ruby-lang.org/ruby.git/commit/?id=e06100d969

From e06100d969c7f6a275e121cb1154d3947d1ebe32 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Thu, 10 Feb 2022 08:13:57 +0900
Subject: [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
---
 lib/rdoc/cross_reference.rb            |  8 +++++++-
 test/rdoc/test_rdoc_cross_reference.rb | 14 ++++++++------
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/lib/rdoc/cross_reference.rb b/lib/rdoc/cross_reference.rb
index 0f301dcbb3..319bbc02ac 100644
--- a/lib/rdoc/cross_reference.rb
+++ b/lib/rdoc/cross_reference.rb
@@ -1,4 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/lib/rdoc/cross_reference.rb#L1
 # frozen_string_literal: true
+
+require_relative 'markup/attribute_manager' # for PROTECT_ATTR
+
 ##
 # RDoc::CrossReference is a reusable way to create cross references for names.
 
@@ -29,7 +32,10 @@ class RDoc::CrossReference https://github.com/ruby/ruby/blob/trunk/lib/rdoc/cross_reference.rb#L32
   #
   # 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
diff --git a/test/rdoc/test_rdoc_cross_reference.rb b/test/rdoc/test_rdoc_cross_reference.rb
index fee6fe59eb..cbda77a798 100644
--- a/test/rdoc/test_rdoc_cross_reference.rb
+++ b/test/rdoc/test_rdoc_cross_reference.rb
@@ -2,7 +2,9 @@ https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_cross_reference.rb#L2
 require_relative 'xref_test_case'
 
 class TestRDocCrossReference < XrefTestCase
-  OPERATOR_METHODS = %w'== === != =~ !~ < > <= >= <=> [] []= << >> -@ +@ ! - + * / % ** !@ ` | & ^ ~'
+  EXAMPLE_METHODS = %w'== === != =~ !~ < > <= >= <=> [] []= << >>
+    -@ +@ ! - + * / % ** !@ ` | & ^ ~ __id__
+  '
 
   def setup
     super
@@ -21,7 +23,7 @@ class TestRDocCrossReference < XrefTestCase https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_cross_reference.rb#L23
   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
@@ -170,7 +172,7 @@ class TestRDocCrossReference < XrefTestCase https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_cross_reference.rb#L172
     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
@@ -189,9 +191,9 @@ class TestRDocCrossReference < XrefTestCase https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_cross_reference.rb#L191
     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
 
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]