* lib/rdoc.rb, lib/rdoc, test/rdoc: Update to RDoc 4.2.0.alpha(313287)

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47391 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
hsbt 2014-09-05 01:41:25 +00:00
parent 670c6e8ce9
commit d42d6e690e
56 changed files with 1597 additions and 223 deletions

View File

@ -1,3 +1,7 @@
Fri Sep 5 10:39:14 2014 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
* lib/rdoc.rb, lib/rdoc, test/rdoc: Update to RDoc 4.2.0.alpha(313287)
Fri Sep 5 06:04:22 2014 Eric Wong <e@80x24.org>
* vm.c: remove unused USE_THREAD_RECYCLE [misc #10198]

View File

@ -64,7 +64,7 @@ module RDoc
##
# RDoc version you are using
VERSION = '4.1.0'
VERSION = '4.2.0.alpha'
##
# Method visibilities
@ -151,6 +151,8 @@ module RDoc
autoload :Comment, 'rdoc/comment'
autoload :I18n, 'rdoc/i18n'
# code objects
#
# We represent the various high-level code constructs that appear in Ruby

View File

@ -240,7 +240,15 @@ class RDoc::AnyMethod < RDoc::MethodAttr
return []
end
params = params.gsub(/\s+/, '').split ','
if @block_params then
# If this method has explicit block parameters, remove any explicit
# &block
params.sub!(/,?\s*&\w+/, '')
else
params.sub!(/\&(\w+)/, '\1')
end
params = params.gsub(/\s+/, '').split(',').reject(&:empty?)
params.map { |param| param.sub(/=.*/, '') }
end

View File

@ -164,6 +164,8 @@ class RDoc::Context < RDoc::CodeObject
# Contexts are sorted by full_name
def <=>(other)
return nil unless RDoc::CodeObject === other
full_name <=> other.full_name
end
@ -321,10 +323,11 @@ class RDoc::Context < RDoc::CodeObject
end
# fix up superclass
superclass = nil if full_name == 'BasicObject'
superclass = nil if full_name == 'Object' and defined?(::BasicObject)
superclass = '::BasicObject' if
defined?(::BasicObject) and full_name == 'Object'
if full_name == 'BasicObject' then
superclass = nil
elsif full_name == 'Object' then
superclass = defined?(::BasicObject) ? '::BasicObject' : nil
end
# find the superclass full name
if superclass then

View File

@ -29,7 +29,9 @@ module RDoc::Encoding
encoding ||= Encoding.default_external
orig_encoding = content.encoding
if utf8 then
if not orig_encoding.ascii_compatible? then
content.encode! encoding
elsif utf8 then
content.force_encoding Encoding::UTF_8
content.encode! encoding
else

View File

@ -45,6 +45,7 @@ module RDoc::Generator
autoload :Darkfish, 'rdoc/generator/darkfish'
autoload :JsonIndex, 'rdoc/generator/json_index'
autoload :RI, 'rdoc/generator/ri'
autoload :POT, 'rdoc/generator/pot'
end

97
lib/rdoc/generator/pot.rb Normal file
View File

@ -0,0 +1,97 @@
##
# Generates a POT file.
#
# Here is a translator work flow with the generator.
#
# == Create .pot
#
# You create .pot file by pot formatter:
#
# % rdoc --format pot
#
# It generates doc/rdoc.pot.
#
# == Create .po
#
# You create .po file from doc/rdoc.pot. This operation is needed only
# the first time. This work flow assumes that you are a translator
# for Japanese.
#
# You create locale/ja/rdoc.po from doc/rdoc.pot. You can use msginit
# provided by GNU gettext or rmsginit provided by gettext gem. This
# work flow uses gettext gem because it is more portable than GNU
# gettext for Rubyists. Gettext gem is implemented by pure Ruby.
#
# % gem install gettext
# % mkdir -p locale/ja
# % rmsginit --input doc/rdoc.pot --output locale/ja/rdoc.po --locale ja
#
# Translate messages in .po
#
# You translate messages in .po by a PO file editor. po-mode.el exists
# for Emacs users. There are some GUI tools such as GTranslator.
# There are some Web services such as POEditor and Tansifex. You can
# edit by your favorite text editor because .po is a text file.
# Generate localized documentation
#
# You can generate localized documentation with locale/ja/rdoc.po:
#
# % rdoc --locale ja
#
# You can find documentation in Japanese in doc/. Yay!
#
# == Update translation
#
# You need to update translation when your application is added or
# modified messages.
#
# You can update .po by the following command lines:
#
# % rdoc --format pot
# % rmsgmerge --update locale/ja/rdoc.po doc/rdoc.pot
#
# You edit locale/ja/rdoc.po to translate new messages.
class RDoc::Generator::POT
RDoc::RDoc.add_generator self
##
# Description of this generator
DESCRIPTION = 'creates .pot file'
##
# Set up a new .pot generator
def initialize store, options #:not-new:
@options = options
@store = store
end
##
# Writes .pot to disk.
def generate
po = extract_messages
pot_path = 'rdoc.pot'
File.open(pot_path, "w") do |pot|
pot.print(po.to_s)
end
end
def class_dir
nil
end
private
def extract_messages
extractor = MessageExtractor.new(@store)
extractor.extract
end
autoload :MessageExtractor, 'rdoc/generator/pot/message_extractor'
autoload :PO, 'rdoc/generator/pot/po'
autoload :POEntry, 'rdoc/generator/pot/po_entry'
end

View File

@ -0,0 +1,67 @@
##
# Extracts message from RDoc::Store
class RDoc::Generator::POT::MessageExtractor
##
# Creates a message extractor for +store+.
def initialize store
@store = store
@po = RDoc::Generator::POT::PO.new
end
##
# Extracts messages from +store+, stores them into
# RDoc::Generator::POT::PO and returns it.
def extract
@store.all_classes_and_modules.each do |klass|
extract_from_klass(klass)
end
@po
end
private
def extract_from_klass klass
extract_text(klass.comment_location, klass.full_name)
klass.each_section do |section, constants, attributes|
extract_text(section.title ,"#{klass.full_name}: section title")
section.comments.each do |comment|
extract_text(comment, "#{klass.full_name}: #{section.title}")
end
end
klass.each_constant do |constant|
extract_text(constant.comment, constant.full_name)
end
klass.each_attribute do |attribute|
extract_text(attribute.comment, attribute.full_name)
end
klass.each_method do |method|
extract_text(method.comment, method.full_name)
end
end
def extract_text text, comment, location = nil
return if text.nil?
options = {
:extracted_comment => comment,
:references => [location].compact,
}
i18n_text = RDoc::I18n::Text.new(text)
i18n_text.extract_messages do |part|
@po.add(entry(part[:paragraph], options))
end
end
def entry msgid, options
RDoc::Generator::POT::POEntry.new(msgid, options)
end
end

View File

@ -0,0 +1,84 @@
##
# Generates a PO format text
class RDoc::Generator::POT::PO
##
# Creates an object that represents PO format.
def initialize
@entries = {}
add_header
end
##
# Adds a PO entry to the PO.
def add entry
existing_entry = @entries[entry.msgid]
if existing_entry
entry = existing_entry.merge(entry)
end
@entries[entry.msgid] = entry
end
##
# Returns PO format text for the PO.
def to_s
po = ''
sort_entries.each do |entry|
po << "\n" unless po.empty?
po << entry.to_s
end
po
end
private
def add_header
add(header_entry)
end
def header_entry
comment = <<-COMMENT
SOME DESCRIPTIVE TITLE.
Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
This file is distributed under the same license as the PACKAGE package.
FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
COMMENT
content = <<-CONTENT
Project-Id-Version: PACKAGE VERSEION
Report-Msgid-Bugs-To:
PO-Revision-Date: YEAR-MO_DA HO:MI+ZONE
Last-Translator: FULL NAME <EMAIL@ADDRESS>
Language-Team: LANGUAGE <LL@li.org>
Language:
MIME-Version: 1.0
Content-Type: text/plain; charset=CHARSET
Content-Transfer-Encoding: 8bit
Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;
CONTENT
options = {
:msgstr => content,
:translator_comment => comment,
:flags => ['fuzzy'],
}
RDoc::Generator::POT::POEntry.new('', options)
end
def sort_entries
headers, messages = @entries.values.partition do |entry|
entry.msgid.empty?
end
# TODO: sort by location
sorted_messages = messages.sort_by do |entry|
entry.msgid
end
headers + sorted_messages
end
end

View File

@ -0,0 +1,140 @@
##
# A PO entry in PO
class RDoc::Generator::POT::POEntry
# The msgid content
attr_reader :msgid
# The msgstr content
attr_reader :msgstr
# The comment content created by translator (PO editor)
attr_reader :translator_comment
# The comment content extracted from source file
attr_reader :extracted_comment
# The locations where the PO entry is extracted
attr_reader :references
# The flags of the PO entry
attr_reader :flags
##
# Creates a PO entry for +msgid+. Other valus can be specified by
# +options+.
def initialize msgid, options = {}
@msgid = msgid
@msgstr = options[:msgstr] || ""
@translator_comment = options[:translator_comment]
@extracted_comment = options[:extracted_comment]
@references = options[:references] || []
@flags = options[:flags] || []
end
##
# Returns the PO entry in PO format.
def to_s
entry = ''
entry << format_translator_comment
entry << format_extracted_comment
entry << format_references
entry << format_flags
entry << <<-ENTRY
msgid #{format_message(@msgid)}
msgstr #{format_message(@msgstr)}
ENTRY
end
##
# Merges the PO entry with +other_entry+.
def merge other_entry
options = {
:extracted_comment => merge_string(@extracted_comment,
other_entry.extracted_comment),
:translator_comment => merge_string(@translator_comment,
other_entry.translator_comment),
:references => merge_array(@references,
other_entry.references),
:flags => merge_array(@flags,
other_entry.flags),
}
self.class.new(@msgid, options)
end
private
def format_comment mark, comment
return '' unless comment
return '' if comment.empty?
formatted_comment = ''
comment.each_line do |line|
formatted_comment << "#{mark} #{line}"
end
formatted_comment << "\n" unless formatted_comment.end_with?("\n")
formatted_comment
end
def format_translator_comment
format_comment('#', @translator_comment)
end
def format_extracted_comment
format_comment('#.', @extracted_comment)
end
def format_references
return '' if @references.empty?
formatted_references = ''
@references.sort.each do |file, line|
formatted_references << "\#: #{file}:#{line}\n"
end
formatted_references
end
def format_flags
return '' if @flags.empty?
formatted_flags = flags.join(",")
"\#, #{formatted_flags}\n"
end
def format_message message
return "\"#{escape(message)}\"" unless message.include?("\n")
formatted_message = '""'
message.each_line do |line|
formatted_message << "\n"
formatted_message << "\"#{escape(line)}\""
end
formatted_message
end
def escape string
string.gsub(/["\\\t\n]/) do |special_character|
case special_character
when "\t"
"\\t"
when "\n"
"\\n"
else
"\\#{special_character}"
end
end
end
def merge_string string1, string2
[string1, string2].compact.join("\n")
end
def merge_array array1, array2
(array1 + array2).uniq
end
end

View File

@ -2,6 +2,13 @@
<title><%= h @title %></title>
<script type="text/javascript">
var rdoc_rel_prefix = "<%= rel_prefix %>/";
</script>
<script src="<%= asset_rel_prefix %>/js/jquery.js"></script>
<script src="<%= asset_rel_prefix %>/js/darkfish.js"></script>
<link href="<%= asset_rel_prefix %>/fonts.css" rel="stylesheet">
<link href="<%= asset_rel_prefix %>/rdoc.css" rel="stylesheet">
<% if @options.template_stylesheets.flatten.any? then %>
@ -10,13 +17,3 @@
<% end %>
<% end %>
<script type="text/javascript">
var rdoc_rel_prefix = "<%= rel_prefix %>/";
</script>
<script src="<%= asset_rel_prefix %>/js/jquery.js"></script>
<script src="<%= asset_rel_prefix %>/js/navigation.js"></script>
<script src="<%= search_index_rel_prefix %>/js/search_index.js"></script>
<script src="<%= asset_rel_prefix %>/js/search.js"></script>
<script src="<%= asset_rel_prefix %>/js/searcher.js"></script>
<script src="<%= asset_rel_prefix %>/js/darkfish.js"></script>

0
lib/rdoc/generator/template/darkfish/images/add.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 733 B

After

Width:  |  Height:  |  Size: 733 B

View File

Before

Width:  |  Height:  |  Size: 372 B

After

Width:  |  Height:  |  Size: 372 B

0
lib/rdoc/generator/template/darkfish/images/delete.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 715 B

After

Width:  |  Height:  |  Size: 715 B

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -44,14 +44,6 @@ function hookSourceViews() {
$('.method-heading').click( showSource );
};
function toggleDebuggingSection() {
$('.debugging-section').slideToggle();
};
function hookDebuggingToggle() {
$('#debugging-toggle img').click( toggleDebuggingSection );
};
function hookSearch() {
var input = $('#search-field').eq(0);
var result = $('#search-results').eq(0);
@ -129,12 +121,41 @@ function highlightClickTarget( event ) {
};
};
function loadAsync(path, success) {
$.ajax({
url: rdoc_rel_prefix + path,
dataType: 'script',
success: success,
cache: true
});
};
$(document).ready( function() {
hookSourceViews();
hookDebuggingToggle();
hookSearch();
highlightLocationTarget();
$('ul.link-list a').bind( "click", highlightClickTarget );
var search_scripts_loaded = {
navigation_loaded: false,
search_loaded: false,
search_index_loaded: false,
searcher_loaded: false,
}
var search_success_function = function(variable) {
return (function (data, status, xhr) {
search_scripts_loaded[variable] = true;
if (search_scripts_loaded['navigation_loaded'] == true &&
search_scripts_loaded['search_loaded'] == true &&
search_scripts_loaded['search_index_loaded'] == true &&
search_scripts_loaded['searcher_loaded'] == true)
hookSearch();
});
}
loadAsync('js/navigation.js', search_success_function('navigation_loaded'));
loadAsync('js/search.js', search_success_function('search_loaded'));
loadAsync('js/search_index.js', search_success_function('search_index_loaded'));
loadAsync('js/searcher.js', search_success_function('searcher_loaded'));
});

View File

@ -23,12 +23,22 @@ h3 span,
h4 span,
h5 span,
h6 span {
position: relative;
display: none;
padding-left: 1em;
line-height: 0;
vertical-align: baseline;
font-size: 10px;
vertical-align: super;
}
h1 span { top: -1.3em; }
h2 span { top: -1.2em; }
h3 span { top: -1.0em; }
h4 span { top: -0.8em; }
h5 span { top: -0.5em; }
h6 span { top: -0.5em; }
h1:hover span,
h2:hover span,
h3:hover span,

9
lib/rdoc/i18n.rb Normal file
View File

@ -0,0 +1,9 @@
##
# This module provides i18n realated features.
module RDoc::I18n
autoload :Locale, 'rdoc/i18n/locale'
autoload :Text, 'rdoc/i18n/text'
end

101
lib/rdoc/i18n/locale.rb Normal file
View File

@ -0,0 +1,101 @@
##
# A message container for a locale.
#
# This object provides the following two features:
#
# * Loads translated messages from .po file.
# * Translates a message into the locale.
class RDoc::I18n::Locale
@@locales = {} # :nodoc:
class << self
##
# Returns the locale object for +locale_name+.
def [](locale_name)
@@locales[locale_name] ||= new(locale_name)
end
##
# Sets the locale object for +locale_name+.
#
# Normally, this method is not used. This method is useful for
# testing.
def []=(locale_name, locale)
@@locales[locale_name] = locale
end
end
##
# The name of the locale. It uses IETF language tag format
# +[language[_territory][.codeset][@modifier]]+.
#
# See also {BCP 47 - Tags for Identifying
# Languages}[http://tools.ietf.org/rfc/bcp/bcp47.txt].
attr_reader :name
##
# Creates a new locale object for +name+ locale. +name+ must
# follow IETF language tag format.
def initialize(name)
@name = name
@messages = {}
end
##
# Loads translation messages from +locale_directory+/+@name+/rdoc.po
# or +locale_directory+/+@name+.po. The former has high priority.
#
# This method requires gettext gem for parsing .po file. If you
# don't have gettext gem, this method doesn't load .po file. This
# method warns and returns +false+.
#
# Returns +true+ if succeeded, +false+ otherwise.
def load(locale_directory)
return false if @name.nil?
po_file_candidates = [
File.join(locale_directory, @name, 'rdoc.po'),
File.join(locale_directory, "#{@name}.po"),
]
po_file = po_file_candidates.find do |po_file_candidate|
File.exist?(po_file_candidate)
end
return false unless po_file
begin
require 'gettext/po_parser'
require 'gettext/mo'
rescue LoadError
warn('Need gettext gem for i18n feature:')
warn(' gem install gettext')
return false
end
po_parser = GetText::POParser.new
messages = GetText::MO.new
po_parser.report_warning = false
po_parser.parse_file(po_file, messages)
@messages.merge!(messages)
true
end
##
# Translates the +message+ into locale. If there is no tranlsation
# messages for +message+ in locale, +message+ itself is returned.
def translate(message)
@messages[message] || message
end
end

125
lib/rdoc/i18n/text.rb Normal file
View File

@ -0,0 +1,125 @@
##
# An i18n supported text.
#
# This object provides the following two features:
#
# * Extracts translation messages from wrapped raw text.
# * Translates wrapped raw text in specified locale.
#
# Wrapped raw text is one of String, RDoc::Comment or Array of them.
class RDoc::I18n::Text
##
# Creates a new i18n supported text for +raw+ text.
def initialize(raw)
@raw = raw
end
##
# Extracts translation target messages and yields each message.
#
# Each yielded message is a Hash. It consists of the followings:
#
# :type :: :paragraph
# :paragraph :: String (The translation target message itself.)
# :line_no :: Integer (The line number of the :paragraph is started.)
#
# The above content may be added in the future.
def extract_messages
parse do |part|
case part[:type]
when :empty_line
# ignore
when :paragraph
yield(part)
end
end
end
# Translates raw text into +locale+.
def translate(locale)
translated_text = ''
parse do |part|
case part[:type]
when :paragraph
translated_text << locale.translate(part[:paragraph])
when :empty_line
translated_text << part[:line]
else
raise "should not reach here: unexpected type: #{type}"
end
end
translated_text
end
private
def parse(&block)
paragraph = ''
paragraph_start_line = 0
line_no = 0
each_line(@raw) do |line|
line_no += 1
case line
when /\A\s*\z/
if paragraph.empty?
emit_empty_line_event(line, line_no, &block)
else
paragraph << line
emit_paragraph_event(paragraph, paragraph_start_line, line_no,
&block)
paragraph = ''
end
else
paragraph_start_line = line_no if paragraph.empty?
paragraph << line
end
end
unless paragraph.empty?
emit_paragraph_event(paragraph, paragraph_start_line, line_no, &block)
end
end
def each_line(raw, &block)
case raw
when RDoc::Comment
raw.text.each_line(&block)
when Array
raw.each do |comment, location|
each_line(comment, &block)
end
else
raw.each_line(&block)
end
end
def emit_empty_line_event(line, line_no)
part = {
:type => :empty_line,
:line => line,
:line_no => line_no,
}
yield(part)
end
def emit_paragraph_event(paragraph, paragraph_start_line, line_no, &block)
paragraph_part = {
:type => :paragraph,
:line_no => paragraph_start_line,
}
match_data = /(\s*)\z/.match(paragraph)
if match_data
paragraph_part[:paragraph] = match_data.pre_match
yield(paragraph_part)
emit_empty_line_event(match_data[1], line_no, &block)
else
paragraph_part[:paragraph] = paragraph
yield(paragraph_part)
end
end
end

View File

@ -84,7 +84,7 @@
#
# markup.add_special(/\b([A-Z][a-z]+[A-Z]\w+)/, :WIKIWORD)
#
# wh = WikiHtml.new markup
# wh = WikiHtml.new RDoc::Options.new, markup
# wh.add_tag(:STRIKE, "<strike>", "</strike>")
#
# puts "<body>#{wh.convert ARGF.read}</body>"
@ -163,7 +163,7 @@
#
# The header's id would be:
#
# <h1 id="method-i-do_fun_things-label-Example">Example</h3>
# <h1 id="method-i-do_fun_things-label-Example">Example</h1>
#
# The label can be linked-to using <tt>SomeClass@Headers</tt>. See
# {Links}[RDoc::Markup@Links] for further details.

View File

@ -110,6 +110,9 @@ class RDoc::MethodAttr < RDoc::CodeObject
# Order by #singleton then #name
def <=>(other)
return unless other.respond_to?(:singleton) &&
other.respond_to?(:name)
[ @singleton ? 0 : 1, name] <=>
[other.singleton ? 0 : 1, other.name]
end

View File

@ -213,6 +213,16 @@ class RDoc::Options
attr_accessor :line_numbers
##
# The output locale.
attr_accessor :locale
##
# The directory where locale data live.
attr_accessor :locale_dir
##
# Name of the file, class or module to display in the initial index page (if
# not specified the first file we encounter is used)
@ -325,7 +335,7 @@ class RDoc::Options
# other visibilities may be overridden on a per-method basis with the :doc:
# directive.
attr_accessor :visibility
attr_reader :visibility
def initialize # :nodoc:
init_ivars
@ -343,6 +353,9 @@ class RDoc::Options
@generators = RDoc::RDoc::GENERATORS
@hyperlink_all = false
@line_numbers = false
@locale = nil
@locale_name = nil
@locale_dir = 'locale'
@main_page = nil
@markup = 'rdoc'
@coverage_report = false
@ -388,6 +401,8 @@ class RDoc::Options
@generator_name = map['generator_name']
@hyperlink_all = map['hyperlink_all']
@line_numbers = map['line_numbers']
@locale_name = map['locale_name']
@locale_dir = map['locale_dir']
@main_page = map['main_page']
@markup = map['markup']
@op_dir = map['op_dir']
@ -412,6 +427,8 @@ class RDoc::Options
@generator_name == other.generator_name and
@hyperlink_all == other.hyperlink_all and
@line_numbers == other.line_numbers and
@locale == other.locale and
@locale_dir == other.locale_dir and
@main_page == other.main_page and
@markup == other.markup and
@op_dir == other.op_dir and
@ -515,6 +532,13 @@ class RDoc::Options
@template_dir = template_dir_for @template
end
if @locale_name
@locale = RDoc::I18n::Locale[@locale_name]
@locale.load(@locale_dir)
else
@locale = nil
end
self
end
@ -677,6 +701,19 @@ Usage: #{opt.program_name} [options] [names...]
opt.separator nil
end
opt.on("--locale=NAME",
"Specifies the output locale.") do |value|
@locale_name = value
end
opt.on("--locale-data-dir=DIR",
"Specifies the directory where locale data live.") do |value|
@locale_dir = value
end
opt.separator nil
opt.on("--all", "-a",
"Synonym for --visibility=private.") do |value|
@visibility = :private
@ -1016,8 +1053,7 @@ Usage: #{opt.program_name} [options] [names...]
opt.separator nil
opt.on("--help",
"Display this help") do
opt.on("--help", "-h", "Display this help") do
RDoc::RDoc::GENERATORS.each_key do |generator|
setup_generator generator
end
@ -1174,6 +1210,22 @@ Usage: #{opt.program_name} [options] [names...]
end
end
# Sets the minimum visibility of a documented method.
#
# Accepts +:public+, +:protected+, +:private+, +:nodoc+, or +:all+.
#
# When +:all+ is passed, visibility is set to +:private+, similarly to
# RDOCOPT="--all", see #visibility for more information.
def visibility= visibility
case visibility
when :all
@visibility = :private
else
@visibility = visibility
end
end
##
# Displays a warning using Kernel#warn if we're being verbose

View File

@ -83,7 +83,7 @@ class RDoc::Parser
mode = "r"
s.sub!(/\A#!.*\n/, '') # assume shebang line isn't longer than 1024.
encoding = s[/^\s*\#\s*(?:-\*-\s*)?(?:en)?coding:\s*([^\s;]+?)(?:-\*-|[\s;])/, 1]
mode = "r:#{encoding}" if encoding
mode = "rb:#{encoding}" if encoding
s = File.open(file, mode) {|f| f.gets(nil, 1024)}
not s.valid_encoding?

View File

@ -594,9 +594,10 @@ class RDoc::Parser::C < RDoc::Parser
\s*#{attr_name}\s*,
#{rw},.*?\)\s*;%xm then
$1
elsif @content =~ %r%Document-attr:\s#{attr_name}\s*?\n
((?>.*?\*/))%xm then
$1
elsif @content =~ %r%(/\*.*?(?:\s*\*\s*)?)
Document-attr:\s#{attr_name}\s*?\n
((?>(.|\n)*?\*/))%x then
"#{$1}\n#{$2}"
else
''
end
@ -610,7 +611,7 @@ class RDoc::Parser::C < RDoc::Parser
def find_body class_name, meth_name, meth_obj, file_content, quiet = false
case file_content
when %r%((?>/\*.*?\*/\s*)?)
((?:(?:static|SWIGINTERN)\s+)?
((?:(?:\w+)\s+)?
(?:intern\s+)?VALUE\s+#{meth_name}
\s*(\([^)]*\))([^;]|$))%xm then
comment = RDoc::Comment.new $1, @top_level
@ -1185,7 +1186,6 @@ class RDoc::Parser::C < RDoc::Parser
if hash then
args << "p#{position} = {}"
position += 1
end
args << '&block' if block

View File

@ -146,10 +146,10 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
entry_name = nil unless entry_name =~ /#{time.year}/
rescue NoMethodError
# HACK Ruby 2.1.2 and earlier raises NoMethodError if time part is absent
time, = entry_name.split ' ', 2
entry_name.split ' ', 2
rescue ArgumentError
if /out of range/ =~ $!.message
time = Time.parse(entry_name.split(' ', 2)[0]) rescue entry_name = nil
Time.parse(entry_name.split(' ', 2)[0]) rescue entry_name = nil
else
entry_name = nil
end

View File

@ -187,15 +187,16 @@ class RDoc::Parser::Ruby < RDoc::Parser
end
##
# Extracts the visibility information for the visibility token +tk+.
# Extracts the visibility information for the visibility token +tk+
# and +single+ class type identifier.
#
# Returns the visibility type (a string), the visibility (a symbol) and
# +singleton+ if the methods following should be converted to singleton
# methods.
def get_visibility_information tk # :nodoc:
def get_visibility_information tk, single # :nodoc:
vis_type = tk.name
singleton = false
singleton = single == SINGLE
vis =
case vis_type
@ -226,6 +227,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
comment = ''
comment.force_encoding @encoding if @encoding
first_line = true
first_comment_tk_class = nil
tk = get_tk
@ -238,6 +240,9 @@ class RDoc::Parser::Ruby < RDoc::Parser
skip_tkspace
tk = get_tk
else
break if first_comment_tk_class and not first_comment_tk_class === tk
first_comment_tk_class = tk.class
first_line = false
comment << tk.text << "\n"
tk = get_tk
@ -841,7 +846,6 @@ class RDoc::Parser::Ruby < RDoc::Parser
# true, no found constants will be added to RDoc.
def parse_constant container, tk, comment, ignore_constants = false
prev_container = container
offset = tk.seek
line_no = tk.line_no
@ -864,8 +868,6 @@ class RDoc::Parser::Ruby < RDoc::Parser
end
unless TkASSIGN === eq_tk then
suppress_parents container, prev_container
unget_tk eq_tk
return false
end
@ -889,7 +891,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
read_documentation_modifiers con, RDoc::CONSTANT_MODIFIERS
@stats.add_constant con
con = container.add_constant con
container.add_constant con
true
end
@ -1305,7 +1307,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
return unless name
meth = RDoc::AnyMethod.new get_tkread, name
meth.singleton = singleton
meth.singleton = single == SINGLE ? true : singleton
record_location meth
meth.offset = offset
@ -1875,9 +1877,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
# Determines the visibility in +container+ from +tk+
def parse_visibility(container, single, tk)
singleton = (single == SINGLE)
vis_type, vis, singleton = get_visibility_information tk
vis_type, vis, singleton = get_visibility_information tk, single
skip_tkspace_comment false
@ -2078,7 +2078,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
def skip_for_variable
skip_tkspace false
tk = get_tk
get_tk
skip_tkspace false
tk = get_tk
unget_tk(tk) unless TkIN === tk

View File

@ -1,6 +1,6 @@
#
# DO NOT MODIFY!!!!
# This file is automatically generated by Racc 1.4.9
# This file is automatically generated by Racc 1.4.11
# from Racc grammer file "".
#

View File

@ -1,6 +1,6 @@
#
# DO NOT MODIFY!!!!
# This file is automatically generated by Racc 1.4.9
# This file is automatically generated by Racc 1.4.11
# from Racc grammer file "".
#

View File

@ -305,6 +305,9 @@ option)
when "directory" then
next if rel_file_name == "CVS" || rel_file_name == ".svn"
created_rid = File.join rel_file_name, "created.rid"
next if File.file? created_rid
dot_doc = File.join rel_file_name, RDoc::DOT_DOC_FILENAME
if File.file? dot_doc then
@ -336,7 +339,7 @@ option)
# Parses +filename+ and returns an RDoc::TopLevel
def parse_file filename
if defined?(Encoding) then
if Object.const_defined? :Encoding then
encoding = @options.encoding
filename = filename.encode encoding
end
@ -411,8 +414,6 @@ The internal error was:
return [] if file_list.empty?
file_info = []
@stats.begin_adding
file_info = file_list.map do |filename|
@ -565,4 +566,5 @@ end
# require built-in generators after discovery in case they've been replaced
require 'rdoc/generator/darkfish'
require 'rdoc/generator/ri'
require 'rdoc/generator/pot'

View File

@ -434,7 +434,7 @@ class RDoc::RubyLex
|op, io|
@ltype = "="
res = ''
nil until (ch = getc) == "\n"
nil until getc == "\n"
until ( peek_equal?("=end") && peek(4) =~ /\s/ ) do
(ch = getc)

View File

@ -73,7 +73,7 @@ module RDoc::RubyToken
@node = node
end
attr_reader :node
attr_reader:node
def ==(other)
self.class == other.class and
@ -101,7 +101,7 @@ module RDoc::RubyToken
super(seek, line_no, char_no)
@name = name
end
attr_reader :name
attr_reader:name
def ==(other)
self.class == other.class and
@ -192,7 +192,7 @@ module RDoc::RubyToken
@text = nil
end
attr_reader :op
attr_reader:op
def ==(other)
self.class == other.class and
@ -217,7 +217,7 @@ module RDoc::RubyToken
super(seek, line_no, char_no)
@name = name
end
attr_reader :name
attr_reader:name
def ==(other)
self.class == other.class and

View File

@ -153,7 +153,13 @@ class RDoc::RubygemsHook
options = nil
args = @spec.rdoc_options
args.concat @spec.require_paths
if @spec.respond_to? :source_paths then
args.concat @spec.source_paths
else
args.concat @spec.require_paths
end
args.concat @spec.extra_rdoc_files
case config_args = Gem.configuration[:rdoc]

View File

@ -1,4 +1,7 @@
require 'io/console/size'
begin
require 'io/console/size'
rescue LoadError
end
##
# Stats printer that prints just the files being documented with a progress
@ -22,7 +25,11 @@ class RDoc::Stats::Normal < RDoc::Stats::Quiet
# Print a progress bar, but make sure it fits on a single line. Filename
# will be truncated if necessary.
terminal_width = IO.console_size[1].to_i.nonzero? || 80
terminal_width = if defined?(IO) && IO.respond_to?(:console_size)
IO.console_size[1].to_i.nonzero? || 80
else
80
end
max_filename_size = terminal_width - progress_bar.size
if filename.size > max_filename_size then

View File

@ -291,7 +291,7 @@ class RDoc::Task < Rake::TaskLib
private
def rdoc_target
"#{rdoc_dir}/index.html"
"#{rdoc_dir}/created.rid"
end
def rdoc_task_name

View File

@ -103,6 +103,15 @@ module RDoc::Text
# Requires the including class to implement #formatter
def markup text
if @store.rdoc.options
locale = @store.rdoc.options.locale
else
locale = nil
end
if locale
i18n_text = RDoc::I18n::Text.new(text)
text = i18n_text.translate(locale)
end
parse(text).accept formatter
end

View File

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

View File

@ -1,120 +0,0 @@
require 'rdoc/test_case'
class TestAttributeManager < RDoc::TestCase # HACK fix test name
def setup
super
@options = RDoc::Options.new
@am = RDoc::Markup::AttributeManager.new
@klass = RDoc::Markup::AttributeManager
@formatter = RDoc::Markup::Formatter.new @options
@formatter.add_tag :BOLD, '<B>', '</B>'
@formatter.add_tag :EM, '<EM>', '</EM>'
@formatter.add_tag :TT, '<CODE>', '</CODE>'
end
def test_convert_attrs_ignores_code
assert_equal 'foo <CODE>__send__</CODE> bar', output('foo <code>__send__</code> bar')
end
def test_convert_attrs_ignores_tt
assert_equal 'foo <CODE>__send__</CODE> bar', output('foo <tt>__send__</tt> bar')
end
def test_convert_attrs_preserves_double
assert_equal 'foo.__send__ :bar', output('foo.__send__ :bar')
assert_equal 'use __FILE__ to', output('use __FILE__ to')
end
def test_convert_attrs_does_not_ignore_after_tt
assert_equal 'the <CODE>IF:</CODE><EM>key</EM> directive', output('the <tt>IF:</tt>_key_ directive')
end
def test_initial_word_pairs
word_pairs = @am.matching_word_pairs
assert word_pairs.is_a?(Hash)
assert_equal(3, word_pairs.size)
end
def test_initial_html
html_tags = @am.html_tags
assert html_tags.is_a?(Hash)
assert_equal(5, html_tags.size)
end
def test_add_matching_word_pair
@am.add_word_pair("x","x", :TEST)
word_pairs = @am.matching_word_pairs
assert_equal(4,word_pairs.size)
assert(word_pairs.has_key?("x"))
end
def test_add_invalid_word_pair
assert_raises ArgumentError do
@am.add_word_pair("<", "<", :TEST)
end
end
def test_add_word_pair_map
@am.add_word_pair("x", "y", :TEST)
word_pair_map = @am.word_pair_map
assert_equal(1,word_pair_map.size)
assert_equal(word_pair_map. keys.first.source, "(x)(\\S+)(y)")
end
def test_add_html_tag
@am.add_html("Test", :TEST)
tags = @am.html_tags
assert_equal(6, tags.size)
assert(tags.has_key?("test"))
end
def test_add_special
@am.add_special "WikiWord", :WIKIWORD
specials = @am.special
assert_equal 1, specials.size
assert specials.assoc "WikiWord"
end
def test_escapes
assert_equal '<CODE>text</CODE>', output('<tt>text</tt>')
assert_equal '<tt>text</tt>', output('\\<tt>text</tt>')
assert_equal '<tt>', output('\\<tt>')
assert_equal '<CODE><tt></CODE>', output('<tt>\\<tt></tt>')
assert_equal '<CODE>\\<tt></CODE>', output('<tt>\\\\<tt></tt>')
assert_equal '<B>text</B>', output('*text*')
assert_equal '*text*', output('\\*text*')
assert_equal '\\', output('\\')
assert_equal '\\text', output('\\text')
assert_equal '\\\\text', output('\\\\text')
assert_equal 'text \\ text', output('text \\ text')
assert_equal 'and <CODE>\\s</CODE> matches space',
output('and <tt>\\s</tt> matches space')
assert_equal 'use <CODE><tt>text</CODE></tt> for code',
output('use <tt>\\<tt>text</tt></tt> for code')
assert_equal 'use <CODE><tt>text</tt></CODE> for code',
output('use <tt>\\<tt>text\\</tt></tt> for code')
assert_equal 'use <tt><tt>text</tt></tt> for code',
output('use \\<tt>\\<tt>text</tt></tt> for code')
assert_equal 'use <tt><CODE>text</CODE></tt> for code',
output('use \\<tt><tt>text</tt></tt> for code')
assert_equal 'use <CODE>+text+</CODE> for code',
output('use <tt>\\+text+</tt> for code')
assert_equal 'use <tt><CODE>text</CODE></tt> for code',
output('use \\<tt>+text+</tt> for code')
assert_equal 'illegal <tag>not</tag> changed',
output('illegal <tag>not</tag> changed')
assert_equal 'unhandled <p>tag</p> unchanged',
output('unhandled <p>tag</p> unchanged')
end
def output str
@formatter.convert_flow @am.flow str
end
end

View File

@ -334,6 +334,35 @@ method(a, b) { |c, d| ... }
assert_equal %w[a b c d], m.param_list
end
def test_param_list_empty_params_with_block
m = RDoc::AnyMethod.new nil, 'method'
m.parent = @c1
m.params = '()'
m.block_params = 'a, b'
assert_equal %w[a b], m.param_list
end
def test_param_list_ampersand_param_block_params
m = RDoc::AnyMethod.new nil, 'method'
m.parent = @c1
m.params = '(a, b, &block)'
m.block_params = 'c, d'
assert_equal %w[a b c d], m.param_list
end
def test_param_list_ampersand_param
m = RDoc::AnyMethod.new nil, 'method'
m.parent = @c1
m.params = '(a, b, &block)'
assert_equal %w[a b block], m.param_list
end
def test_param_seq
m = RDoc::AnyMethod.new nil, 'method'
m.parent = @c1

View File

@ -8,6 +8,36 @@ class TestRDocConstant < XrefTestCase
@const = @c1.constants.first
end
def test_documented_eh
top_level = @store.add_file 'file.rb'
const = RDoc::Constant.new 'CONST', nil, nil
top_level.add_constant const
refute const.documented?
const.comment = comment 'comment'
assert const.documented?
end
def test_documented_eh_alias
top_level = @store.add_file 'file.rb'
const = RDoc::Constant.new 'CONST', nil, nil
top_level.add_constant const
refute const.documented?
const.is_alias_for = 'C1'
refute const.documented?
@c1.add_comment comment('comment'), @top_level
assert const.documented?
end
def test_full_name
assert_equal 'C1::CONST', @const.full_name
end

View File

@ -621,6 +621,8 @@ class TestRDocContext < XrefTestCase
assert_equal 1, @c2_c3.<=>(@c2)
assert_equal(-1, @c2_c3.<=>(@c3))
assert_nil @c2.<=>(Gem.loaded_specs.values.first)
end
def test_methods_by_type

View File

@ -131,6 +131,23 @@ class TestRDocEncoding < RDoc::TestCase
assert_equal "hi everybody", content, bug3360
end
def test_class_read_file_encoding_iso_2022_jp
skip "Encoding not implemented" unless Object.const_defined? :Encoding
input = "# coding: ISO-2022-JP\n:\e$B%3%^%s%I\e(B:"
@tempfile.write input
@tempfile.flush
contents = RDoc::Encoding.read_file @tempfile.path, Encoding::UTF_8
expected = ":\xe3\x82\xb3\xe3\x83\x9e\xe3\x83\xb3\xe3\x83\x89:"
expected.force_encoding Encoding::UTF_8
assert_equal expected, contents
assert_equal Encoding::UTF_8, contents.encoding
end
def test_class_set_encoding
s = "# coding: UTF-8\n"
RDoc::Encoding.set_encoding s

View File

@ -0,0 +1,92 @@
require 'rdoc/test_case'
class TestRDocGeneratorPOT < RDoc::TestCase
def setup
super
@options = RDoc::Options.new
@tmpdir = File.join Dir.tmpdir, "test_rdoc_generator_pot_#{$$}"
FileUtils.mkdir_p @tmpdir
@generator = RDoc::Generator::POT.new @store, @options
@top_level = @store.add_file 'file.rb'
@klass = @top_level.add_class RDoc::NormalClass, 'Object'
@klass.add_comment 'This is a class', @top_level
@klass.add_section 'This is a section', comment('This is a section comment')
@const = RDoc::Constant.new "CONSTANT", "29", "This is a constant"
@meth = RDoc::AnyMethod.new nil, 'method'
@meth.record_location @top_level
@meth.comment = 'This is a method'
@attr = RDoc::Attr.new nil, 'attr', 'RW', ''
@attr.record_location @top_level
@attr.comment = 'This is an attribute'
@klass.add_constant @const
@klass.add_method @meth
@klass.add_attribute @attr
Dir.chdir @tmpdir
end
def teardown
super
Dir.chdir @pwd
FileUtils.rm_rf @tmpdir
end
def test_generate
@generator.generate
assert_equal <<-POT, File.read(File.join(@tmpdir, 'rdoc.pot'))
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSEION\\n"
"Report-Msgid-Bugs-To: \\n"
"PO-Revision-Date: YEAR-MO_DA HO:MI+ZONE\\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"
"Language-Team: LANGUAGE <LL@li.org>\\n"
"Language: \\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=CHARSET\\n"
"Content-Transfer-Encoding: 8bit\\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\\n"
#. Object
msgid "This is a class"
msgstr ""
#. Object::CONSTANT
msgid "This is a constant"
msgstr ""
#. Object#method
msgid "This is a method"
msgstr ""
#. Object: section title
msgid "This is a section"
msgstr ""
#. Object: This is a section
msgid "This is a section comment"
msgstr ""
#. Object#attr
msgid "This is an attribute"
msgstr ""
POT
end
end

View File

@ -0,0 +1,52 @@
require 'rdoc/test_case'
class TestRDocGeneratorPOTPO < RDoc::TestCase
def setup
super
@po = RDoc::Generator::POT::PO.new
end
def test_empty
assert_equal header, @po.to_s
end
def test_have_entry
@po.add(entry("Hello", {}))
assert_equal <<-PO, @po.to_s
#{header}
msgid "Hello"
msgstr ""
PO
end
private
def entry(msgid, options)
RDoc::Generator::POT::POEntry.new(msgid, options)
end
def header
<<-'HEADER'
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSEION\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: YEAR-MO_DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
HEADER
end
end

View File

@ -0,0 +1,139 @@
require 'rdoc/test_case'
class TestRDocGeneratorPOTPOEntry < RDoc::TestCase
def test_msgid_normal
assert_equal <<-'ENTRY', entry("Hello", {}).to_s
msgid "Hello"
msgstr ""
ENTRY
end
def test_msgid_multiple_lines
assert_equal <<-'ENTRY', entry("Hello\nWorld", {}).to_s
msgid ""
"Hello\n"
"World"
msgstr ""
ENTRY
end
def test_msgid_tab
assert_equal <<-'ENTRY', entry("Hello\tWorld", {}).to_s
msgid "Hello\tWorld"
msgstr ""
ENTRY
end
def test_msgid_back_slash
assert_equal <<-'ENTRY', entry("Hello \\ World", {}).to_s
msgid "Hello \\ World"
msgstr ""
ENTRY
end
def test_msgid_double_quote
assert_equal <<-'ENTRY', entry("Hello \"World\"!", {}).to_s
msgid "Hello \"World\"!"
msgstr ""
ENTRY
end
def test_translator_comment_normal
options = {:translator_comment => "Greeting"}
assert_equal <<-'ENTRY', entry("Hello", options).to_s
# Greeting
msgid "Hello"
msgstr ""
ENTRY
end
def test_translator_comment_multiple_lines
options = {:translator_comment => "Greeting\nfor morning"}
assert_equal <<-'ENTRY', entry("Hello", options).to_s
# Greeting
# for morning
msgid "Hello"
msgstr ""
ENTRY
end
def test_extracted_comment_normal
options = {:extracted_comment => "Object"}
assert_equal <<-'ENTRY', entry("Hello", options).to_s
#. Object
msgid "Hello"
msgstr ""
ENTRY
end
def test_extracted_comment_multiple_lines
options = {:extracted_comment => "Object\nMorning#greeting"}
assert_equal <<-'ENTRY', entry("Hello", options).to_s
#. Object
#. Morning#greeting
msgid "Hello"
msgstr ""
ENTRY
end
def test_references_normal
options = {:references => [["lib/rdoc.rb", 29]]}
assert_equal <<-'ENTRY', entry("Hello", options).to_s
#: lib/rdoc.rb:29
msgid "Hello"
msgstr ""
ENTRY
end
def test_references_multiple
options = {:references => [["lib/rdoc.rb", 29], ["lib/rdoc/i18n.rb", 9]]}
assert_equal <<-'ENTRY', entry("Hello", options).to_s
#: lib/rdoc.rb:29
#: lib/rdoc/i18n.rb:9
msgid "Hello"
msgstr ""
ENTRY
end
def test_flags_normal
options = {:flags => ["fuzzy"]}
assert_equal <<-'ENTRY', entry("Hello", options).to_s
#, fuzzy
msgid "Hello"
msgstr ""
ENTRY
end
def test_flags_multiple
options = {:flags => ["fuzzy", "ruby-format"]}
assert_equal <<-'ENTRY', entry("Hello", options).to_s
#, fuzzy,ruby-format
msgid "Hello"
msgstr ""
ENTRY
end
def test_full
options = {
:translator_comment => "Greeting",
:extracted_comment => "Morning#greeting",
:references => [["lib/rdoc.rb", 29]],
:flags => ["fuzzy"],
}
assert_equal <<-'ENTRY', entry("Hello", options).to_s
# Greeting
#. Morning#greeting
#: lib/rdoc.rb:29
#, fuzzy
msgid "Hello"
msgstr ""
ENTRY
end
private
def entry(msgid, options)
RDoc::Generator::POT::POEntry.new(msgid, options)
end
end

View File

@ -0,0 +1,73 @@
require 'rdoc/test_case'
class TestRDocI18nLocale < RDoc::TestCase
def setup
super
@locale = locale('fr')
@tmpdir = File.join Dir.tmpdir, "test_rdoc_i18n_locale_#{$$}"
FileUtils.mkdir_p @tmpdir
@locale_dir = @tmpdir
end
def teardown
FileUtils.rm_rf @tmpdir
super
end
def test_name
assert_equal 'fr', locale('fr').name
end
def test_load_nonexistent_po
File.stub(:exist?, false) do
refute @locale.load('nonexsitent-locale')
end
end
def test_load_existent_po
begin
require 'gettext/po_parser'
rescue LoadError
skip 'gettext gem is not found'
end
fr_locale_dir = File.join @locale_dir, 'fr'
FileUtils.mkdir_p fr_locale_dir
File.open File.join(fr_locale_dir, 'rdoc.po'), 'w' do |po|
po.puts <<-PO
msgid ""
msgstr ""
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
msgid "Hello"
msgstr "Bonjour"
PO
end
assert @locale.load(@locale_dir)
assert_equal 'Bonjour', @locale.translate('Hello')
end
def test_translate_existent_message
messages = @locale.instance_variable_get(:@messages)
messages['Hello'] = 'Bonjour'
assert_equal 'Bonjour', @locale.translate('Hello')
end
def test_translate_nonexistent_message
assert_equal 'Hello', @locale.translate('Hello')
end
private
def locale(name)
RDoc::I18n::Locale.new(name)
end
end

View File

@ -0,0 +1,123 @@
require 'rdoc/test_case'
class TestRDocI18nText < RDoc::TestCase
def test_multiple_paragraphs
paragraph1 = <<-PARAGRAPH.strip
RDoc produces HTML and command-line documentation for Ruby projects. RDoc
includes the +rdoc+ and +ri+ tools for generating and displaying documentation
from the command-line.
PARAGRAPH
paragraph2 = <<-PARAGRAPH.strip
This command generates documentation for all the Ruby and C source
files in and below the current directory. These will be stored in a
documentation tree starting in the subdirectory +doc+.
PARAGRAPH
raw = <<-RAW
#{paragraph1}
#{paragraph2}
RAW
expected = [
{
:type => :paragraph,
:paragraph => paragraph1,
:line_no => 1,
},
{
:type => :paragraph,
:paragraph => paragraph2,
:line_no => 5,
},
]
assert_equal expected, extract_messages(raw)
end
def test_translate_multiple_paragraphs
paragraph1 = <<-PARAGRAPH.strip
Paragraph 1.
PARAGRAPH
paragraph2 = <<-PARAGRAPH.strip
Paragraph 2.
PARAGRAPH
raw = <<-RAW
#{paragraph1}
#{paragraph2}
RAW
expected = <<-TRANSLATED
Paragraphe 1.
Paragraphe 2.
TRANSLATED
assert_equal expected, translate(raw)
end
def test_translate_not_transalted_message
nonexistent_paragraph = <<-PARAGRAPH.strip
Nonexistent paragraph.
PARAGRAPH
raw = <<-RAW
#{nonexistent_paragraph}
RAW
expected = <<-TRANSLATED
#{nonexistent_paragraph}
TRANSLATED
assert_equal expected, translate(raw)
end
def test_translate_keep_empty_lines
raw = <<-RAW
Paragraph 1.
Paragraph 2.
RAW
expected = <<-TRANSLATED
Paragraphe 1.
Paragraphe 2.
TRANSLATED
assert_equal expected, translate(raw)
end
private
def extract_messages(raw)
text = RDoc::I18n::Text.new(raw)
messages = []
text.extract_messages do |message|
messages << message
end
messages
end
def locale
locale = RDoc::I18n::Locale.new('fr')
messages = locale.instance_variable_get(:@messages)
messages['markdown'] = 'markdown (markdown in fr)'
messages['Hello'] = 'Bonjour (Hello in fr)'
messages['Paragraph 1.'] = 'Paragraphe 1.'
messages['Paragraph 2.'] = 'Paragraphe 2.'
locale
end
def translate(raw)
text = RDoc::I18n::Text.new(raw)
text.translate(locale)
end
end

View File

@ -7,7 +7,6 @@ class TestRDocMethodAttr < XrefTestCase
end
def test_block_params_equal
m = RDoc::MethodAttr.new(nil, 'foo')
m.block_params = ''
@ -148,6 +147,10 @@ class TestRDocMethodAttr < XrefTestCase
assert_equal expected, @c1_m.search_record
end
def test_spaceship
assert_nil @c1_m.<=>(RDoc::CodeObject.new)
end
def test_equals2
assert_equal @c1_m, @c1_m
refute_equal @c1_m, @parent_m

View File

@ -67,6 +67,9 @@ class TestRDocOptions < RDoc::TestCase
'exclude' => [],
'hyperlink_all' => false,
'line_numbers' => false,
'locale' => nil,
'locale_dir' => 'locale',
'locale_name' => nil,
'main_page' => nil,
'markup' => 'rdoc',
'output_decoration' => true,
@ -334,6 +337,18 @@ rdoc_include:
e.message
end
def test_parse_h
out, = capture_io do
begin
@options.parse %w[-h]
rescue SystemExit
end
end
assert_equal 1, out.scan(/HTML generator options:/).length
assert_equal 1, out.scan(/ri generator options:/). length
end
def test_parse_help
out, = capture_io do
begin
@ -743,5 +758,9 @@ rdoc_include:
assert out.include?(RDoc::VERSION)
end
def test_visibility
@options.visibility = :all
assert_equal :private, @options.visibility
end
end

View File

@ -15,6 +15,19 @@ class TestRDocParser < RDoc::TestCase
@options = RDoc::Options.new
end
def test_class_binary_eh_ISO_2022_JP
iso_2022_jp = File.join Dir.tmpdir, "test_rdoc_parser_#{$$}.rd"
open iso_2022_jp, 'wb' do |io|
io.write "# coding: ISO-2022-JP\n"
io.write ":\e$B%3%^%s%I\e(B:\n"
end
refute @RP.binary? iso_2022_jp
ensure
File.unlink iso_2022_jp
end
def test_class_binary_eh_marshal
marshal = File.join Dir.tmpdir, "test_rdoc_parser_#{$$}.marshal"
open marshal, 'wb' do |io|
@ -96,7 +109,7 @@ class TestRDocParser < RDoc::TestCase
def test_class_for_forbidden
skip 'chmod not supported' if Gem.win_platform?
Tempfile.create 'forbidden' do |io|
tf = Tempfile.open 'forbidden' do |io|
begin
File.chmod 0000, io.path
forbidden = @store.add_file io.path
@ -107,7 +120,9 @@ class TestRDocParser < RDoc::TestCase
ensure
File.chmod 0400, io.path
end
io
end
tf.close! if tf.respond_to? :close!
end
def test_class_for_modeline

View File

@ -736,6 +736,47 @@ rb_define_alias(C, "[]", "index");
assert_equal "/*\n * comment\n */\n\n", comment.text
end
def test_find_attr_comment_document_attr
parser= util_parser <<-C
/*
* Document-attr: y
* comment
*/
C
comment = parser.find_attr_comment nil, 'y'
assert_equal "/*\n * \n * comment\n */", comment.text
end
def test_find_attr_comment_document_attr_oneline
parser= util_parser <<-C
/* Document-attr: y
* comment
*/
C
comment = parser.find_attr_comment nil, 'y'
assert_equal "/* \n * comment\n */", comment.text
end
def test_find_attr_comment_document_attr_overlap
parser= util_parser <<-C
/* Document-attr: x
* comment
*/
/* Document-attr: y
* comment
*/
C
comment = parser.find_attr_comment nil, 'y'
assert_equal "/* \n * comment\n */", comment.text
end
def test_find_class_comment
@options.rdoc_include << File.dirname(__FILE__)
@ -1205,6 +1246,36 @@ Init_Foo(void) {
assert_equal "a comment for Foo#bar", bar.comment.text
end
def test_find_body_macro
content = <<-EOF
/*
* a comment for other_function
*/
DLL_LOCAL VALUE
other_function() {
}
void
Init_Foo(void) {
VALUE foo = rb_define_class("Foo", rb_cObject);
rb_define_method(foo, "my_method", other_function, 0);
}
EOF
klass = util_get_class content, 'foo'
other_function = klass.method_list.first
assert_equal 'my_method', other_function.name
assert_equal "a comment for other_function",
other_function.comment.text
assert_equal '()', other_function.params
code = other_function.token_stream.first.text
assert_equal "DLL_LOCAL VALUE\nother_function() {\n}", code
end
def test_find_modifiers_call_seq
comment = RDoc::Comment.new <<-COMMENT
call-seq:

View File

@ -63,6 +63,21 @@ class C; end
assert_equal Encoding::CP852, comment.text.encoding
end
def test_collect_first_comment_rd_hash
parser = util_parser <<-CONTENT
=begin
first
=end
# second
class C; end
CONTENT
comment = parser.collect_first_comment
assert_equal RDoc::Comment.new("first\n\n", @top_level), comment
end
def test_get_class_or_module
ctxt = RDoc::Context.new
ctxt.store = @store
@ -773,7 +788,7 @@ end
assert_equal 2, foo.method_list.length
end
def test_parse_const_fail_w_meta_method
def test_parse_const_fail_w_meta
util_parser <<-CLASS
class ConstFailMeta
##
@ -795,27 +810,6 @@ end
assert_equal 1, const_fail_meta.attributes.length
end
def test_parse_const_third_party
util_parser <<-CLASS
class A
true if B::C
true if D::E::F
end
CLASS
tk = @parser.get_tk
@parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, @comment
a = @top_level.classes.first
assert_equal 'A', a.full_name
visible = @store.all_modules.reject { |mod| mod.suppressed? }
visible = visible.map { |mod| mod.full_name }
assert_empty visible
end
def test_parse_class_nested_superclass
foo = @top_level.add_module RDoc::NormalModule, 'Foo'
@ -3251,7 +3245,25 @@ end
c_b = c.find_method_named 'b'
assert_equal :private, c_b.visibility
refute c_b.singleton
assert c_b.singleton
end
def test_singleton_method_via_eigenclass
util_parser <<-RUBY
class C
class << self
def a() end
end
end
RUBY
@parser.scan
c = @store.find_class_named 'C'
c_a = c.find_method_named 'a'
assert_equal :public, c_a.visibility
assert c_a.singleton
end
def test_stopdoc_after_comment

View File

@ -153,7 +153,7 @@ class TestRDocRdBlockParser < RDoc::TestCase
blank_line,
blank_line)
Tempfile.create %w[parse_include .rd] do |io|
tf = Tempfile.open %w[parse_include .rd] do |io|
io.puts "=begin\ninclude ((*worked*))\n=end"
io.flush
@ -162,7 +162,9 @@ class TestRDocRdBlockParser < RDoc::TestCase
STR
assert_equal expected, parse(str)
io
end
tf.close! if tf.respond_to? :close!
end
def test_parse_heading

View File

@ -252,14 +252,16 @@ class TestRDocRDoc < RDoc::TestCase
@rdoc.options.encoding = Encoding::ISO_8859_1
@rdoc.store = RDoc::Store.new
Tempfile.create 'test.txt' do |io|
tf = Tempfile.open 'test.txt' do |io|
io.write 'hi'
io.rewind
top_level = @rdoc.parse_file io.path
assert_equal Encoding::ISO_8859_1, top_level.absolute_name.encoding
io
end
tf.close! if tf.respond_to? :close?
end
def test_parse_file_forbidden
@ -267,7 +269,7 @@ class TestRDocRDoc < RDoc::TestCase
@rdoc.store = RDoc::Store.new
Tempfile.create 'test.txt' do |io|
tf = Tempfile.open 'test.txt' do |io|
io.write 'hi'
io.rewind
@ -286,7 +288,9 @@ class TestRDocRDoc < RDoc::TestCase
ensure
File.chmod 0400, io.path
end
io
end
tf.close! if tf.respond_to? :close!
end
def test_remove_unparseable
@ -382,7 +386,7 @@ class TestRDocRDoc < RDoc::TestCase
end
def test_setup_output_dir_exists_file
Tempfile.create 'test_rdoc_rdoc' do |tempfile|
tf = Tempfile.open 'test_rdoc_rdoc' do |tempfile|
path = tempfile.path
e = assert_raises RDoc::Error do
@ -391,7 +395,9 @@ class TestRDocRDoc < RDoc::TestCase
assert_match(%r%#{Regexp.escape path} exists and is not a directory%,
e.message)
tempfile
end
tf.close! if tf.respond_to? :close!
end
def test_setup_output_dir_exists_not_rdoc
@ -430,5 +436,20 @@ class TestRDocRDoc < RDoc::TestCase
end
end
def test_normalized_file_list_removes_created_rid_dir
temp_dir do |d|
FileUtils.mkdir "doc"
flag_file = @rdoc.output_flag_file "doc"
file = File.join "doc", "test"
FileUtils.touch flag_file
FileUtils.touch file
file_list = ["doc"]
output = @rdoc.normalized_file_list file_list
assert_empty output
end
end
end

View File

@ -138,9 +138,6 @@ class TestRDocRubygemsHook < Gem::TestCase
@a.loaded_from =
File.join Gem::Specification.default_specifications_dir, 'a.gemspec'
FileUtils.mkdir_p @a.doc_dir
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
@hook.generate
refute @hook.rdoc_installed?

View File

@ -46,6 +46,7 @@ class TestRDocTask < RDoc::TestCase
assert Rake::Task[:rdoc]
assert Rake::Task[:clobber_rdoc]
assert Rake::Task[:rerdoc]
assert_equal ["html/created.rid"], Rake::Task[:rdoc].prerequisites
end
def test_tasks_creation_with_custom_name_symbol
@ -56,6 +57,23 @@ class TestRDocTask < RDoc::TestCase
assert_equal :rdoc_dev, rd.name
end
def test_tasks_option_parser
rdoc_task = RDoc::Task.new do |rd|
rd.title = "Test Tasks Option Parser"
rd.main = "README.md"
rd.rdoc_files.include("README.md")
rd.options << "--all"
end
assert rdoc_task.title, "Test Tasks Option Parser"
assert rdoc_task.main, "README.md"
assert rdoc_task.rdoc_files.include?("README.md")
assert rdoc_task.options.include?("--all")
args = %w[--all -o html --main README.md] << "--title" << "Test Tasks Option Parser" << "README.md"
assert_equal args, rdoc_task.option_list + rdoc_task.rdoc_files
end
def test_generator_option
rdoc_task = RDoc::Task.new do |rd|
rd.generator = "ri"
@ -64,6 +82,22 @@ class TestRDocTask < RDoc::TestCase
assert_equal %w[-o html -f ri], rdoc_task.option_list
end
def test_main_option
rdoc_task = RDoc::Task.new do |rd|
rd.main = "README.md"
end
assert_equal %w[-o html --main README.md], rdoc_task.option_list
end
def test_output_dir_option
rdoc_task = RDoc::Task.new do |rd|
rd.rdoc_dir = "zomg"
end
assert_equal %w[-o zomg], rdoc_task.option_list
end
def test_rdoc_task_description
assert_equal 'Build RDoc HTML files', @t.rdoc_task_description
end
@ -116,5 +150,21 @@ class TestRDocTask < RDoc::TestCase
end
end
def test_template_option
rdoc_task = RDoc::Task.new do |rd|
rd.template = "foo"
end
assert_equal %w[-o html -T foo], rdoc_task.option_list
end
def test_title_option
rdoc_task = RDoc::Task.new do |rd|
rd.title = "Test Title Option"
end
assert_equal %w[-o html] << "--title" << "Test Title Option", rdoc_task.option_list
end
end