diff options
Diffstat (limited to 'test/rdoc/test_rdoc_parser_c.rb')
-rw-r--r-- | test/rdoc/test_rdoc_parser_c.rb | 189 |
1 files changed, 113 insertions, 76 deletions
diff --git a/test/rdoc/test_rdoc_parser_c.rb b/test/rdoc/test_rdoc_parser_c.rb index d3138d23aa..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' @@ -132,51 +157,7 @@ class TestRDocParserC < RDoc::TestCase assert_equal expected, known_classes end - def test_do_attr_rb_attr - content = <<-EOF -void Init_Blah(void) { - cBlah = rb_define_class("Blah", rb_cObject); - - /* - * This is an accessor - */ - rb_attr(cBlah, rb_intern("accessor"), 1, 1, Qfalse); - - /* - * This is a reader - */ - rb_attr(cBlah, rb_intern("reader"), 1, 0, Qfalse); - - /* - * This is a writer - */ - rb_attr(cBlah, rb_intern("writer"), 0, 1, Qfalse); -} - EOF - - klass = util_get_class content, 'cBlah' - - attrs = klass.attributes - assert_equal 3, attrs.length, attrs.inspect - - accessor = attrs.shift - assert_equal 'accessor', accessor.name - assert_equal 'RW', accessor.rw - assert_equal 'This is an accessor', accessor.comment.text - assert_equal @top_level, accessor.file - - reader = attrs.shift - assert_equal 'reader', reader.name - assert_equal 'R', reader.rw - assert_equal 'This is a reader', reader.comment.text - - writer = attrs.shift - assert_equal 'writer', writer.name - assert_equal 'W', writer.rw - assert_equal 'This is a writer', writer.comment.text - end - - def test_do_attr_rb_attr_2 + def assert_do_attr(flags) content = <<-EOF void Init_Blah(void) { cBlah = rb_define_class("Blah", rb_cObject); @@ -184,17 +165,17 @@ void Init_Blah(void) { /* * This is an accessor */ - rb_attr(cBlah, rb_intern_const("accessor"), 1, 1, Qfalse); + #{yield "cBlah", "accessor", flags[1], flags[1]}; /* * This is a reader */ - rb_attr(cBlah, rb_intern_const("reader"), 1, 0, Qfalse); + #{yield "cBlah", "reader", flags[1], flags[0]}; /* * This is a writer */ - rb_attr(cBlah, rb_intern_const("writer"), 0, 1, Qfalse); + #{yield "cBlah", "writer", flags[0], flags[1]}; } EOF @@ -220,28 +201,21 @@ void Init_Blah(void) { assert_equal 'This is a writer', writer.comment.text end - def test_do_attr_rb_define_attr - content = <<-EOF -void Init_Blah(void) { - cBlah = rb_define_class("Blah", rb_cObject); - - /* - * This is an accessor - */ - rb_define_attr(cBlah, "accessor", 1, 1); -} - EOF - - klass = util_get_class content, 'cBlah' - - attrs = klass.attributes - assert_equal 1, attrs.length, attrs.inspect - - accessor = attrs.shift - assert_equal 'accessor', accessor.name - assert_equal 'RW', accessor.rw - assert_equal 'This is an accessor', accessor.comment.text - assert_equal @top_level, accessor.file + { + num: %w[0 1], + macro: %w[FALSE TRUE], + ruby: %w[Qfalse Qtrue], + bool: %w[false true], + }.each_pair do |name, values| + define_method("test_do_attr:rb_attr:intern:#{name}") do + assert_do_attr(values) {|c, name, r, w| %[rb_attr(#{c}, rb_intern("#{name}"), #{r}, #{w}, Qfalse)]} + end + define_method("test_do_attr:rb_attr:intern_const:#{name}") do + assert_do_attr(values) {|c, name, r, w| %[rb_attr(#{c}, rb_intern_const("#{name}"), #{r}, #{w}, Qfalse)]} + end + define_method("test_do_attr:rb_define_attr:#{name}") do + assert_do_attr(values) {|c, name, r, w| %[rb_define_attr(#{c}, "#{name}", #{r}, #{w})]} + end end def test_do_aliases @@ -362,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 @@ -377,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 @@ -391,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 @@ -406,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 @@ -472,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(){ @@ -487,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("\\")); @@ -550,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 @@ -589,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); @@ -615,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)); @@ -908,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 /* @@ -1368,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: @@ -2063,4 +2101,3 @@ void Init_Blah(void) { end end - |