Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added support for rb_file_const() to the C parser

  • Loading branch information...
commit 4b76cba4ec17afa865d272e4d737eb3ab8aa5f8b 1 parent 0eb1dd7
@drbrain drbrain authored
Showing with 47 additions and 0 deletions.
  1. +1 −0  History.rdoc
  2. +14 −0 lib/rdoc/parser/c.rb
  3. +32 −0 test/test_rdoc_parser_c.rb
View
1  History.rdoc
@@ -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
View
14 lib/rdoc/parser/c.rb
@@ -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
##
View
32 test/test_rdoc_parser_c.rb
@@ -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() {
Please sign in to comment.
Something went wrong with that request. Please try again.