diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | lib/rdoc.rb | 2 | ||||
-rw-r--r-- | lib/rdoc/class_module.rb | 43 | ||||
-rw-r--r-- | lib/rdoc/known_classes.rb | 2 | ||||
-rw-r--r-- | lib/rdoc/parser/c.rb | 2 | ||||
-rw-r--r-- | lib/rdoc/parser/ruby.rb | 44 | ||||
-rw-r--r-- | lib/rdoc/ri/store.rb | 6 | ||||
-rw-r--r-- | lib/rdoc/top_level.rb | 4 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_class_module.rb | 38 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_parser_ruby.rb | 292 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_ri_store.rb | 27 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_top_level.rb | 81 |
13 files changed, 501 insertions, 47 deletions
@@ -1,3 +1,8 @@ +Thu Jun 30 06:16:53 2011 Eric Hodel <[email protected]> + + * lib/rdoc: Update to RDoc 3.8 which contains fixes for documentation + in trunk. + Thu Jun 30 02:53:26 2011 KOSAKI Motohiro <[email protected]> * thread.c (rb_threadptr_execute_interrupts_common): remove @@ -218,7 +218,7 @@ with all sufficient information, see the ChangeLog file. https://github.com/jimweirich/rake/blob/master/CHANGES * RDoc - * RDoc has been upgraded from 2.5.8 to 3.7. For full release notes see + * RDoc has been upgraded from 2.5.8 to 3.8. For full release notes see http://docs.seattlerb.org/rdoc/History_txt.html * rexml diff --git a/lib/rdoc.rb b/lib/rdoc.rb index 3aa15dfa52..187b7d4d51 100644 --- a/lib/rdoc.rb +++ b/lib/rdoc.rb @@ -104,7 +104,7 @@ module RDoc ## # RDoc version you are using - VERSION = '3.7' + VERSION = '3.8' ## # Method visibilities diff --git a/lib/rdoc/class_module.rb b/lib/rdoc/class_module.rb index d7a14b73eb..e104101dcc 100644 --- a/lib/rdoc/class_module.rb +++ b/lib/rdoc/class_module.rb @@ -115,7 +115,7 @@ class RDoc::ClassModule < RDoc::Context # across multiple runs. def add_comment comment, location - return if comment.empty? + return if comment.empty? or not document_self original = comment @@ -328,7 +328,10 @@ class RDoc::ClassModule < RDoc::Context @comment = @comment_location = document end - merge_collections attributes, class_module.attributes do |add, attr| + cm = class_module + other_files = cm.in_files + + merge_collections attributes, cm.attributes, other_files do |add, attr| if add then add_attribute attr else @@ -337,7 +340,7 @@ class RDoc::ClassModule < RDoc::Context end end - merge_collections constants, class_module.constants do |add, const| + merge_collections constants, cm.constants, other_files do |add, const| if add then add_constant const else @@ -346,7 +349,7 @@ class RDoc::ClassModule < RDoc::Context end end - merge_collections includes, class_module.includes do |add, incl| + merge_collections includes, cm.includes, other_files do |add, incl| if add then add_include incl else @@ -354,7 +357,7 @@ class RDoc::ClassModule < RDoc::Context end end - merge_collections method_list, class_module.method_list do |add, meth| + merge_collections method_list, cm.method_list, other_files do |add, meth| if add then add_method meth else @@ -367,15 +370,37 @@ class RDoc::ClassModule < RDoc::Context end ## - # Merges collection +mine+ with +other+ preferring other. - - def merge_collections mine, other, &block # :nodoc: + # Merges collection +mine+ with +other+ preferring other. +other_files+ is + # used to help determine which items should be deleted. + # + # Yields whether the item should be added or removed (true or false) and the + # item to be added or removed. + # + # merge_collections things, other.things, other.in_files do |add, thing| + # if add then + # # add the thing + # else + # # remove the thing + # end + # end + + def merge_collections mine, other, other_files, &block # :nodoc: my_things = mine. group_by { |thing| thing.file } other_things = other.group_by { |thing| thing.file } + my_things.delete_if do |file, things| + next false unless other_files.include? file + + things.each do |thing| + yield false, thing + end + + true + end + other_things.each do |file, things| my_things[file].each { |thing| yield false, thing } if - my_things.include? file + my_things.include?(file) things.each do |thing| yield true, thing diff --git a/lib/rdoc/known_classes.rb b/lib/rdoc/known_classes.rb index 3feb31eae1..863be4bd5c 100644 --- a/lib/rdoc/known_classes.rb +++ b/lib/rdoc/known_classes.rb @@ -26,6 +26,7 @@ module RDoc "rb_cRange" => "Range", "rb_cRegexp" => "Regexp", "rb_cRubyVM" => "RubyVM", + "rb_cSocket" => "Socket", "rb_cString" => "String", "rb_cStruct" => "Struct", "rb_cSymbol" => "Symbol", @@ -58,6 +59,7 @@ module RDoc "rb_eZeroDivError" => "ZeroDivError", "rb_mComparable" => "Comparable", + "rb_mDL" => "DL", "rb_mEnumerable" => "Enumerable", "rb_mErrno" => "Errno", "rb_mFileTest" => "FileTest", diff --git a/lib/rdoc/parser/c.rb b/lib/rdoc/parser/c.rb index 7d05d12fb4..a0282d69f1 100644 --- a/lib/rdoc/parser/c.rb +++ b/lib/rdoc/parser/c.rb @@ -340,8 +340,6 @@ class RDoc::Parser::C < RDoc::Parser # Ignore top-object and weird struct.c dynamic stuff next if var_name == "ruby_top_self" next if var_name == "nstr" - next if var_name == "envtbl" - next if var_name == "argf" # it'd be nice to handle this one var_name = "rb_cObject" if var_name == "rb_mKernel" handle_method(type, var_name, meth_name, function, param_count, diff --git a/lib/rdoc/parser/ruby.rb b/lib/rdoc/parser/ruby.rb index 50071ab736..8b7c9c3eff 100644 --- a/lib/rdoc/parser/ruby.rb +++ b/lib/rdoc/parser/ruby.rb @@ -478,7 +478,7 @@ class RDoc::Parser::Ruby < RDoc::Parser read_documentation_modifiers att, RDoc::ATTR_MODIFIERS - context.add_attribute att if att.document_self + context.add_attribute att @stats.add_attribute att else @@ -499,6 +499,8 @@ class RDoc::Parser::Ruby < RDoc::Parser tmp = RDoc::CodeObject.new read_documentation_modifiers tmp, RDoc::ATTR_MODIFIERS + # TODO In most other places we let the context keep track of document_self + # and add found items appropriately but here we do not. I'm not sure why. return unless tmp.document_self case tk.name @@ -557,7 +559,7 @@ class RDoc::Parser::Ruby < RDoc::Parser al.line = line_no read_documentation_modifiers al, RDoc::ATTR_MODIFIERS - context.add_alias al if al.document_self + context.add_alias al @stats.add_alias al al @@ -633,7 +635,7 @@ class RDoc::Parser::Ruby < RDoc::Parser cls.offset = offset cls.line = line_no - cls.add_comment comment, @top_level if cls.document_self + cls.add_comment comment, @top_level @top_level.add_to_classes_or_modules cls @stats.add_class cls @@ -657,7 +659,7 @@ class RDoc::Parser::Ruby < RDoc::Parser # notify :nodoc: all if not a constant-named class/module # (and remove any comment) - unless name =~ /\A(::)?[A-Z]/ + unless name =~ /\A(::)?[A-Z]/ then other.document_self = nil other.document_children = false other.clear_comment @@ -758,7 +760,7 @@ class RDoc::Parser::Ruby < RDoc::Parser read_documentation_modifiers con, RDoc::CONSTANT_MODIFIERS @stats.add_constant con - container.add_constant con if con.document_self + container.add_constant con true end @@ -797,7 +799,7 @@ class RDoc::Parser::Ruby < RDoc::Parser return unless meth.name - container.add_method meth if meth.document_self + container.add_method meth meth.comment = comment @@ -818,7 +820,6 @@ class RDoc::Parser::Ruby < RDoc::Parser att.line = line_no container.add_attribute att - @stats.add_attribute att end @@ -882,7 +883,6 @@ class RDoc::Parser::Ruby < RDoc::Parser tmp = RDoc::CodeObject.new read_documentation_modifiers tmp, RDoc::ATTR_MODIFIERS - return unless tmp.document_self if comment.sub!(/^# +:?(attr(_reader|_writer|_accessor)?): *(\S*).*?\n/i, '') then rw = case $1 @@ -969,7 +969,7 @@ class RDoc::Parser::Ruby < RDoc::Parser extract_call_seq comment, meth - container.add_method meth if meth.document_self + container.add_method meth last_tk = tk @@ -1238,7 +1238,7 @@ class RDoc::Parser::Ruby < RDoc::Parser mod.record_location @top_level read_documentation_modifiers mod, RDoc::CLASS_MODIFIERS - mod.add_comment comment, @top_level if mod.document_self + mod.add_comment comment, @top_level parse_statements(mod) @top_level.add_to_classes_or_modules mod @@ -1341,23 +1341,15 @@ class RDoc::Parser::Ruby < RDoc::Parser end when TkDEF then - if container.document_self then - parse_method container, single, tk, comment - else - nest += 1 - end + parse_method container, single, tk, comment when TkCONSTANT then - if container.document_self then - if not parse_constant container, tk, comment then - try_parse_comment = true - end + unless parse_constant container, tk, comment then + try_parse_comment = true end when TkALIAS then - if container.document_self and not current_method then - parse_alias container, single, tk, comment - end + parse_alias container, single, tk, comment unless current_method when TkYIELD then if current_method.nil? then @@ -1395,12 +1387,11 @@ class RDoc::Parser::Ruby < RDoc::Parser when /^attr_(reader|writer|accessor)$/ then parse_attr_accessor container, single, tk, comment when 'alias_method' then - parse_alias container, single, tk, comment if - container.document_self + parse_alias container, single, tk, comment when 'require', 'include' then # ignore else - if container.document_self and comment =~ /\A#\#$/ then + if comment =~ /\A#\#$/ then case comment when /^# +:?attr(_reader|_writer|_accessor)?:/ then parse_meta_attr container, single, tk, comment @@ -1523,11 +1514,12 @@ class RDoc::Parser::Ruby < RDoc::Parser end ## - # Parses statements at the toplevel in +container+ + # Parses statements in the top-level +container+ def parse_top_level_statements(container) comment = collect_first_comment look_for_directives_in(container, comment) + # HACK move if to RDoc::Context#comment= container.comment = comment if container.document_self unless comment.empty? parse_statements container, NORMAL, nil, comment end diff --git a/lib/rdoc/ri/store.rb b/lib/rdoc/ri/store.rb index e48386adcb..fe4ccc244d 100644 --- a/lib/rdoc/ri/store.rb +++ b/lib/rdoc/ri/store.rb @@ -268,11 +268,7 @@ class RDoc::RI::Store path = class_file full_name begin - disk_klass = nil - - open path, 'rb' do |io| - disk_klass = Marshal.load io.read - end + disk_klass = load_class full_name klass = disk_klass.merge klass rescue Errno::ENOENT diff --git a/lib/rdoc/top_level.rb b/lib/rdoc/top_level.rb index b9fd5c9f6f..3825a091fe 100644 --- a/lib/rdoc/top_level.rb +++ b/lib/rdoc/top_level.rb @@ -322,6 +322,7 @@ class RDoc::TopLevel < RDoc::Context # Adds +an_alias+ to +Object+ instead of +self+. def add_alias(an_alias) + object_class.record_location self return an_alias unless @document_self object_class.add_alias an_alias end @@ -330,6 +331,7 @@ class RDoc::TopLevel < RDoc::Context # Adds +constant+ to +Object+ instead of +self+. def add_constant(constant) + object_class.record_location self return constant unless @document_self object_class.add_constant constant end @@ -338,6 +340,7 @@ class RDoc::TopLevel < RDoc::Context # Adds +include+ to +Object+ instead of +self+. def add_include(include) + object_class.record_location self return include unless @document_self object_class.add_include include end @@ -346,6 +349,7 @@ class RDoc::TopLevel < RDoc::Context # Adds +method+ to +Object+ instead of +self+. def add_method(method) + object_class.record_location self return method unless @document_self object_class.add_method method end diff --git a/test/rdoc/test_rdoc_class_module.rb b/test/rdoc/test_rdoc_class_module.rb index 1ac0eda298..7d32a91580 100644 --- a/test/rdoc/test_rdoc_class_module.rb +++ b/test/rdoc/test_rdoc_class_module.rb @@ -40,6 +40,17 @@ class TestRDocClassModule < XrefTestCase assert_equal "comment 1\n---\ncomment 2\n---\n* comment 3", cm.comment end + def test_add_comment_stopdoc + tl = RDoc::TopLevel.new 'file.rb' + + cm = RDoc::ClassModule.new 'Klass' + cm.stop_doc + + cm.add_comment '# comment 1', tl + + assert_empty cm.comment + end + def test_ancestors assert_equal [@parent], @child.ancestors end @@ -258,6 +269,33 @@ class TestRDocClassModule < XrefTestCase assert_equal expected, cm1.attributes.sort end + def test_merge_collections_drop + tl = RDoc::TopLevel.new 'file' + + cm1 = RDoc::ClassModule.new 'C' + cm1.record_location tl + + const = cm1.add_constant RDoc::Constant.new('CONST', nil, nil) + const.record_location tl + + cm2 = RDoc::ClassModule.new 'C' + cm2.record_location tl + + added = [] + removed = [] + + cm1.merge_collections cm1.constants, cm2.constants, cm2.in_files do |add, c| + if add then + added << c + else + removed << c + end + end + + assert_empty added + assert_equal [const], removed + end + def test_merge_comment tl1 = RDoc::TopLevel.new 'one.rb' tl2 = RDoc::TopLevel.new 'two.rb' diff --git a/test/rdoc/test_rdoc_parser_ruby.rb b/test/rdoc/test_rdoc_parser_ruby.rb index e02ed56beb..4904d5dfca 100644 --- a/test/rdoc/test_rdoc_parser_ruby.rb +++ b/test/rdoc/test_rdoc_parser_ruby.rb @@ -437,6 +437,21 @@ class C; end assert alas.singleton end + def test_parse_alias_stopdoc + klass = RDoc::NormalClass.new 'Foo' + klass.parent = @top_level + klass.stop_doc + + util_parser "alias :next= :bar" + + tk = @parser.get_tk + + @parser.parse_alias klass, RDoc::Parser::Ruby::NORMAL, tk, 'comment' + + assert_empty klass.aliases + assert_empty klass.unmatched_alias_lists + end + def test_parse_alias_meta klass = RDoc::NormalClass.new 'Foo' klass.parent = @top_level @@ -472,6 +487,22 @@ class C; end assert_equal 1, foo.line end + def test_parse_attr_stopdoc + klass = RDoc::NormalClass.new 'Foo' + klass.parent = @top_level + klass.stop_doc + + comment = "##\n# my attr\n" + + util_parser "attr :foo, :bar" + + tk = @parser.get_tk + + @parser.parse_attr klass, RDoc::Parser::Ruby::NORMAL, tk, comment + + assert_empty klass.attributes + end + def test_parse_attr_accessor klass = RDoc::NormalClass.new 'Foo' klass.parent = @top_level @@ -515,6 +546,22 @@ class C; end assert_equal 0, klass.attributes.length end + def test_parse_attr_accessor_stopdoc + klass = RDoc::NormalClass.new 'Foo' + klass.parent = @top_level + klass.stop_doc + + comment = "##\n# my attr\n" + + util_parser "attr_accessor :foo, :bar" + + tk = @parser.get_tk + + @parser.parse_attr_accessor klass, RDoc::Parser::Ruby::NORMAL, tk, comment + + assert_empty klass.attributes + end + def test_parse_attr_accessor_writer klass = RDoc::NormalClass.new 'Foo' klass.parent = @top_level @@ -620,6 +667,22 @@ class C; end assert_equal @top_level, foo.file end + def test_parse_meta_attr_stopdoc + klass = RDoc::NormalClass.new 'Foo' + klass.parent = @top_level + klass.stop_doc + + comment = "##\n# :attr: \n# my method\n" + + util_parser "add_my_method :foo, :bar" + + tk = @parser.get_tk + + @parser.parse_meta_attr klass, RDoc::Parser::Ruby::NORMAL, tk, comment + + assert_empty klass.attributes + end + def test_parse_meta_attr_writer klass = RDoc::NormalClass.new 'Foo' klass.parent = @top_level @@ -640,7 +703,7 @@ class C; end end def test_parse_class - comment = "##\n# my method\n" + comment = "##\n# my class\n" util_parser "class Foo\nend" @@ -650,7 +713,7 @@ class C; end foo = @top_level.classes.first assert_equal 'Foo', foo.full_name - assert_equal 'my method', foo.comment + assert_equal 'my class', foo.comment assert_equal [@top_level], foo.in_files assert_equal 0, foo.offset assert_equal 1, foo.line @@ -706,6 +769,42 @@ end assert_equal 2, foo.method_list.length end + def test_parse_class_nodoc + comment = "##\n# my class\n" + + util_parser "class Foo # :nodoc:\nend" + + tk = @parser.get_tk + + @parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, comment + + foo = @top_level.classes.first + assert_equal 'Foo', foo.full_name + assert_empty foo.comment + assert_equal [@top_level], foo.in_files + assert_equal 0, foo.offset + assert_equal 1, foo.line + end + + def test_parse_class_stopdoc + @top_level.stop_doc + + comment = "##\n# my class\n" + + util_parser "class Foo\nend" + + tk = @parser.get_tk + + @parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, comment + + foo = @top_level.classes.first + assert_equal 'Foo', foo.full_name + assert_equal 'my class', foo.comment + assert_equal [@top_level], foo.in_files + assert_equal 0, foo.offset + assert_equal 1, foo.line + end + def test_parse_multi_ghost_methods util_parser <<-'CLASS' class Foo @@ -785,6 +884,38 @@ end assert_equal 'my module', foo.comment end + def test_parse_module_nodoc + @top_level.stop_doc + + comment = "##\n# my module\n" + + util_parser "module Foo # :nodoc:\nend" + + tk = @parser.get_tk + + @parser.parse_module @top_level, RDoc::Parser::Ruby::NORMAL, tk, comment + + foo = @top_level.modules.first + assert_equal 'Foo', foo.full_name + assert_empty foo.comment + end + + def test_parse_module_stopdoc + @top_level.stop_doc + + comment = "##\n# my module\n" + + util_parser "module Foo\nend" + + tk = @parser.get_tk + + @parser.parse_module @top_level, RDoc::Parser::Ruby::NORMAL, tk, comment + + foo = @top_level.modules.first + assert_equal 'Foo', foo.full_name + assert_equal 'my module', foo.comment + end + def test_parse_class_colon3 code = <<-CODE class A @@ -976,6 +1107,22 @@ EOF assert_equal klass.current_section, foo.section end + def test_parse_comment_attr_stopdoc + klass = RDoc::NormalClass.new 'Foo' + klass.parent = @top_level + klass.stop_doc + + comment = "##\n# :attr: foo\n# my attr\n" + + util_parser "\n" + + tk = @parser.get_tk + + @parser.parse_comment klass, tk, comment + + assert_empty klass.attributes + end + def test_parse_comment_method klass = RDoc::NormalClass.new 'Foo' klass.parent = @top_level @@ -1021,6 +1168,22 @@ EOF assert_equal stream, foo.token_stream end + def test_parse_comment_method_stopdoc + klass = RDoc::NormalClass.new 'Foo' + klass.parent = @top_level + klass.stop_doc + + comment = "##\n# :method: foo\n# my method\n" + + util_parser "\n" + + tk = @parser.get_tk + + @parser.parse_comment klass, tk, comment + + assert_empty klass.method_list + end + def test_parse_constant util_top_level @@ -1084,6 +1247,21 @@ EOF assert_equal top_bar, bar.find_module_named('A') end + def test_parse_constant_stopdoc + util_top_level + + klass = @top_level.add_class RDoc::NormalClass, 'Foo' + klass.stop_doc + + util_parser "A = v" + + tk = @parser.get_tk + + @parser.parse_constant klass, tk, '' + + assert_empty klass.constants + end + def test_parse_include klass = RDoc::NormalClass.new 'C' klass.parent = @top_level @@ -1249,6 +1427,22 @@ end assert_equal @top_level, foo.file end + def test_parse_meta_method_stopdoc + klass = RDoc::NormalClass.new 'Foo' + klass.parent = @top_level + klass.stop_doc + + comment = "##\n# my method\n" + + util_parser "add_my_method :foo, :bar\nadd_my_method :baz" + + tk = @parser.get_tk + + @parser.parse_meta_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment + + assert_empty klass.method_list + end + def test_parse_meta_method_unknown klass = RDoc::NormalClass.new 'Foo' comment = "##\n# my method\n" @@ -1464,6 +1658,22 @@ end assert_equal '(arg1, arg2, arg3)', foo.params end + def test_parse_method_stopdoc + klass = RDoc::NormalClass.new 'Foo' + klass.parent = @top_level + klass.stop_doc + + comment = "##\n# my method\n" + + util_parser "def foo() :bar end" + + tk = @parser.get_tk + + @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment + + assert_empty klass.method_list + end + def test_parse_method_toplevel klass = @top_level @@ -1879,6 +2089,69 @@ end assert_equal 1, @top_level.requires.length end + def test_parse_statements_stopdoc_TkALIAS + util_top_level + + klass = @top_level.add_class RDoc::NormalClass, 'Foo' + + util_parser "\n# :stopdoc:\nalias old new" + + @parser.parse_statements klass, RDoc::Parser::Ruby::NORMAL, nil + + assert_empty klass.aliases + assert_empty klass.unmatched_alias_lists + end + + def test_parse_statements_stopdoc_TkIDENTIFIER_alias_method + util_top_level + + klass = @top_level.add_class RDoc::NormalClass, 'Foo' + + util_parser "\n# :stopdoc:\nalias_method :old :new" + + @parser.parse_statements klass, RDoc::Parser::Ruby::NORMAL, nil + + assert_empty klass.aliases + assert_empty klass.unmatched_alias_lists + end + + def test_parse_statements_stopdoc_TkIDENTIFIER_metaprogrammed + util_top_level + + klass = @top_level.add_class RDoc::NormalClass, 'Foo' + + util_parser "\n# :stopdoc:\n# attr :meta" + + @parser.parse_statements klass, RDoc::Parser::Ruby::NORMAL, nil + + assert_empty klass.method_list + assert_empty klass.attributes + end + + def test_parse_statements_stopdoc_TkCONSTANT + util_top_level + + klass = @top_level.add_class RDoc::NormalClass, 'Foo' + + util_parser "\n# :stopdoc:\nA = v" + + @parser.parse_statements klass, RDoc::Parser::Ruby::NORMAL, nil + + assert_empty klass.constants + end + + def test_parse_statements_stopdoc_TkDEF + util_top_level + + klass = @top_level.add_class RDoc::NormalClass, 'Foo' + + util_parser "\n# :stopdoc:\ndef m\n end" + + @parser.parse_statements klass, RDoc::Parser::Ruby::NORMAL, nil + + assert_empty klass.method_list + end + def test_parse_statements_while_begin util_parser <<-RUBY class A @@ -1924,7 +2197,7 @@ end assert_equal nil, @parser.parse_symbol_in_arg end - def test_parse_top_level_statements_alias_method + def test_parse_statements_alias_method content = <<-CONTENT class A alias_method :a, :[] unless c @@ -1939,6 +2212,19 @@ end util_parser content @parser.parse_statements @top_level + + # HACK where are the assertions? + end + + def test_parse_top_level_statements_stopdoc + @top_level.stop_doc + content = "# this is the top-level comment" + + util_parser content + + @parser.parse_top_level_statements @top_level + + assert_empty @top_level.comment end def test_parse_yield_in_braces_with_parens diff --git a/test/rdoc/test_rdoc_ri_store.rb b/test/rdoc/test_rdoc_ri_store.rb index 1077383d86..23e441b633 100644 --- a/test/rdoc/test_rdoc_ri_store.rb +++ b/test/rdoc/test_rdoc_ri_store.rb @@ -1,5 +1,6 @@ require 'rubygems' require 'minitest/autorun' +require 'rdoc/rdoc' require 'rdoc/ri' require 'rdoc/markup' require 'tmpdir' @@ -392,6 +393,32 @@ class TestRDocRIStore < MiniTest::Unit::TestCase assert_equal document, s.load_class('Object').comment end + # This is a functional test + def test_save_class_merge_constant + tl = RDoc::TopLevel.new 'file.rb' + klass = RDoc::NormalClass.new 'C' + klass.add_comment 'comment', tl + + const = klass.add_constant RDoc::Constant.new('CONST', nil, nil) + const.record_location tl + + @s.save_class klass + + RDoc::RDoc.reset + + klass2 = RDoc::NormalClass.new 'C' + klass2.record_location tl + + s = RDoc::RI::Store.new @tmpdir + s.save_class klass2 + + s = RDoc::RI::Store.new @tmpdir + + result = s.load_class 'C' + + assert_empty result.constants + end + def test_save_class_methods @s.save_class @klass diff --git a/test/rdoc/test_rdoc_top_level.rb b/test/rdoc/test_rdoc_top_level.rb index 6c1bc43e7a..9e68bc4bdd 100644 --- a/test/rdoc/test_rdoc_top_level.rb +++ b/test/rdoc/test_rdoc_top_level.rb @@ -98,6 +98,87 @@ class TestRDocTopLevel < XrefTestCase assert_empty RDoc::TopLevel.files end + def test_add_alias + a = RDoc::Alias.new nil, 'old', 'new', nil + @top_level.add_alias a + + object = RDoc::TopLevel.find_class_named 'Object' + expected = { '#old' => [a] } + assert_equal expected, object.unmatched_alias_lists + assert_includes object.in_files, @top_level + end + + def test_add_alias_nodoc + @top_level.document_self = false + + a = RDoc::Alias.new nil, 'old', 'new', nil + @top_level.add_alias a + + object = RDoc::TopLevel.find_class_named('Object') + assert_empty object.unmatched_alias_lists + assert_includes object.in_files, @top_level + end + + def test_add_constant + const = RDoc::Constant.new 'C', nil, nil + @top_level.add_constant const + + object = RDoc::TopLevel.find_class_named 'Object' + assert_equal [const], object.constants + assert_includes object.in_files, @top_level + end + + def test_add_constant_nodoc + @top_level.document_self = false + + const = RDoc::Constant.new 'C', nil, nil + @top_level.add_constant const + + object = RDoc::TopLevel.find_class_named 'Object' + assert_empty object.constants + assert_includes object.in_files, @top_level + end + + def test_add_include + include = RDoc::Include.new 'C', nil + @top_level.add_include include + + object = RDoc::TopLevel.find_class_named 'Object' + assert_equal [include], object.includes + assert_includes object.in_files, @top_level + end + + def test_add_include_nodoc + @top_level.document_self = false + + include = RDoc::Include.new 'C', nil + @top_level.add_include include + + object = RDoc::TopLevel.find_class_named('Object') + assert_empty object.includes + assert_includes object.in_files, @top_level + end + + def test_add_method + method = RDoc::AnyMethod.new nil, 'm' + @top_level.add_method method + + object = RDoc::TopLevel.find_class_named 'Object' + assert_equal [method], object.method_list + assert_includes object.in_files, @top_level + end + + def test_add_method_stopdoc + @top_level.document_self = false + + method = RDoc::AnyMethod.new nil, 'm' + @top_level.add_method method + + object = RDoc::TopLevel.find_class_named('Object') + assert_empty object.method_list + assert_includes object.in_files, @top_level + end + def test_base_name assert_equal 'top_level.rb', @top_level.base_name end |