Skip to content

Commit

Permalink
Added support for rb_file_const() to the C parser
Browse files Browse the repository at this point in the history
  • Loading branch information
drbrain committed Nov 18, 2012
1 parent 0eb1dd7 commit 4b76cba
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions History.rdoc
Expand Up @@ -65,6 +65,7 @@
Hollensbe.
* Added methods ::system_dir, ::site_dir, ::home_dir and ::gem_dir to fetch
the components of RDoc::RI::Paths.path individually.
* Added support for rb_file_const.

* Bug fixes
* A word that is directly followed by a multi-word tidy link label no longer
Expand Down
14 changes: 14 additions & 0 deletions lib/rdoc/parser/c.rb
Expand Up @@ -298,8 +298,22 @@ def do_constants
\)
\s*;%xm) do |consts|
const = consts.first

handle_constants 'const', 'mCurses', const, "UINT2NUM(#{const})"
end

@content.scan(%r%
\Wrb_file_const
\s*\(
\s*
"([^"]+)",
\s*
(.*?)
\s*
\)
\s*;%xm) do |name, value|
handle_constants 'const', 'rb_mFConst', name, value
end
end

##
Expand Down
32 changes: 32 additions & 0 deletions test/test_rdoc_parser_c.rb
Expand Up @@ -469,6 +469,38 @@ def test_do_constants_curses
assert_equal 'Value of the color black', constants.first.comment.text
end

def test_do_constants_file
content = <<-EOF
void Init_File(void) {
rb_cFile = rb_define_class("File", rb_cIO);
rb_mFConst = rb_define_module_under(rb_cFile, "Constants");
rb_include_module(rb_cIO, rb_mFConst);
/* Document-const: LOCK_SH
*
* Shared lock
*/
rb_file_const("LOCK_SH", INT2FIX(LOCK_SH));
}
EOF

@parser = util_parser content

@parser.do_classes
@parser.do_constants

klass = @parser.classes['rb_mFConst']

constants = klass.constants
refute_empty klass.constants

constant = constants.first

assert_equal 'LOCK_SH', constant.name
assert_equal 'INT2FIX(LOCK_SH)', constant.value
assert_equal 'Shared lock', constant.comment.text
end

def test_do_includes
content = <<-EOF
Init_foo() {
Expand Down

0 comments on commit 4b76cba

Please sign in to comment.