Skip to content

ClassModule#add_comment should receive RDoc::Comment #688

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
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
2 changes: 1 addition & 1 deletion lib/rdoc/class_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def comment= comment # :nodoc:
normalize_comment comment
end

comment = "#{@comment}\n---\n#{comment}" unless @comment.empty?
comment = "#{@comment.to_s}\n---\n#{comment.to_s}" unless @comment.empty?

super comment
end
Expand Down
5 changes: 5 additions & 0 deletions lib/rdoc/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ class RDoc::Comment

attr_reader :text

##
# Alias for text

alias to_s text

##
# Overrides the content returned by #parse. Use when there is no #text
# source for this comment
Expand Down
21 changes: 12 additions & 9 deletions test/test_rdoc_class_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,24 @@ def test_add_comment
tl3 = @store.add_file 'three.rb'

cm = RDoc::ClassModule.new 'Klass'
cm.add_comment '# comment 1', tl1
comment_tl1 = RDoc::Comment.new('# comment 1')
cm.add_comment comment_tl1, tl1

assert_equal [['comment 1', tl1]], cm.comment_location
assert_equal 'comment 1', cm.comment
assert_equal [[comment_tl1, tl1]], cm.comment_location
assert_equal 'comment 1', cm.comment.text

cm.add_comment '# comment 2', tl2
comment_tl2 = RDoc::Comment.new('# comment 2')
cm.add_comment comment_tl2, tl2

assert_equal [['comment 1', tl1], ['comment 2', tl2]], cm.comment_location
assert_equal [[comment_tl1, tl1], [comment_tl2, tl2]], cm.comment_location
assert_equal "comment 1\n---\ncomment 2", cm.comment

cm.add_comment "# * comment 3", tl3
comment_tl3 = RDoc::Comment.new('# * comment 3')
cm.add_comment comment_tl3, tl3

assert_equal [['comment 1', tl1],
['comment 2', tl2],
['* comment 3', tl3]], cm.comment_location
assert_equal [[comment_tl1, tl1],
[comment_tl2, tl2],
[comment_tl3, tl3]], cm.comment_location
assert_equal "comment 1\n---\ncomment 2\n---\n* comment 3", cm.comment
end

Expand Down