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

Import RDoc 3.1

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30413 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
drbrain 2010-12-28 22:08:56 +00:00
parent 90d5bcf910
commit e2efe8e81d
28 changed files with 494 additions and 56 deletions

View file

@ -1,3 +1,7 @@
Wed Dec 29 07:07:06 2010 Eric Hodel <drbrain@segment7.net>
* lib/rdoc: Import RDoc 3.1
Tue Dec 28 18:36:38 2010 NAKAMURA Usaku <usa@ruby-lang.org>
* re.c (rb_reg_expr_str): need to escape if the coderage is invalid.

2
NEWS
View file

@ -89,7 +89,7 @@ with all sufficient information, see the ChangeLog file.
* IO.console
* RDoc
* RDoc has been upgraded to RDoc 3.0.1. For full release notes see
* RDoc has been upgraded to RDoc 3.1. For full release notes see
http://rdoc.rubyforge.org/History_txt.html
* rexml

View file

@ -95,7 +95,7 @@ module RDoc
##
# RDoc version you are using
VERSION = '3.0'
VERSION = '3.1'
##
# Method visibilities

View file

@ -118,7 +118,8 @@ class RDoc::ClassModule < RDoc::Context
def comment= comment
return if comment.empty?
comment = "#{@comment}\n---\n#{normalize_comment comment}" unless
comment = normalize_comment comment
comment = "#{@comment}\n---\n#{comment}" unless
@comment.empty?
super

View file

@ -60,8 +60,6 @@ module RDoc::Encoding
# Sets the encoding of +string+ based on the magic comment
def self.set_encoding string
return unless Object.const_defined? :Encoding
first_line = string[/\A(?:#!.*\n)?.*\n/]
name = case first_line
@ -70,6 +68,10 @@ module RDoc::Encoding
else return
end
string.sub! first_line, ''
return unless Object.const_defined? :Encoding
enc = Encoding.find name
string.force_encoding enc if enc
end

View file

@ -63,6 +63,11 @@ class RDoc::Generator::Darkfish
VERSION = '2'
##
# Description of this generator
DESCRIPTION = 'HTML generator, written by Michael Granger'
##
# Initialize a few instance variables before we start

View file

@ -8,6 +8,11 @@ class RDoc::Generator::RI
RDoc::RDoc.add_generator self
##
# Description of this generator
DESCRIPTION = 'creates ri data files'
##
# Set up a new ri generator

View file

@ -134,7 +134,7 @@
<% end %>
<div id="classindex-section" class="section project-section">
<h3 class="section-header">Class Index
<h3 class="section-header">Class/Module Index
<span class="search-toggle"><img src="<%= rel_prefix %>/images/find.png"
height="16" width="16" alt="[+]"
title="show/hide quicksearch" /></span></h3>
@ -225,16 +225,22 @@
<div id="<%= method.html_name %>-method" class="method-detail <%= method.is_alias_for ? "method-alias" : '' %>">
<a name="<%= h method.aref %>"></a>
<div class="method-heading">
<% if method.call_seq %>
<span class="method-callseq"><%= method.call_seq.strip.gsub(/->/, '&rarr;').gsub( /^\w.+\./m, '') %></span>
<% method.call_seq.strip.split("\n").each_with_index do |call_seq, i| %>
<div class="method-heading">
<span class="method-callseq"><%= call_seq.strip.gsub(/->/, '&rarr;').gsub( /^\w.+\./m, '') %></span>
<% if i == 0 %>
<span class="method-click-advice">click to toggle source</span>
<% end %>
</div>
<% end %>
<% else %>
<div class="method-heading">
<span class="method-name"><%= h method.name %></span><span
class="method-args"><%= method.params %></span>
<span class="method-click-advice">click to toggle source</span>
<% end %>
</div>
<% end %>
<div class="method-description">
<% if method.comment %>

View file

@ -26,6 +26,11 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
attr_reader :in_list_entry # :nodoc:
attr_reader :list # :nodoc:
##
# Path to this document for relative links
attr_accessor :from_path
##
# Converts a target url to one that is relative to a given path
@ -59,6 +64,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
@th = nil
@in_list_entry = nil
@list = nil
@from_path = ''
# external hyperlinks
@markup.add_special(/((link:|https?:|mailto:|ftp:|www\.)\S+\w)/, :HYPERLINK)
@ -79,8 +85,8 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
end
##
# Generate a hyperlink for url, labeled with text. Handle the
# special cases for img: and link: described under handle_special_HYPERLINK
# Generate a hyperlink for +url+, labeled with +text+. Handles the special
# cases for img: and link: described under handle_special_HYPERLINK
def gen_url(url, text)
if url =~ /([A-Za-z]+):(.*)/ then

View file

@ -240,6 +240,32 @@ class RDoc::Options
@title ||= string
end
##
# Returns a properly-space list of generators and their descriptions.
def generator_descriptions
lengths = []
generators = RDoc::RDoc::GENERATORS.map do |name, generator|
lengths << name.length
description = generator::DESCRIPTION if
generator.const_defined? :DESCRIPTION
[name, description]
end
longest = lengths.max
generators.sort.map do |name, description|
if description then
" %-*s - %s" % [longest, name, description]
else
" #{name}"
end
end.join "\n"
end
##
# Parse command line options.
@ -274,8 +300,9 @@ Usage: #{opt.program_name} [options] [names...]
will make rdoc show hashes in method links by default. Command-line options
always will override those in RDOCOPT.
- Darkfish creates frameless HTML output by Michael Granger.
- ri creates ri data files
Available formatters:
#{generator_descriptions}
RDoc understands the following file formats:

View file

@ -371,7 +371,7 @@ class RDoc::Parser::C < RDoc::Parser
def find_body(class_name, meth_name, meth_obj, body, quiet = false)
case body
when %r%((?>/\*.*?\*/\s*))
when %r%((?>/\*.*?\*/\s*)?)
((?:(?:static|SWIGINTERN)\s+)?
(?:intern\s+)?VALUE\s+#{meth_name}
\s*(\([^)]*\))([^;]|$))%xm then
@ -547,7 +547,7 @@ class RDoc::Parser::C < RDoc::Parser
# with ARGF at the same indent, but that are after the first description
# paragraph.
if comment =~ /call-seq:(.*?[^\s\*].*?)^\s*\*?\s*$/m then
if comment =~ /call-seq:(.*?(?:\S|\*\/?).*?)^\s*(?:\*\/?)?\s*$/m then
all_start, all_stop = $~.offset(0)
seq_start, seq_stop = $~.offset(1)

View file

@ -224,9 +224,11 @@ class RDoc::Parser::Ruby < RDoc::Parser
##
# Look for a 'call-seq' in the comment, and override the normal parameter
# stuff
#--
# TODO handle undent
def extract_call_seq(comment, meth)
if comment.sub!(/:?call-seq:(.*?)^\s*\#?\s*$/m, '') then
if comment.sub!(/:?call-seq:(.*?)(^\s*#?\s*$|\z)/m, '') then
seq = $1
seq.gsub!(/^\s*\#\s*/, '')
meth.call_seq = seq
@ -779,6 +781,8 @@ class RDoc::Parser::Ruby < RDoc::Parser
@stats.add_attribute att
end
true
end
##
@ -1230,10 +1234,10 @@ class RDoc::Parser::Ruby < RDoc::Parser
if TkCOMMENT === tk then
if non_comment_seen then
# Look for RDoc in a comment about to be thrown away
parse_comment container, tk, comment unless comment.empty?
non_comment_seen = parse_comment container, tk, comment unless
comment.empty?
comment = ''
non_comment_seen = false
end
while TkCOMMENT === tk do
@ -1360,6 +1364,11 @@ class RDoc::Parser::Ruby < RDoc::Parser
return
end
else
non_comment_seen = parse_comment container, tk, comment unless
comment.empty?
comment = ''
end
comment = '' unless keep_comment

View file

@ -610,7 +610,7 @@ Options may also be set in the 'RI' environment variable.
end
if class_methods or instance_methods or not klass.constants.empty? then
out << RDoc::Markup::Rule.new
out << RDoc::Markup::Rule.new(1)
end
unless klass.constants.empty? then

View file

@ -19,7 +19,17 @@ module RDoc::RI::Paths
SYSDIR = File.join base, "system"
SITEDIR = File.join base, "site"
HOMEDIR = File.expand_path('~/.rdoc') rescue nil
homedir = begin
File.expand_path('~')
rescue ArgumentError
end
homedir ||= ENV['HOME'] ||
ENV['USERPROFILE'] || ENV['HOMEPATH'] # for 1.8 compatibility
HOMEDIR = if homedir then
File.join homedir, ".rdoc"
end
#:startdoc:
@gemdirs = nil

View file

@ -541,12 +541,12 @@ class RDoc::RubyLex
catch(:RET) do
if @lex_state == EXPR_ARG
if @space_seen and peek(0) =~ /[0-9]/
throw :RET, identify_number
throw :RET, identify_number(op)
else
@lex_state = EXPR_BEG
end
elsif @lex_state != EXPR_END and peek(0) =~ /[0-9]/
throw :RET, identify_number
throw :RET, identify_number(op)
else
@lex_state = EXPR_BEG
end
@ -1010,10 +1010,10 @@ class RDoc::RubyLex
identify_string(lt, @quoted)
end
def identify_number
def identify_number(op = "")
@lex_state = EXPR_END
num = ''
num = op
if peek(0) == "0" && peek(1) !~ /[.eE]/
num << getc

View file

@ -24,6 +24,7 @@ class RDoc::Stats
@files_so_far = 0
@num_files = num_files
@fully_documented = nil
@percent_doc = nil
@start = Time.now
@ -215,7 +216,9 @@ class RDoc::Stats
report << nil
cm.each_constant do |constant|
next if constant.documented?
# TODO constant aliases are listed in the summary but not reported
# figure out what to do here
next if constant.documented? || constant.is_alias_for
report << " # in file #{constant.file.full_name}"
report << " #{constant.name} = nil"
end
@ -255,22 +258,36 @@ class RDoc::Stats
def summary
calculate
num_width = [@num_files, @num_items].max.to_s.length
nodoc_width = [
@undoc_attributes,
@undoc_classes,
@undoc_constants,
@undoc_items,
@undoc_methods,
@undoc_modules,
].max.to_s.length
report = []
report << 'Files: %5d' % @num_files
report << 'Files: %*d' % [num_width, @num_files]
report << nil
report << 'Classes: %5d (%5d undocumented)' % [@num_classes,
@undoc_classes]
report << 'Modules: %5d (%5d undocumented)' % [@num_modules,
@undoc_modules]
report << 'Constants: %5d (%5d undocumented)' % [@num_constants,
@undoc_constants]
report << 'Attributes: %5d (%5d undocumented)' % [@num_attributes,
@undoc_attributes]
report << 'Methods: %5d (%5d undocumented)' % [@num_methods,
@undoc_methods]
report << 'Classes: %*d (%*d undocumented)' % [
num_width, @num_classes, nodoc_width, @undoc_classes]
report << 'Modules: %*d (%*d undocumented)' % [
num_width, @num_modules, nodoc_width, @undoc_modules]
report << 'Constants: %*d (%*d undocumented)' % [
num_width, @num_constants, nodoc_width, @undoc_constants]
report << 'Attributes: %*d (%*d undocumented)' % [
num_width, @num_attributes, nodoc_width, @undoc_attributes]
report << 'Methods: %*d (%*d undocumented)' % [
num_width, @num_methods, nodoc_width, @undoc_methods]
report << nil
report << 'Total: %5d (%5d undocumented)' % [@num_items,
@undoc_items]
report << 'Total: %*d (%*d undocumented)' % [
num_width, @num_items, nodoc_width, @undoc_items]
report << '%6.2f%% documented' % @percent_doc if @percent_doc
report << nil

View file

@ -53,6 +53,9 @@ require 'rake/tasklib'
#
# Simple Example:
#
# gem 'rdoc'
# require 'rdoc/task'
#
# RDoc::Task.new do |rd|
# rd.main = "README.rdoc"
# rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")
@ -67,6 +70,9 @@ require 'rake/tasklib'
# generating two sets of documentation. For instance, if you want to have a
# development set of documentation including private methods:
#
# gem 'rdoc'
# require 'rdoc/task'
#
# RDoc::Task.new :rdoc_dev do |rd|
# rd.main = "README.doc"
# rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")
@ -82,6 +88,9 @@ require 'rake/tasklib'
#
# For example:
#
# gem 'rdoc'
# require 'rdoc/task'
#
# RDoc::Task.new(:rdoc => "rdoc", :clobber_rdoc => "rdoc:clean",
# :rerdoc => "rdoc:force")
#
@ -116,6 +125,11 @@ class RDoc::Task < Rake::TaskLib
attr_accessor :template
##
# Name of format generator (--fmt) used by rdoc. (defaults to rdoc's default)
attr_accessor :generator
##
# List of files to be included in the rdoc generation. (default is [])
@ -151,11 +165,27 @@ class RDoc::Task < Rake::TaskLib
@main = nil
@title = nil
@template = nil
@generator = nil
@options = []
yield self if block_given?
define
end
##
# All source is inline now. This method is deprecated
def inline_source() # :nodoc:
warn "RDoc::Task#inline_source is deprecated"
true
end
##
# All source is inline now. This method is deprecated
def inline_source=(value) # :nodoc:
warn "RDoc::Task#inline_source is deprecated"
end
##
# Create the tasks defined by this task lib.
@ -201,9 +231,10 @@ class RDoc::Task < Rake::TaskLib
def option_list
result = @options.dup
result << "-o" << @rdoc_dir
result << "--main" << main if main
result << "--title" << title if title
result << "-T" << template if template
result << "--main" << main if main
result << "--title" << title if title
result << "-T" << template if template
result << '-f' << generator if generator
result
end

View file

@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
吾輩(わがはい)は猫である。名前はまだ無い。
どこで生れたかとんと見当(けんとう)がつかぬ。何でも薄暗いじめじめした所でニャーニャー泣いていた事だけは記憶している。吾輩はここで始めて人間というものを見た。しかもあとで聞くとそれは書生という人間中で一番獰悪(どうあく)な種族であったそうだ。この書生というのは時々我々を捕(つかま)えて煮(に)て食うという話である。しかしその当時は何という考もなかったから別段恐しいとも思わなかった。ただ彼の掌(てのひら)に載せられてスーと持ち上げられた時何だかフワフワした感じがあったばかりである。掌の上で少し落ちついて書生の顔を見たのがいわゆる人間というものの見始(みはじめ)であろう。この時妙なものだと思った感じが今でも残っている。第一毛をもって装飾されべきはずの顔がつるつるしてまるで薬缶(やかん)だ。その後(ご)猫にもだいぶ逢(あ)ったがこんな片輪(かたわ)には一度も出会(でく)わした事がない。のみならず顔の真中があまりに突起している。そうしてその穴の中から時々ぷうぷうと煙(けむり)を吹く。どうも咽(む)せぽくて実に弱った。これが人間の飲む煙草(たばこ)というものである事はようやくこの頃知った。

View file

@ -30,7 +30,7 @@ class TestRDocEncoding < MiniTest::Unit::TestCase
expected.gsub!("\n", "\r\n") if RUBY_VERSION =~ /^1.9/ && RUBY_PLATFORM =~ /mswin|mingw/
contents = RDoc::Encoding.read_file @tempfile.path, Encoding::UTF_8
assert_equal expected, contents
assert_equal "hi everybody", contents
assert_equal Encoding::UTF_8, contents.encoding
end
@ -46,7 +46,7 @@ class TestRDocEncoding < MiniTest::Unit::TestCase
contents = RDoc::Encoding.read_file @tempfile.path, Encoding::UTF_8
assert_equal Encoding::UTF_8, contents.encoding
assert_equal "# coding: ISO-8859-1\nhi \u00e9verybody", contents.sub("\r", '')
assert_equal "hi \u00e9verybody", contents.sub("\r", '')
end
def test_class_read_file_encoding_fancy
@ -62,7 +62,7 @@ class TestRDocEncoding < MiniTest::Unit::TestCase
expected.gsub!("\n", "\r\n") if RUBY_VERSION =~ /^1.9/ && RUBY_PLATFORM =~ /win32|mingw32/
contents = RDoc::Encoding.read_file @tempfile.path, Encoding::UTF_8
assert_equal expected, contents
assert_equal "hi everybody", contents
assert_equal Encoding::UTF_8, contents.encoding
end
@ -115,6 +115,20 @@ class TestRDocEncoding < MiniTest::Unit::TestCase
assert_equal Encoding::UTF_8, s.encoding
end
def test_class_set_encoding_strip
s = "# coding: UTF-8\n# more comments"
RDoc::Encoding.set_encoding s
assert_equal "# more comments", s
s = "#!/bin/ruby\n# coding: UTF-8\n# more comments"
RDoc::Encoding.set_encoding s
assert_equal "# more comments", s
end
def test_class_set_encoding_bad
skip "Encoding not implemented" unless Object.const_defined? :Encoding
@ -141,5 +155,12 @@ class TestRDocEncoding < MiniTest::Unit::TestCase
end
end
def test_sanity
skip "Encoding not implemented" unless Object.const_defined? :Encoding
assert_equal Encoding::US_ASCII, ''.encoding,
'If this file is not ASCII tests may incorrectly pass'
end
end

View file

@ -297,6 +297,11 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase
assert_equal '&lt;&gt;', @to.convert_string('<>')
end
def test_gen_url
assert_equal '<a href="example">example</a>',
@to.gen_url('link:example', 'example')
end
def test_list_verbatim_2
str = "* one\n verb1\n verb2\n* two\n"

View file

@ -9,6 +9,11 @@ class TestRDocOptions < MiniTest::Unit::TestCase
def setup
@options = RDoc::Options.new
@generators = RDoc::RDoc::GENERATORS.dup
end
def teardown
RDoc::RDoc::GENERATORS.replace @generators
end
def test_check_files
@ -47,6 +52,20 @@ file 'unreadable' not readable
assert_equal Encoding.default_external, @options.encoding
end
def test_generator_descriptions
# HACK autotest/isolate should take care of this
RDoc::RDoc::GENERATORS.clear
RDoc::RDoc::GENERATORS['darkfish'] = RDoc::Generator::Darkfish
RDoc::RDoc::GENERATORS['ri'] = RDoc::Generator::RI
expected = <<-EXPECTED.chomp
darkfish - HTML generator, written by Michael Granger
ri - creates ri data files
EXPECTED
assert_equal expected, @options.generator_descriptions
end
def test_parse_dash_p
out, err = capture_io do
@options.parse %w[-p]
@ -178,6 +197,27 @@ file 'unreadable' not readable
assert_equal 1, out.scan(/ri generator options:/). length
end
def test_parse_help_extra_generator
RDoc::RDoc::GENERATORS['test'] = Class.new do
def self.setup_options options
op = options.option_parser
op.separator 'test generator options:'
end
end
out, = capture_io do
begin
@options.parse %w[--help]
rescue SystemExit
end
end
assert_equal 1, out.scan(/HTML generator options:/).length
assert_equal 1, out.scan(/ri generator options:/). length
assert_equal 1, out.scan(/test generator options:/).length
end
def test_parse_ignore_invalid
out, err = capture_io do
@options.parse %w[--ignore-invalid --bogus]
@ -278,12 +318,13 @@ file 'unreadable' not readable
end
def test_setup_generator
test_generator = Object.new
def test_generator.setup_options(op)
@op = op
end
test_generator = Class.new do
def self.setup_options op
@op = op
end
def test_generator.op() @op end
def self.op() @op end
end
RDoc::RDoc::GENERATORS['TestGenerator'] = test_generator
@ -293,6 +334,8 @@ file 'unreadable' not readable
assert_equal [test_generator], @options.generator_options
assert_equal @options, test_generator.op
ensure
RDoc::RDoc::GENERATORS.delete 'TestGenerator'
end
end

View file

@ -28,6 +28,11 @@ class TestRDocParser < MiniTest::Unit::TestCase
refute @RP.binary?(file_name)
end
def test_class_binary_large_japanese_rdoc
file_name = File.expand_path '../test.ja.large.rdoc', __FILE__
assert !@RP.binary?(file_name)
end
def test_class_binary_japanese_rdoc
skip "Encoding not implemented" unless Object.const_defined? :Encoding

View file

@ -532,6 +532,46 @@ Init_Foo(void) {
assert_equal "VALUE\nother_function() ", code
end
def test_find_body_2
content = <<-CONTENT
/* Copyright (C) 2010 Sven Herzberg
*
* This file is free software; the author(s) gives unlimited
* permission to copy and/or distribute it, with or without
* modifications, as long as this notice is preserved.
*/
#include <ruby.h>
static VALUE
wrap_initialize (VALUE self)
{
return self;
}
/* */
static VALUE
wrap_shift (VALUE self,
VALUE arg)
{
return self;
}
void
init_gi_repository (void)
{
VALUE mTest = rb_define_module ("Test");
VALUE cTest = rb_define_class_under (mTest, "Test", rb_cObject);
rb_define_method (cTest, "initialize", wrap_initialize, 0);
rb_define_method (cTest, "shift", wrap_shift, 0);
}
CONTENT
klass = util_get_class content, 'cTest'
assert_equal 2, klass.method_list.length
end
def test_find_body_define
content = <<-EOF
/*
@ -633,6 +673,31 @@ commercial(cwyear, cweek=1, cwday=1, sg=nil) -> Date [ruby 1.9]
assert_equal expected, method_obj.call_seq
end
def test_find_modifiers_call_seq_no_blank
comment = <<-COMMENT
/* call-seq:
* commercial() -> Date <br />
* commercial(cwyear, cweek=41, cwday=5, sg=nil) -> Date [ruby 1.8] <br />
* commercial(cwyear, cweek=1, cwday=1, sg=nil) -> Date [ruby 1.9]
*/
COMMENT
parser = util_parser ''
method_obj = RDoc::AnyMethod.new nil, 'blah'
parser.find_modifiers comment, method_obj
expected = <<-CALL_SEQ.chomp
commercial() -> Date <br />
commercial(cwyear, cweek=41, cwday=5, sg=nil) -> Date [ruby 1.8] <br />
commercial(cwyear, cweek=1, cwday=1, sg=nil) -> Date [ruby 1.9]
CALL_SEQ
assert_equal expected, method_obj.call_seq
end
def test_find_modifiers_nodoc
comment = <<-COMMENT
/* :nodoc:

View file

@ -32,6 +32,66 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase
@tempfile2.close
end
def test_extract_call_seq
m = RDoc::AnyMethod.new nil, 'm'
p = util_parser ''
comment = <<-COMMENT
# call-seq:
# bla => true or false
#
# moar comment
COMMENT
p.extract_call_seq comment, m
assert_equal "bla => true or false\n", m.call_seq
end
def test_extract_call_seq_blank
m = RDoc::AnyMethod.new nil, 'm'
p = util_parser ''
comment = <<-COMMENT
# call-seq:
# bla => true or false
#
COMMENT
p.extract_call_seq comment, m
assert_equal "bla => true or false\n", m.call_seq
end
def test_extract_call_seq_no_blank
m = RDoc::AnyMethod.new nil, 'm'
p = util_parser ''
comment = <<-COMMENT
# call-seq:
# bla => true or false
COMMENT
p.extract_call_seq comment, m
assert_equal "bla => true or false\n", m.call_seq
end
def test_extract_call_seq_undent
m = RDoc::AnyMethod.new nil, 'm'
p = util_parser ''
comment = <<-COMMENT
# call-seq:
# bla => true or false
# moar comment
COMMENT
p.extract_call_seq comment, m
assert_equal "bla => true or false\nmoar comment\n", m.call_seq
end
def test_get_symbol_or_name
util_parser "* & | + 5 / 4"
@ -503,6 +563,35 @@ end
assert_equal @top_level, blah.file
end
def test_parse_class_multi_ghost_methods
util_parser <<-'CLASS'
class Foo
##
# :method: one
#
# my method
##
# :method: two
#
# my method
[:one, :two].each do |t|
eval("def #{t}; \"#{t}\"; end")
end
end
CLASS
tk = @parser.get_tk
@parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, ''
foo = @top_level.classes.first
assert_equal 'Foo', foo.full_name
assert_equal 2, foo.method_list.length
end
def test_parse_class_nested_superclass
util_top_level
foo = @top_level.add_module RDoc::NormalModule, 'Foo'

View file

@ -1,11 +1,10 @@
require 'rubygems'
require 'test/unit'
require 'minitest/autorun'
require 'tmpdir'
require 'fileutils'
require 'rdoc/ri/paths'
require_relative '../ruby/envutil'
class TestRDocRIPaths < Test::Unit::TestCase
class TestRDocRIPaths < MiniTest::Unit::TestCase
def setup
RDoc::RI::Paths.instance_variable_set :@gemdirs, %w[/nonexistent/gemdir]
@ -40,9 +39,5 @@ class TestRDocRIPaths < Test::Unit::TestCase
assert_equal '/nonexistent/gemdir', path.shift
end
def test_homeless
bug4202 = '[ruby-core:33867]'
assert(assert_in_out_err([{"HOME"=>nil}, *%w"-rrdoc/ri/paths -e;"], bug4202).success?, bug4202)
end
end

View file

@ -0,0 +1,23 @@
require 'rubygems'
require 'minitest/autorun'
require 'rdoc/rdoc'
require 'rdoc/ruby_lex'
class TestRubyLex < MiniTest::Unit::TestCase
def test_unary_minus
ruby_lex = RDoc::RubyLex.new("-1", nil)
assert_equal("-1", ruby_lex.token.value)
ruby_lex = RDoc::RubyLex.new("a[-2]", nil)
2.times { ruby_lex.token } # skip "a" and "["
assert_equal("-2", ruby_lex.token.value)
ruby_lex = RDoc::RubyLex.new("a[0..-12]", nil)
4.times { ruby_lex.token } # skip "a", "[", "0", and ".."
assert_equal("-12", ruby_lex.token.value)
ruby_lex = RDoc::RubyLex.new("0+-0.1", nil)
2.times { ruby_lex.token } # skip "0" and "+"
assert_equal("-0.1", ruby_lex.token.value)
end
end

View file

@ -0,0 +1,38 @@
require 'rubygems'
require 'minitest/autorun'
require 'rdoc/stats'
require 'rdoc/code_objects'
require 'rdoc/markup'
require 'rdoc/parser'
class TestRDocStats < MiniTest::Unit::TestCase
def setup
RDoc::TopLevel.reset
@s = RDoc::Stats.new 0
end
def test_report_constant_alias
tl = RDoc::TopLevel.new 'fake.rb'
mod = tl.add_module RDoc::NormalModule, 'M'
c = tl.add_class RDoc::NormalClass, 'C'
mod.add_constant c
ca = RDoc::Constant.new 'CA', nil, nil
ca.is_alias_for = c
tl.add_constant ca
RDoc::TopLevel.complete :public
report = @s.report
# TODO change this to refute match, aliases should be ignored as they are
# programmer convenience constructs
assert_match(/class Object/, report)
end
end

View file

@ -8,6 +8,26 @@ class TestRDocTask < MiniTest::Unit::TestCase
Rake::Task.clear
end
def test_inline_source
t = RDoc::Task.new
_, err = capture_io do
assert t.inline_source
end
assert_equal "RDoc::Task#inline_source is deprecated\n", err
_, err = capture_io do
t.inline_source = false
end
assert_equal "RDoc::Task#inline_source is deprecated\n", err
capture_io do
assert t.inline_source
end
end
def test_tasks_creation
RDoc::Task.new
assert Rake::Task[:rdoc]
@ -23,6 +43,14 @@ class TestRDocTask < MiniTest::Unit::TestCase
assert_equal :rdoc_dev, rd.name
end
def test_generator_option
rdoc_task = RDoc::Task.new do |rd|
rd.generator = "ri"
end
assert_equal %w[-o html -f ri], rdoc_task.option_list
end
def test_tasks_creation_with_custom_name_string
rd = RDoc::Task.new("rdoc_dev")
assert Rake::Task[:rdoc_dev]