diff --git a/lib/rdoc/comment.rb b/lib/rdoc/comment.rb index e4ef3c4495..b50193d56c 100644 --- a/lib/rdoc/comment.rb +++ b/lib/rdoc/comment.rb @@ -76,49 +76,6 @@ def ==(other) # :nodoc: other.text == @text and other.location == @location end - ## - # Look for a 'call-seq' in the comment to override the normal parameter - # handling. The :call-seq: is indented from the baseline. All lines of the - # same indentation level and prefix are consumed. - # - # For example, all of the following will be used as the :call-seq: - # - # # :call-seq: - # # ARGF.readlines(sep=$/) -> array - # # ARGF.readlines(limit) -> array - # # ARGF.readlines(sep, limit) -> array - # # - # # ARGF.to_a(sep=$/) -> array - # # ARGF.to_a(limit) -> array - # # ARGF.to_a(sep, limit) -> array - - def extract_call_seq - # we must handle situations like the above followed by an unindented first - # comment. The difficulty is to make sure not to match lines starting - # with ARGF at the same indent, but that are after the first description - # paragraph. - if /^(? ((?!\n)\s)*+ (?# whitespaces except newline)) - :?call-seq: - (? \g(?\n|\z) (?# trailing spaces))? - (? - (\g(?!\w)\S.*\g)* - (?> - (? \g\w+ (?# ' # ARGF' in the example above)) - .*\g)? - (\g\S.*\g (?# other non-blank line))*+ - (\g+(\k.*\g (?# ARGF.to_a lines))++)*+ - ) - (?m:^\s*$|\z) - /x =~ @text - seq = $~[:seq] - - all_start, all_stop = $~.offset(0) - @text.slice! all_start...all_stop - - seq.gsub!(/^\s*/, '') - end - end - ## # A comment is empty if its text String is empty. @@ -187,28 +144,6 @@ def parse @document end - ## - # Removes private sections from this comment. Private sections are flush to - # the comment marker and start with -- and end with ++. - # For C-style comments, a private marker may not start at the opening of the - # comment. - # - # /* - # *-- - # * private - # *++ - # * public - # */ - - def remove_private - # Workaround for gsub encoding for Ruby 1.9.2 and earlier - empty = '' - empty = RDoc::Encoding.change_encoding empty, @text.encoding - - @text = @text.gsub(%r%^\s*([#*]?)--.*?^\s*(\1)\+\+\n?%m, empty) - @text = @text.sub(%r%^\s*[#*]?--.*%m, '') - end - ## # Replaces this comment's text with +text+ and resets the parsed document. # diff --git a/test/rdoc/rdoc_comment_test.rb b/test/rdoc/rdoc_comment_test.rb index 66a2c658db..8fa5e281fb 100644 --- a/test/rdoc/rdoc_comment_test.rb +++ b/test/rdoc/rdoc_comment_test.rb @@ -41,154 +41,6 @@ def test_equals2 refute_equal @comment, c3 end - def test_extract_call_seq - comment = RDoc::Comment.new <<-COMMENT, @top_level -call-seq: - bla => true or false - -moar comment - COMMENT - - assert_equal "bla => true or false\n", comment.extract_call_seq - end - - def test_extract_call_seq_blank - comment = RDoc::Comment.new <<-COMMENT, @top_level -call-seq: - bla => true or false - - COMMENT - - assert_equal "bla => true or false\n", comment.extract_call_seq - end - - def test_extract_call_seq_commented - comment = RDoc::Comment.new <<-COMMENT, @top_level -# call-seq: -# bla => true or false -# -# moar comment - COMMENT - - assert_nil comment.extract_call_seq - end - - def test_extract_call_seq_no_blank - comment = RDoc::Comment.new <<-COMMENT, @top_level -call-seq: - bla => true or false - COMMENT - - assert_equal "bla => true or false\n", comment.extract_call_seq - end - - def test_extract_call_seq_undent - comment = RDoc::Comment.new <<-COMMENT, @top_level -call-seq: - bla => true or false -moar comment - COMMENT - - assert_equal "bla => true or false\nmoar comment\n", comment.extract_call_seq - end - - def test_extract_call_seq_c - comment = RDoc::Comment.new <<-COMMENT -call-seq: - commercial() -> Date
- commercial(cwyear, cweek=41, cwday=5, sg=nil) -> Date [ruby 1.8]
- commercial(cwyear, cweek=1, cwday=1, sg=nil) -> Date [ruby 1.9] - -If no arguments are given: -* ruby 1.8: returns a +Date+ for 1582-10-15 (the Day of Calendar Reform in - Italy) -* ruby 1.9: returns a +Date+ for julian day 0 - -Otherwise, returns a +Date+ for the commercial week year, commercial week, -and commercial week day given. Ignores the 4th argument. - COMMENT - - expected = <<-CALL_SEQ.chomp -commercial() -> Date
-commercial(cwyear, cweek=41, cwday=5, sg=nil) -> Date [ruby 1.8]
-commercial(cwyear, cweek=1, cwday=1, sg=nil) -> Date [ruby 1.9] - - CALL_SEQ - - assert_equal expected, comment.extract_call_seq - end - - def test_extract_call_seq_c_no_blank - comment = RDoc::Comment.new <<-COMMENT -call-seq: - commercial() -> Date
- commercial(cwyear, cweek=41, cwday=5, sg=nil) -> Date [ruby 1.8]
- commercial(cwyear, cweek=1, cwday=1, sg=nil) -> Date [ruby 1.9] - COMMENT - - expected = <<-CALL_SEQ.chomp -commercial() -> Date
-commercial(cwyear, cweek=41, cwday=5, sg=nil) -> Date [ruby 1.8]
-commercial(cwyear, cweek=1, cwday=1, sg=nil) -> Date [ruby 1.9] - - CALL_SEQ - - assert_equal expected, comment.extract_call_seq - end - - def test_extract_call_seq_c_separator - comment = RDoc::Comment.new <<-'COMMENT' -call-seq: - ARGF.readlines(sep=$/) -> array - ARGF.readlines(limit) -> array - ARGF.readlines(sep, limit) -> array - - ARGF.to_a(sep=$/) -> array - ARGF.to_a(limit) -> array - ARGF.to_a(sep, limit) -> array - -Reads +ARGF+'s current file in its entirety, returning an +Array+ of its -lines, one line per element. Lines are assumed to be separated by _sep_. - - lines = ARGF.readlines - lines[0] #=> "This is line one\n" - - COMMENT - - expected = <<-CALL_SEQ -ARGF.readlines(sep=$/) -> array -ARGF.readlines(limit) -> array -ARGF.readlines(sep, limit) -> array -ARGF.to_a(sep=$/) -> array -ARGF.to_a(limit) -> array -ARGF.to_a(sep, limit) -> array - CALL_SEQ - - assert_equal expected, comment.extract_call_seq - - expected = <<-'COMMENT' - -Reads +ARGF+'s current file in its entirety, returning an +Array+ of its -lines, one line per element. Lines are assumed to be separated by _sep_. - - lines = ARGF.readlines - lines[0] #=> "This is line one\n" - - COMMENT - - assert_equal expected, comment.text - end - - # This test relies on AnyMethod#call_seq's behaviour as well - def test_extract_call_linear_performance - pre = ->(n) {[n, RDoc::Comment.new("\n"*n + 'call-seq:' + 'a'*n)]} - method_obj = RDoc::AnyMethod.new nil, 'blah' - assert_linear_performance((2..5).map {|i| 10**i}, pre: pre) do |n, comment| - method_obj.call_seq = comment.extract_call_seq - assert_equal n, method_obj.call_seq.size - end - end - def test_force_encoding @comment = RDoc::Encoding.change_encoding @comment, Encoding::UTF_8 @@ -324,159 +176,6 @@ def test_parse_rd assert_equal expected, c.parse end - def test_remove_private_encoding - comment = RDoc::Comment.new <<-EOS, @top_level -# This is text -#-- -# this is private - EOS - - comment = RDoc::Encoding.change_encoding comment, Encoding::IBM437 - - comment.remove_private - - assert_equal Encoding::IBM437, comment.text.encoding - end - - def test_remove_private_hash - @comment.text = <<-TEXT -#-- -# private -#++ -# public - TEXT - - @comment.remove_private - - assert_equal "# public\n", @comment.text - end - - def test_remove_private_hash_trail - comment = RDoc::Comment.new <<-EOS, @top_level -# This is text -#-- -# this is private - EOS - - expected = RDoc::Comment.new <<-EOS, @top_level -# This is text - EOS - - comment.remove_private - - assert_equal expected, comment - end - - def test_remove_private_long - comment = RDoc::Comment.new <<-EOS, @top_level -#----- -#++ -# this is text -#----- - EOS - - expected = RDoc::Comment.new <<-EOS, @top_level -# this is text - EOS - - comment.remove_private - - assert_equal expected, comment - end - - def test_remove_private_rule - comment = RDoc::Comment.new <<-EOS, @top_level -# This is text with a rule: -# --- -# this is also text - EOS - - expected = comment.dup - - comment.remove_private - - assert_equal expected, comment - end - - def test_remove_private_star - @comment.text = <<-TEXT -/* - *-- - * private - *++ - * public - */ - TEXT - - @comment.remove_private - - assert_equal "/*\n * public\n */\n", @comment.text - end - - def test_remove_private_star2 - @comment.text = <<-TEXT -/*-- - * private - *++ - * public - */ - TEXT - - @comment.remove_private - - assert_equal "/*--\n * private\n *++\n * public\n */\n", @comment.text - end - - def test_remove_private_toggle - comment = RDoc::Comment.new <<-EOS, @top_level -# This is text -#-- -# this is private -#++ -# This is text again. - EOS - - expected = RDoc::Comment.new <<-EOS, @top_level -# This is text -# This is text again. - EOS - - comment.remove_private - - assert_equal expected, comment - end - - def test_remove_private_toggle_encoding - comment = RDoc::Comment.new <<-EOS, @top_level -# This is text -#-- -# this is private -#++ -# This is text again. - EOS - - comment = RDoc::Encoding.change_encoding comment, Encoding::IBM437 - - comment.remove_private - - assert_equal Encoding::IBM437, comment.text.encoding - end - - def test_remove_private_toggle_encoding_ruby_bug? - comment = RDoc::Comment.new <<-EOS, @top_level -#-- -# this is private -#++ -# This is text again. - EOS - - comment = RDoc::Encoding.change_encoding comment, Encoding::IBM437 - - comment.remove_private - - assert_equal Encoding::IBM437, comment.text.encoding - end - def test_parse_directives comment = <<~COMMENT comment1