Skip to content

Commit

Permalink
Cross references to operator methods
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Feb 7, 2022
1 parent fd9c58b commit abf36d5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
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
25 changes: 21 additions & 4 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 @@ -10,17 +11,17 @@ def setup
end

def assert_ref expected, name
assert_equal expected, @xref.resolve(name, 'fail')
assert_equal expected, @xref.resolve(name, 'fail'), name
end

def refute_ref name
assert_equal name, @xref.resolve(name, name)
assert_equal name, @xref.resolve(name, name), 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 @@ -170,6 +171,22 @@ def test_resolve_method_equals3
assert_ref m, '==='
end

def test_resolve_method_operator
stats = RDoc::Stats.new @store, 0
OPERATOR_METHODS.each do |x|
RDoc::Parser::Ruby.new(@xref_data, @file_name, "#{<<~"begin;"}\n#{<<~"end;"}", @options, stats).scan
begin;
class C1
def #{x}(*)
end
end
end;

m = @c1.find_instance_method_named(x)
assert_ref m, x
end
end

def test_resolve_page
page = @store.add_file 'README.txt', parser: RDoc::Parser::Simple

Expand Down

0 comments on commit abf36d5

Please sign in to comment.