summaryrefslogtreecommitdiff
path: root/test/rdoc/parsers/test_parse_c.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/rdoc/parsers/test_parse_c.rb')
-rw-r--r--test/rdoc/parsers/test_parse_c.rb117
1 files changed, 115 insertions, 2 deletions
diff --git a/test/rdoc/parsers/test_parse_c.rb b/test/rdoc/parsers/test_parse_c.rb
index c7815a95c09..6157a9e1d4c 100644
--- a/test/rdoc/parsers/test_parse_c.rb
+++ b/test/rdoc/parsers/test_parse_c.rb
@@ -1,4 +1,3 @@
-require 'pp'
require 'stringio'
require 'tempfile'
require 'test/unit'
@@ -28,6 +27,66 @@ class TestRdocC_Parser < Test::Unit::TestCase
@tempfile.unlink
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
content = <<-EOF
#include <ruby.h>
@@ -83,7 +142,7 @@ void Init_foo(){
parser.do_classes
parser.do_constants
- klass = parser.classes['cFoo']
+ klass = parser.classes['cFoo']
assert klass
constants = klass.constants
@@ -138,6 +197,60 @@ void Init_foo(){
assert constants.empty?, constants.inspect
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)
parser = RDoc::C_Parser.new @top_level, @fn, content, @options, @stats
parser.progress = @progress