1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Update to RDoc 2.1.0 r112

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18147 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
drbrain 2008-07-21 18:35:14 +00:00
parent c62db0676b
commit cd9e9c6deb
19 changed files with 460 additions and 285 deletions

View file

@ -1,3 +1,7 @@
Tue Jul 22 03:34:01 2008 Eric Hodel <drbrain@segment7.net>
* lib/rdoc*: Update to RDoc 2.1.0 r112.
Tue Jul 22 02:51:46 2008 Nobuyoshi Nakada <nobu@ruby-lang.org> Tue Jul 22 02:51:46 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* include/ruby/intern.h (rb_str_buf_cat2, rb_str_cat2): optimization * include/ruby/intern.h (rb_str_buf_cat2, rb_str_cat2): optimization

View file

@ -71,6 +71,14 @@ module RDoc
# Do we _force_ documentation, even is we wouldn't normally show the entity # Do we _force_ documentation, even is we wouldn't normally show the entity
attr_accessor :force_documentation attr_accessor :force_documentation
def parent_file_name
@parent ? @parent.file_base_name : '(unknown)'
end
def parent_name
@parent ? @parent.name : '(unknown)'
end
# Default callbacks to nothing, but this is overridden for classes # Default callbacks to nothing, but this is overridden for classes
# and modules # and modules
def remove_classes_and_modules def remove_classes_and_modules
@ -264,7 +272,7 @@ module RDoc
end end
def add_class(class_type, name, superclass) def add_class(class_type, name, superclass)
add_class_or_module(@classes, class_type, name, superclass) add_class_or_module @classes, class_type, name, superclass
end end
def add_module(class_type, name) def add_module(class_type, name)
@ -272,7 +280,6 @@ module RDoc
end end
def add_method(a_method) def add_method(a_method)
puts "Adding #@visibility method #{a_method.name} to #@name" if $DEBUG_RDOC
a_method.visibility = @visibility a_method.visibility = @visibility
add_to(@method_list, a_method) add_to(@method_list, a_method)
end end
@ -283,7 +290,8 @@ module RDoc
def add_alias(an_alias) def add_alias(an_alias)
meth = find_instance_method_named(an_alias.old_name) meth = find_instance_method_named(an_alias.old_name)
if meth
if meth then
new_meth = AnyMethod.new(an_alias.text, an_alias.new_name) new_meth = AnyMethod.new(an_alias.text, an_alias.new_name)
new_meth.is_alias_for = meth new_meth.is_alias_for = meth
new_meth.singleton = meth.singleton new_meth.singleton = meth.singleton
@ -294,6 +302,8 @@ module RDoc
else else
add_to(@aliases, an_alias) add_to(@aliases, an_alias)
end end
an_alias
end end
def add_include(an_include) def add_include(an_include)
@ -315,11 +325,12 @@ module RDoc
def add_class_or_module(collection, class_type, name, superclass=nil) def add_class_or_module(collection, class_type, name, superclass=nil)
cls = collection[name] cls = collection[name]
if cls
if cls then
cls.superclass = superclass unless cls.module?
puts "Reusing class/module #{name}" if $DEBUG_RDOC puts "Reusing class/module #{name}" if $DEBUG_RDOC
else else
cls = class_type.new(name, superclass) cls = class_type.new(name, superclass)
puts "Adding class/module #{name} to #@name" if $DEBUG_RDOC
# collection[name] = cls if @document_self && !@done_documenting # collection[name] = cls if @document_self && !@done_documenting
collection[name] = cls if !@done_documenting collection[name] = cls if !@done_documenting
cls.parent = self cls.parent = self
@ -550,10 +561,11 @@ module RDoc
def add_class_or_module(collection, class_type, name, superclass) def add_class_or_module(collection, class_type, name, superclass)
cls = collection[name] cls = collection[name]
if cls if cls then
puts "Reusing class/module #{name}" #if $DEBUG_RDOC cls.superclass = superclass unless cls.module?
puts "Reusing class/module #{cls.full_name}" if $DEBUG_RDOC
else else
if class_type == NormalModule if class_type == NormalModule then
all = @@all_modules all = @@all_modules
else else
all = @@all_classes all = @@all_classes
@ -561,13 +573,11 @@ module RDoc
cls = all[name] cls = all[name]
if !cls unless cls then
cls = class_type.new(name, superclass) cls = class_type.new name, superclass
all[name] = cls unless @done_documenting all[name] = cls unless @done_documenting
end end
puts "Adding class/module #{name} to #{@name}" if $DEBUG_RDOC
collection[name] = cls unless @done_documenting collection[name] = cls unless @done_documenting
cls.parent = self cls.parent = self
@ -609,6 +619,15 @@ module RDoc
find_class_or_module_named(name) || find_enclosing_module_named(name) find_class_or_module_named(name) || find_enclosing_module_named(name)
end end
def inspect
"#<%s:0x%x %p modules: %p classes: %p>" % [
self.class, object_id,
file_base_name,
@modules.map { |n,m| m },
@classes.map { |n,c| c }
]
end
end end
## ##
@ -617,7 +636,6 @@ module RDoc
class ClassModule < Context class ClassModule < Context
attr_reader :superclass
attr_accessor :diagram attr_accessor :diagram
def initialize(name, superclass = nil) def initialize(name, superclass = nil)
@ -628,7 +646,15 @@ module RDoc
super() super()
end end
def find_class_named(name)
return self if full_name == name
@classes.each_value {|c| return c if c.find_class_named(name) }
nil
end
##
# Return the fully qualified name of this class or module # Return the fully qualified name of this class or module
def full_name def full_name
if @parent && @parent.full_name if @parent && @parent.full_name
@parent.full_name + "::" + @name @parent.full_name + "::" + @name
@ -642,24 +668,47 @@ module RDoc
File.join(prefix, *path) + ".html" File.join(prefix, *path) + ".html"
end end
# Return +true+ if this object represents a module ##
def is_module? # Does this object represent a module?
def module?
false false
end end
# to_s is simply for debugging ##
def to_s # Get the superclass of this class. Attempts to retrieve the superclass'
res = self.class.name + ": " + @name # real name by following module nesting.
res << @comment.to_s
res << super def superclass
res raise NoMethodError, "#{full_name} is a module" if module?
scope = self
begin
superclass = scope.classes.find { |c| c.name == @superclass }
return superclass.full_name if superclass
scope = scope.parent
end until scope.nil? or TopLevel === scope
@superclass
end end
def find_class_named(name) ##
return self if full_name == name # Set the superclass of this class
@classes.each_value {|c| return c if c.find_class_named(name) }
nil def superclass=(superclass)
raise NoMethodError, "#{full_name} is a module" if module?
if @superclass.nil? or @superclass == 'Object' then
@superclass = superclass
end
end end
def to_s
"#{self.class}: #{@name} #{@comment} #{super}"
end
end end
## ##
@ -708,7 +757,7 @@ module RDoc
] ]
end end
def is_module? def module?
true true
end end
@ -764,7 +813,7 @@ module RDoc
alias_for = @is_alias_for ? " (alias for #{@is_alias_for.name})" : nil alias_for = @is_alias_for ? " (alias for #{@is_alias_for.name})" : nil
"#<%s:0x%x %s%s%s (%s)%s>" % [ "#<%s:0x%x %s%s%s (%s)%s>" % [
self.class, object_id, self.class, object_id,
@parent.name, parent_name,
singleton ? '::' : '#', singleton ? '::' : '#',
name, name,
visibility, visibility,
@ -773,25 +822,24 @@ module RDoc
end end
def param_seq def param_seq
p = params.gsub(/\s*\#.*/, '') params = params.gsub(/\s*\#.*/, '')
p = p.tr("\n", " ").squeeze(" ") params = params.tr("\n", " ").squeeze(" ")
p = "(" + p + ")" unless p[0] == ?( params = "(#{params})" unless p[0] == ?(
if (block = block_params) if block = block_params then # yes, =
# If this method has explicit block parameters, remove any # If this method has explicit block parameters, remove any explicit
# explicit &block # &block
$stderr.puts p params.sub!(/,?\s*&\w+/)
p.sub!(/,?\s*&\w+/)
$stderr.puts p
block.gsub!(/\s*\#.*/, '') block.gsub!(/\s*\#.*/, '')
block = block.tr("\n", " ").squeeze(" ") block = block.tr("\n", " ").squeeze(" ")
if block[0] == ?( if block[0] == ?(
block.sub!(/^\(/, '').sub!(/\)/, '') block.sub!(/^\(/, '').sub!(/\)/, '')
end end
p << " {|#{block}| ...}" params << " { |#{block}| ... }"
end end
p
params
end end
def to_s def to_s
@ -887,7 +935,7 @@ $stderr.puts p
"#<%s:0x%x %s.%s :%s>" % [ "#<%s:0x%x %s.%s :%s>" % [
self.class, object_id, self.class, object_id,
@parent.name, attr, @name, parent_name, attr, @name,
] ]
end end
@ -914,7 +962,7 @@ $stderr.puts p
self.class, self.class,
object_id, object_id,
@name, @name,
@parent.file_base_name, parent_file_name,
] ]
end end
@ -938,8 +986,7 @@ $stderr.puts p
"#<%s:0x%x %s.include %s>" % [ "#<%s:0x%x %s.include %s>" % [
self.class, self.class,
object_id, object_id,
@parent.name, parent_name, @name,
@name,
] ]
end end

View file

@ -489,7 +489,7 @@ module RDoc::Generator
@html_file = html_file @html_file = html_file
@html_class = self @html_class = self
@is_module = context.is_module? @is_module = context.module?
@values = {} @values = {}
context.viewer = self context.viewer = self
@ -619,16 +619,16 @@ module RDoc::Generator
@values["title"] = "#{@values['classmod']}: #{h_name}" @values["title"] = "#{@values['classmod']}: #{h_name}"
c = @context c = @context
c = c.parent while c and !c.diagram c = c.parent while c and not c.diagram
if c && c.diagram
if c and c.diagram then
@values["diagram"] = diagram_reference(c.diagram) @values["diagram"] = diagram_reference(c.diagram)
end end
@values["full_name"] = h_name @values["full_name"] = h_name
parent_class = @context.superclass if not @context.module? and @context.superclass then
parent_class = @context.superclass
if parent_class
@values["parent"] = CGI.escapeHTML(parent_class) @values["parent"] = CGI.escapeHTML(parent_class)
if parent_name if parent_name

View file

@ -16,12 +16,8 @@ class RDoc::Generator::RI
new(options) new(options)
end end
class << self
protected :new
end
## ##
# Set up a new RDoc::Generator::RI. # Set up a new ri generator
def initialize(options) #:not-new: def initialize(options) #:not-new:
@options = options @options = options
@ -52,11 +48,12 @@ class RDoc::Generator::RI
end end
def generate_class_info(cls) def generate_class_info(cls)
if cls === RDoc::NormalModule case cls
when RDoc::NormalModule then
cls_desc = RDoc::RI::ModuleDescription.new cls_desc = RDoc::RI::ModuleDescription.new
else else
cls_desc = RDoc::RI::ClassDescription.new cls_desc = RDoc::RI::ClassDescription.new
cls_desc.superclass = cls.superclass cls_desc.superclass = cls.superclass
end end
cls_desc.name = cls.name cls_desc.name = cls.name

View file

@ -174,21 +174,16 @@ class RDoc::Markup::AttributeManager
def flow(str) def flow(str)
@str = str @str = str
puts("Before flow, str='#{@str.dump}'") if $DEBUG_RDOC
mask_protected_sequences mask_protected_sequences
@attrs = RDoc::Markup::AttrSpan.new @str.length @attrs = RDoc::Markup::AttrSpan.new @str.length
puts("After protecting, str='#{@str.dump}'") if $DEBUG_RDOC
convert_attrs(@str, @attrs) convert_attrs(@str, @attrs)
convert_html(@str, @attrs) convert_html(@str, @attrs)
convert_specials(str, @attrs) convert_specials(str, @attrs)
unmask_protected_sequences unmask_protected_sequences
puts("After flow, str='#{@str.dump}'") if $DEBUG_RDOC
return split_into_flow return split_into_flow
end end
@ -215,8 +210,6 @@ class RDoc::Markup::AttributeManager
end end
def split_into_flow def split_into_flow
display_attributes if $DEBUG_RDOC
res = [] res = []
current_attr = 0 current_attr = 0
str = "" str = ""

View file

@ -107,11 +107,6 @@ class RDoc::Options
attr_reader :promiscuous attr_reader :promiscuous
##
# Don't display progress as we process the files
attr_accessor :quiet
## ##
# Array of directories to search for files to satisfy an :include: # Array of directories to search for files to satisfy an :include:
@ -149,6 +144,11 @@ class RDoc::Options
attr_reader :title attr_reader :title
##
# Verbosity, zero means quiet
attr_accessor :verbosity
## ##
# URL of web cvs frontend # URL of web cvs frontend
@ -161,7 +161,6 @@ class RDoc::Options
@main_page = nil @main_page = nil
@merge = false @merge = false
@exclude = [] @exclude = []
@quiet = false
@generators = generators @generators = generators
@generator_name = 'html' @generator_name = 'html'
@generator = @generators[@generator_name] @generator = @generators[@generator_name]
@ -180,6 +179,7 @@ class RDoc::Options
@extra_accessor_flags = {} @extra_accessor_flags = {}
@promiscuous = false @promiscuous = false
@force_update = false @force_update = false
@verbosity = 1
@css = nil @css = nil
@webcvs = nil @webcvs = nil
@ -424,9 +424,15 @@ Usage: #{opt.program_name} [options] [names...]
opt.on("--quiet", "-q", opt.on("--quiet", "-q",
"Don't show progress as we parse.") do |value| "Don't show progress as we parse.") do |value|
@quiet = value @verbosity = 0
end end
opt.on("--verbose", "-v",
"Display extra progress as we parse.") do |value|
@verbosity = 2
end
opt.separator nil opt.separator nil
opt.on("--ri", "-r", opt.on("--ri", "-r",
@ -559,6 +565,17 @@ Usage: #{opt.program_name} [options] [names...]
@title ||= string @title ||= string
end end
##
# Don't display progress as we process the files
def quiet
@verbosity.zero?
end
def quiet=(bool)
@verbosity = bool ? 0 : 1
end
private private
## ##

View file

@ -46,8 +46,6 @@ class RDoc::Parser
attr_reader :parsers attr_reader :parsers
end end
attr_writer :progress
## ##
# Alias an extension to another extension. After this call, files ending # Alias an extension to another extension. After this call, files ending
# "new_ext" will be parsed using the same parser as "old_ext" # "new_ext" will be parsed using the same parser as "old_ext"
@ -103,7 +101,6 @@ class RDoc::Parser
@content = content @content = content
@options = options @options = options
@stats = stats @stats = stats
@progress = $stderr unless options.quiet
end end
end end

View file

@ -95,8 +95,6 @@ class RDoc::Parser::C < RDoc::Parser
parse_files_matching(/\.(?:([CcHh])\1?|c([+xp])\2|y)\z/) parse_files_matching(/\.(?:([CcHh])\1?|c([+xp])\2|y)\z/)
attr_writer :progress
@@enclosure_classes = {} @@enclosure_classes = {}
@@known_bodies = {} @@known_bodies = {}
@ -115,11 +113,12 @@ class RDoc::Parser::C < RDoc::Parser
def do_aliases def do_aliases
@content.scan(%r{rb_define_alias\s*\(\s*(\w+),\s*"([^"]+)",\s*"([^"]+)"\s*\)}m) do @content.scan(%r{rb_define_alias\s*\(\s*(\w+),\s*"([^"]+)",\s*"([^"]+)"\s*\)}m) do
|var_name, new_name, old_name| |var_name, new_name, old_name|
@stats.num_methods += 1
class_name = @known_classes[var_name] || var_name class_name = @known_classes[var_name] || var_name
class_obj = find_class(var_name, class_name) class_obj = find_class(var_name, class_name)
class_obj.add_alias RDoc::Alias.new("", old_name, new_name, "") as = class_obj.add_alias RDoc::Alias.new("", old_name, new_name, "")
@stats.add_alias as
end end
end end
@ -306,7 +305,7 @@ class RDoc::Parser::C < RDoc::Parser
meth_obj.comment = mangle_comment(comment) + meth_obj.comment meth_obj.comment = mangle_comment(comment) + meth_obj.comment
when %r{^\s*\#\s*define\s+#{meth_name}\s+(\w+)}m when %r{^\s*\#\s*define\s+#{meth_name}\s+(\w+)}m
unless find_body($1, meth_obj, body, true) unless find_body($1, meth_obj, body, true)
warn "No definition for #{meth_name}" unless quiet warn "No definition for #{meth_name}" unless @options.quiet
return false return false
end end
else else
@ -318,7 +317,7 @@ class RDoc::Parser::C < RDoc::Parser
find_modifiers(comment, meth_obj) find_modifiers(comment, meth_obj)
meth_obj.comment = mangle_comment(comment) meth_obj.comment = mangle_comment(comment)
else else
warn "No definition for #{meth_name}" unless quiet warn "No definition for #{meth_name}" unless @options.quiet
return false return false
end end
end end
@ -460,8 +459,6 @@ class RDoc::Parser::C < RDoc::Parser
end end
def handle_class_module(var_name, class_mod, class_name, parent, in_module) def handle_class_module(var_name, class_mod, class_name, parent, in_module)
progress(class_mod[0, 1])
parent_name = @known_classes[parent] || parent parent_name = @known_classes[parent] || parent
if in_module if in_module
@ -482,13 +479,14 @@ class RDoc::Parser::C < RDoc::Parser
enclosure = @top_level enclosure = @top_level
end end
if class_mod == "class" if class_mod == "class" then
cm = enclosure.add_class RDoc::NormalClass, class_name, parent_name cm = enclosure.add_class RDoc::NormalClass, class_name, parent_name
@stats.num_classes += 1 @stats.add_class cm
else else
cm = enclosure.add_module RDoc::NormalModule, class_name cm = enclosure.add_module RDoc::NormalModule, class_name
@stats.num_modules += 1 @stats.add_module cm
end end
cm.record_location(enclosure.toplevel) cm.record_location(enclosure.toplevel)
find_class_comment(cm.full_name, cm) find_class_comment(cm.full_name, cm)
@ -560,9 +558,6 @@ class RDoc::Parser::C < RDoc::Parser
def handle_method(type, var_name, meth_name, meth_body, param_count, def handle_method(type, var_name, meth_name, meth_body, param_count,
source_file = nil) source_file = nil)
progress(".")
@stats.num_methods += 1
class_name = @known_classes[var_name] class_name = @known_classes[var_name]
return unless class_name return unless class_name
@ -578,6 +573,8 @@ class RDoc::Parser::C < RDoc::Parser
meth_obj.singleton = meth_obj.singleton =
%w{singleton_method module_function}.include?(type) %w{singleton_method module_function}.include?(type)
@stats.add_method meth_obj
p_count = (Integer(param_count) rescue -1) p_count = (Integer(param_count) rescue -1)
if p_count < 0 if p_count < 0
@ -622,13 +619,6 @@ class RDoc::Parser::C < RDoc::Parser
comment comment
end end
def progress(char)
unless @options.quiet
@progress.print(char)
@progress.flush
end
end
## ##
# Removes lines that are commented out that might otherwise get picked up # Removes lines that are commented out that might otherwise get picked up
# when scanning for classes and methods # when scanning for classes and methods

View file

@ -289,11 +289,12 @@ class RDoc::Parser::F95 < RDoc::Parser
module_name = module_program_name module_name = module_program_name
module_code = module_program_code module_code = module_program_code
module_trailing = module_program_trailing module_trailing = module_program_trailing
progress "m"
@stats.num_modules += 1
f9x_module = @top_level.add_module NormalClass, module_name f9x_module = @top_level.add_module NormalClass, module_name
f9x_module.record_location @top_level f9x_module.record_location @top_level
@stats.add_module f9x_module
f9x_comment = COMMENTS_ARE_UPPER ? f9x_comment = COMMENTS_ARE_UPPER ?
find_comments(pre_comment.join("\n")) + "\n" + module_trailing : find_comments(pre_comment.join("\n")) + "\n" + module_trailing :
module_trailing + "\n" + find_comments(module_code.sub(/^.*$\n/i, '')) module_trailing + "\n" + find_comments(module_code.sub(/^.*$\n/i, ''))
@ -318,7 +319,7 @@ class RDoc::Parser::F95 < RDoc::Parser
program_name = module_program_name program_name = module_program_name
program_code = module_program_code program_code = module_program_code
program_trailing = module_program_trailing program_trailing = module_program_trailing
progress "p" # progress "p" # HACK what stats thingy does this correspond to?
program_comment = COMMENTS_ARE_UPPER ? program_comment = COMMENTS_ARE_UPPER ?
find_comments(pre_comment.join("\n")) + "\n" + program_trailing : find_comments(pre_comment.join("\n")) + "\n" + program_trailing :
program_trailing + "\n" + find_comments(program_code.sub(/^.*$\n/i, '')) program_trailing + "\n" + find_comments(program_code.sub(/^.*$\n/i, ''))
@ -396,7 +397,7 @@ class RDoc::Parser::F95 < RDoc::Parser
used_trailing = $3 || "" used_trailing = $3 || ""
next if used_trailing =~ /!:nodoc:/ next if used_trailing =~ /!:nodoc:/
if !container.include_includes?(used_mod_name, @options.ignore_case) if !container.include_includes?(used_mod_name, @options.ignore_case)
progress "." # progress "." # HACK what stats thingy does this correspond to?
container.add_include Include.new(used_mod_name, "") container.add_include Include.new(used_mod_name, "")
end end
if ! (used_list =~ /\,\s*?only\s*?:/i ) if ! (used_list =~ /\,\s*?only\s*?:/i )
@ -460,7 +461,7 @@ class RDoc::Parser::F95 < RDoc::Parser
used_trailing = $3 || "" used_trailing = $3 || ""
next if used_trailing =~ /!:nodoc:/ next if used_trailing =~ /!:nodoc:/
if !container.include_includes?(used_mod_name, @options.ignore_case) if !container.include_includes?(used_mod_name, @options.ignore_case)
progress "." # progress "." # HACK what stats thingy does this correspond to?
container.add_include Include.new(used_mod_name, "") container.add_include Include.new(used_mod_name, "")
end end
end end
@ -532,8 +533,9 @@ class RDoc::Parser::F95 < RDoc::Parser
type.comment = "<b><em> Derived Type </em></b> :: <tt></tt>\n" type.comment = "<b><em> Derived Type </em></b> :: <tt></tt>\n"
type.comment << args_comment if args_comment type.comment << args_comment if args_comment
type.comment << type_comment if type_comment type.comment << type_comment if type_comment
progress "t"
@stats.num_methods += 1 @stats.add_method type
container.add_method type container.add_method type
set_visibility(container, typename, visibility_default, @@public_methods) set_visibility(container, typename, visibility_default, @@public_methods)
@ -607,8 +609,9 @@ class RDoc::Parser::F95 < RDoc::Parser
self_comment = find_arguments([defitem.varname], before_contains_code) self_comment = find_arguments([defitem.varname], before_contains_code)
const_or_var.comment = "<b><em>" + const_or_var_type + "</em></b> :: <tt></tt>\n" const_or_var.comment = "<b><em>" + const_or_var_type + "</em></b> :: <tt></tt>\n"
const_or_var.comment << self_comment if self_comment const_or_var.comment << self_comment if self_comment
progress const_or_var_progress
@stats.num_methods += 1 @stats.add_method const_or_var_progress
container.add_method const_or_var container.add_method const_or_var
set_visibility(container, defitem.varname, visibility_default, @@public_methods) set_visibility(container, defitem.varname, visibility_default, @@public_methods)
@ -737,8 +740,9 @@ class RDoc::Parser::F95 < RDoc::Parser
parse_subprogram(subroutine, subroutine_params, parse_subprogram(subroutine, subroutine_params,
subroutine_comment, subroutine_code, subroutine_comment, subroutine_code,
before_contains_code, nil, subroutine_prefix) before_contains_code, nil, subroutine_prefix)
progress "s"
@stats.num_methods += 1 @stats.add_method subroutine
container.add_method subroutine container.add_method subroutine
subroutine_function = subroutine subroutine_function = subroutine
@ -774,8 +778,8 @@ class RDoc::Parser::F95 < RDoc::Parser
function.start_collecting_tokens function.start_collecting_tokens
function.add_token Token.new(1,1).set_text(function_code_org) function.add_token Token.new(1,1).set_text(function_code_org)
progress "f" @stats.add_method function
@stats.num_methods += 1
container.add_method function container.add_method function
subroutine_function = function subroutine_function = function
@ -875,8 +879,8 @@ class RDoc::Parser::F95 < RDoc::Parser
true, nolink) true, nolink)
new_meth.singleton = old_meth.singleton new_meth.singleton = old_meth.singleton
progress "i" @stats.add_method new_meth
@stats.num_methods += 1
container.add_method new_meth container.add_method new_meth
set_visibility(container, generic_name, visibility_default, @@public_methods) set_visibility(container, generic_name, visibility_default, @@public_methods)
@ -939,8 +943,8 @@ class RDoc::Parser::F95 < RDoc::Parser
indicated_file, indicated_file,
indicated_method.comment) indicated_method.comment)
progress "e" @stats.add_method external_method
@stats.num_methods += 1
container.add_method external_method container.add_method external_method
set_visibility(container, generic_name, visibility_default, @@public_methods) set_visibility(container, generic_name, visibility_default, @@public_methods)
if !container.include_requires?(indicated_file, @options.ignore_case) if !container.include_requires?(indicated_file, @options.ignore_case)
@ -982,8 +986,9 @@ class RDoc::Parser::F95 < RDoc::Parser
if pub_meth["local_name"] if pub_meth["local_name"]
new_meth.name = pub_meth["local_name"] new_meth.name = pub_meth["local_name"]
end end
progress "e"
@stats.num_methods += 1 @stats.add_method new_meth
container.add_method new_meth container.add_method new_meth
end end
} }
@ -1162,13 +1167,6 @@ EOF
nice_lines.shift nice_lines.shift
end end
def progress(char)
unless @options.quiet
@progress.print(char)
@progress.flush
end
end
## ##
# Create method for internal alias # Create method for internal alias
@ -1332,8 +1330,8 @@ EOF
comment) comment)
new_meth.visibility = alias_item["visibility"] new_meth.visibility = alias_item["visibility"]
progress "e" @stats.add_method new_meth
@stats.num_methods += 1
alias_item["file_or_module"].add_method(new_meth) alias_item["file_or_module"].add_method(new_meth)
if !alias_item["file_or_module"].include_requires?(@file_name, @options.ignore_case) if !alias_item["file_or_module"].include_requires?(@file_name, @options.ignore_case)
@ -1368,8 +1366,8 @@ EOF
new_meth.name = alias_item["local_name"] new_meth.name = alias_item["local_name"]
end end
progress "e" @stats.add_method new_meth
@stats.num_methods += 1
alias_item["file_or_module"].add_method new_meth alias_item["file_or_module"].add_method new_meth
end end
} }

View file

@ -1847,8 +1847,6 @@ class RDoc::Parser::Ruby < RDoc::Parser
nest = 0 nest = 0
loop do loop do
puts("Call param: #{tk}, #{@scanner.continue} " +
"#{@scanner.lex_state} #{nest}") if $DEBUG_RDOC
case tk case tk
when TkSEMICOLON when TkSEMICOLON
break break
@ -1872,11 +1870,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
res res
end end
def parse_class(container, single, tk, comment, &block) def parse_class(container, single, tk, comment)
progress("c")
@stats.num_classes += 1
container, name_t = get_class_or_module(container) container, name_t = get_class_or_module(container)
case name_t case name_t
@ -1891,22 +1885,21 @@ class RDoc::Parser::Ruby < RDoc::Parser
superclass = "<unknown>" if superclass.empty? superclass = "<unknown>" if superclass.empty?
end end
if single == SINGLE cls_type = single == SINGLE ? RDoc::SingleClass : RDoc::NormalClass
cls_type = RDoc::SingleClass
else
cls_type = RDoc::NormalClass
end
cls = container.add_class cls_type, name, superclass cls = container.add_class cls_type, name, superclass
@stats.add_class cls
read_documentation_modifiers cls, RDoc::CLASS_MODIFIERS read_documentation_modifiers cls, RDoc::CLASS_MODIFIERS
cls.record_location(@top_level) cls.record_location @top_level
parse_statements(cls)
parse_statements cls
cls.comment = comment cls.comment = comment
when TkLSHFT when TkLSHFT
case name = get_class_specification case name = get_class_specification
when "self", container.name when "self", container.name
parse_statements(container, SINGLE, &block) parse_statements(container, SINGLE)
else else
other = RDoc::TopLevel.find_class_named(name) other = RDoc::TopLevel.find_class_named(name)
unless other unless other
@ -1915,8 +1908,11 @@ class RDoc::Parser::Ruby < RDoc::Parser
# other.comment = comment # other.comment = comment
other = RDoc::NormalClass.new "Dummy", nil other = RDoc::NormalClass.new "Dummy", nil
end end
@stats.add_class other
read_documentation_modifiers other, RDoc::CLASS_MODIFIERS read_documentation_modifiers other, RDoc::CLASS_MODIFIERS
parse_statements(other, SINGLE, &block) parse_statements(other, SINGLE)
end end
else else
@ -1946,9 +1942,6 @@ class RDoc::Parser::Ruby < RDoc::Parser
end end
loop do loop do
puts "Param: %p, %s %s %s" %
[tk.text, @scanner.continue, @scanner.lex_state, nest] if $DEBUG_RDOC
case tk case tk
when TkSEMICOLON when TkSEMICOLON
break break
@ -1982,8 +1975,6 @@ class RDoc::Parser::Ruby < RDoc::Parser
end end
def parse_comment(container, tk, comment) def parse_comment(container, tk, comment)
progress(".")
@stats.num_methods += 1
line_no = tk.line_no line_no = tk.line_no
column = tk.char_no column = tk.char_no
@ -1998,6 +1989,8 @@ class RDoc::Parser::Ruby < RDoc::Parser
meth = RDoc::GhostMethod.new get_tkread, name meth = RDoc::GhostMethod.new get_tkread, name
meth.singleton = singleton meth.singleton = singleton
@stats.add_method meth
meth.start_collecting_tokens meth.start_collecting_tokens
indent = TkSPACE.new 1, 1 indent = TkSPACE.new 1, 1
indent.set_text " " * column indent.set_text " " * column
@ -2030,8 +2023,6 @@ class RDoc::Parser::Ruby < RDoc::Parser
# Parses a meta-programmed method # Parses a meta-programmed method
def parse_meta_method(container, single, tk, comment) def parse_meta_method(container, single, tk, comment)
progress(".")
@stats.num_methods += 1
line_no = tk.line_no line_no = tk.line_no
column = tk.char_no column = tk.char_no
@ -2063,6 +2054,8 @@ class RDoc::Parser::Ruby < RDoc::Parser
meth = RDoc::MetaMethod.new get_tkread, name meth = RDoc::MetaMethod.new get_tkread, name
meth.singleton = singleton meth.singleton = singleton
@stats.add_method meth
remove_token_listener self remove_token_listener self
meth.start_collecting_tokens meth.start_collecting_tokens
@ -2105,8 +2098,6 @@ class RDoc::Parser::Ruby < RDoc::Parser
# Parses a method # Parses a method
def parse_method(container, single, tk, comment) def parse_method(container, single, tk, comment)
progress(".")
@stats.num_methods += 1
line_no = tk.line_no line_no = tk.line_no
column = tk.char_no column = tk.char_no
@ -2175,6 +2166,8 @@ class RDoc::Parser::Ruby < RDoc::Parser
meth.singleton = (single == SINGLE) meth.singleton = (single == SINGLE)
end end
@stats.add_method meth
remove_token_listener self remove_token_listener self
meth.start_collecting_tokens meth.start_collecting_tokens
@ -2239,8 +2232,6 @@ class RDoc::Parser::Ruby < RDoc::Parser
nest = 0 nest = 0
loop do loop do
puts "Param: %p, %s %s %s" %
[tk.text, @scanner.continue, @scanner.lex_state, nest] if $DEBUG_RDOC
case tk case tk
when TkSEMICOLON when TkSEMICOLON
break break
@ -2290,14 +2281,15 @@ class RDoc::Parser::Ruby < RDoc::Parser
end end
def parse_module(container, single, tk, comment) def parse_module(container, single, tk, comment)
progress("m")
@stats.num_modules += 1
container, name_t = get_class_or_module(container) container, name_t = get_class_or_module(container)
# skip_tkspace
name = name_t.name name = name_t.name
mod = container.add_module RDoc::NormalModule, name mod = container.add_module RDoc::NormalModule, name
mod.record_location @top_level mod.record_location @top_level
@stats.add_module mod
read_documentation_modifiers mod, RDoc::CLASS_MODIFIERS read_documentation_modifiers mod, RDoc::CLASS_MODIFIERS
parse_statements(mod) parse_statements(mod)
mod.comment = comment mod.comment = comment
@ -2422,22 +2414,16 @@ class RDoc::Parser::Ruby < RDoc::Parser
when TkUNTIL, TkWHILE then when TkUNTIL, TkWHILE then
nest += 1 nest += 1
puts "Found #{tk.class} in #{container.name}, nest = #{nest}, " +
"line #{tk.line_no}" if $DEBUG_RDOC
skip_optional_do_after_expression skip_optional_do_after_expression
# 'for' is trickier # 'for' is trickier
when TkFOR then when TkFOR then
nest += 1 nest += 1
puts "Found #{tk.class} in #{container.name}, nest = #{nest}, " +
"line #{tk.line_no}" if $DEBUG_RDOC
skip_for_variable skip_for_variable
skip_optional_do_after_expression skip_optional_do_after_expression
when TkCASE, TkDO, TkIF, TkUNLESS, TkBEGIN then when TkCASE, TkDO, TkIF, TkUNLESS, TkBEGIN then
nest += 1 nest += 1
puts "Found #{tk.class} in #{container.name}, nest = #{nest}, " +
"line #{tk.line_no}" if $DEBUG_RDOC
when TkIDENTIFIER then when TkIDENTIFIER then
if nest == 1 and current_method.nil? then if nest == 1 and current_method.nil? then
@ -2470,8 +2456,6 @@ class RDoc::Parser::Ruby < RDoc::Parser
when TkEND then when TkEND then
nest -= 1 nest -= 1
puts "Found 'end' in #{container.name}, nest = #{nest}, line #{tk.line_no}" if $DEBUG_RDOC
puts "Method = #{current_method.name}" if $DEBUG_RDOC and current_method
if nest == 0 then if nest == 0 then
read_documentation_modifiers container, RDoc::CLASS_MODIFIERS read_documentation_modifiers container, RDoc::CLASS_MODIFIERS
container.ongoing_visibility = save_visibility container.ongoing_visibility = save_visibility
@ -2641,13 +2625,6 @@ class RDoc::Parser::Ruby < RDoc::Parser
tk tk
end end
def progress(char)
unless @options.quiet
@progress.print(char)
@progress.flush
end
end
## ##
# Directives are modifier comments that can appear after class, module, or # Directives are modifier comments that can appear after class, module, or
# method names. For example: # method names. For example:
@ -2662,7 +2639,6 @@ class RDoc::Parser::Ruby < RDoc::Parser
def read_directive(allowed) def read_directive(allowed)
tk = get_tk tk = get_tk
puts "directive: #{tk.text.inspect}" if $DEBUG_RDOC
result = nil result = nil
if TkCOMMENT === tk if TkCOMMENT === tk
if tk.text =~ /\s*:?(\w+):\s*(.*)/ if tk.text =~ /\s*:?(\w+):\s*(.*)/
@ -2769,8 +2745,6 @@ The internal error was:
@scanner.instance_eval{@continue = false} @scanner.instance_eval{@continue = false}
loop do loop do
puts("\nWhile: #{tk.text.inspect}, #{@scanner.continue} " \
"#{@scanner.lex_state} #{nest}") if $DEBUG_RDOC
case tk case tk
when TkSEMICOLON when TkSEMICOLON
break break

View file

@ -20,21 +20,24 @@ require 'time'
module RDoc module RDoc
## ##
# Encapsulate the production of rdoc documentation. Basically # Encapsulate the production of rdoc documentation. Basically you can use
# you can use this as you would invoke rdoc from the command # this as you would invoke rdoc from the command line:
# line:
# #
# rdoc = RDoc::RDoc.new # rdoc = RDoc::RDoc.new
# rdoc.document(args) # rdoc.document(args)
# #
# where _args_ is an array of strings, each corresponding to # Where +args+ is an array of strings, each corresponding to an argument
# an argument you'd give rdoc on the command line. See rdoc/rdoc.rb # you'd give rdoc on the command line. See rdoc/rdoc.rb for details.
# for details.
class RDoc class RDoc
Generator = Struct.new(:file_name, :class_name, :key) Generator = Struct.new(:file_name, :class_name, :key)
##
# Accessor for statistics. Available after each call to parse_files
attr_reader :stats
## ##
# This is the list of output generator that we support # This is the list of output generator that we support
@ -57,7 +60,7 @@ module RDoc
end end
def initialize def initialize
@stats = Stats.new @stats = nil
end end
## ##
@ -185,6 +188,8 @@ module RDoc
# Parse each file on the command line, recursively entering directories. # Parse each file on the command line, recursively entering directories.
def parse_files(options) def parse_files(options)
@stats = Stats.new options.verbosity
files = options.files files = options.files
files = ["."] if files.empty? files = ["."] if files.empty?
@ -193,15 +198,14 @@ module RDoc
return [] if file_list.empty? return [] if file_list.empty?
file_info = [] file_info = []
width = file_list.map { |name| name.length }.max + 1
file_list.each do |fn| file_list.each do |filename|
$stderr.printf("\n%*s: ", width, fn) unless options.quiet @stats.add_file filename
content = if RUBY_VERSION >= '1.9' then content = if RUBY_VERSION >= '1.9' then
File.open(fn, "r:ascii-8bit") { |f| f.read } File.open(filename, "r:ascii-8bit") { |f| f.read }
else else
File.read fn File.read filename
end end
if defined? Encoding then if defined? Encoding then
@ -212,12 +216,12 @@ module RDoc
end end
end end
top_level = ::RDoc::TopLevel.new fn top_level = ::RDoc::TopLevel.new filename
parser = ::RDoc::Parser.for top_level, fn, content, options, @stats parser = ::RDoc::Parser.for top_level, filename, content, options,
@stats
file_info << parser.scan file_info << parser.scan
@stats.num_files += 1
end end
file_info file_info

View file

@ -93,8 +93,12 @@ class RDoc::RI::ModuleDescription < RDoc::RI::Description
@comment = old.comment @comment = old.comment
else else
unless old.comment.nil? or old.comment.empty? then unless old.comment.nil? or old.comment.empty? then
@comment << RDoc::Markup::Flow::RULE.new if @comment.nil? or @comment.empty? then
@comment.concat old.comment @comment = old.comment
else
@comment << RDoc::Markup::Flow::RULE.new
@comment.concat old.comment
end
end end
end end
end end

View file

@ -303,6 +303,9 @@ Options may also be set in the 'RI' environment variable.
populate_class_cache class_cache, classes, true populate_class_cache class_cache, classes, true
write_cache class_cache, class_cache_file_path write_cache class_cache, class_cache_file_path
end end
@class_cache = RDoc::RI::Driver::Hash.convert @class_cache
@class_cache
end end
def class_cache_file_path def class_cache_file_path
@ -335,13 +338,13 @@ Options may also be set in the 'RI' environment variable.
if File.exist? path and if File.exist? path and
File.mtime(path) >= File.mtime(class_cache_file_path) then File.mtime(path) >= File.mtime(class_cache_file_path) then
File.open path, 'rb' do |fp| open path, 'rb' do |fp|
cache = Marshal.load fp.read cache = Marshal.load fp.read
end end
else else
class_cache = nil class_cache = nil
File.open class_cache_file_path, 'rb' do |fp| open class_cache_file_path, 'rb' do |fp|
class_cache = Marshal.load fp.read class_cache = Marshal.load fp.read
end end
@ -372,17 +375,34 @@ Options may also be set in the 'RI' environment variable.
RDoc::RI::Driver::Hash.convert cache RDoc::RI::Driver::Hash.convert cache
end end
##
# Finds the next ancestor of +orig_klass+ after +klass+.
def lookup_ancestor(klass, orig_klass)
cache = class_cache[orig_klass]
return nil unless cache
ancestors = [orig_klass]
ancestors.push(*cache.includes.map { |inc| inc['name'] })
ancestors << cache.superclass
ancestor = ancestors[ancestors.index(klass) + 1]
return ancestor if ancestor
lookup_ancestor klass, cache.superclass
end
## ##
# Finds the method # Finds the method
def lookup_method(name, klass) def lookup_method(name, klass)
cache = load_cache_for klass cache = load_cache_for klass
raise NotFoundError, name unless cache return nil unless cache
method = cache[name.gsub('.', '#')] method = cache[name.gsub('.', '#')]
method = cache[name.gsub('.', '::')] unless method method = cache[name.gsub('.', '::')] unless method
raise NotFoundError, name unless method
method method
end end
@ -435,6 +455,8 @@ Options may also be set in the 'RI' environment variable.
desc["class_method_extensions"] = desc.delete "class_methods" desc["class_method_extensions"] = desc.delete "class_methods"
end end
klass = RDoc::RI::Driver::Hash.convert klass
klass.merge_enums desc klass.merge_enums desc
klass["sources"] << cdesc klass["sources"] << cdesc
end end
@ -459,11 +481,25 @@ Options may also be set in the 'RI' environment variable.
if class_cache.key? name then if class_cache.key? name then
display_class name display_class name
else else
meth = nil klass, = parse_name name
klass, meth = parse_name name orig_klass = klass
orig_name = name
method = lookup_method name, klass until klass == 'Kernel' do
method = lookup_method name, klass
break method if method
ancestor = lookup_ancestor klass, orig_klass
break unless ancestor
name = name.sub klass, ancestor
klass = ancestor
end
raise NotFoundError, orig_name unless method
@display.display_method_info method @display.display_method_info method
end end
@ -472,6 +508,7 @@ Options may also be set in the 'RI' environment variable.
display_class name display_class name
else else
methods = select_methods(/^#{name}/) methods = select_methods(/^#{name}/)
if methods.size == 0 if methods.size == 0
raise NotFoundError, name raise NotFoundError, name
elsif methods.size == 1 elsif methods.size == 1

View file

@ -5,11 +5,49 @@ require 'rdoc'
class RDoc::Stats class RDoc::Stats
attr_accessor :num_files, :num_classes, :num_modules, :num_methods attr_reader :num_classes
attr_reader :num_files
attr_reader :num_methods
attr_reader :num_modules
def initialize(verbosity = 1)
@num_classes = 0
@num_files = 0
@num_methods = 0
@num_modules = 0
def initialize
@num_files = @num_classes = @num_modules = @num_methods = 0
@start = Time.now @start = Time.now
@display = case verbosity
when 0 then Quiet.new
when 1 then Normal.new
else Verbose.new
end
end
def add_alias(as)
@display.print_alias as
@num_methods += 1
end
def add_class(klass)
@display.print_class klass
@num_classes += 1
end
def add_file(file)
@display.print_file file
@num_files += 1
end
def add_method(method)
@display.print_method method
@num_methods += 1
end
def add_module(mod)
@display.print_module mod
@num_modules += 1
end end
def print def print
@ -17,7 +55,59 @@ class RDoc::Stats
puts "Classes: #@num_classes" puts "Classes: #@num_classes"
puts "Modules: #@num_modules" puts "Modules: #@num_modules"
puts "Methods: #@num_methods" puts "Methods: #@num_methods"
puts "Elapsed: " + sprintf("%0.3fs", Time.now - @start) puts "Elapsed: " + sprintf("%0.1fs", Time.now - @start)
end
class Quiet
def print_alias(*) end
def print_class(*) end
def print_file(*) end
def print_method(*) end
def print_module(*) end
end
class Normal
def print_alias(as)
print 'a'
end
def print_class(klass)
print 'C'
end
def print_file(file)
print "\n#{file}: "
end
def print_method(method)
print 'm'
end
def print_module(mod)
print 'M'
end
end
class Verbose
def print_alias(as)
puts "\t\talias #{as.new_name} #{as.old_name}"
end
def print_class(klass)
puts "\tclass #{klass.full_name}"
end
def print_file(file)
puts file
end
def print_method(method)
puts "\t\t#{method.singleton ? '::' : '#'}#{method.name}"
end
def print_module(mod)
puts "\tmodule #{mod.full_name}"
end
end end
end end

View file

@ -1,29 +1,25 @@
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib/'
require 'fileutils' require 'fileutils'
require 'tmpdir'
require 'test/unit' require 'test/unit'
require 'rdoc/generator/texinfo' require 'rdoc/generator/texinfo'
require 'yaml'
# From chapter 18 of the Pickaxe 3rd ed. and the TexInfo manual. # From chapter 18 of the Pickaxe 3rd ed. and the TexInfo manual.
class TestRdocInfoFormatting < Test::Unit::TestCase class TestRdocInfoFormatting < Test::Unit::TestCase
OUTPUT_DIR = "/tmp/rdoc-#{$$}"
def setup def setup
# supress stdout @output_dir = File.join Dir.tmpdir, "test_rdoc_info_formatting_#{$$}"
$stdout = File.new('/dev/null','w') @output_file = File.join @output_dir, 'rdoc.texinfo'
$stderr = File.new('/dev/null','w')
RDoc::RDoc.new.document(['--fmt=texinfo', RDoc::RDoc.new.document(['--fmt=texinfo', '--quiet',
File.expand_path(__FILE__), File.expand_path(__FILE__),
"--op=#{OUTPUT_DIR}"]) "--op=#{@output_dir}"])
@text = File.read(OUTPUT_DIR + '/rdoc.texinfo') @text = File.read @output_file
# File.open('rdoc.texinfo', 'w') { |f| f.puts @text } # File.open('rdoc.texinfo', 'w') { |f| f.puts @text }
end end
def teardown def teardown
$stdout = STDOUT FileUtils.rm_rf @output_dir
$stderr = STDERR
FileUtils.rm_rf OUTPUT_DIR
end end
# Make sure tags like *this* do not make HTML # Make sure tags like *this* do not make HTML

View file

@ -76,8 +76,8 @@ class TestRdocInfoSections < Test::Unit::TestCase
# if system "makeinfo --version > /dev/null" # if system "makeinfo --version > /dev/null"
# def test_compiles_to_info # def test_compiles_to_info
# makeinfo_output = `cd #{OUTPUT_DIR} && makeinfo rdoc.texinfo` # makeinfo_output = `cd #{@output_dir} && makeinfo rdoc.texinfo`
# assert(File.exist?(File.join(OUTPUT_DIR, 'rdoc.info')), # assert(File.exist?(File.join(@output_dir, 'rdoc.info')),
# "Info file was not compiled: #{makeinfo_output}") # "Info file was not compiled: #{makeinfo_output}")
# end # end
# end # end

View file

@ -18,10 +18,8 @@ class TestRdocParserC < Test::Unit::TestCase
@top_level = RDoc::TopLevel.new filename @top_level = RDoc::TopLevel.new filename
@fn = filename @fn = filename
@options = RDoc::Options.new Hash.new @options = RDoc::Options.new
@stats = RDoc::Stats.new @stats = RDoc::Stats.new 0
@progress = StringIO.new
end end
def teardown def teardown
@ -253,9 +251,7 @@ Init_Foo(void) {
end end
def util_parser(content) def util_parser(content)
parser = RDoc::Parser::C.new @top_level, @fn, content, @options, @stats RDoc::Parser::C.new @top_level, @fn, content, @options, @stats
parser.progress = @progress
parser
end end
end end

View file

@ -13,11 +13,9 @@ class TestRdocParserRuby < Test::Unit::TestCase
@filename = @tempfile.path @filename = @tempfile.path
util_toplevel util_toplevel
@options = RDoc::Options.new Hash.new @options = RDoc::Options.new
@options.quiet = true @options.quiet = true
@stats = RDoc::Stats.new @stats = RDoc::Stats.new 0
@progress = StringIO.new
end end
def teardown def teardown
@ -132,6 +130,84 @@ class TestRdocParserRuby < Test::Unit::TestCase
assert_equal 'hi', @options.title assert_equal 'hi', @options.title
end end
def test_parse_class
comment = "##\n# my method\n"
util_parser 'class Foo; end'
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 comment, foo.comment
end
def test_parse_class_nested_superclass
foo = RDoc::NormalModule.new 'Foo'
foo.parent = @top_level
util_parser "class Bar < Super\nend"
tk = @parser.get_tk
@parser.parse_class foo, RDoc::Parser::Ruby::NORMAL, tk, ''
bar = foo.classes.first
assert_equal 'Super', bar.superclass
end
def test_parse_comment
content = <<-EOF
class Foo
##
# :method: my_method
# my method comment
end
EOF
klass = RDoc::NormalClass.new 'Foo'
klass.parent = @top_level
comment = "##\n# :method: foo\n# my method\n"
util_parser "\n"
tk = @parser.get_tk
@parser.parse_comment klass, tk, comment
foo = klass.method_list.first
assert_equal 'foo', foo.name
assert_equal comment, foo.comment
assert_equal [], foo.aliases
assert_equal nil, foo.block_params
assert_equal nil, foo.call_seq
assert_equal nil, foo.is_alias_for
assert_equal nil, foo.viewer
assert_equal true, foo.document_children
assert_equal true, foo.document_self
assert_equal '', foo.params
assert_equal false, foo.done_documenting
assert_equal false, foo.dont_rename_initialize
assert_equal false, foo.force_documentation
assert_equal klass, foo.parent
assert_equal false, foo.singleton
assert_equal :public, foo.visibility
assert_equal "\n", foo.text
assert_equal klass.current_section, foo.section
stream = [
tk(:COMMENT, 1, 1, nil, "# File #{@top_level.file_absolute_name}, line 1"),
RDoc::Parser::Ruby::NEWLINE_TOKEN,
tk(:SPACE, 1, 1, nil, ''),
]
assert_equal stream, foo.token_stream
end
def test_parse_meta_method def test_parse_meta_method
klass = RDoc::NormalClass.new 'Foo' klass = RDoc::NormalClass.new 'Foo'
klass.parent = @top_level klass.parent = @top_level
@ -301,54 +377,19 @@ class TestRdocParserRuby < Test::Unit::TestCase
assert_equal stream, foo.token_stream assert_equal stream, foo.token_stream
end end
def test_parse_statements_comment def test_parse_statements_class_nested
content = <<-EOF comment = "##\n# my method\n"
class Foo
##
# :method: my_method
# my method comment
end util_parser "module Foo\n#{comment}class Bar\nend\nend"
EOF
klass = RDoc::NormalClass.new 'Foo'
klass.parent = @top_level
comment = "##\n# :method: foo\n# my method\n" @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, ''
util_parser "\n" foo = @top_level.modules.first
assert_equal 'Foo', foo.full_name, 'module Foo'
tk = @parser.get_tk bar = foo.classes.first
assert_equal 'Foo::Bar', bar.full_name, 'class Foo::Bar'
@parser.parse_comment klass, tk, comment assert_equal comment, bar.comment
foo = klass.method_list.first
assert_equal 'foo', foo.name
assert_equal comment, foo.comment
assert_equal [], foo.aliases
assert_equal nil, foo.block_params
assert_equal nil, foo.call_seq
assert_equal nil, foo.is_alias_for
assert_equal nil, foo.viewer
assert_equal true, foo.document_children
assert_equal true, foo.document_self
assert_equal '', foo.params
assert_equal false, foo.done_documenting
assert_equal false, foo.dont_rename_initialize
assert_equal false, foo.force_documentation
assert_equal klass, foo.parent
assert_equal false, foo.singleton
assert_equal :public, foo.visibility
assert_equal "\n", foo.text
assert_equal klass.current_section, foo.section
stream = [
tk(:COMMENT, 1, 1, nil, "# File #{@top_level.file_absolute_name}, line 1"),
RDoc::Parser::Ruby::NEWLINE_TOKEN,
tk(:SPACE, 1, 1, nil, ''),
]
assert_equal stream, foo.token_stream
end end
def test_parse_statements_identifier_meta_method def test_parse_statements_identifier_meta_method
@ -487,8 +528,6 @@ end
def util_parser(content) def util_parser(content)
@parser = RDoc::Parser::Ruby.new @top_level, @filename, content, @options, @parser = RDoc::Parser::Ruby.new @top_level, @filename, content, @options,
@stats @stats
@parser.progress = @progress
@parser
end end
def util_toplevel def util_toplevel

View file

@ -41,11 +41,7 @@ class TestRDocRIDriver < Test::Unit::TestCase
def test_lookup_method_class_missing def test_lookup_method_class_missing
def @driver.load_cache_for(klassname) end def @driver.load_cache_for(klassname) end
e = assert_raise RDoc::RI::Driver::NotFoundError do assert_nil @driver.lookup_method('Foo#bar', 'Foo')
@driver.lookup_method 'Foo#bar', 'Foo'
end
assert_equal 'Nothing known about Foo#bar', e.message
end end
def test_lookup_method_dot_instance def test_lookup_method_dot_instance
@ -67,11 +63,7 @@ class TestRDocRIDriver < Test::Unit::TestCase
def test_lookup_method_method_missing def test_lookup_method_method_missing
def @driver.load_cache_for(klassname) {} end def @driver.load_cache_for(klassname) {} end
e = assert_raise RDoc::RI::Driver::NotFoundError do assert_nil @driver.lookup_method('Foo#bar', 'Foo')
@driver.lookup_method 'Foo#bar', 'Foo'
end
assert_equal 'Nothing known about Foo#bar', e.message
end end
def test_parse_name def test_parse_name