[ruby/rdoc] Fix to parse rb_define_global_const
https://github.com/ruby/ruby/pull/12357 https://github.com/ruby/rdoc/commit/458ecbb7f7
This commit is contained in:
parent
4428c51f01
commit
a46fe5c807
@ -405,6 +405,7 @@ class RDoc::Parser::C < RDoc::Parser
|
||||
\s*(.*?)\s*\)\s*;
|
||||
%xm) do |type, var_name, const_name, definition|
|
||||
var_name = "rb_cObject" if !var_name or var_name == "rb_mKernel"
|
||||
type = "const" if type == "global_const"
|
||||
handle_constants type, var_name, const_name, definition
|
||||
end
|
||||
|
||||
@ -760,6 +761,10 @@ class RDoc::Parser::C < RDoc::Parser
|
||||
rb_define_(?<type>\w+)\(\s*(?:\w+),\s*
|
||||
"(?<name>\w+)"\s*,
|
||||
.*?\)\s*;
|
||||
| (?<doc>(?>^\s*/\*.*?\*/\s+))
|
||||
rb_define_global_(?<type>const)\(\s*
|
||||
"(?<name>\w+)"\s*,
|
||||
.*?\)\s*;
|
||||
| (?<doc>(?>^\s*/\*.*?\*/\s+))
|
||||
rb_file_(?<type>const)\(\s*
|
||||
"(?<name>\w+)"\s*,
|
||||
|
@ -577,6 +577,38 @@ Multiline comment goes here because this comment spans multiple lines.
|
||||
assert constants.empty?, constants.inspect
|
||||
end
|
||||
|
||||
def test_do_constants_global
|
||||
content = <<-'EOF'
|
||||
#include <ruby.h>
|
||||
|
||||
void Init_foo(){
|
||||
|
||||
/* Toplevel const */
|
||||
rb_define_global_const("ANSWER", INT2FIX(42));
|
||||
|
||||
}
|
||||
EOF
|
||||
|
||||
@parser = util_parser content
|
||||
|
||||
@parser.do_classes_and_modules
|
||||
@parser.do_constants
|
||||
|
||||
klass = @parser.classes['rb_cObject']
|
||||
assert klass
|
||||
|
||||
constants = klass.constants
|
||||
assert !klass.constants.empty?
|
||||
|
||||
assert_equal @top_level, constants.first.file
|
||||
|
||||
constants = constants.map { |c| [c.name, c.value, c.comment.text] }
|
||||
assert_equal ['ANSWER', 'INT2FIX(42)', "Toplevel const "],
|
||||
constants.shift
|
||||
|
||||
assert constants.empty?, constants.inspect
|
||||
end
|
||||
|
||||
def test_do_constants_curses
|
||||
content = <<-EOF
|
||||
void Init_curses(){
|
||||
@ -1037,6 +1069,21 @@ rb_define_const(cFoo, "CONST", value);
|
||||
assert_equal "/*\n * A comment\n */\n", comment.text
|
||||
end
|
||||
|
||||
def test_find_const_comment_rb_define_global
|
||||
content = <<-EOF
|
||||
/*
|
||||
* A comment
|
||||
*/
|
||||
rb_define_global_const("CONST", value);
|
||||
EOF
|
||||
|
||||
parser = util_parser content
|
||||
|
||||
comment = parser.find_const_comment 'const', 'CONST'
|
||||
|
||||
assert_equal "/*\n * A comment\n */\n", comment.text
|
||||
end
|
||||
|
||||
def test_find_const_comment_document_const
|
||||
content = <<-EOF
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user