ruby-changes:19518
From: drbrain <ko1@a...>
Date: Sat, 14 May 2011 09:39:30 +0900 (JST)
Subject: [ruby-changes:19518] drbrain:r31558 (trunk): * lib/rdoc.rb: Updated to RDoc 3.6
drbrain 2011-05-14 09:39:16 +0900 (Sat, 14 May 2011) New Revision: 31558 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31558 Log: * lib/rdoc.rb: Updated to RDoc 3.6 Modified files: trunk/ChangeLog trunk/NEWS trunk/lib/rdoc/attr.rb trunk/lib/rdoc/class_module.rb trunk/lib/rdoc/code_object.rb trunk/lib/rdoc/context.rb trunk/lib/rdoc/method_attr.rb trunk/lib/rdoc/options.rb trunk/lib/rdoc/parser/c.rb trunk/lib/rdoc/parser/ruby.rb trunk/lib/rdoc/rdoc.rb trunk/lib/rdoc/ri/driver.rb trunk/lib/rdoc/ri/store.rb trunk/lib/rdoc/ruby_lex.rb trunk/lib/rdoc/stats.rb trunk/lib/rdoc/task.rb trunk/lib/rdoc/text.rb trunk/lib/rdoc.rb trunk/test/rdoc/test_rdoc_class_module.rb trunk/test/rdoc/test_rdoc_code_object.rb trunk/test/rdoc/test_rdoc_context.rb trunk/test/rdoc/test_rdoc_markup_parser.rb trunk/test/rdoc/test_rdoc_parser_c.rb trunk/test/rdoc/test_rdoc_parser_ruby.rb trunk/test/rdoc/test_rdoc_ri_driver.rb trunk/test/rdoc/test_rdoc_top_level.rb trunk/test/rdoc/xref_data.rb trunk/test/rdoc/xref_test_case.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 31557) +++ ChangeLog (revision 31558) @@ -1,3 +1,7 @@ +Sat May 14 09:31:43 2011 Eric Hodel <drbrain@s...> + + * lib/rdoc.rb: Updated to RDoc 3.6 + Sat May 14 07:30:29 2011 Aaron Patterson <aaron@t...> * ext/psych/lib/psych.rb: released a new gem, so increasing version. Index: lib/rdoc.rb =================================================================== --- lib/rdoc.rb (revision 31557) +++ lib/rdoc.rb (revision 31558) @@ -3,31 +3,39 @@ # :main: README.txt ## -# = \RDoc - Ruby Documentation System +# RDoc is a Ruby documentation system which contains RDoc::RDoc for generating +# documentation, RDoc::RI for interactive documentation and RDoc::Markup for +# text markup. # -# This package contains RDoc and RDoc::Markup. RDoc is an application that -# produces documentation for one or more Ruby source files. It works similarly -# to JavaDoc, parsing the source, and extracting the definition for classes, -# modules, and methods (along with includes and requires). It associates with -# these optional documentation contained in the immediately preceding comment -# block, and then renders the result using a pluggable output formatter. -# RDoc::Markup is a library that converts plain text into various output -# formats. The markup library is used to interpret the comment blocks that -# RDoc uses to document methods, classes, and so on. +# RDoc::RDoc produces documentation for Ruby source files. It works similarly +# to JavaDoc, parsing the source and extracting the definition for classes, +# modules, methods, includes and requires. It associates these with optional +# documentation contained in an immediately preceding comment block then +# renders the result using an output formatter. # +# RDoc::Markup that converts plain text into various output formats. The +# markup library is used to interpret the comment blocks that RDoc uses to +# document methods, classes, and so on. +# +# RDoc::RI implements the +ri+ command-line tool which displays on-line +# documentation for ruby classes, methods, etc. +ri+ features several output +# formats and an interactive mode (<tt>ri -i</tt>). See <tt>ri --help</tt> +# for further details. +# # == Roadmap # # * If you want to use RDoc to create documentation for your Ruby source files, -# read the summary below, and refer to <tt>rdoc --help</tt> for command line -# usage, and RDoc::Markup for a detailed description of RDoc's markup. +# see RDoc::Markup and refer to <tt>rdoc --help</tt> for command line +# usage. # * If you want to generate documentation for extensions written in C, see # RDoc::Parser::C +# * If you want to generate documentation using <tt>rake</tt> see RDoc::Task. # * If you want to drive RDoc programmatically, see RDoc::RDoc. # * If you want to use the library to format text blocks into HTML, look at # RDoc::Markup. # * If you want to make an RDoc plugin such as a generator or directive # handler see RDoc::RDoc. -# * If you want to try writing your own output generator see RDoc::Generator. +# * If you want to write your own output generator see RDoc::Generator. # # == Summary # @@ -95,7 +103,7 @@ ## # RDoc version you are using - VERSION = '3.5.3' + VERSION = '3.6' ## # Method visibilities Index: lib/rdoc/context.rb =================================================================== --- lib/rdoc/context.rb (revision 31557) +++ lib/rdoc/context.rb (revision 31558) @@ -480,7 +480,7 @@ # Adds included module +include+ which should be an RDoc::Include def add_include(include) - add_to @includes, include + add_to @includes, include unless @includes.map { |i| i.full_name }.include?( include.full_name ) end ## @@ -950,10 +950,14 @@ ## # Yields AnyMethod and Attr entries matching the list of names in +methods+. - def methods_matching(methods, singleton = false) + def methods_matching(methods, singleton = false, &block) (@method_list + @attributes).each do |m| yield m if methods.include?(m.name) and m.singleton == singleton end + + each_ancestor do |parent| + parent.methods_matching(methods, singleton, &block) + end end ## @@ -1021,11 +1025,19 @@ remove_invisible_in @attributes, min_visibility end + ## + # Only called when min_visibility == :public or :private + def remove_invisible_in(array, min_visibility) # :nodoc: if min_visibility == :public - array.reject! { |e| e.visibility != :public } + array.reject! { |e| + e.visibility != :public and not e.force_documentation + } else - array.reject! { |e| e.visibility == :private } + array.reject! { |e| + e.visibility == :private and + not e.force_documentation + } end end Index: lib/rdoc/rdoc.rb =================================================================== --- lib/rdoc/rdoc.rb (revision 31557) +++ lib/rdoc/rdoc.rb (revision 31558) @@ -418,7 +418,7 @@ @last_modified = setup_output_dir @options.op_dir, @options.force_update end - start_time = Time.now + @start_time = Time.now file_info = parse_files @options.files @@ -439,20 +439,7 @@ @generator = gen_klass.new @options - Dir.chdir @options.op_dir do - begin - self.class.current = self - - unless @options.quiet then - $stderr.puts "\nGenerating #{gen_klass.name.sub(/^.*::/, '')} format into #{Dir.pwd}..." - end - - @generator.generate file_info - update_output_dir ".", start_time, @last_modified - ensure - self.class.current = nil - end - end + generate file_info end if @stats and (@options.coverage_report or not @options.quiet) then @@ -464,6 +451,28 @@ end ## + # Generates documentation for +file_info+ (from #parse_files) into the + # output dir using the generator selected + # by the RDoc options + + def generate file_info + Dir.chdir @options.op_dir do + begin + self.class.current = self + + unless @options.quiet then + $stderr.puts "\nGenerating #{@generator.class.name.sub(/^.*::/, '')} format into #{Dir.pwd}..." + end + + @generator.generate file_info + update_output_dir '.', @start_time, @last_modified + ensure + self.class.current = nil + end + end + end + + ## # Removes a siginfo handler and replaces the previous def remove_siginfo_handler Index: lib/rdoc/stats.rb =================================================================== --- lib/rdoc/stats.rb (revision 31557) +++ lib/rdoc/stats.rb (revision 31558) @@ -31,7 +31,7 @@ @coverage_level = 0 @doc_items = nil - @fully_documented = nil + @fully_documented = false @num_params = 0 @percent_doc = nil @start = Time.now Index: lib/rdoc/code_object.rb =================================================================== --- lib/rdoc/code_object.rb (revision 31557) +++ lib/rdoc/code_object.rb (revision 31558) @@ -181,6 +181,20 @@ end ## + # Yields each parent of this CodeObject. See also + # RDoc::ClassModule#each_ancestor + + def each_parent + code_object = self + + while code_object = code_object.parent do + yield code_object + end + + self + end + + ## # Force the documentation of this object unless documentation # has been turned off by :endoc: #-- Index: lib/rdoc/ri/driver.rb =================================================================== --- lib/rdoc/ri/driver.rb (revision 31557) +++ lib/rdoc/ri/driver.rb (revision 31558) @@ -197,6 +197,13 @@ opt.separator nil + opt.on("--list", "-l", + "List classes ri knows about.") do + options[:list] = true + end + + opt.separator nil + opt.on("--[no-]profile", "Run with the ruby profiler") do |value| options[:profile] = value @@ -331,6 +338,7 @@ require 'profile' if options[:profile] @names = options[:names] + @list = options[:list] @doc_dirs = [] @stores = [] @@ -524,7 +532,10 @@ klass_name = method ? name : klass if name !~ /#|\./ then - completions.push(*klasses.grep(/^#{klass_name}/)) + completions = klasses.grep(/^#{klass_name}[^:]*$/) + completions.concat klasses.grep(/^#{name}[^:]*$/) if name =~ /::$/ + + completions << klass if classes.key? klass # to complete a method name elsif selector then completions << klass if classes.key? klass elsif classes.key? klass_name then @@ -546,7 +557,7 @@ completions.push(*methods) end - completions.sort + completions.sort.uniq end ## @@ -878,9 +889,10 @@ end ## - # Lists classes known to ri + # Lists classes known to ri starting with +names+. If +names+ is empty all + # known classes are shown. - def list_known_classes + def list_known_classes names = [] classes = [] stores.each do |store| @@ -889,9 +901,19 @@ classes = classes.flatten.uniq.sort + unless names.empty? then + filter = Regexp.union names.map { |name| /^#{name}/ } + + classes = classes.grep filter + end + page do |io| if paging? or io.tty? then - io.puts "Classes and Modules known to ri:" + if names.empty? then + io.puts "Classes and Modules known to ri:" + else + io.puts "Classes and Modules starting with #{names.join ', '}:" + end io.puts end @@ -910,7 +932,7 @@ methods = store.instance_methods[ancestor] if methods then - matches = methods.grep(/^#{method}/) + matches = methods.grep(/^#{Regexp.escape method.to_s}/) matches = matches.map do |match| "#{klass}##{match}" @@ -924,7 +946,7 @@ methods = store.class_methods[ancestor] next unless methods - matches = methods.grep(/^#{method}/) + matches = methods.grep(/^#{Regexp.escape method.to_s}/) matches = matches.map do |match| "#{klass}::#{match}" @@ -996,9 +1018,9 @@ case type when '#', '::' then - /^#{klass}#{type}#{name}$/ + /^#{klass}#{type}#{Regexp.escape name}$/ else - /^#{klass}(#|::)#{name}$/ + /^#{klass}(#|::)#{Regexp.escape name}$/ end end @@ -1064,10 +1086,10 @@ def run if @list_doc_dirs then puts @doc_dirs - elsif @interactive then + elsif @list then + list_known_classes @names + elsif @interactive or @names.empty? then interactive - elsif @names.empty? then - list_known_classes else display_names @names end Index: lib/rdoc/ri/store.rb =================================================================== --- lib/rdoc/ri/store.rb (revision 31557) +++ lib/rdoc/ri/store.rb (revision 31558) @@ -7,6 +7,18 @@ # The store manages reading and writing ri data for a project (gem, path, # etc.) and maintains a cache of methods, classes and ancestors in the # store. +# +# The store maintains a #cache of its contents for faster lookup. After +# adding items to the store it must be flushed using #save_cache. The cache +# contains the following structures: +# +# @cache = { +# :class_methods => {}, # class name => class methods +# :instance_methods => {}, # class name => instance methods +# :attributes => {}, # class name => attributes +# :modules => [], # classes and modules in this store +# :ancestors => {}, # class name => ancestor names +# } class RDoc::RI::Store Index: lib/rdoc/class_module.rb =================================================================== --- lib/rdoc/class_module.rb (revision 31557) +++ lib/rdoc/class_module.rb (revision 31558) @@ -138,11 +138,21 @@ end ## + # Iterates the ancestors of this class or module for which an + # RDoc::ClassModule exists. + + def each_ancestor # :yields: module + ancestors.each do |mod| + next if String === mod + yield mod + end + end + + ## # Looks for a symbol in the #ancestors. See Context#find_local_symbol. def find_ancestor_local_symbol symbol - ancestors.each do |m| - next if m.is_a?(String) + each_ancestor do |m| res = m.find_local_symbol(symbol) return res if res end @@ -263,7 +273,7 @@ class_module.each_attribute do |attr| if match = attributes.find { |a| a.name == attr.name } then - match.rw = [match.rw, attr.rw].compact.join + match.rw = [match.rw, attr.rw].compact.uniq.join else add_attribute attr end Index: lib/rdoc/text.rb =================================================================== --- lib/rdoc/text.rb (revision 31557) +++ lib/rdoc/text.rb (revision 31558) @@ -61,25 +61,17 @@ # Flush +text+ left based on the shortest line def flush_left text - indents = [] + indent = 9999 text.each_line do |line| - indents << (line =~ /[^\s]/ || 9999) + line_indent = line =~ /\S/ || 9999 + indent = line_indent if indent > line_indent end - indent = indents.min - - flush = [] - empty = '' empty.force_encoding text.encoding if Object.const_defined? :Encoding - text.each_line do |line| - line[/^ {0,#{indent}}/] = empty - flush << line - end - - flush.join + text.gsub(/^ {0,#{indent}}/, empty) end ## Index: lib/rdoc/ruby_lex.rb =================================================================== --- lib/rdoc/ruby_lex.rb (revision 31557) +++ lib/rdoc/ruby_lex.rb (revision 31558) @@ -403,9 +403,11 @@ res = '' nil until (ch = getc) == "\n" - until peek_equal?("=end") && peek(4) =~ /\s/ do - until (ch = getc) == "\n" do res << ch end + until ( peek_equal?("=end") && peek(4) =~ /\s/ ) do + (ch = getc) + res << ch end + gets # consume =end @ltype = nil Index: lib/rdoc/parser/ruby.rb =================================================================== --- lib/rdoc/parser/ruby.rb (revision 31557) +++ lib/rdoc/parser/ruby.rb (revision 31558) @@ -1558,32 +1558,45 @@ when TkNL, TkUNLESS_MOD, TkIF_MOD, TkSEMICOLON then container.ongoing_visibility = vis else - if vis_type == 'module_function' then + new_methods = [] + + case vis_type + when 'module_function' then args = parse_symbol_arg container.set_visibility_for args, :private, false - module_functions = [] - container.methods_matching args do |m| s_m = m.dup s_m.record_location @top_level s_m.singleton = true - s_m.visibility = :public - module_functions << s_m + new_methods << s_m end + when 'public_class_method', 'private_class_method' then + args = parse_symbol_arg - module_functions.each do |s_m| - case s_m - when RDoc::AnyMethod then - container.add_method s_m - when RDoc::Attr then - container.add_attribute s_m + container.methods_matching args, true do |m| + if m.parent != container then + m = m.dup + m.record_location @top_level + new_methods << m end + + m.visibility = vis end else args = parse_symbol_arg container.set_visibility_for args, vis, singleton end + + new_methods.each do |method| + case method + when RDoc::AnyMethod then + container.add_method method + when RDoc::Attr then + container.add_attribute method + end + method.visibility = vis + end end end Index: lib/rdoc/parser/c.rb =================================================================== --- lib/rdoc/parser/c.rb (revision 31557) +++ lib/rdoc/parser/c.rb (revision 31558) @@ -376,7 +376,7 @@ when %r%((?>/\*.*?\*/\s*)?) ((?:(?:static|SWIGINTERN)\s+)? (?:intern\s+)?VALUE\s+#{meth_name} - \s*(\(.*?\))([^;]|$))%xm then + \s*(\([^)]*\))([^;]|$))%xm then comment = $1 body = $2 offset = $~.offset(2).first Index: lib/rdoc/options.rb =================================================================== --- lib/rdoc/options.rb (revision 31557) +++ lib/rdoc/options.rb (revision 31558) @@ -256,7 +256,9 @@ @rdoc_include << "." if @rdoc_include.empty? - if @exclude.empty? then + if @exclude.nil? or Regexp === @exclude then + # done, #finish is being re-run + elsif @exclude.empty? then @exclude = nil else @exclude = Regexp.new(@exclude.join("|")) Index: lib/rdoc/task.rb =================================================================== --- lib/rdoc/task.rb (revision 31557) +++ lib/rdoc/task.rb (revision 31558) @@ -37,10 +37,9 @@ require 'rake/tasklib' ## -# Create a documentation task that will generate the RDoc files for a project. +# RDoc::Task creates the following rake tasks to generate and clean up RDoc +# output: # -# The RDoc::Task will create the following targets: -# # [rdoc] # Main task for this RDoc task. # @@ -56,12 +55,12 @@ # gem 'rdoc' # require 'rdoc/task' # -# RDoc::Task.new do |rd| -# rd.main = "README.rdoc" -# rd.rdoc_files.include("README.rdoc", "lib/**/*.rb") +# RDoc::Task.new do |rdoc| +# rdoc.main = "README.rdoc" +# rdoc.rdoc_files.include("README.rdoc", "lib/**/*.rb") # end # -# The +rd+ object passed to the block is an RDoc::Task object. See the +# The +rdoc+ object passed to the block is an RDoc::Task object. See the # attributes list for the RDoc::Task class for available customization options. # # == Specifying different task names @@ -73,10 +72,10 @@ # gem 'rdoc' # require 'rdoc/task' # -# RDoc::Task.new :rdoc_dev do |rd| -# rd.main = "README.doc" -# rd.rdoc_files.include("README.rdoc", "lib/**/*.rb") -# rd.options << "--all" +# RDoc::Task.new :rdoc_dev do |rdoc| +# rdoc.main = "README.doc" +# rdoc.rdoc_files.include("README.rdoc", "lib/**/*.rb") +# rdoc.options << "--all" # end # # The tasks would then be named :<em>rdoc_dev</em>, Index: lib/rdoc/method_attr.rb =================================================================== --- lib/rdoc/method_attr.rb (revision 31557) +++ lib/rdoc/method_attr.rb (revision 31558) @@ -333,6 +333,8 @@ def inspect # :nodoc: alias_for = @is_alias_for ? " (alias for #{@is_alias_for.name})" : nil + visibility = self.visibility + visibility = "forced #{visibility}" if force_documentation "#<%s:0x%x %s (%s)%s>" % [ self.class, object_id, full_name, Index: lib/rdoc/attr.rb =================================================================== --- lib/rdoc/attr.rb (revision 31557) +++ lib/rdoc/attr.rb (revision 31558) @@ -68,6 +68,19 @@ end end + def inspect # :nodoc: + alias_for = @is_alias_for ? " (alias for #{@is_alias_for.name})" : nil + visibility = self.visibility + visibility = "forced #{visibility}" if force_documentation + "#<%s:0x%x %s %s (%s)%s>" % [ + self.class, object_id, + full_name, + rw, + visibility, + alias_for, + ] + end + ## # Dumps this Attr for use by ri. See also #marshal_load Index: NEWS =================================================================== --- NEWS (revision 31557) +++ NEWS (revision 31558) @@ -108,7 +108,7 @@ * support for bash/zsh completion. * RDoc - * RDoc has been upgraded to RDoc 3.5.3. For full release notes see + * RDoc has been upgraded to RDoc 3.6. For full release notes see http://docs.seattlerb.org/rdoc/History_txt.html * rexml Index: test/rdoc/test_rdoc_context.rb =================================================================== --- test/rdoc/test_rdoc_context.rb (revision 31557) +++ test/rdoc/test_rdoc_context.rb (revision 31558) @@ -143,6 +143,16 @@ assert_equal [incl], @context.includes end + def test_add_include_twice + incl1 = RDoc::Include.new 'Name', 'comment' + @context.add_include incl1 + + incl2 = RDoc::Include.new 'Name', 'comment' + @context.add_include incl2 + + assert_equal [incl1], @context.includes + end + def test_add_method meth = RDoc::AnyMethod.new nil, 'old_name' meth.visibility = nil @@ -438,5 +448,146 @@ assert_equal expected, @c1.methods_by_type(separate) end + def test_methods_matching + methods = [] + + @parent.methods_matching 'm' do |m| + methods << m + end + + assert_equal [@parent_m], methods + end + + def test_methods_matching_singleton + methods = [] + + @parent.methods_matching 'm', true do |m| + methods << m + end + + assert_equal [@parent__m], methods + end + + def test_methods_matching_inherit + methods = [] + + @child.methods_matching 'm' do |m| + methods << m + end + + assert_equal [@parent_m], methods + end + + def test_remove_invisible_private + util_visibilities + + @vis.remove_invisible :private + + assert_equal [@pub, @prot, @priv], @vis.method_list + assert_equal [@apub, @aprot, @apriv], @vis.attributes + end + + def test_remove_invisible_protected + util_visibilities + + @vis.remove_invisible :protected + + assert_equal [@pub, @prot], @vis.method_list + assert_equal [@apub, @aprot], @vis.attributes + end + + def test_remove_invisible_public + util_visibilities + + @vis.remove_invisible :public + + assert_equal [@pub], @vis.method_list + assert_equal [@apub], @vis.attributes + end + + def test_remove_invisible_public_force + util_visibilities + + @priv.force_documentation = true + @prot.force_documentation = true + @apriv.force_documentation = true + @aprot.force_documentation = true + + @vis.remove_invisible :public + + assert_equal [@pub, @prot, @priv], @vis.method_list + assert_equal [@apub, @aprot, @apriv], @vis.attributes + end + + def test_remove_invisible_in_protected + util_visibilities + + methods = [@pub, @prot, @priv] + + @c1.remove_invisible_in methods, :protected + + assert_equal [@pub, @prot], methods + end + + def test_remove_invisible_in_protected_force + util_visibilities + + @priv.force_documentation = true + + methods = [@pub, @prot, @priv] + + @c1.remove_invisible_in methods, :protected + + assert_equal [@pub, @prot, @priv], methods + end + + def test_remove_invisible_in_public + util_visibilities + + methods = [@pub, @prot, @priv] + + @c1.remove_invisible_in methods, :public + + assert_equal [@pub], methods + end + + def test_remove_invisible_in_public_force + util_visibilities + + @prot.force_documentation = true + @priv.force_documentation = true + + methods = [@pub, @prot, @priv] + + @c1.remove_invisible_in methods, :public + + assert_equal [@pub, @prot, @priv], methods + end + + def util_visibilities + @pub = RDoc::AnyMethod.new nil, 'pub' + @prot = RDoc::AnyMethod.new nil, 'prot' + @priv = RDoc::AnyMethod.new nil, 'priv' + + @apub = RDoc::Attr.new nil, 'pub', 'RW', nil + @aprot = RDoc::Attr.new nil, 'prot', 'RW', nil + @apriv = RDoc::Attr.new nil, 'priv', 'RW', nil + + @vis = RDoc::NormalClass.new 'Vis' + @vis.add_method @pub + @vis.add_method @prot + @vis.add_method @priv + + @vis.add_attribute @apub + @vis.add_attribute @aprot + @vis.add_attribute @apriv + + @prot.visibility = :protected + @priv.visibility = :private + + @aprot.visibility = :protected + @apriv.visibility = :private + end + end Index: test/rdoc/xref_test_case.rb =================================================================== --- test/rdoc/xref_test_case.rb (revision 31557) +++ test/rdoc/xref_test_case.rb (revision 31558) @@ -38,7 +38,6 @@ @c1_m = @c1.method_list.last # C1#m @c1__m = @c1.method_list.first # C1::m - @c2 = @xref_data.find_module_named 'C2' @c2_a = @c2.method_list.last @c2_b = @c2.method_list.first @@ -55,6 +54,12 @@ @m1_m = @m1.method_list.first @m1_m2 = @xref_data.find_module_named 'M1::M2' + + @parent = @xref_data.find_module_named 'Parent' + @child = @xref_data.find_module_named 'Child' + + @parent_m = @parent.method_list.first # Parent#m + @parent__m = @parent.method_list.last # Parent::m end end Index: test/rdoc/test_rdoc_top_level.rb =================================================================== --- test/rdoc/test_rdoc_top_level.rb (revision 31557) +++ test/rdoc/test_rdoc_top_level.rb (revision 31558) @@ -12,7 +12,10 @@ def test_class_all_classes_and_modules expected = %w[ - C1 C2 C2::C3 C2::C3::H1 C3 C3::H1 C3::H2 C4 C4::C4 C5 C5::C1 M1 M1::M2 + C1 C2 C2::C3 C2::C3::H1 C3 C3::H1 C3::H2 C4 C4::C4 C5 C5::C1 + Child + M1 M1::M2 + Parent ] assert_equal expected, @@ -22,6 +25,7 @@ def test_class_classes expected = %w[ C1 C2 C2::C3 C2::C3::H1 C3 C3::H1 C3::H2 C4 C4::C4 C5 C5::C1 + Child Parent ] assert_equal expected, RDoc::TopLevel.classes.map { |m| m.full_name }.sort Index: test/rdoc/test_rdoc_code_object.rb =================================================================== --- test/rdoc/test_rdoc_code_object.rb (revision 31557) +++ test/rdoc/test_rdoc_code_object.rb (revision 31558) @@ -119,6 +119,16 @@ assert @co.document_children end + def test_each_parent + parents = [] + + @parent_m.each_parent do |code_object| + parents << code_object + end + + assert_equal [@parent, @xref_data], parents + end + def test_full_name_equals @co.full_name = 'hi' Index: test/rdoc/test_rdoc_class_module.rb =================================================================== --- test/rdoc/test_rdoc_class_module.rb (revision 31557) +++ test/rdoc/test_rdoc_class_module.rb (revision 31558) @@ -8,6 +8,10 @@ @RM = RDoc::Markup end + def test_ancestors + assert_equal [@parent], @child.ancestors + end + def test_comment_equals cm = RDoc::ClassModule.new 'Klass' cm.comment = '# comment 1' @@ -23,6 +27,16 @@ assert_equal "comment 1\n---\ncomment 2\n---\n* comment 3", cm.comment end + def test_each_ancestor + ancestors = [] + + @child.each_ancestor do |mod| + ancestors << mod + end + + assert_equal [@parent], ancestors + end + # handle making a short module alias of yourself def test_find_class_named @@ -36,6 +50,7 @@ cm1.comment = 'klass 1' cm1.add_attribute RDoc::Attr.new(nil, 'a1', 'RW', '') cm1.add_attribute RDoc::Attr.new(nil, 'a3', 'R', '') + cm1.add_attribute RDoc::Attr.new(nil, 'a4', 'R', '') cm1.add_constant RDoc::Constant.new('C1', nil, '') cm1.add_include RDoc::Include.new('I1', '') cm1.add_method RDoc::AnyMethod.new(nil, 'm1') @@ -46,6 +61,7 @@ @RM::Paragraph.new('klass 2'))) cm2.add_attribute RDoc::Attr.new(nil, 'a2', 'RW', '') cm2.add_attribute RDoc::Attr.new(nil, 'a3', 'W', '') + cm2.add_attribute RDoc::Attr.new(nil, 'a4', 'R', '') cm2.add_constant RDoc::Constant.new('C2', nil, '') cm2.add_include RDoc::Include.new('I2', '') cm2.add_method RDoc::AnyMethod.new(nil, 'm2') @@ -62,6 +78,7 @@ RDoc::Attr.new(nil, 'a1', 'RW', ''), RDoc::Attr.new(nil, 'a2', 'RW', ''), RDoc::Attr.new(nil, 'a3', 'RW', ''), + RDoc::Attr.new(nil, 'a4', 'R', ''), ] expected.each do |a| a.parent = cm1 end Index: test/rdoc/test_rdoc_markup_parser.rb =================================================================== --- test/rdoc/test_rdoc_markup_parser.rb (revision 31557) +++ test/rdoc/test_rdoc_markup_parser.rb (revision 31558) @@ -625,6 +625,25 @@ assert_equal expected, @RMP.parse(str).parts end + def test_parse_rule + str = <<-STR +now is the time + +--- + +for all good men + STR + + expected = [ + @RM::Paragraph.new('now is the time'), + @RM::BlankLine.new, + @RM::Rule.new(1), + @RM::BlankLine.new, + @RM::Paragraph.new('for all good men')] + + assert_equal expected, @RMP.parse(str).parts + end + def test_parse_ualpha str = <<-STR A. l1 Index: test/rdoc/test_rdoc_ri_driver.rb =================================================================== --- test/rdoc/test_rdoc_ri_driver.rb (revision 31557) +++ test/rdoc/test_rdoc_ri_driver.rb (revision 31558) @@ -3,6 +3,7 @@ require 'minitest/autorun' require 'tmpdir' require 'fileutils' +require 'stringio' require 'rdoc/ri/driver' class TestRDocRIDriver < MiniTest::Unit::TestCase @@ -249,12 +250,14 @@ @driver.stores = [store] - assert_equal %w[Foo Foo::Bar], @driver.complete('F') + assert_equal %w[Foo ], @driver.complete('F') assert_equal %w[ Foo::Bar], @driver.complete('Foo::B') - assert_equal %w[Foo#Bar], @driver.complete('Foo#'), 'Foo#' - assert_equal %w[Foo#Bar Foo::bar], @driver.complete('Foo.'), 'Foo.' - assert_equal %w[Foo::Bar Foo::bar], @driver.complete('Foo::'), 'Foo::' + assert_equal %w[Foo#Bar], @driver.complete('Foo#'), 'Foo#' + assert_equal %w[Foo#Bar Foo::bar], @driver.complete('Foo.'), 'Foo.' + assert_equal %w[Foo::Bar Foo::bar], @driver.complete('Foo::'), 'Foo::' + + assert_equal %w[ Foo::bar], @driver.complete('Foo::b'), 'Foo::b' end def test_complete_ancestor @@ -269,7 +272,7 @@ def test_complete_classes util_store - assert_equal %w[Foo Foo::Bar Foo::Baz], @driver.complete('F') + assert_equal %w[Foo ], @driver.complete('F') assert_equal %w[Foo:: Foo::Bar Foo::Baz], @driver.complete('Foo::') assert_equal %w[ Foo::Bar Foo::Baz], @driver.complete('Foo::B') end @@ -278,7 +281,8 @@ util_multi_store assert_equal %w[Bar], @driver.complete('B') - assert_equal %w[Foo Foo::Bar Foo::Baz], @driver.complete('F') + assert_equal %w[Foo], @driver.complete('F') + assert_equal %w[Foo::Bar Foo::Baz], @driver.complete('Foo::B') end def test_display @@ -572,11 +576,18 @@ def test_name_regexp assert_equal %r%^RDoc::AnyMethod#new$%, @driver.name_regexp('RDoc::AnyMethod#new') + assert_equal %r%^RDoc::AnyMethod::new$%, @driver.name_regexp('RDoc::AnyMethod::new') assert_equal %r%^RDoc::AnyMethod(#|::)new$%, @driver.name_regexp('RDoc::AnyMethod.new') + + assert_equal %r%^Hash(#|::)\[\]$%, + @driver.name_regexp('Hash.[]') + + assert_equal %r%^Hash::\[\]$%, + @driver.name_regexp('Hash::[]') end def test_list_known_classes @@ -589,6 +600,16 @@ assert_equal "Ambiguous\nFoo\nFoo::Bar\nFoo::Baz\nInc\n", out end + def test_list_known_classes_name + util_store + + out, = capture_io do + @driver.list_known_classes %w[F I] + end + + assert_equal "Foo\nFoo::Bar\nFoo::Baz\nInc\n", out + end + def test_list_methods_matching util_store @@ -596,6 +617,24 @@ @driver.list_methods_matching('Foo::Bar.') end + def test_list_methods_matching_regexp + util_store + + index = RDoc::AnyMethod.new nil, '[]' + @cFoo.add_method index + @store.save_method @cFoo, index + + c_index = RDoc::AnyMethod.new nil, '[]' + c_index.singleton = true + @cFoo.add_method c_index + @store.save_method @cFoo, c_index + + @store.save_cache + + assert_equal %w[Foo#[]], @driver.list_methods_matching('Foo#[]') + assert_equal %w[Foo::[]], @driver.list_methods_matching('Foo::[]') + end + def test_load_method util_store Index: test/rdoc/xref_data.rb =================================================================== --- test/rdoc/xref_data.rb (revision 31557) +++ test/rdoc/xref_data.rb (revision 31558) @@ -63,5 +63,14 @@ module M1::M2 end + +class Parent + def m() end + def self.m() end +end + +class Child < Parent +end + XREF_DATA Index: test/rdoc/test_rdoc_parser_ruby.rb =================================================================== --- test/rdoc/test_rdoc_parser_ruby.rb (revision 31557) +++ test/rdoc/test_rdoc_parser_ruby.rb (revision 31558) @@ -1799,6 +1799,56 @@ assert_equal :private, foo.visibility end + def test_parse_statements_identifier_public_class_method + content = <<-CONTENT +class Date + def self.now; end + private_class_method :now +end + +class DateTime < Date + public_class_method :now +end + CONTENT + + util_parser content + + @parser.parse_statements @top_level + + date, date_time = @top_level.classes + + date_now = date.method_list.first + date_time_now = date_time.method_list.first + + assert_equal :private, date_now.visibility + assert_equal :public, date_time_now.visibility + end + + def test_parse_statements_identifier_private_class_method + content = <<-CONTENT +class Date + def self.now; end + public_class_method :now +end + +class DateTime < Date + private_class_method :now +end + CONTENT + + util_parser content + + @parser.parse_statements @top_level + + date, date_time = @top_level.classes + + date_now = date.method_list.first + date_time_now = date_time.method_list.first + + assert_equal :public, date_now.visibility, date_now.full_name + assert_equal :private, date_time_now.visibility, date_time_now.full_name + end + def test_parse_statements_identifier_require content = "require 'bar'" @@ -1978,6 +2028,53 @@ assert_equal 'm comment', m.comment end + def test_scan_block_comment_notflush + ## + # + # The previous test assumes that between the =begin/=end blocs that there is + # only one line, or minima formatting directives. This test tests for those + # who use the =begin bloc with longer / more advanced formatting within. + # + ## + content = <<-CONTENT +=begin rdoc + += DESCRIPTION + +This is a simple test class + += RUMPUS + +Is a silly word + +=end +class StevenSimpleClass + # A band on my iPhone as I wrote this test + FRUIT_BATS="Make nice music" + +=begin rdoc +A nice girl +=end + + def lauren + puts "Summoning Lauren!" + end +end + CONTENT + util_parser content + + @parser.scan + + foo = @top_level.classes.first + + assert_equal "= DESCRIPTION\n\nThis is a simple test class\n\n= RUMPUS\n\nIs a silly word", + foo.comment + + m = foo.method_list.first + + assert_equal 'A nice girl', m.comment + end + def test_scan_meta_method_block content = <<-CONTENT class C Index: test/rdoc/test_rdoc_parser_c.rb =================================================================== --- test/rdoc/test_rdoc_parser_c.rb (revision 31557) +++ test/rdoc/test_rdoc_parser_c.rb (revision 31558) @@ -680,7 +680,7 @@ baz = methods.last assert_equal 'Foo#baz', baz.full_name - assert_equal "a comment for bar", bar.comment + assert_equal "a comment for bar", baz.comment end def test_find_modifiers_call_seq @@ -929,6 +929,37 @@ assert read_method.singleton end + def test_define_method_with_prototype + content = <<-EOF +static VALUE rb_io_s_read(int, VALUE*, VALUE); + +/* Method Comment! */ +static VALUE +rb_io_s_read(argc, argv, io) + int argc; + VALUE *argv; + VALUE io; +{ +} + +void +Init_IO(void) { + /* + * a comment for class Foo on rb_define_class + */ + VALUE rb_cIO = rb_define_class("IO", rb_cObject); + rb_define_singleton_method(rb_cIO, "read", rb_io_s_read, -1); +} + EOF + + klass = util_get_class content, 'rb_cIO' + read_method = klass.method_list.first + assert_equal "read", read_method.name + assert_equal "Method Comment! ", read_method.comment + assert_equal "rb_io_s_read", read_method.c_function + assert read_method.singleton + end + def test_define_method_private content = <<-EOF /*Method Comment! */ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/