From 1d8674a835eca84831d3516e6af722f86af17c63 Mon Sep 17 00:00:00 2001 From: Code Ass Date: Sun, 24 Sep 2017 06:04:38 +0900 Subject: [PATCH 1/3] Skip the same of outside of nested namespace In the code below, the fullname of A::B is A::B, but it's treated as A::A::A::B now. module A class A::B end end This commit fixes it. --- lib/rdoc/parser/ruby.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/rdoc/parser/ruby.rb b/lib/rdoc/parser/ruby.rb index 130eca89c7..fc323b92cf 100644 --- a/lib/rdoc/parser/ruby.rb +++ b/lib/rdoc/parser/ruby.rb @@ -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 From 96964f58825681935fd1881fb2905a2d0f3c60c2 Mon Sep 17 00:00:00 2001 From: Code Ass Date: Sun, 24 Sep 2017 16:25:17 +0900 Subject: [PATCH 2/3] Add test_parse_class_the_same_of_outside --- test/test_rdoc_parser_ruby.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/test_rdoc_parser_ruby.rb b/test/test_rdoc_parser_ruby.rb index cda407ed51..5d09fa1c84 100644 --- a/test/test_rdoc_parser_ruby.rb +++ b/test/test_rdoc_parser_ruby.rb @@ -1360,6 +1360,23 @@ 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_with_bracket util_parser <<-RUBY class Klass From cc55d917d545f9f7258f0b7384f41561b17f80ac Mon Sep 17 00:00:00 2001 From: Code Ass Date: Sun, 24 Sep 2017 16:25:27 +0900 Subject: [PATCH 3/3] Add test_parse_constant_the_same_of_outside --- test/test_rdoc_parser_ruby.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/test_rdoc_parser_ruby.rb b/test/test_rdoc_parser_ruby.rb index 5d09fa1c84..df414348f6 100644 --- a/test/test_rdoc_parser_ruby.rb +++ b/test/test_rdoc_parser_ruby.rb @@ -1377,6 +1377,35 @@ class A::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 = <def self.foo + A::B::C +end +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