Skip to content

Skip the same of outside of nested namespace #523

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

Merged
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
6 changes: 5 additions & 1 deletion lib/rdoc/parser/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,11 @@ def get_class_or_module container, ignore_constants = false
unless :on_const == name_t[:kind] || :on_ident == name_t[:kind]
raise RDoc::Error, "Invalid class or module definition: #{given_name}"
end
given_name << '::' << name_t[:text]
if prev_container == container and !ignore_constants
given_name = name_t[:text]
else
given_name << '::' << name_t[:text]
end
end

skip_tkspace false
Expand Down
46 changes: 46 additions & 0 deletions test/test_rdoc_parser_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,52 @@ def test_parse_comment_nested
assert_equal 'comment', c.comment
end

def test_parse_class_the_same_of_outside
util_parser <<-RUBY
module A
class A::B
end
end
RUBY

@parser.scan

assert_includes @store.modules_hash, 'A'
module_a = @store.find_module_named 'A'
refute_empty module_a.classes_hash
assert_includes module_a.classes_hash, 'B'
refute_includes module_a.classes_hash, 'A'
end

def test_parse_constant_the_same_of_outside
util_parser <<-RUBY
module A
class B
class C
end
end

def self.foo
A::B::C
end
end
RUBY

expected = <<EXPECTED
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">foo</span>
<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>
<span class="ruby-keyword">end</span>
EXPECTED
expected = expected.rstrip

@parser.scan

module_a = @store.find_module_named 'A'
foo = module_a.method_list.first
markup_code = foo.markup_code.sub(/^.*\n/, '')
assert_equal expected, markup_code
end

def test_parse_constant_with_bracket
util_parser <<-RUBY
class Klass
Expand Down