From a86d4eef4b4551a48a5329bb993c3c6c39a1b1f3 Mon Sep 17 00:00:00 2001 From: aycabta Date: Tue, 22 Jan 2019 04:46:46 +0900 Subject: [ruby/rdoc] Normalization of comment should check language RDoc::Text#normalize_comment that is included RDoc::Comment always remove Ruby style comment indicator "#" and C style comment indicator "/**/", but should check language and remove only the language's comment indicator. https://github.com/ruby/rdoc/commit/ca68ba1e73 --- test/rdoc/minitest_helper.rb | 5 ++-- test/rdoc/test_rdoc_class_module.rb | 28 +++++++++++---------- test/rdoc/test_rdoc_comment.rb | 1 + test/rdoc/test_rdoc_context_section.rb | 2 +- test/rdoc/test_rdoc_parser_c.rb | 2 +- test/rdoc/test_rdoc_parser_ruby.rb | 46 +++++++++++++++++----------------- test/rdoc/test_rdoc_text.rb | 9 +++++++ 7 files changed, 53 insertions(+), 40 deletions(-) (limited to 'test/rdoc') diff --git a/test/rdoc/minitest_helper.rb b/test/rdoc/minitest_helper.rb index 9fb0cd676b..5db0c315ef 100644 --- a/test/rdoc/minitest_helper.rb +++ b/test/rdoc/minitest_helper.rb @@ -97,8 +97,9 @@ class RDoc::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Un # Creates an RDoc::Comment with +text+ which was defined on +top_level+. # By default the comment has the 'rdoc' format. - def comment text, top_level = @top_level - RDoc::Comment.new text, top_level + def comment text, top_level = @top_level, language = nil + comment = RDoc::Comment.new text, top_level, language + comment end ## diff --git a/test/rdoc/test_rdoc_class_module.rb b/test/rdoc/test_rdoc_class_module.rb index 138ede58b6..4dcc5d15ab 100644 --- a/test/rdoc/test_rdoc_class_module.rb +++ b/test/rdoc/test_rdoc_class_module.rb @@ -9,19 +9,19 @@ class TestRDocClassModule < XrefTestCase tl3 = @store.add_file 'three.rb' cm = RDoc::ClassModule.new 'Klass' - comment_tl1 = RDoc::Comment.new('# comment 1') + comment_tl1 = RDoc::Comment.new('# comment 1', @top_level, :ruby) cm.add_comment comment_tl1, tl1 assert_equal [[comment_tl1, tl1]], cm.comment_location assert_equal 'comment 1', cm.comment.text - comment_tl2 = RDoc::Comment.new('# comment 2') + comment_tl2 = RDoc::Comment.new('# comment 2', @top_level, :ruby) cm.add_comment comment_tl2, tl2 assert_equal [[comment_tl1, tl1], [comment_tl2, tl2]], cm.comment_location assert_equal "comment 1\n---\ncomment 2", cm.comment - comment_tl3 = RDoc::Comment.new('# * comment 3') + comment_tl3 = RDoc::Comment.new('# * comment 3', @top_level, :ruby) cm.add_comment comment_tl3, tl3 assert_equal [[comment_tl1, tl1], @@ -42,11 +42,13 @@ class TestRDocClassModule < XrefTestCase tl1 = @store.add_file 'one.rb' cm = RDoc::ClassModule.new 'Klass' - cm.add_comment '# comment 1', tl1 - cm.add_comment '# comment 2', tl1 + comment1 = RDoc::Comment.new('# comment 1', @top_level, :ruby) + comment2 = RDoc::Comment.new('# comment 2', @top_level, :ruby) + cm.add_comment comment1, tl1 + cm.add_comment comment2, tl1 - assert_equal [['comment 1', tl1], - ['comment 2', tl1]], cm.comment_location + assert_equal [[comment1, tl1], + [comment2, tl1]], cm.comment_location end def test_add_comment_stopdoc @@ -66,17 +68,17 @@ class TestRDocClassModule < XrefTestCase def test_comment_equals cm = RDoc::ClassModule.new 'Klass' - cm.comment = '# comment 1' + cm.comment = RDoc::Comment.new('# comment 1', @top_level, :ruby) - assert_equal 'comment 1', cm.comment + assert_equal 'comment 1', cm.comment.to_s - cm.comment = '# comment 2' + cm.comment = RDoc::Comment.new('# comment 2', @top_level, :ruby) - assert_equal "comment 1\n---\ncomment 2", cm.comment + assert_equal "comment 1\n---\ncomment 2", cm.comment.to_s - cm.comment = "# * comment 3" + cm.comment = RDoc::Comment.new('# * comment 3', @top_level, :ruby) - assert_equal "comment 1\n---\ncomment 2\n---\n* comment 3", cm.comment + assert_equal "comment 1\n---\ncomment 2\n---\n* comment 3", cm.comment.to_s end def test_comment_equals_comment diff --git a/test/rdoc/test_rdoc_comment.rb b/test/rdoc/test_rdoc_comment.rb index 9b3c105bb0..48d0042f16 100644 --- a/test/rdoc/test_rdoc_comment.rb +++ b/test/rdoc/test_rdoc_comment.rb @@ -241,6 +241,7 @@ lines, one line per element. Lines are assumed to be separated by _sep_. @comment.text = <<-TEXT # comment TEXT + @comment.language = :ruby assert_same @comment, @comment.normalize diff --git a/test/rdoc/test_rdoc_context_section.rb b/test/rdoc/test_rdoc_context_section.rb index f1cf493d3d..93cfbdf0a7 100644 --- a/test/rdoc/test_rdoc_context_section.rb +++ b/test/rdoc/test_rdoc_context_section.rb @@ -11,7 +11,7 @@ class TestRDocContextSection < RDoc::TestCase @klass = @top_level.add_class RDoc::NormalClass, 'Object' @S = RDoc::Context::Section - @s = @S.new @klass, 'section', comment('# comment', @top_level) + @s = @S.new @klass, 'section', comment('# comment', @top_level, :ruby) end def test_add_comment diff --git a/test/rdoc/test_rdoc_parser_c.rb b/test/rdoc/test_rdoc_parser_c.rb index 3d30d767df..ca668f61fc 100644 --- a/test/rdoc/test_rdoc_parser_c.rb +++ b/test/rdoc/test_rdoc_parser_c.rb @@ -1381,7 +1381,7 @@ commercial() -> Date
end def test_find_modifiers_yields - comment = RDoc::Comment.new <<-COMMENT + comment = RDoc::Comment.new <<-COMMENT, @top_level, :c /* :yields: a, b * * Blah diff --git a/test/rdoc/test_rdoc_parser_ruby.rb b/test/rdoc/test_rdoc_parser_ruby.rb index 97abafca58..95a8658fdb 100644 --- a/test/rdoc/test_rdoc_parser_ruby.rb +++ b/test/rdoc/test_rdoc_parser_ruby.rb @@ -435,7 +435,7 @@ ruby klass = RDoc::NormalClass.new 'Foo' klass.parent = @top_level - comment = RDoc::Comment.new "##\n# my attr\n", @top_level + comment = RDoc::Comment.new "##\n# my attr\n", @top_level, :ruby util_parser "attr :foo, :bar" @@ -472,7 +472,7 @@ ruby klass = RDoc::NormalClass.new 'Foo' klass.parent = @top_level - comment = RDoc::Comment.new "##\n# my attr\n", @top_level + comment = RDoc::Comment.new "##\n# my attr\n", @top_level, :ruby util_parser "attr_accessor :foo, :bar" @@ -499,7 +499,7 @@ ruby klass = RDoc::NormalClass.new 'Foo' klass.parent = @top_level - comment = RDoc::Comment.new "##\n# my attr\n", @top_level + comment = RDoc::Comment.new "##\n# my attr\n", @top_level, :ruby util_parser "attr_accessor :foo, :bar,\n :baz,\n :qux" @@ -584,7 +584,7 @@ ruby klass = RDoc::NormalClass.new 'Foo' klass.parent = @top_level - comment = RDoc::Comment.new "##\n# my attr\n", @top_level + comment = RDoc::Comment.new "##\n# my attr\n", @top_level, :ruby util_parser "attr_writer :foo, :bar" @@ -610,7 +610,7 @@ ruby klass = RDoc::NormalClass.new 'Foo' klass.parent = @top_level - comment = RDoc::Comment.new "##\n# :attr: \n# my method\n", @top_level + comment = RDoc::Comment.new "##\n# :attr: \n# my method\n", @top_level, :ruby util_parser "add_my_method :foo, :bar" @@ -631,7 +631,7 @@ ruby klass.parent = @top_level comment = - RDoc::Comment.new "##\n# :attr_accessor: \n# my method\n", @top_level + RDoc::Comment.new "##\n# :attr_accessor: \n# my method\n", @top_level, :ruby util_parser "add_my_method :foo, :bar" @@ -651,7 +651,7 @@ ruby klass = RDoc::NormalClass.new 'Foo' klass.parent = @top_level - comment = RDoc::Comment.new "##\n# :attr: foo\n# my method\n", @top_level + comment = RDoc::Comment.new "##\n# :attr: foo\n# my method\n", @top_level, :ruby util_parser "add_my_method :foo, :bar" @@ -672,7 +672,7 @@ ruby klass.parent = @top_level comment = - RDoc::Comment.new "##\n# :attr_reader: \n# my method\n", @top_level + RDoc::Comment.new "##\n# :attr_reader: \n# my method\n", @top_level, :ruby util_parser "add_my_method :foo, :bar" @@ -708,7 +708,7 @@ ruby klass.parent = @top_level comment = - RDoc::Comment.new "##\n# :attr_writer: \n# my method\n", @top_level + RDoc::Comment.new "##\n# :attr_writer: \n# my method\n", @top_level, :ruby util_parser "add_my_method :foo, :bar" @@ -724,7 +724,7 @@ ruby end def test_parse_class - comment = RDoc::Comment.new "##\n# my class\n", @top_level + comment = RDoc::Comment.new "##\n# my class\n", @top_level, :ruby util_parser "class Foo\nend" @@ -1001,7 +1001,7 @@ end end def test_parse_module - comment = RDoc::Comment.new "##\n# my module\n", @top_level + comment = RDoc::Comment.new "##\n# my module\n", @top_level, :ruby util_parser "module Foo\nend" @@ -1247,7 +1247,7 @@ EOF klass = RDoc::NormalClass.new 'Foo' klass.parent = @top_level - comment = RDoc::Comment.new "##\n# :attr: foo\n# my attr\n", @top_level + comment = RDoc::Comment.new "##\n# :attr: foo\n# my attr\n", @top_level, :ruby util_parser "\n" @@ -1311,7 +1311,7 @@ EOF klass = RDoc::NormalClass.new 'Foo' klass.parent = @top_level - comment = RDoc::Comment.new "##\n# :method: foo\n# my method\n", @top_level + comment = RDoc::Comment.new "##\n# :method: foo\n# my method\n", @top_level, :ruby util_parser "\n" @@ -1595,7 +1595,7 @@ end klass = RDoc::NormalClass.new 'C' klass.parent = @top_level - comment = RDoc::Comment.new "# my extend\n", @top_level + comment = RDoc::Comment.new "# my extend\n", @top_level, :ruby util_parser "extend I" @@ -1615,7 +1615,7 @@ end klass = RDoc::NormalClass.new 'C' klass.parent = @top_level - comment = RDoc::Comment.new "# my include\n", @top_level + comment = RDoc::Comment.new "# my include\n", @top_level, :ruby util_parser "include I" @@ -1635,7 +1635,7 @@ end klass = RDoc::NormalClass.new 'Foo' klass.parent = @top_level - comment = RDoc::Comment.new "##\n# my method\n", @top_level + comment = RDoc::Comment.new "##\n# my method\n", @top_level, :ruby util_parser "add_my_method :foo, :bar\nadd_my_method :baz" @@ -1719,7 +1719,7 @@ end def test_parse_meta_method_define_method klass = RDoc::NormalClass.new 'Foo' - comment = RDoc::Comment.new "##\n# my method\n", @top_level + comment = RDoc::Comment.new "##\n# my method\n", @top_level, :ruby util_parser "define_method :foo do end" @@ -1738,7 +1738,7 @@ end klass.parent = @top_level comment = - RDoc::Comment.new "##\n# :method: woo_hoo!\n# my method\n", @top_level + RDoc::Comment.new "##\n# :method: woo_hoo!\n# my method\n", @top_level, :ruby util_parser "add_my_method :foo, :bar\nadd_my_method :baz" @@ -1757,7 +1757,7 @@ end klass.parent = @top_level comment = - RDoc::Comment.new "##\n# :singleton-method:\n# my method\n", @top_level + RDoc::Comment.new "##\n# :singleton-method:\n# my method\n", @top_level, :ruby util_parser "add_my_method :foo, :bar\nadd_my_method :baz" @@ -1778,7 +1778,7 @@ end comment = RDoc::Comment.new "##\n# :singleton-method: woo_hoo!\n# my method\n", - @top_level + @top_level, :ruby util_parser "add_my_method :foo, :bar\nadd_my_method :baz" @@ -1795,7 +1795,7 @@ end def test_parse_meta_method_string_name klass = RDoc::NormalClass.new 'Foo' - comment = RDoc::Comment.new "##\n# my method\n", @top_level + comment = RDoc::Comment.new "##\n# my method\n", @top_level, :ruby util_parser "add_my_method 'foo'" @@ -1827,7 +1827,7 @@ end def test_parse_meta_method_unknown klass = RDoc::NormalClass.new 'Foo' - comment = RDoc::Comment.new "##\n# my method\n", @top_level + comment = RDoc::Comment.new "##\n# my method\n", @top_level, :ruby util_parser "add_my_method ('foo')" @@ -1845,7 +1845,7 @@ end klass = RDoc::NormalClass.new 'Foo' klass.parent = @top_level - comment = RDoc::Comment.new "##\n# my method\n", @top_level + comment = RDoc::Comment.new "##\n# my method\n", @top_level, :ruby util_parser "def foo() :bar end" diff --git a/test/rdoc/test_rdoc_text.rb b/test/rdoc/test_rdoc_text.rb index 2669766e71..fcd993f834 100644 --- a/test/rdoc/test_rdoc_text.rb +++ b/test/rdoc/test_rdoc_text.rb @@ -13,6 +13,7 @@ class TestRDocText < RDoc::TestCase @options = RDoc::Options.new @top_level = @store.add_file 'file.rb' + @language = nil end def test_self_encode_fallback @@ -137,6 +138,8 @@ we don't worry too much. The comments associated with EXPECTED + @language = :ruby + assert_equal expected, normalize_comment(text) end @@ -155,6 +158,8 @@ we don't worry too much. The comments associated with EXPECTED + @language = :c + assert_equal expected, normalize_comment(text) end @@ -173,6 +178,8 @@ we don't worry too much. The comments associated with EXPECTED + @language = :c + assert_equal expected, normalize_comment(text) end @@ -200,6 +207,8 @@ The comments associated with end def test_parse_empty_newline + @language = :ruby + assert_equal RDoc::Markup::Document.new, parse("#\n") end -- cgit v1.2.3