summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-02-07 22:06:53 +0900
committergit <svn-admin@ruby-lang.org>2022-02-09 18:44:40 +0900
commit202f690a5edef6d0b8f73c6df53edc02a0f16c7e (patch)
treef6826400d0f0c715e9b14910b52ba1f8c8142422
parentdec96dd89744695d310b70a672b9ea044eeed89f (diff)
[ruby/rdoc] Allow cross references to operator methods
Make operator methods, e.g., `Regexp#=~`, `Integer#<=>`, cross reference targets. https://github.com/ruby/rdoc/commit/5d332a4128
-rw-r--r--lib/rdoc/cross_reference.rb2
-rw-r--r--test/rdoc/test_rdoc_cross_reference.rb44
2 files changed, 24 insertions, 22 deletions
diff --git a/lib/rdoc/cross_reference.rb b/lib/rdoc/cross_reference.rb
index ef8e21bde8..9e4a6ddf69 100644
--- a/lib/rdoc/cross_reference.rb
+++ b/lib/rdoc/cross_reference.rb
@@ -19,7 +19,7 @@ class RDoc::CrossReference
#
# See CLASS_REGEXP_STR
- METHOD_REGEXP_STR = '([A-Za-z]\w*[!?=]?|%|===?|\[\]=?|<<|>>|\+@|-@|-|\+|\*)(?:\([\w.+*/=<>-]*\))?'
+ METHOD_REGEXP_STR = '([A-Za-z]\w*[!?=]?|%|=(?:==?|~)|![=~]|\[\]=?|<(?:<|=>?)?|>[>=]?|[-+!]@?|\*\*?|[/%])(?:\([\w.+*/=<>-]*\))?'
##
# 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 f73681ebc8..17b8bb34bc 100644
--- a/test/rdoc/test_rdoc_cross_reference.rb
+++ b/test/rdoc/test_rdoc_cross_reference.rb
@@ -2,6 +2,7 @@
require File.expand_path '../xref_test_case', __FILE__
class TestRDocCrossReference < XrefTestCase
+ OPERATOR_METHODS = %w'== === != =~ !~ < > <= >= <=> [] []= << >> -@ +@ ! - + * / % ** !@'
def setup
super
@@ -18,9 +19,9 @@ class TestRDocCrossReference < XrefTestCase
end
def test_METHOD_REGEXP_STR
- re = /#{RDoc::CrossReference::METHOD_REGEXP_STR}/
+ re = /\A(?:#{RDoc::CrossReference::METHOD_REGEXP_STR})\z/
- %w'== === [] []= << >>'.each do |x|
+ OPERATOR_METHODS.each do |x|
re =~ x
assert_equal x, $&
end
@@ -163,34 +164,35 @@ class TestRDocCrossReference < XrefTestCase
assert_ref @c9_a_c_bar, 'C9::B.bar'
end
- def test_resolve_method_equals3
- m = RDoc::AnyMethod.new '', '==='
- @c1.add_method m
-
- assert_ref m, '==='
- end
-
def test_resolve_page
page = @store.add_file 'README.txt', parser: RDoc::Parser::Simple
assert_ref page, 'README'
end
- def test_resolve_percent
- i_percent = RDoc::AnyMethod.new nil, '%'
- i_percent.singleton = false
- @c1.add_method i_percent
+ def assert_resolve_oeprator(x)
+ @c1.methods_hash.clear
+
+ i_op = RDoc::AnyMethod.new nil, x
+ i_op.singleton = false
+ @c1.add_method i_op
- c_percent = RDoc::AnyMethod.new nil, '%'
- c_percent.singleton = true
- @c1.add_method c_percent
+ c_op = RDoc::AnyMethod.new nil, x
+ c_op.singleton = true
+ @c1.add_method c_op
- assert_ref i_percent, '%'
- assert_ref i_percent, '#%'
- assert_ref c_percent, '::%'
+ assert_ref i_op, x
+ assert_ref i_op, "##{x}"
+ assert_ref c_op, "::#{x}"
- assert_ref i_percent, 'C1#%'
- assert_ref c_percent, 'C1::%'
+ assert_ref i_op, "C1##{x}"
+ assert_ref c_op, "C1::#{x}"
+ end
+
+ OPERATOR_METHODS.each do |x|
+ define_method("test_resolve_operator:#{x}") do
+ assert_resolve_oeprator(x)
+ end
end
def test_resolve_no_ref