diff options
author | Nobuyoshi Nakada <[email protected]> | 2024-12-16 23:49:00 +0900 |
---|---|---|
committer | git <[email protected]> | 2024-12-16 14:55:39 +0000 |
commit | a46fe5c807361f07604eaba447f0487076977e7e (patch) | |
tree | 3a31538efeaf663ea944091a64d86027936f6962 | |
parent | 4428c51f01638c1ce6ba8a9eb8ffea00a4c78318 (diff) |
[ruby/rdoc] Fix to parse `rb_define_global_const`
https://github.com/ruby/ruby/pull/12357
https://github.com/ruby/rdoc/commit/458ecbb7f7
-rw-r--r-- | lib/rdoc/parser/c.rb | 5 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_parser_c.rb | 47 |
2 files changed, 52 insertions, 0 deletions
diff --git a/lib/rdoc/parser/c.rb b/lib/rdoc/parser/c.rb index 8a1bf821ce..7e83a6151f 100644 --- a/lib/rdoc/parser/c.rb +++ b/lib/rdoc/parser/c.rb @@ -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*, diff --git a/test/rdoc/test_rdoc_parser_c.rb b/test/rdoc/test_rdoc_parser_c.rb index ab4f149869..31702a7cd0 100644 --- a/test/rdoc/test_rdoc_parser_c.rb +++ b/test/rdoc/test_rdoc_parser_c.rb @@ -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 /* |