diff --git a/History.rdoc b/History.rdoc index 42d2a7283b..a295734a8a 100644 --- a/History.rdoc +++ b/History.rdoc @@ -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 diff --git a/lib/rdoc/parser/c.rb b/lib/rdoc/parser/c.rb index 299873d6a3..df668e306a 100644 --- a/lib/rdoc/parser/c.rb +++ b/lib/rdoc/parser/c.rb @@ -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 diff --git a/test/test_rdoc_parser_c.rb b/test/test_rdoc_parser_c.rb index fac7481980..8f78e0a6f5 100644 --- a/test/test_rdoc_parser_c.rb +++ b/test/test_rdoc_parser_c.rb @@ -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 /*