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

* lib/rdoc.rb: Updated to RDoc 3.6

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31558 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
drbrain 2011-05-14 00:39:16 +00:00
parent fe89874540
commit 0b6da24a5e
28 changed files with 593 additions and 97 deletions

View file

@ -1,3 +1,7 @@
Sat May 14 09:31:43 2011 Eric Hodel <drbrain@segment7.net>
* lib/rdoc.rb: Updated to RDoc 3.6
Sat May 14 07:30:29 2011 Aaron Patterson <aaron@tenderlovemaking.com> Sat May 14 07:30:29 2011 Aaron Patterson <aaron@tenderlovemaking.com>
* ext/psych/lib/psych.rb: released a new gem, so increasing version. * ext/psych/lib/psych.rb: released a new gem, so increasing version.

2
NEWS
View file

@ -108,7 +108,7 @@ with all sufficient information, see the ChangeLog file.
* support for bash/zsh completion. * support for bash/zsh completion.
* RDoc * 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 http://docs.seattlerb.org/rdoc/History_txt.html
* rexml * rexml

View file

@ -3,31 +3,39 @@ $DEBUG_RDOC = nil
# :main: README.txt # :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 # RDoc::RDoc produces documentation for Ruby source files. It works similarly
# produces documentation for one or more Ruby source files. It works similarly # to JavaDoc, parsing the source and extracting the definition for classes,
# to JavaDoc, parsing the source, and extracting the definition for classes, # modules, methods, includes and requires. It associates these with optional
# modules, and methods (along with includes and requires). It associates with # documentation contained in an immediately preceding comment block then
# these optional documentation contained in the immediately preceding comment # renders the result using an output formatter.
# block, and then renders the result using a pluggable output formatter. #
# RDoc::Markup is a library that converts plain text into various output # RDoc::Markup that converts plain text into various output formats. The
# formats. The markup library is used to interpret the comment blocks that # markup library is used to interpret the comment blocks that RDoc uses to
# RDoc uses to document methods, classes, and so on. # 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 # == Roadmap
# #
# * If you want to use RDoc to create documentation for your Ruby source files, # * 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 # see RDoc::Markup and refer to <tt>rdoc --help</tt> for command line
# usage, and RDoc::Markup for a detailed description of RDoc's markup. # usage.
# * If you want to generate documentation for extensions written in C, see # * If you want to generate documentation for extensions written in C, see
# RDoc::Parser::C # 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 drive RDoc programmatically, see RDoc::RDoc.
# * If you want to use the library to format text blocks into HTML, look at # * If you want to use the library to format text blocks into HTML, look at
# RDoc::Markup. # RDoc::Markup.
# * If you want to make an RDoc plugin such as a generator or directive # * If you want to make an RDoc plugin such as a generator or directive
# handler see RDoc::RDoc. # 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 # == Summary
# #
@ -95,7 +103,7 @@ module RDoc
## ##
# RDoc version you are using # RDoc version you are using
VERSION = '3.5.3' VERSION = '3.6'
## ##
# Method visibilities # Method visibilities

View file

@ -68,6 +68,19 @@ class RDoc::Attr < RDoc::MethodAttr
end end
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 # Dumps this Attr for use by ri. See also #marshal_load

View file

@ -137,12 +137,22 @@ class RDoc::ClassModule < RDoc::Context
remove_invisible min_visibility remove_invisible min_visibility
end 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. # Looks for a symbol in the #ancestors. See Context#find_local_symbol.
def find_ancestor_local_symbol symbol def find_ancestor_local_symbol symbol
ancestors.each do |m| each_ancestor do |m|
next if m.is_a?(String)
res = m.find_local_symbol(symbol) res = m.find_local_symbol(symbol)
return res if res return res if res
end end
@ -263,7 +273,7 @@ class RDoc::ClassModule < RDoc::Context
class_module.each_attribute do |attr| class_module.each_attribute do |attr|
if match = attributes.find { |a| a.name == attr.name } then 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 else
add_attribute attr add_attribute attr
end end

View file

@ -180,6 +180,20 @@ class RDoc::CodeObject
@document_children = @document_self @document_children = @document_self
end 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 # Force the documentation of this object unless documentation
# has been turned off by :endoc: # has been turned off by :endoc:

View file

@ -480,7 +480,7 @@ class RDoc::Context < RDoc::CodeObject
# Adds included module +include+ which should be an RDoc::Include # Adds included module +include+ which should be an RDoc::Include
def add_include(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 end
## ##
@ -950,10 +950,14 @@ class RDoc::Context < RDoc::CodeObject
## ##
# Yields AnyMethod and Attr entries matching the list of names in +methods+. # 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| (@method_list + @attributes).each do |m|
yield m if methods.include?(m.name) and m.singleton == singleton yield m if methods.include?(m.name) and m.singleton == singleton
end end
each_ancestor do |parent|
parent.methods_matching(methods, singleton, &block)
end
end end
## ##
@ -1021,11 +1025,19 @@ class RDoc::Context < RDoc::CodeObject
remove_invisible_in @attributes, min_visibility remove_invisible_in @attributes, min_visibility
end end
##
# Only called when min_visibility == :public or :private
def remove_invisible_in(array, min_visibility) # :nodoc: def remove_invisible_in(array, min_visibility) # :nodoc:
if min_visibility == :public if min_visibility == :public
array.reject! { |e| e.visibility != :public } array.reject! { |e|
e.visibility != :public and not e.force_documentation
}
else else
array.reject! { |e| e.visibility == :private } array.reject! { |e|
e.visibility == :private and
not e.force_documentation
}
end end
end end

View file

@ -333,6 +333,8 @@ class RDoc::MethodAttr < RDoc::CodeObject
def inspect # :nodoc: def inspect # :nodoc:
alias_for = @is_alias_for ? " (alias for #{@is_alias_for.name})" : nil 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:0x%x %s (%s)%s>" % [
self.class, object_id, self.class, object_id,
full_name, full_name,

View file

@ -256,7 +256,9 @@ class RDoc::Options
@rdoc_include << "." if @rdoc_include.empty? @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 @exclude = nil
else else
@exclude = Regexp.new(@exclude.join("|")) @exclude = Regexp.new(@exclude.join("|"))

View file

@ -376,7 +376,7 @@ class RDoc::Parser::C < RDoc::Parser
when %r%((?>/\*.*?\*/\s*)?) when %r%((?>/\*.*?\*/\s*)?)
((?:(?:static|SWIGINTERN)\s+)? ((?:(?:static|SWIGINTERN)\s+)?
(?:intern\s+)?VALUE\s+#{meth_name} (?:intern\s+)?VALUE\s+#{meth_name}
\s*(\(.*?\))([^;]|$))%xm then \s*(\([^)]*\))([^;]|$))%xm then
comment = $1 comment = $1
body = $2 body = $2
offset = $~.offset(2).first offset = $~.offset(2).first

View file

@ -1558,32 +1558,45 @@ class RDoc::Parser::Ruby < RDoc::Parser
when TkNL, TkUNLESS_MOD, TkIF_MOD, TkSEMICOLON then when TkNL, TkUNLESS_MOD, TkIF_MOD, TkSEMICOLON then
container.ongoing_visibility = vis container.ongoing_visibility = vis
else else
if vis_type == 'module_function' then new_methods = []
case vis_type
when 'module_function' then
args = parse_symbol_arg args = parse_symbol_arg
container.set_visibility_for args, :private, false container.set_visibility_for args, :private, false
module_functions = []
container.methods_matching args do |m| container.methods_matching args do |m|
s_m = m.dup s_m = m.dup
s_m.record_location @top_level s_m.record_location @top_level
s_m.singleton = true s_m.singleton = true
s_m.visibility = :public new_methods << s_m
module_functions << s_m
end end
when 'public_class_method', 'private_class_method' then
args = parse_symbol_arg
module_functions.each do |s_m| container.methods_matching args, true do |m|
case s_m if m.parent != container then
when RDoc::AnyMethod then m = m.dup
container.add_method s_m m.record_location @top_level
when RDoc::Attr then new_methods << m
container.add_attribute s_m
end end
m.visibility = vis
end end
else else
args = parse_symbol_arg args = parse_symbol_arg
container.set_visibility_for args, vis, singleton container.set_visibility_for args, vis, singleton
end 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
end end

View file

@ -418,7 +418,7 @@ The internal error was:
@last_modified = setup_output_dir @options.op_dir, @options.force_update @last_modified = setup_output_dir @options.op_dir, @options.force_update
end end
start_time = Time.now @start_time = Time.now
file_info = parse_files @options.files file_info = parse_files @options.files
@ -439,20 +439,7 @@ The internal error was:
@generator = gen_klass.new @options @generator = gen_klass.new @options
Dir.chdir @options.op_dir do generate file_info
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
end end
if @stats and (@options.coverage_report or not @options.quiet) then if @stats and (@options.coverage_report or not @options.quiet) then
@ -463,6 +450,28 @@ The internal error was:
exit @stats.fully_documented? if @options.coverage_report exit @stats.fully_documented? if @options.coverage_report
end 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 # Removes a siginfo handler and replaces the previous

View file

@ -197,6 +197,13 @@ Options may also be set in the 'RI' environment variable.
opt.separator nil opt.separator nil
opt.on("--list", "-l",
"List classes ri knows about.") do
options[:list] = true
end
opt.separator nil
opt.on("--[no-]profile", opt.on("--[no-]profile",
"Run with the ruby profiler") do |value| "Run with the ruby profiler") do |value|
options[:profile] = value options[:profile] = value
@ -331,6 +338,7 @@ Options may also be set in the 'RI' environment variable.
require 'profile' if options[:profile] require 'profile' if options[:profile]
@names = options[:names] @names = options[:names]
@list = options[:list]
@doc_dirs = [] @doc_dirs = []
@stores = [] @stores = []
@ -524,7 +532,10 @@ Options may also be set in the 'RI' environment variable.
klass_name = method ? name : klass klass_name = method ? name : klass
if name !~ /#|\./ then 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 elsif selector then
completions << klass if classes.key? klass completions << klass if classes.key? klass
elsif classes.key? klass_name then elsif classes.key? klass_name then
@ -546,7 +557,7 @@ Options may also be set in the 'RI' environment variable.
completions.push(*methods) completions.push(*methods)
end end
completions.sort completions.sort.uniq
end end
## ##
@ -878,9 +889,10 @@ Options may also be set in the 'RI' environment variable.
end 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 = [] classes = []
stores.each do |store| stores.each do |store|
@ -889,9 +901,19 @@ Options may also be set in the 'RI' environment variable.
classes = classes.flatten.uniq.sort classes = classes.flatten.uniq.sort
unless names.empty? then
filter = Regexp.union names.map { |name| /^#{name}/ }
classes = classes.grep filter
end
page do |io| page do |io|
if paging? or io.tty? then 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 io.puts
end end
@ -910,7 +932,7 @@ Options may also be set in the 'RI' environment variable.
methods = store.instance_methods[ancestor] methods = store.instance_methods[ancestor]
if methods then if methods then
matches = methods.grep(/^#{method}/) matches = methods.grep(/^#{Regexp.escape method.to_s}/)
matches = matches.map do |match| matches = matches.map do |match|
"#{klass}##{match}" "#{klass}##{match}"
@ -924,7 +946,7 @@ Options may also be set in the 'RI' environment variable.
methods = store.class_methods[ancestor] methods = store.class_methods[ancestor]
next unless methods next unless methods
matches = methods.grep(/^#{method}/) matches = methods.grep(/^#{Regexp.escape method.to_s}/)
matches = matches.map do |match| matches = matches.map do |match|
"#{klass}::#{match}" "#{klass}::#{match}"
@ -996,9 +1018,9 @@ Options may also be set in the 'RI' environment variable.
case type case type
when '#', '::' then when '#', '::' then
/^#{klass}#{type}#{name}$/ /^#{klass}#{type}#{Regexp.escape name}$/
else else
/^#{klass}(#|::)#{name}$/ /^#{klass}(#|::)#{Regexp.escape name}$/
end end
end end
@ -1064,10 +1086,10 @@ Options may also be set in the 'RI' environment variable.
def run def run
if @list_doc_dirs then if @list_doc_dirs then
puts @doc_dirs puts @doc_dirs
elsif @interactive then elsif @list then
list_known_classes @names
elsif @interactive or @names.empty? then
interactive interactive
elsif @names.empty? then
list_known_classes
else else
display_names @names display_names @names
end end

View file

@ -7,6 +7,18 @@ require 'fileutils'
# The store manages reading and writing ri data for a project (gem, path, # 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 # etc.) and maintains a cache of methods, classes and ancestors in the
# store. # 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 class RDoc::RI::Store

View file

@ -403,9 +403,11 @@ class RDoc::RubyLex
res = '' res = ''
nil until (ch = getc) == "\n" nil until (ch = getc) == "\n"
until peek_equal?("=end") && peek(4) =~ /\s/ do until ( peek_equal?("=end") && peek(4) =~ /\s/ ) do
until (ch = getc) == "\n" do res << ch end (ch = getc)
res << ch
end end
gets # consume =end gets # consume =end
@ltype = nil @ltype = nil

View file

@ -31,7 +31,7 @@ class RDoc::Stats
@coverage_level = 0 @coverage_level = 0
@doc_items = nil @doc_items = nil
@fully_documented = nil @fully_documented = false
@num_params = 0 @num_params = 0
@percent_doc = nil @percent_doc = nil
@start = Time.now @start = Time.now

View file

@ -37,9 +37,8 @@ require 'rake'
require 'rake/tasklib' 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] # [rdoc]
# Main task for this RDoc task. # Main task for this RDoc task.
@ -56,12 +55,12 @@ require 'rake/tasklib'
# gem 'rdoc' # gem 'rdoc'
# require 'rdoc/task' # require 'rdoc/task'
# #
# RDoc::Task.new do |rd| # RDoc::Task.new do |rdoc|
# rd.main = "README.rdoc" # rdoc.main = "README.rdoc"
# rd.rdoc_files.include("README.rdoc", "lib/**/*.rb") # rdoc.rdoc_files.include("README.rdoc", "lib/**/*.rb")
# end # 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. # attributes list for the RDoc::Task class for available customization options.
# #
# == Specifying different task names # == Specifying different task names
@ -73,10 +72,10 @@ require 'rake/tasklib'
# gem 'rdoc' # gem 'rdoc'
# require 'rdoc/task' # require 'rdoc/task'
# #
# RDoc::Task.new :rdoc_dev do |rd| # RDoc::Task.new :rdoc_dev do |rdoc|
# rd.main = "README.doc" # rdoc.main = "README.doc"
# rd.rdoc_files.include("README.rdoc", "lib/**/*.rb") # rdoc.rdoc_files.include("README.rdoc", "lib/**/*.rb")
# rd.options << "--all" # rdoc.options << "--all"
# end # end
# #
# The tasks would then be named :<em>rdoc_dev</em>, # The tasks would then be named :<em>rdoc_dev</em>,

View file

@ -61,25 +61,17 @@ module RDoc::Text
# Flush +text+ left based on the shortest line # Flush +text+ left based on the shortest line
def flush_left text def flush_left text
indents = [] indent = 9999
text.each_line do |line| text.each_line do |line|
indents << (line =~ /[^\s]/ || 9999) line_indent = line =~ /\S/ || 9999
indent = line_indent if indent > line_indent
end end
indent = indents.min
flush = []
empty = '' empty = ''
empty.force_encoding text.encoding if Object.const_defined? :Encoding empty.force_encoding text.encoding if Object.const_defined? :Encoding
text.each_line do |line| text.gsub(/^ {0,#{indent}}/, empty)
line[/^ {0,#{indent}}/] = empty
flush << line
end
flush.join
end end
## ##

View file

@ -8,6 +8,10 @@ class TestRDocClassModule < XrefTestCase
@RM = RDoc::Markup @RM = RDoc::Markup
end end
def test_ancestors
assert_equal [@parent], @child.ancestors
end
def test_comment_equals def test_comment_equals
cm = RDoc::ClassModule.new 'Klass' cm = RDoc::ClassModule.new 'Klass'
cm.comment = '# comment 1' cm.comment = '# comment 1'
@ -23,6 +27,16 @@ class TestRDocClassModule < XrefTestCase
assert_equal "comment 1\n---\ncomment 2\n---\n* comment 3", cm.comment assert_equal "comment 1\n---\ncomment 2\n---\n* comment 3", cm.comment
end 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 # handle making a short module alias of yourself
def test_find_class_named def test_find_class_named
@ -36,6 +50,7 @@ class TestRDocClassModule < XrefTestCase
cm1.comment = 'klass 1' cm1.comment = 'klass 1'
cm1.add_attribute RDoc::Attr.new(nil, 'a1', 'RW', '') 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, 'a3', 'R', '')
cm1.add_attribute RDoc::Attr.new(nil, 'a4', 'R', '')
cm1.add_constant RDoc::Constant.new('C1', nil, '') cm1.add_constant RDoc::Constant.new('C1', nil, '')
cm1.add_include RDoc::Include.new('I1', '') cm1.add_include RDoc::Include.new('I1', '')
cm1.add_method RDoc::AnyMethod.new(nil, 'm1') cm1.add_method RDoc::AnyMethod.new(nil, 'm1')
@ -46,6 +61,7 @@ class TestRDocClassModule < XrefTestCase
@RM::Paragraph.new('klass 2'))) @RM::Paragraph.new('klass 2')))
cm2.add_attribute RDoc::Attr.new(nil, 'a2', 'RW', '') 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, 'a3', 'W', '')
cm2.add_attribute RDoc::Attr.new(nil, 'a4', 'R', '')
cm2.add_constant RDoc::Constant.new('C2', nil, '') cm2.add_constant RDoc::Constant.new('C2', nil, '')
cm2.add_include RDoc::Include.new('I2', '') cm2.add_include RDoc::Include.new('I2', '')
cm2.add_method RDoc::AnyMethod.new(nil, 'm2') cm2.add_method RDoc::AnyMethod.new(nil, 'm2')
@ -62,6 +78,7 @@ class TestRDocClassModule < XrefTestCase
RDoc::Attr.new(nil, 'a1', 'RW', ''), RDoc::Attr.new(nil, 'a1', 'RW', ''),
RDoc::Attr.new(nil, 'a2', 'RW', ''), RDoc::Attr.new(nil, 'a2', 'RW', ''),
RDoc::Attr.new(nil, 'a3', 'RW', ''), RDoc::Attr.new(nil, 'a3', 'RW', ''),
RDoc::Attr.new(nil, 'a4', 'R', ''),
] ]
expected.each do |a| a.parent = cm1 end expected.each do |a| a.parent = cm1 end

View file

@ -119,6 +119,16 @@ class TestRDocCodeObject < XrefTestCase
assert @co.document_children assert @co.document_children
end 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 def test_full_name_equals
@co.full_name = 'hi' @co.full_name = 'hi'

View file

@ -143,6 +143,16 @@ class TestRDocContext < XrefTestCase
assert_equal [incl], @context.includes assert_equal [incl], @context.includes
end 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 def test_add_method
meth = RDoc::AnyMethod.new nil, 'old_name' meth = RDoc::AnyMethod.new nil, 'old_name'
meth.visibility = nil meth.visibility = nil
@ -438,5 +448,146 @@ class TestRDocContext < XrefTestCase
assert_equal expected, @c1.methods_by_type(separate) assert_equal expected, @c1.methods_by_type(separate)
end 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 end

View file

@ -625,6 +625,25 @@ for all good men
assert_equal expected, @RMP.parse(str).parts assert_equal expected, @RMP.parse(str).parts
end 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 def test_parse_ualpha
str = <<-STR str = <<-STR
A. l1 A. l1

View file

@ -680,7 +680,7 @@ Init_Foo(void) {
baz = methods.last baz = methods.last
assert_equal 'Foo#baz', baz.full_name assert_equal 'Foo#baz', baz.full_name
assert_equal "a comment for bar", bar.comment assert_equal "a comment for bar", baz.comment
end end
def test_find_modifiers_call_seq def test_find_modifiers_call_seq
@ -911,6 +911,37 @@ rb_io_s_read(argc, argv, 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_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 void
Init_IO(void) { Init_IO(void) {
/* /*

View file

@ -1799,6 +1799,56 @@ EOF
assert_equal :private, foo.visibility assert_equal :private, foo.visibility
end 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 def test_parse_statements_identifier_require
content = "require 'bar'" content = "require 'bar'"
@ -1978,6 +2028,53 @@ end
assert_equal 'm comment', m.comment assert_equal 'm comment', m.comment
end 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 def test_scan_meta_method_block
content = <<-CONTENT content = <<-CONTENT
class C class C

View file

@ -3,6 +3,7 @@ require 'rubygems'
require 'minitest/autorun' require 'minitest/autorun'
require 'tmpdir' require 'tmpdir'
require 'fileutils' require 'fileutils'
require 'stringio'
require 'rdoc/ri/driver' require 'rdoc/ri/driver'
class TestRDocRIDriver < MiniTest::Unit::TestCase class TestRDocRIDriver < MiniTest::Unit::TestCase
@ -249,12 +250,14 @@ class TestRDocRIDriver < MiniTest::Unit::TestCase
@driver.stores = [store] @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::B')
assert_equal %w[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 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 end
def test_complete_ancestor def test_complete_ancestor
@ -269,7 +272,7 @@ class TestRDocRIDriver < MiniTest::Unit::TestCase
def test_complete_classes def test_complete_classes
util_store 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:: Foo::Bar Foo::Baz], @driver.complete('Foo::')
assert_equal %w[ Foo::Bar Foo::Baz], @driver.complete('Foo::B') assert_equal %w[ Foo::Bar Foo::Baz], @driver.complete('Foo::B')
end end
@ -278,7 +281,8 @@ class TestRDocRIDriver < MiniTest::Unit::TestCase
util_multi_store util_multi_store
assert_equal %w[Bar], @driver.complete('B') 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 end
def test_display def test_display
@ -572,11 +576,18 @@ Foo::Bar#bother
def test_name_regexp def test_name_regexp
assert_equal %r%^RDoc::AnyMethod#new$%, assert_equal %r%^RDoc::AnyMethod#new$%,
@driver.name_regexp('RDoc::AnyMethod#new') @driver.name_regexp('RDoc::AnyMethod#new')
assert_equal %r%^RDoc::AnyMethod::new$%, assert_equal %r%^RDoc::AnyMethod::new$%,
@driver.name_regexp('RDoc::AnyMethod::new') @driver.name_regexp('RDoc::AnyMethod::new')
assert_equal %r%^RDoc::AnyMethod(#|::)new$%, assert_equal %r%^RDoc::AnyMethod(#|::)new$%,
@driver.name_regexp('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 end
def test_list_known_classes def test_list_known_classes
@ -589,6 +600,16 @@ Foo::Bar#bother
assert_equal "Ambiguous\nFoo\nFoo::Bar\nFoo::Baz\nInc\n", out assert_equal "Ambiguous\nFoo\nFoo::Bar\nFoo::Baz\nInc\n", out
end 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 def test_list_methods_matching
util_store util_store
@ -596,6 +617,24 @@ Foo::Bar#bother
@driver.list_methods_matching('Foo::Bar.') @driver.list_methods_matching('Foo::Bar.')
end 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 def test_load_method
util_store util_store

View file

@ -12,7 +12,10 @@ class TestRDocTopLevel < XrefTestCase
def test_class_all_classes_and_modules def test_class_all_classes_and_modules
expected = %w[ 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, assert_equal expected,
@ -22,6 +25,7 @@ class TestRDocTopLevel < XrefTestCase
def test_class_classes def test_class_classes
expected = %w[ expected = %w[
C1 C2 C2::C3 C2::C3::H1 C3 C3::H1 C3::H2 C4 C4::C4 C5 C5::C1 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 assert_equal expected, RDoc::TopLevel.classes.map { |m| m.full_name }.sort

View file

@ -63,5 +63,14 @@ end
module M1::M2 module M1::M2
end end
class Parent
def m() end
def self.m() end
end
class Child < Parent
end
XREF_DATA XREF_DATA

View file

@ -38,7 +38,6 @@ class XrefTestCase < MiniTest::Unit::TestCase
@c1_m = @c1.method_list.last # C1#m @c1_m = @c1.method_list.last # C1#m
@c1__m = @c1.method_list.first # C1::m @c1__m = @c1.method_list.first # C1::m
@c2 = @xref_data.find_module_named 'C2' @c2 = @xref_data.find_module_named 'C2'
@c2_a = @c2.method_list.last @c2_a = @c2.method_list.last
@c2_b = @c2.method_list.first @c2_b = @c2.method_list.first
@ -55,6 +54,12 @@ class XrefTestCase < MiniTest::Unit::TestCase
@m1_m = @m1.method_list.first @m1_m = @m1.method_list.first
@m1_m2 = @xref_data.find_module_named 'M1::M2' @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
end end