diff options
Diffstat (limited to 'test/rdoc/test_rdoc_parser_c.rb')
-rw-r--r-- | test/rdoc/test_rdoc_parser_c.rb | 100 |
1 files changed, 94 insertions, 6 deletions
diff --git a/test/rdoc/test_rdoc_parser_c.rb b/test/rdoc/test_rdoc_parser_c.rb index c7312bebba..ab4f149869 100644 --- a/test/rdoc/test_rdoc_parser_c.rb +++ b/test/rdoc/test_rdoc_parser_c.rb @@ -101,6 +101,31 @@ class TestRDocParserC < RDoc::TestCase end end + def test_known_classes + RDoc::KNOWN_CLASSES.each do |var, name| + case name + when "Refinement" + next unless defined?(Refinement) + when "RubyVM" + next unless defined?(RubyVM) + when "Bignum", "Fixnum", "Data", "Socket", /\A(?![A-Z])/ + next + end + obj = Object.const_get(name) + assert_equal obj.name, name + case var + when /\Arb_c/ + assert_kind_of Class, obj + when /\Arb_m/ + assert_kind_of Module, obj + when /\Arb_e/ + assert_operator obj, :<=, Exception + else + raise "unknown prefix: #{var} => #{name}" + end + end + end + def test_initialize some_ext = @top_level.add_class RDoc::NormalClass, 'SomeExt' @top_level.add_class RDoc::SingleClass, 'SomeExtSingle' @@ -311,6 +336,12 @@ VALUE cFoo = rb_struct_define( klass = util_get_class content, 'cFoo' assert_equal "this is the Foo class", klass.comment.text + + attributes = klass.attributes + assert_equal 3, attributes.size, -> {attributes} + ["some", "various", "fields"].zip(attributes) do |name, attr| + assert_equal RDoc::Attr.new("", name, "RW", ""), attr + end end def test_do_classes_struct_under @@ -326,6 +357,12 @@ VALUE cFoo = rb_struct_define_under( klass = util_get_class content, 'cFoo' assert_equal 'Kernel::Foo', klass.full_name assert_equal "this is the Foo class under Kernel", klass.comment.text + + attributes = klass.attributes + assert_equal 3, attributes.size, -> {attributes} + ["some", "various", "fields"].zip(attributes) do |name, attr| + assert_equal RDoc::Attr.new("", name, "RW", ""), attr + end end def test_do_classes_struct_without_accessor @@ -340,6 +377,7 @@ VALUE cFoo = rb_struct_define_without_accessor( klass = util_get_class content, 'cFoo' assert_equal "this is the Foo class", klass.comment.text + assert_empty klass.attributes end def test_do_classes_struct_without_accessor_under @@ -355,6 +393,7 @@ VALUE cFoo = rb_struct_define_without_accessor_under( klass = util_get_class content, 'cFoo' assert_equal 'Kernel::Foo', klass.full_name assert_equal "this is the Foo class under Kernel", klass.comment.text + assert_empty klass.attributes end def test_do_classes_class_under @@ -421,7 +460,7 @@ VALUE mFoo = rb_define_module_under(rb_mKernel, "Foo"); end def test_do_constants - content = <<-EOF + content = <<-'EOF' #include <ruby.h> void Init_foo(){ @@ -436,6 +475,9 @@ void Init_foo(){ /* TEST\:TEST: Checking to see if escaped colon works */ rb_define_const(cFoo, "TEST", rb_str_new2("TEST:TEST")); + /* TEST: TEST:Checking to see if only word-ending colon works */ + rb_define_const(cFoo, "TEST2", rb_str_new2("TEST:TEST")); + /* \\: The file separator on MS Windows */ rb_define_const(cFoo, "MSEPARATOR", rb_str_new2("\\")); @@ -499,6 +541,9 @@ void Init_foo(){ assert_equal ['TEST', 'TEST:TEST', 'Checking to see if escaped colon works '], constants.shift + assert_equal ['TEST2', 'TEST', + 'TEST:Checking to see if only word-ending colon works '], + constants.shift assert_equal ['MSEPARATOR', '\\', 'The file separator on MS Windows '], constants.shift @@ -538,8 +583,6 @@ void Init_curses(){ mCurses = rb_define_module("Curses"); /* - * Document-const: Curses::COLOR_BLACK - * * Value of the color black */ rb_curses_define_const(COLOR_BLACK); @@ -564,8 +607,7 @@ void Init_curses(){ def test_do_constants_file content = <<-EOF void Init_File(void) { - /* Document-const: LOCK_SH - * + /* * Shared lock */ rb_file_const("LOCK_SH", INT2FIX(LOCK_SH)); @@ -857,6 +899,23 @@ Init_Foo(void) { assert_equal "a comment for class Foo", klass.comment.text end + + def test_find_class_comment_initvm + content = <<-EOF +/* + * a comment for class Foo + */ +void +InitVM_Foo(void) { + VALUE foo = rb_define_class("Foo", rb_cObject); +} + EOF + + klass = util_get_class content, 'foo' + + assert_equal "a comment for class Foo", klass.comment.text + end + def test_find_class_comment_define_class content = <<-EOF /* @@ -1317,6 +1376,36 @@ Init_Foo(void) { assert_equal "DLL_LOCAL VALUE\nother_function() {\n}", code end + def test_find_body_static_inline + content = <<-EOF +/* + * a comment for other_function + */ +static inline VALUE +other_function() { +} + +void +Init_Foo(void) { + VALUE foo = rb_define_class("Foo", rb_cObject); + + rb_define_method(foo, "my_method", other_function, 0); +} + EOF + + klass = util_get_class content, 'foo' + other_function = klass.method_list.first + + assert_equal 'my_method', other_function.name + assert_equal "a comment for other_function", + other_function.comment.text + assert_equal '()', other_function.params + + code = other_function.token_stream.first[:text] + + assert_equal "static inline VALUE\nother_function() {\n}", code + end + def test_find_modifiers_call_seq comment = RDoc::Comment.new <<-COMMENT call-seq: @@ -2012,4 +2101,3 @@ void Init_Blah(void) { end end - |