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

Cross references to operator methods #865

Merged
merged 2 commits into from
Feb 9, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rdoc/cross_reference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 23 additions & 21 deletions test/rdoc/test_rdoc_cross_reference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require File.expand_path '../xref_test_case', __FILE__

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

def setup
super
Expand All @@ -18,9 +19,9 @@ def refute_ref name
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
Expand Down Expand Up @@ -163,34 +164,35 @@ def test_resolve_the_same_name_in_instance_and_class_method
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
Expand Down