[前][次][番号順一覧][スレッド一覧]

ruby-changes:18391

From: drbrain <ko1@a...>
Date: Wed, 29 Dec 2010 07:09:22 +0900 (JST)
Subject: [ruby-changes:18391] Ruby:r30413 (trunk): Import RDoc 3.1

drbrain	2010-12-29 07:08:56 +0900 (Wed, 29 Dec 2010)

  New Revision: 30413

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=30413

  Log:
    Import RDoc 3.1

  Added files:
    trunk/test/rdoc/test.ja.large.rdoc
    trunk/test/rdoc/test_rdoc_ruby_lex.rb
    trunk/test/rdoc/test_rdoc_stats.rb
  Modified files:
    trunk/ChangeLog
    trunk/NEWS
    trunk/lib/rdoc/class_module.rb
    trunk/lib/rdoc/encoding.rb
    trunk/lib/rdoc/generator/darkfish.rb
    trunk/lib/rdoc/generator/ri.rb
    trunk/lib/rdoc/generator/template/darkfish/classpage.rhtml
    trunk/lib/rdoc/markup/to_html.rb
    trunk/lib/rdoc/options.rb
    trunk/lib/rdoc/parser/c.rb
    trunk/lib/rdoc/parser/ruby.rb
    trunk/lib/rdoc/ri/driver.rb
    trunk/lib/rdoc/ri/paths.rb
    trunk/lib/rdoc/ruby_lex.rb
    trunk/lib/rdoc/stats.rb
    trunk/lib/rdoc/task.rb
    trunk/lib/rdoc.rb
    trunk/test/rdoc/test_rdoc_encoding.rb
    trunk/test/rdoc/test_rdoc_markup_to_html.rb
    trunk/test/rdoc/test_rdoc_options.rb
    trunk/test/rdoc/test_rdoc_parser.rb
    trunk/test/rdoc/test_rdoc_parser_c.rb
    trunk/test/rdoc/test_rdoc_parser_ruby.rb
    trunk/test/rdoc/test_rdoc_ri_paths.rb
    trunk/test/rdoc/test_rdoc_task.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 30412)
+++ ChangeLog	(revision 30413)
@@ -1,3 +1,7 @@
+Wed Dec 29 07:07:06 2010  Eric Hodel  <drbrain@s...>
+
+	* lib/rdoc: Import RDoc 3.1
+
 Tue Dec 28 18:36:38 2010  NAKAMURA Usaku  <usa@r...>
 
 	* re.c (rb_reg_expr_str): need to escape if the coderage is invalid.
Index: lib/rdoc.rb
===================================================================
--- lib/rdoc.rb	(revision 30412)
+++ lib/rdoc.rb	(revision 30413)
@@ -95,7 +95,7 @@
   ##
   # RDoc version you are using
 
-  VERSION = '3.0'
+  VERSION = '3.1'
 
   ##
   # Method visibilities
Index: lib/rdoc/generator/template/darkfish/classpage.rhtml
===================================================================
--- lib/rdoc/generator/template/darkfish/classpage.rhtml	(revision 30412)
+++ lib/rdoc/generator/template/darkfish/classpage.rhtml	(revision 30413)
@@ -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>
 
+        <% if method.call_seq %>
+        <% method.call_seq.strip.split("\n").each_with_index do |call_seq, i| %>
         <div class="method-heading">
-        <% if method.call_seq %>
-          <span class="method-callseq"><%= method.call_seq.strip.gsub(/->/, '&rarr;').gsub( /^\w.+\./m, '') %></span>
+          <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>
+        </div>
         <% end %>
-        </div>
 
         <div class="method-description">
           <% if method.comment %>
Index: lib/rdoc/generator/ri.rb
===================================================================
--- lib/rdoc/generator/ri.rb	(revision 30412)
+++ lib/rdoc/generator/ri.rb	(revision 30413)
@@ -9,6 +9,11 @@
   RDoc::RDoc.add_generator self
 
   ##
+  # Description of this generator
+
+  DESCRIPTION = 'creates ri data files'
+
+  ##
   # Set up a new ri generator
 
   def initialize options #:not-new:
Index: lib/rdoc/generator/darkfish.rb
===================================================================
--- lib/rdoc/generator/darkfish.rb	(revision 30412)
+++ lib/rdoc/generator/darkfish.rb	(revision 30413)
@@ -64,6 +64,11 @@
   VERSION = '2'
 
   ##
+  # Description of this generator
+
+  DESCRIPTION = 'HTML generator, written by Michael Granger'
+
+  ##
   # Initialize a few instance variables before we start
 
   def initialize options
Index: lib/rdoc/markup/to_html.rb
===================================================================
--- lib/rdoc/markup/to_html.rb	(revision 30412)
+++ lib/rdoc/markup/to_html.rb	(revision 30413)
@@ -27,6 +27,11 @@
   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
 
   def self.gen_relative_url(path, target)
@@ -59,6 +64,7 @@
     @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 @@
   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
Index: lib/rdoc/stats.rb
===================================================================
--- lib/rdoc/stats.rb	(revision 30412)
+++ lib/rdoc/stats.rb	(revision 30413)
@@ -24,6 +24,7 @@
     @files_so_far = 0
     @num_files = num_files
     @fully_documented = nil
+    @percent_doc = nil
 
     @start = Time.now
 
@@ -215,7 +216,9 @@
         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,23 +258,37 @@
   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
     report << 'Elapsed: %0.1fs' % (Time.now - @start)
Index: lib/rdoc/ri/paths.rb
===================================================================
--- lib/rdoc/ri/paths.rb	(revision 30412)
+++ lib/rdoc/ri/paths.rb	(revision 30413)
@@ -19,7 +19,17 @@
   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
Index: lib/rdoc/ri/driver.rb
===================================================================
--- lib/rdoc/ri/driver.rb	(revision 30412)
+++ lib/rdoc/ri/driver.rb	(revision 30413)
@@ -610,7 +610,7 @@
       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
Index: lib/rdoc/class_module.rb
===================================================================
--- lib/rdoc/class_module.rb	(revision 30412)
+++ lib/rdoc/class_module.rb	(revision 30413)
@@ -118,7 +118,8 @@
   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
Index: lib/rdoc/encoding.rb
===================================================================
--- lib/rdoc/encoding.rb	(revision 30412)
+++ lib/rdoc/encoding.rb	(revision 30413)
@@ -60,8 +60,6 @@
   # 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 @@
            else                                           return
            end
 
+    string.sub! first_line, ''
+
+    return unless Object.const_defined? :Encoding
+
     enc = Encoding.find name
     string.force_encoding enc if enc
   end
Index: lib/rdoc/ruby_lex.rb
===================================================================
--- lib/rdoc/ruby_lex.rb	(revision 30412)
+++ lib/rdoc/ruby_lex.rb	(revision 30413)
@@ -541,12 +541,12 @@
       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 @@
     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
Index: lib/rdoc/parser/ruby.rb
===================================================================
--- lib/rdoc/parser/ruby.rb	(revision 30412)
+++ lib/rdoc/parser/ruby.rb	(revision 30413)
@@ -224,9 +224,11 @@
   ##
   # 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 @@
 
       @stats.add_attribute att
     end
+
+    true
   end
 
   ##
@@ -1230,10 +1234,10 @@
         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 @@
 
           return
         end
+      else
+        non_comment_seen = parse_comment container, tk, comment unless
+          comment.empty?
+
+        comment = ''
       end
 
       comment = '' unless keep_comment
Index: lib/rdoc/parser/c.rb
===================================================================
--- lib/rdoc/parser/c.rb	(revision 30412)
+++ lib/rdoc/parser/c.rb	(revision 30413)
@@ -371,7 +371,7 @@
 
   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 @@
     # 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)
 
Index: lib/rdoc/options.rb
===================================================================
--- lib/rdoc/options.rb	(revision 30412)
+++ lib/rdoc/options.rb	(revision 30413)
@@ -241,6 +241,32 @@
   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.
 
   def parse(argv)
@@ -274,9 +300,10 @@
   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:
 
       EOF
Index: lib/rdoc/task.rb
===================================================================
--- lib/rdoc/task.rb	(revision 30412)
+++ lib/rdoc/task.rb	(revision 30413)
@@ -53,6 +53,9 @@
 #
 # 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 @@
 # 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 @@
 #
 # For example:
 #
+#   gem 'rdoc'
+#   require 'rdoc/task'
+#
 #   RDoc::Task.new(:rdoc => "rdoc", :clobber_rdoc => "rdoc:clean",
 #                  :rerdoc => "rdoc:force")
 #
@@ -117,6 +126,11 @@
   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 [])
 
   attr_accessor :rdoc_files
@@ -151,12 +165,28 @@
     @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.
 
   def define
@@ -201,9 +231,10 @@
   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
 
Index: NEWS
===================================================================
--- NEWS	(revision 30412)
+++ NEWS	(revision 30413)
@@ -89,7 +89,7 @@
     * 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
Index: test/rdoc/test.ja.large.rdoc
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: test/rdoc/test.ja.large.rdoc
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Index: test/rdoc/test_rdoc_markup_to_html.rb
===================================================================
--- test/rdoc/test_rdoc_markup_to_html.rb	(revision 30412)
+++ test/rdoc/test_rdoc_markup_to_html.rb	(revision 30413)
@@ -297,6 +297,11 @@
     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"
 
Index: test/rdoc/test_rdoc_parser.rb
===================================================================
--- test/rdoc/test_rdoc_parser.rb	(revision 30412)
+++ test/rdoc/test_rdoc_parser.rb	(revision 30413)
@@ -28,6 +28,11 @@
     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
 
Index: test/rdoc/test_rdoc_stats.rb
===================================================================
--- test/rdoc/test_rdoc_stats.rb	(revision 0)
+++ test/rdoc/test_rdoc_stats.rb	(revision 30413)
@@ -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
+
Index: test/rdoc/test_rdoc_ri_paths.rb
===================================================================
--- test/rdoc/test_rdoc_ri_paths.rb	(revision 30412)
+++ test/rdoc/test_rdoc_ri_paths.rb	(revision 30413)
@@ -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 @@
     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
 
Index: test/rdoc/test_rdoc_encoding.rb
===================================================================
--- test/rdoc/test_rdoc_encoding.rb	(revision 30412)
+++ test/rdoc/test_rdoc_encoding.rb	(revision 30413)
@@ -30,7 +30,7 @@
     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 @@
 
     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 @@
     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 @@
     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 @@
     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
 
Index: test/rdoc/test_rdoc_ruby_lex.rb
===================================================================
--- test/rdoc/test_rdoc_ruby_lex.rb	(revision 0)
+++ test/rdoc/test_rdoc_ruby_lex.rb	(revision 30413)
@@ -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
Index: test/rdoc/test_rdoc_options.rb
===================================================================
--- test/rdoc/test_rdoc_options.rb	(revision 30412)
+++ test/rdoc/test_rdoc_options.rb	(revision 30413)
@@ -9,8 +9,13 @@
 
   def setup
     @options = RDoc::Options.new
+    @generators = RDoc::RDoc::GENERATORS.dup
   end
 
+  def teardown
+    RDoc::RDoc::GENERATORS.replace @generators
+  end
+
   def test_check_files
     out, err = capture_io do
       Dir.mktmpdir do |dir|
@@ -47,6 +52,20 @@
     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 @@
     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,13 +318,14 @@
   end
 
   def test_setup_generator
-    test_generator = Object.new
-    def test_generator.setup_options(op)
-      @op = op
+    test_generator = Class.new do
+      def self.setup_options op
+        @op = op
+      end
+
+      def self.op() @op end
     end
 
-    def test_generator.op() @op end
-
     RDoc::RDoc::GENERATORS['TestGenerator'] = test_generator
 
     @options.setup_generator 'TestGenerator'
@@ -293,6 +334,8 @@
     assert_equal [test_generator], @options.generator_options
 
     assert_equal @options, test_generator.op
+  ensure
+    RDoc::RDoc::GENERATORS.delete 'TestGenerator'
   end
 
 end
Index: test/rdoc/test_rdoc_parser_ruby.rb
===================================================================
--- test/rdoc/test_rdoc_parser_ruby.rb	(revision 30412)
+++ test/rdoc/test_rdoc_parser_ruby.rb	(revision 30413)
@@ -32,6 +32,66 @@
     @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 @@
     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'
Index: test/rdoc/test_rdoc_parser_c.rb
===================================================================
--- test/rdoc/test_rdoc_parser_c.rb	(revision 30412)
+++ test/rdoc/test_rdoc_parser_c.rb	(revision 30413)
@@ -532,6 +532,46 @@
     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 @@
     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:
Index: test/rdoc/test_rdoc_task.rb
===================================================================
--- test/rdoc/test_rdoc_task.rb	(revision 30412)
+++ test/rdoc/test_rdoc_task.rb	(revision 30413)
@@ -8,6 +8,26 @@
     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 @@
     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]

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]