Skip to content

Handle all definitions per file in Ruby #542

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 1 commit into from
Oct 24, 2017
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
4 changes: 3 additions & 1 deletion lib/rdoc/class_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ def add_comment comment, location
normalize_comment comment
end

@comment_location.delete_if { |(_, l)| l == location }
if location.parser == RDoc::Parser::C
@comment_location.delete_if { |(_, l)| l == location }
end

@comment_location << [comment, location]

Expand Down
3 changes: 2 additions & 1 deletion test/test_rdoc_class_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def test_add_comment_duplicate
cm.add_comment '# comment 1', tl1
cm.add_comment '# comment 2', tl1

assert_equal [['comment 2', tl1]], cm.comment_location
assert_equal [['comment 1', tl1],
['comment 2', tl1]], cm.comment_location
end

def test_add_comment_stopdoc
Expand Down
19 changes: 19 additions & 0 deletions test/test_rdoc_parser_c.rb
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,25 @@ def test_do_classes_class
assert_equal "this is the Foo class", klass.comment.text
end

def test_do_classes_duplicate_class
content = <<-EOF
/* Document-class: Foo
* first
*/
VALUE cFoo = rb_define_class("Foo", rb_cObject);
/* Document-class: Foo
* second
*/
VALUE cFoo = rb_define_class("Foo", rb_cObject);
EOF

klass = util_get_class content, 'cFoo'
assert_equal 1, klass.comment_location.size
first = klass.comment_location.first
first_comment = first[0]
assert_equal 'first', first_comment.text
end

def test_do_classes_struct
content = <<-EOF
/* Document-class: Foo
Expand Down
27 changes: 27 additions & 0 deletions test/test_rdoc_parser_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,32 @@ class Foo
assert_equal @top_level, blah.file
end

def test_parse_class_in_a_file_repeatedly
@filename = 'a.rb'
comment_a = RDoc::Comment.new "# aaa\n", @top_level
util_parser "class Foo\nend"
tk = @parser.get_tk
@parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, comment_a
comment_b = RDoc::Comment.new "# bbb\n", @top_level
util_parser "class Foo\nend"
tk = @parser.get_tk
@parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, comment_b

@filename = 'b.rb'
comment_c = RDoc::Comment.new "# ccc\n", @top_level
util_parser "class Foo\nend"
tk = @parser.get_tk
@parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, comment_c

foo = @top_level.classes.first
assert_equal 'Foo', foo.full_name
assert_equal [[comment_a, @top_level],
[comment_b, @top_level],
[comment_c, @top_level]], foo.comment_location
assert_equal [@top_level], foo.in_files
assert_equal 1, foo.line
end

def test_parse_class_ghost_method_yields
util_parser <<-CLASS
class Foo
Expand Down Expand Up @@ -3393,6 +3419,7 @@ module Foo
foo = @top_level.modules.first

expected = [
RDoc::Comment.new('comment a', @top_level),
RDoc::Comment.new('comment b', @top_level)
]

Expand Down