Merge RDoc updates from matzruby 11502, 11503, 11504
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11505 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d7dbd877ff
commit
d9591028f2
13
ChangeLog
13
ChangeLog
@ -1,3 +1,16 @@
|
|||||||
|
Sun Jan 7 12:13:26 2007 Eric Hodel <drbrain@segment7.net>
|
||||||
|
|
||||||
|
* lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser#find_class_comment):
|
||||||
|
Look for class and module comments above rb_define_class and
|
||||||
|
rb_define_module. Patch by Daniel Berger <djberg96 at gmail.com>
|
||||||
|
|
||||||
|
Sun Jan 7 10:32:12 2007 Eric Hodel <drbrain@segment7.net>
|
||||||
|
|
||||||
|
* lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser#handle_constants):
|
||||||
|
Properly handle escaping of : in comments.
|
||||||
|
* test/rdoc/parsers/test_parse_c.rb:
|
||||||
|
Test RDoc::C_Parser#do_classes and Rdoc::C_Parser#find_class_comment.
|
||||||
|
|
||||||
Sun Jan 7 09:31:18 2007 Tadayoshi Funaba <tadf@dotrb.org>
|
Sun Jan 7 09:31:18 2007 Tadayoshi Funaba <tadf@dotrb.org>
|
||||||
|
|
||||||
* lib/date/format.rb: updated based on date2 4.0.1.
|
* lib/date/format.rb: updated based on date2 4.0.1.
|
||||||
|
@ -266,7 +266,31 @@ module RDoc
|
|||||||
@known_classes[var_name] = cm.full_name
|
@known_classes[var_name] = cm.full_name
|
||||||
end
|
end
|
||||||
|
|
||||||
############################################################
|
##
|
||||||
|
# Look for class or module documentation above Init_+class_name+(void),
|
||||||
|
# in a Document-class +class_name+ (or module) comment or above an
|
||||||
|
# rb_define_class (or module). If a comment is supplied above a matching
|
||||||
|
# Init_ and a rb_define_class the Init_ comment is used.
|
||||||
|
#
|
||||||
|
# /*
|
||||||
|
# * This is a comment for Foo
|
||||||
|
# */
|
||||||
|
# Init_Foo(void) {
|
||||||
|
# VALUE cFoo = rb_define_class("Foo", rb_cObject);
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# /*
|
||||||
|
# * Document-class: Foo
|
||||||
|
# * This is a comment for Foo
|
||||||
|
# */
|
||||||
|
# Init_foo(void) {
|
||||||
|
# VALUE cFoo = rb_define_class("Foo", rb_cObject);
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# /*
|
||||||
|
# * This is a comment for Foo
|
||||||
|
# */
|
||||||
|
# VALUE cFoo = rb_define_class("Foo", rb_cObject);
|
||||||
|
|
||||||
def find_class_comment(class_name, class_meth)
|
def find_class_comment(class_name, class_meth)
|
||||||
comment = nil
|
comment = nil
|
||||||
@ -275,6 +299,18 @@ module RDoc
|
|||||||
comment = $1
|
comment = $1
|
||||||
elsif @body =~ %r{Document-(class|module):\s#{class_name}\s*?\n((?>.*?\*/))}m
|
elsif @body =~ %r{Document-(class|module):\s#{class_name}\s*?\n((?>.*?\*/))}m
|
||||||
comment = $2
|
comment = $2
|
||||||
|
else
|
||||||
|
if @body =~ /rb_define_(class|module)/m then
|
||||||
|
class_name = class_name.split("::").last
|
||||||
|
comments = []
|
||||||
|
@body.split(/(\/\*.*?\*\/)\s*?\n/m).each_with_index do |chunk, index|
|
||||||
|
comments[index] = chunk
|
||||||
|
if chunk =~ /rb_define_(class|module).*?"(#{class_name})"/m then
|
||||||
|
comment = comments[index-1]
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
class_meth.comment = mangle_comment(comment) if comment
|
class_meth.comment = mangle_comment(comment) if comment
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
require 'pp'
|
|
||||||
require 'stringio'
|
require 'stringio'
|
||||||
require 'tempfile'
|
require 'tempfile'
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
@ -28,6 +27,66 @@ class TestRdocC_Parser < Test::Unit::TestCase
|
|||||||
@tempfile.unlink
|
@tempfile.unlink
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_do_classes_boot_class
|
||||||
|
content = <<-EOF
|
||||||
|
/* Document-class: Foo
|
||||||
|
* this is the Foo boot class
|
||||||
|
*/
|
||||||
|
VALUE cFoo = boot_defclass("Foo", 0);
|
||||||
|
EOF
|
||||||
|
|
||||||
|
klass = util_get_class content, 'cFoo'
|
||||||
|
assert_equal " this is the Foo boot class\n ", klass.comment
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_do_classes_class
|
||||||
|
content = <<-EOF
|
||||||
|
/* Document-class: Foo
|
||||||
|
* this is the Foo class
|
||||||
|
*/
|
||||||
|
VALUE cFoo = rb_define_class("Foo", rb_cObject);
|
||||||
|
EOF
|
||||||
|
|
||||||
|
klass = util_get_class content, 'cFoo'
|
||||||
|
assert_equal " this is the Foo class\n ", klass.comment
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_do_classes_class_under
|
||||||
|
content = <<-EOF
|
||||||
|
/* Document-class: Kernel::Foo
|
||||||
|
* this is the Foo class under Kernel
|
||||||
|
*/
|
||||||
|
VALUE cFoo = rb_define_class_under(rb_mKernel, "Foo", rb_cObject);
|
||||||
|
EOF
|
||||||
|
|
||||||
|
klass = util_get_class content, 'cFoo'
|
||||||
|
assert_equal " this is the Foo class under Kernel\n ", klass.comment
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_do_classes_module
|
||||||
|
content = <<-EOF
|
||||||
|
/* Document-module: Foo
|
||||||
|
* this is the Foo module
|
||||||
|
*/
|
||||||
|
VALUE mFoo = rb_define_module("Foo");
|
||||||
|
EOF
|
||||||
|
|
||||||
|
klass = util_get_class content, 'mFoo'
|
||||||
|
assert_equal " this is the Foo module\n ", klass.comment
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_do_classes_module_under
|
||||||
|
content = <<-EOF
|
||||||
|
/* Document-module: Kernel::Foo
|
||||||
|
* this is the Foo module under Kernel
|
||||||
|
*/
|
||||||
|
VALUE mFoo = rb_define_module_under(rb_mKernel, "Foo");
|
||||||
|
EOF
|
||||||
|
|
||||||
|
klass = util_get_class content, 'mFoo'
|
||||||
|
assert_equal " this is the Foo module under Kernel\n ", klass.comment
|
||||||
|
end
|
||||||
|
|
||||||
def test_do_constants
|
def test_do_constants
|
||||||
content = <<-EOF
|
content = <<-EOF
|
||||||
#include <ruby.h>
|
#include <ruby.h>
|
||||||
@ -83,7 +142,7 @@ void Init_foo(){
|
|||||||
parser.do_classes
|
parser.do_classes
|
||||||
parser.do_constants
|
parser.do_constants
|
||||||
|
|
||||||
klass = parser.classes['cFoo']
|
klass = parser.classes['cFoo']
|
||||||
assert klass
|
assert klass
|
||||||
|
|
||||||
constants = klass.constants
|
constants = klass.constants
|
||||||
@ -138,6 +197,60 @@ void Init_foo(){
|
|||||||
assert constants.empty?, constants.inspect
|
assert constants.empty?, constants.inspect
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_find_class_comment_init
|
||||||
|
content = <<-EOF
|
||||||
|
/*
|
||||||
|
* a comment for class Foo
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
Init_Foo(void) {
|
||||||
|
VALUE foo = rb_define_class("Foo", rb_cObject);
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
klass = util_get_class content, 'foo'
|
||||||
|
|
||||||
|
assert_equal " \n a comment for class Foo\n \n", klass.comment
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_find_class_comment_define_class
|
||||||
|
content = <<-EOF
|
||||||
|
/*
|
||||||
|
* a comment for class Foo
|
||||||
|
*/
|
||||||
|
VALUE foo = rb_define_class("Foo", rb_cObject);
|
||||||
|
EOF
|
||||||
|
|
||||||
|
klass = util_get_class content, 'foo'
|
||||||
|
|
||||||
|
assert_equal " \n a comment for class Foo\n ", klass.comment
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_find_class_comment_define_class
|
||||||
|
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("Foo", rb_cObject);
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
klass = util_get_class content, 'foo'
|
||||||
|
|
||||||
|
assert_equal " \n a comment for class Foo on Init\n \n", klass.comment
|
||||||
|
end
|
||||||
|
|
||||||
|
def util_get_class(content, name)
|
||||||
|
parser = util_parser content
|
||||||
|
parser.do_classes
|
||||||
|
parser.classes[name]
|
||||||
|
end
|
||||||
|
|
||||||
def util_parser(content)
|
def util_parser(content)
|
||||||
parser = RDoc::C_Parser.new @top_level, @fn, content, @options, @stats
|
parser = RDoc::C_Parser.new @top_level, @fn, content, @options, @stats
|
||||||
parser.progress = @progress
|
parser.progress = @progress
|
||||||
|
Loading…
x
Reference in New Issue
Block a user