Skip to content

Commit f7fc033

Browse files
authored
Merge pull request #523 from aycabta/skip-the-same-of-outside-of-nested-namespace
Skip the same of outside of nested namespace
2 parents 1557d21 + cc55d91 commit f7fc033

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

lib/rdoc/parser/ruby.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,11 @@ def get_class_or_module container, ignore_constants = false
376376
unless :on_const == name_t[:kind] || :on_ident == name_t[:kind]
377377
raise RDoc::Error, "Invalid class or module definition: #{given_name}"
378378
end
379-
given_name << '::' << name_t[:text]
379+
if prev_container == container and !ignore_constants
380+
given_name = name_t[:text]
381+
else
382+
given_name << '::' << name_t[:text]
383+
end
380384
end
381385

382386
skip_tkspace false

test/test_rdoc_parser_ruby.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,52 @@ def test_parse_comment_nested
13601360
assert_equal 'comment', c.comment
13611361
end
13621362

1363+
def test_parse_class_the_same_of_outside
1364+
util_parser <<-RUBY
1365+
module A
1366+
class A::B
1367+
end
1368+
end
1369+
RUBY
1370+
1371+
@parser.scan
1372+
1373+
assert_includes @store.modules_hash, 'A'
1374+
module_a = @store.find_module_named 'A'
1375+
refute_empty module_a.classes_hash
1376+
assert_includes module_a.classes_hash, 'B'
1377+
refute_includes module_a.classes_hash, 'A'
1378+
end
1379+
1380+
def test_parse_constant_the_same_of_outside
1381+
util_parser <<-RUBY
1382+
module A
1383+
class B
1384+
class C
1385+
end
1386+
end
1387+
1388+
def self.foo
1389+
A::B::C
1390+
end
1391+
end
1392+
RUBY
1393+
1394+
expected = <<EXPECTED
1395+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">foo</span>
1396+
<span class="ruby-constant">A</span><span class="ruby-operator">::</span><span class="ruby-constant">B</span><span class="ruby-operator">::</span><span class="ruby-constant">C</span>
1397+
<span class="ruby-keyword">end</span>
1398+
EXPECTED
1399+
expected = expected.rstrip
1400+
1401+
@parser.scan
1402+
1403+
module_a = @store.find_module_named 'A'
1404+
foo = module_a.method_list.first
1405+
markup_code = foo.markup_code.sub(/^.*\n/, '')
1406+
assert_equal expected, markup_code
1407+
end
1408+
13631409
def test_parse_constant_with_bracket
13641410
util_parser <<-RUBY
13651411
class Klass

0 commit comments

Comments
 (0)