Skip to content

Commit

Permalink
RDoc::Parser::C#find_class_comment can now find a comment immediatly …
Browse files Browse the repository at this point in the history
…before rb_define_class_under (but not Init_Foo, on purpose). Issue ruby#89
  • Loading branch information
drbrain committed Dec 12, 2011
1 parent f281bc0 commit 6c1c0d4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions History.rdoc
Expand Up @@ -21,6 +21,8 @@
* RDoc better understands directives for comments. Comment directives can
now be found anywhere in multi-line comments. Issue #90 by Ryan Davis
* Tidy links to methods show the label again. Issue #88 by Simon Chiang
* RDoc::Parser::C can now find comments directly above
+rb_define_class_under+. Issue #89 by Enrico

=== 3.11 / 2011/10-17

Expand Down
3 changes: 3 additions & 0 deletions lib/rdoc/parser/c.rb
Expand Up @@ -572,6 +572,9 @@ def find_class_comment(class_name, class_mod)
elsif @content =~ %r%((?>/\*.*?\*/\s+))
([\w\.\s]+\s* = \s+)?rb_define_(class|module).*?"(#{class_name})"%xm then
comment = $1
elsif @content =~ %r%((?>/\*.*?\*/\s+))
([\w\.\s]+\s* = \s+)?rb_define_(class|module)_under.*?"(#{class_name.split('::').last})"%xm then
comment = $1
else
comment = ''
end
Expand Down
35 changes: 35 additions & 0 deletions test/test_rdoc_parser_c.rb
Expand Up @@ -701,6 +701,41 @@ def test_find_class_comment_define_class_bogus_comment
assert_equal '', klass.comment.text
end

def test_find_class_comment_define_class_under
content = <<-EOF
/*
* a comment for class Foo
*/
VALUE foo = rb_define_class_under(rb_cObject, "Foo", rb_cObject);
EOF

klass = util_get_class content, 'foo'

assert_equal "a comment for class Foo", klass.comment.text
end

def test_find_class_comment_define_class_under_Init
content = <<-EOF
/*
* a comment for class Foo on Init
*/
void
Init_Foo(void) {
/*
* a comment for class Foo on rb_define_class
*/
VALUE foo = rb_define_class_under(rb_cObject, "Foo", rb_cObject);
}
EOF

klass = util_get_class content, 'foo'

# the inner comment is used since Object::Foo is not necessarily the same
# thing as "Foo" for Init_
assert_equal "a comment for class Foo on rb_define_class",
klass.comment.text
end

def test_find_const_comment_rb_define
content = <<-EOF
/*
Expand Down

0 comments on commit 6c1c0d4

Please sign in to comment.