ruby-changes:3631
From: ko1@a...
Date: Sat, 19 Jan 2008 09:07:31 +0900 (JST)
Subject: [ruby-changes:3631] drbrain - Ruby:r15120 (trunk): * lib/rdoc/markup: Remove ListBase and Line constants.
drbrain 2008-01-19 09:06:19 +0900 (Sat, 19 Jan 2008)
New Revision: 15120
Added files:
trunk/lib/rdoc/markup/to_test.rb
trunk/test/rdoc/test_rdoc_c_parser.rb
trunk/test/rdoc/test_rdoc_markup.rb
trunk/test/rdoc/test_rdoc_markup_attribute_manager.rb
trunk/test/rdoc/test_rdoc_ri_attribute_formatter.rb
trunk/test/rdoc/test_rdoc_ri_formatter.rb
Removed files:
trunk/test/rdoc/parsers/test_parse_c.rb
trunk/test/rdoc/test_simple_markup.rb
trunk/test/rdoc/test_simple_markup_attribute_manager.rb
Modified files:
trunk/ChangeLog
trunk/lib/rdoc/markup/fragments.rb
trunk/lib/rdoc/markup/lines.rb
trunk/lib/rdoc/markup/to_flow.rb
trunk/lib/rdoc/markup/to_html.rb
trunk/lib/rdoc/markup/to_latex.rb
trunk/lib/rdoc/markup.rb
trunk/lib/rdoc/ri/display.rb
trunk/lib/rdoc/ri/formatter.rb
Log:
* lib/rdoc/markup: Remove ListBase and Line constants.
* lib/rdoc/ri: Allow output IO to be specified.
* test/rdoc/parser/test_parse_c.rb: Move up one level, fixed.
* test/rdoc/parser/test_rdoc_markup_attribute_manager.rb: Renamed to
match new class name, updated to match new classes.
* test/rdoc/test_rdoc_ri_formatter.rb: Start of RI formatting tests.
* test/rdoc/test_rdoc_ri_attribute_manager.rb: Start of
RDoc::RI::AttributeManager tests.
* test/rdoc/test_simple_markup.rb: Moved to match new class name.
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/rdoc/test_rdoc_ri_attribute_formatter.rb?revision=15120&view=markup
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/lib/rdoc/ri/formatter.rb?r1=15120&r2=15119&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/lib/rdoc/markup/fragments.rb?r1=15120&r2=15119&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/rdoc/test_rdoc_ri_formatter.rb?revision=15120&view=markup
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15120&r2=15119&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/rdoc/test_simple_markup.rb
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/rdoc/test_rdoc_markup_attribute_manager.rb
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/rdoc/test_rdoc_markup.rb
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/rdoc/test_rdoc_c_parser.rb
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/lib/rdoc/markup/to_test.rb?revision=15120&view=markup
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/lib/rdoc/markup/to_test.rb?r1=15120&r2=15119&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/lib/rdoc/markup/to_flow.rb?r1=15120&r2=15119&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/lib/rdoc/markup/to_latex.rb?r1=15120&r2=15119&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/lib/rdoc/markup/lines.rb?r1=15120&r2=15119&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/rdoc/parsers/test_parse_c.rb
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/lib/rdoc/markup.rb?r1=15120&r2=15119&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/lib/rdoc/markup/to_html.rb?r1=15120&r2=15119&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/rdoc/test_simple_markup_attribute_manager.rb
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/lib/rdoc/ri/display.rb?r1=15120&r2=15119&diff_format=u
Index: ChangeLog
===================================================================
--- ChangeLog (revision 15119)
+++ ChangeLog (revision 15120)
@@ -1,3 +1,21 @@
+Sat Jan 19 08:58:47 2008 Eric Hodel <drbrain@s...>
+
+ * lib/rdoc/markup: Remove ListBase and Line constants.
+
+ * lib/rdoc/ri: Allow output IO to be specified.
+
+ * test/rdoc/parser/test_parse_c.rb: Move up one level, fixed.
+
+ * test/rdoc/parser/test_rdoc_markup_attribute_manager.rb: Renamed to
+ match new class name, updated to match new classes.
+
+ * test/rdoc/test_rdoc_ri_formatter.rb: Start of RI formatting tests.
+
+ * test/rdoc/test_rdoc_ri_attribute_manager.rb: Start of
+ RDoc::RI::AttributeManager tests.
+
+ * test/rdoc/test_simple_markup.rb: Moved to match new class name.
+
Sat Jan 19 08:35:36 2008 Nobuyoshi Nakada <nobu@r...>
* parse.y (parser_prepare): get encoding from the first line.
Index: lib/rdoc/markup/to_latex.rb
===================================================================
--- lib/rdoc/markup/to_latex.rb (revision 15119)
+++ lib/rdoc/markup/to_latex.rb (revision 15120)
@@ -29,12 +29,12 @@
end
LIST_TYPE_TO_LATEX = {
- RDoc::Markup::ListBase::BULLET => [ l("\\begin{itemize}"), l("\\end{itemize}") ],
- RDoc::Markup::ListBase::NUMBER => [ l("\\begin{enumerate}"), l("\\end{enumerate}"), "\\arabic" ],
- RDoc::Markup::ListBase::UPPERALPHA => [ l("\\begin{enumerate}"), l("\\end{enumerate}"), "\\Alph" ],
- RDoc::Markup::ListBase::LOWERALPHA => [ l("\\begin{enumerate}"), l("\\end{enumerate}"), "\\alph" ],
- RDoc::Markup::ListBase::LABELED => [ l("\\begin{description}"), l("\\end{description}") ],
- RDoc::Markup::ListBase::NOTE => [
+ :BULLET => [ l("\\begin{itemize}"), l("\\end{itemize}") ],
+ :NUMBER => [ l("\\begin{enumerate}"), l("\\end{enumerate}"), "\\arabic" ],
+ :UPPERALPHA => [ l("\\begin{enumerate}"), l("\\end{enumerate}"), "\\Alph" ],
+ :LOWERALPHA => [ l("\\begin{enumerate}"), l("\\end{enumerate}"), "\\alph" ],
+ :LABELED => [ l("\\begin{description}"), l("\\end{description}") ],
+ :NOTE => [
l("\\begin{tabularx}{\\linewidth}{@{} l X @{}}"),
l("\\end{tabularx}") ],
}
@@ -299,15 +299,13 @@
def list_item_start(am, fragment)
case fragment.type
- when RDoc::Markup::ListBase::BULLET, RDoc::Markup::ListBase::NUMBER,
- RDoc::Markup::ListBase::UPPERALPHA,
- RDoc::Markup::ListBase::LOWERALPHA then
+ when :BULLET, :NUMBER, :UPPERALPHA, :LOWERALPHA then
"\\item "
- when RDoc::Markup::ListBase::LABELED then
+ when :LABELED then
"\\item[" + convert_flow(am.flow(fragment.param)) + "] "
- when RDoc::Markup::ListBase::NOTE then
+ when :NOTE then
convert_flow(am.flow(fragment.param)) + " & "
else
raise "Invalid list type"
@@ -316,13 +314,9 @@
def list_end_for(fragment_type)
case fragment_type
- when RDoc::Markup::ListBase::BULLET,
- RDoc::Markup::ListBase::NUMBER,
- RDoc::Markup::ListBase::UPPERALPHA,
- RDoc::Markup::ListBase::LOWERALPHA,
- RDoc::Markup::ListBase::LABELED then
+ when :BULLET, :NUMBER, :UPPERALPHA, :LOWERALPHA, :LABELED then
""
- when RDoc::Markup::ListBase::NOTE
+ when :NOTE
"\\\\\n"
else
raise "Invalid list type"
Index: lib/rdoc/markup/to_test.rb
===================================================================
--- lib/rdoc/markup/to_test.rb (revision 0)
+++ lib/rdoc/markup/to_test.rb (revision 15120)
@@ -0,0 +1,49 @@
+require 'rdoc/markup'
+
+##
+# This Markup outputter is used for testing purposes.
+
+class RDoc::Markup::ToTest
+
+ def start_accepting
+ @res = []
+ end
+
+ def end_accepting
+ @res
+ end
+
+ def accept_paragraph(am, fragment)
+ @res << fragment.to_s
+ end
+
+ def accept_verbatim(am, fragment)
+ @res << fragment.to_s
+ end
+
+ def accept_list_start(am, fragment)
+ @res << fragment.to_s
+ end
+
+ def accept_list_end(am, fragment)
+ @res << fragment.to_s
+ end
+
+ def accept_list_item(am, fragment)
+ @res << fragment.to_s
+ end
+
+ def accept_blank_line(am, fragment)
+ @res << fragment.to_s
+ end
+
+ def accept_heading(am, fragment)
+ @res << fragment.to_s
+ end
+
+ def accept_rule(am, fragment)
+ @res << fragment.to_s
+ end
+
+end
+
Property changes on: lib/rdoc/markup/to_test.rb
___________________________________________________________________
Name: svn:eol-style
+ LF
Name: svn:keywords
+ Author Date Id Revision
Index: lib/rdoc/markup/fragments.rb
===================================================================
--- lib/rdoc/markup/fragments.rb (revision 15119)
+++ lib/rdoc/markup/fragments.rb (revision 15120)
@@ -11,6 +11,22 @@
attr_reader :level, :param, :txt
attr_accessor :type
+ ######
+ # This is a simple factory system that lets us associate fragement
+ # types (a string) with a subclass of fragment
+
+ TYPE_MAP = {}
+
+ def self.type_name(name)
+ TYPE_MAP[name] = self
+ end
+
+ def self.for(line)
+ klass = TYPE_MAP[line.type] ||
+ raise("Unknown line type: '#{line.type.inspect}:' '#{line.text}'")
+ return klass.new(line.level, line.param, line.flag, line.text)
+ end
+
def initialize(level, param, type, txt)
@level = level
@param = param
@@ -28,21 +44,6 @@
"L#@level: #{self.class.name.split('::')[-1]}\n#@txt"
end
- ######
- # This is a simple factory system that lets us associate fragement
- # types (a string) with a subclass of fragment
-
- TYPE_MAP = {}
-
- def Fragment.type_name(name)
- TYPE_MAP[name] = self
- end
-
- def Fragment.for(line)
- klass = TYPE_MAP[line.type] ||
- raise("Unknown line type: '#{line.type.inspect}:' '#{line.text}'")
- return klass.new(line.level, line.param, line.flag, line.text)
- end
end
##
@@ -50,15 +51,15 @@
# newlines when we're created, and have them put back on output.
class Paragraph < Fragment
- type_name Line::PARAGRAPH
+ type_name :PARAGRAPH
end
class BlankLine < Paragraph
- type_name Line::BLANK
+ type_name :BLANK
end
class Heading < Paragraph
- type_name Line::HEADING
+ type_name :HEADING
def head_level
@param.to_i
@@ -69,17 +70,18 @@
# A List is a fragment with some kind of label
class ListBase < Paragraph
- # List types
- BULLET = :BULLET
- NUMBER = :NUMBER
- UPPERALPHA = :UPPERALPHA
- LOWERALPHA = :LOWERALPHA
- LABELED = :LABELED
- NOTE = :NOTE
+ LIST_TYPES = [
+ :BULLET,
+ :NUMBER,
+ :UPPERALPHA,
+ :LOWERALPHA,
+ :LABELED,
+ :NOTE,
+ ]
end
class ListItem < ListBase
- type_name Line::LIST
+ type_name :LIST
# def label
# am = AttributeManager.new(@param)
@@ -103,7 +105,7 @@
# Verbatim code contains lines that don't get wrapped.
class Verbatim < Fragment
- type_name Line::VERBATIM
+ type_name :VERBATIM
def add_text(txt)
@txt << txt.chomp << "\n"
@@ -115,7 +117,7 @@
# A horizontal rule
class Rule < Fragment
- type_name Line::RULE
+ type_name :RULE
end
##
Index: lib/rdoc/markup/to_html.rb
===================================================================
--- lib/rdoc/markup/to_html.rb (revision 15119)
+++ lib/rdoc/markup/to_html.rb (revision 15120)
@@ -6,12 +6,12 @@
class RDoc::Markup::ToHtml
LIST_TYPE_TO_HTML = {
- RDoc::Markup::ListBase::BULLET => [ "<ul>", "</ul>" ],
- RDoc::Markup::ListBase::NUMBER => [ "<ol>", "</ol>" ],
- RDoc::Markup::ListBase::UPPERALPHA => [ "<ol>", "</ol>" ],
- RDoc::Markup::ListBase::LOWERALPHA => [ "<ol>", "</ol>" ],
- RDoc::Markup::ListBase::LABELED => [ "<dl>", "</dl>" ],
- RDoc::Markup::ListBase::NOTE => [ "<table>", "</table>" ],
+ :BULLET => [ "<ul>", "</ul>" ],
+ :NUMBER => [ "<ol>", "</ol>" ],
+ :UPPERALPHA => [ "<ol>", "</ol>" ],
+ :LOWERALPHA => [ "<ol>", "</ol>" ],
+ :LABELED => [ "<dl>", "</dl>" ],
+ :NOTE => [ "<table>", "</table>" ],
}
InlineTag = Struct.new(:bit, :on, :off)
@@ -241,22 +241,22 @@
def list_item_start(am, fragment)
case fragment.type
- when RDoc::Markup::ListBase::BULLET, RDoc::Markup::ListBase::NUMBER then
+ when :BULLET, :NUMBER then
annotate("<li>")
- when RDoc::Markup::ListBase::UPPERALPHA then
+ when :UPPERALPHA then
annotate("<li type=\"A\">")
- when RDoc::Markup::ListBase::LOWERALPHA then
+ when :LOWERALPHA then
annotate("<li type=\"a\">")
- when RDoc::Markup::ListBase::LABELED then
+ when :LABELED then
annotate("<dt>") +
convert_flow(am.flow(fragment.param)) +
annotate("</dt>") +
annotate("<dd>")
- when RDoc::Markup::ListBase::NOTE then
+ when :NOTE then
annotate("<tr>") +
annotate("<td valign=\"top\">") +
convert_flow(am.flow(fragment.param)) +
@@ -269,13 +269,11 @@
def list_end_for(fragment_type)
case fragment_type
- when RDoc::Markup::ListBase::BULLET, RDoc::Markup::ListBase::NUMBER,
- RDoc::Markup::ListBase::UPPERALPHA,
- RDoc::Markup::ListBase::LOWERALPHA then
+ when :BULLET, :NUMBER, :UPPERALPHA, :LOWERALPHA then
"</li>"
- when RDoc::Markup::ListBase::LABELED then
+ when :LABELED then
"</dd>"
- when RDoc::Markup::ListBase::NOTE then
+ when :NOTE then
"</td></tr>"
else
raise "Invalid list type"
Index: lib/rdoc/markup/to_flow.rb
===================================================================
--- lib/rdoc/markup/to_flow.rb (revision 15119)
+++ lib/rdoc/markup/to_flow.rb (revision 15120)
@@ -24,12 +24,12 @@
class ToFlow
LIST_TYPE_TO_HTML = {
- RDoc::Markup::ListBase::BULLET => [ "<ul>", "</ul>" ],
- RDoc::Markup::ListBase::NUMBER => [ "<ol>", "</ol>" ],
- RDoc::Markup::ListBase::UPPERALPHA => [ "<ol>", "</ol>" ],
- RDoc::Markup::ListBase::LOWERALPHA => [ "<ol>", "</ol>" ],
- RDoc::Markup::ListBase::LABELED => [ "<dl>", "</dl>" ],
- RDoc::Markup::ListBase::NOTE => [ "<table>", "</table>" ],
+ :BULLET => [ "<ul>", "</ul>" ],
+ :NUMBER => [ "<ol>", "</ol>" ],
+ :UPPERALPHA => [ "<ol>", "</ol>" ],
+ :LOWERALPHA => [ "<ol>", "</ol>" ],
+ :LABELED => [ "<dl>", "</dl>" ],
+ :NOTE => [ "<table>", "</table>" ],
}
InlineTag = Struct.new(:bit, :on, :off)
Index: lib/rdoc/markup/lines.rb
===================================================================
--- lib/rdoc/markup/lines.rb (revision 15119)
+++ lib/rdoc/markup/lines.rb (revision 15120)
@@ -8,12 +8,14 @@
class Line
INFINITY = 9999
- BLANK = :BLANK
- HEADING = :HEADING
- LIST = :LIST
- RULE = :RULE
- PARAGRAPH = :PARAGRAPH
- VERBATIM = :VERBATIM
+ LINE_TYPES = [
+ :BLANK,
+ :HEADING,
+ :LIST,
+ :PARAGRAPH,
+ :RULE,
+ :VERBATIM,
+ ]
# line type
attr_accessor :type
@@ -132,7 +134,7 @@
def normalize
margin = @lines.collect{|l| l.leading_spaces}.min
- margin = 0 if margin == Line::INFINITY
+ margin = 0 if margin == :INFINITY
@lines.each {|line| line.strip_leading(margin) } if margin > 0
end
Index: lib/rdoc/markup.rb
===================================================================
--- lib/rdoc/markup.rb (revision 15119)
+++ lib/rdoc/markup.rb (revision 15120)
@@ -159,7 +159,6 @@
#
#--
# Author:: Dave Thomas, dave@p...
-# Version:: 0.0
# License:: Ruby license
class RDoc::Markup
@@ -256,7 +255,7 @@
while line = @lines.next
if line.isBlank?
- line.stamp(Line::BLANK, level)
+ line.stamp :BLANK, level
next
end
@@ -282,7 +281,7 @@
#
if /^(---+)\s*$/ =~ active_line
- line.stamp(Line::RULE, level, $1.length-2)
+ line.stamp :RULE, level, $1.length-2
next
end
@@ -296,14 +295,14 @@
prefix_length = prefix.length
flag = case prefix
- when "*","-" then ListBase::BULLET
- when /^\d/ then ListBase::NUMBER
- when /^[A-Z]/ then ListBase::UPPERALPHA
- when /^[a-z]/ then ListBase::LOWERALPHA
+ when "*","-" then :BULLET
+ when /^\d/ then :NUMBER
+ when /^[A-Z]/ then :UPPERALPHA
+ when /^[a-z]/ then :LOWERALPHA
else raise "Invalid List Type: #{self.inspect}"
end
- line.stamp(Line::LIST, level+1, prefix, flag)
+ line.stamp :LIST, level+1, prefix, flag
text[margin, prefix_length] = " " * prefix_length
assign_types_to_lines(offset, level + 1)
next
@@ -328,7 +327,7 @@
if active_line[0] == ?= and active_line =~ /^(=+)\s*(.*)/
prefix_length = $1.length
prefix_length = 6 if prefix_length > 6
- line.stamp(Line::HEADING, 0, prefix_length)
+ line.stamp :HEADING, 0, prefix_length
line.strip_leading(margin + prefix_length)
next
end
@@ -338,9 +337,9 @@
if active_line[0] == SPACE
line.strip_leading(margin) if margin > 0
- line.stamp(Line::VERBATIM, level)
+ line.stamp :VERBATIM, level
else
- line.stamp(Line::PARAGRAPH, level)
+ line.stamp :PARAGRAPH, level
end
end
end
@@ -369,10 +368,10 @@
flag = nil
case prefix
when /^\[/
- flag = ListBase::LABELED
+ flag = :LABELED
prefix = prefix[1, prefix.length-2]
when /:$/
- flag = ListBase::NOTE
+ flag = :NOTE
prefix.chop!
else raise "Invalid List Type: #{self.inspect}"
end
@@ -403,7 +402,7 @@
end
end
- line.stamp(Line::LIST, level+1, prefix, flag)
+ line.stamp :LIST, level+1, prefix, flag
text[margin, prefix_length] = " " * prefix_length
assign_types_to_lines(offset, level + 1)
return true
@@ -431,12 +430,12 @@
else
group = block.fragment_for(line)
block.add(group)
- if line.type == Line::LIST
- wantedType = Line::PARAGRAPH
+ if line.type == :LIST
+ wantedType = :PARAGRAPH
else
wantedType = line.type
end
- wantedLevel = line.type == Line::HEADING ? line.param : line.level
+ wantedLevel = line.type == :HEADING ? line.param : line.level
end
end
Index: lib/rdoc/ri/formatter.rb
===================================================================
--- lib/rdoc/ri/formatter.rb (revision 15119)
+++ lib/rdoc/ri/formatter.rb (revision 15120)
@@ -1,27 +1,49 @@
require 'rdoc/ri'
+require 'rdoc/markup'
class RDoc::RI::Formatter
attr_reader :indent
- def initialize(width, indent)
- @width = width
- @indent = indent
+ FORMATTERS = { }
+
+ def self.for(name)
+ FORMATTERS[name.downcase]
end
+ def self.list
+ FORMATTERS.keys.sort.join ", "
+ end
+
+ def initialize(output, width, indent)
+ @output = output
+ @width = width
+ @indent = indent
+ end
+
def draw_line(label=nil)
len = @width
- len -= (label.size+1) if label
- print "-"*len
- if label
- print(" ")
- bold_print(label)
+ len -= (label.size + 1) if label
+
+ if len > 0 then
+ @output.print '-' * len
+ if label
+ @output.print ' '
+ bold_print label
+ end
+
+ @output.puts
+ else
+ @output.print '-' * @width
+ @output.puts
+
+ @output.puts label
end
- puts
end
- def wrap(txt, prefix=@indent, linelen=@width)
+ def wrap(txt, prefix=@indent, linelen=@width)
return unless txt && !txt.empty?
+
work = conv_markup(txt)
textLen = linelen - prefix.length
patt = Regexp.new("^(.{0,#{textLen}})[ \n]")
@@ -38,11 +60,11 @@
end
end
res << work if work.length.nonzero?
- puts(prefix + res.join("\n" + next_prefix))
+ @output.puts(prefix + res.join("\n" + next_prefix))
end
def blankline
- puts
+ @output.puts
end
##
@@ -53,11 +75,11 @@
end
def bold_print(txt)
- print txt
+ @output.print txt
end
def raw_print_line(txt)
- puts txt
+ @output.puts txt
end
##
@@ -69,7 +91,6 @@
gsub(/</, '<').
gsub(/"/, '"').
gsub(/&/, '&')
-
end
##
@@ -78,25 +99,22 @@
def conv_markup(txt)
txt.
gsub(%r{<tt>(.*?)</tt>}) { "+#$1+" } .
- gsub(%r{<code>(.*?)</code>}) { "+#$1+" } .
- gsub(%r{<b>(.*?)</b>}) { "*#$1*" } .
- gsub(%r{<em>(.*?)</em>}) { "_#$1_" }
+ gsub(%r{<code>(.*?)</code>}) { "+#$1+" } .
+ gsub(%r{<b>(.*?)</b>}) { "*#$1*" } .
+ gsub(%r{<em>(.*?)</em>}) { "_#$1_" }
end
def display_list(list)
case list.type
-
- when RDoc::Markup::ListBase::BULLET
+ when :BULLET
prefixer = proc { |ignored| @indent + "* " }
- when RDoc::Markup::ListBase::NUMBER,
- RDoc::Markup::ListBase::UPPERALPHA,
- RDoc::Markup::ListBase::LOWERALPHA
+ when :NUMBER, :UPPERALPHA, :LOWERALPHA then
start = case list.type
- when RDoc::Markup::ListBase::NUMBER then 1
- when RDoc::Markup::ListBase::UPPERALPHA then 'A'
- when RDoc::Markup::ListBase::LOWERALPHA then 'a'
+ when :NUMBER then 1
+ when :UPPERALPHA then 'A'
+ when :LOWERALPHA then 'a'
end
prefixer = proc do |ignored|
res = @indent + "#{start}.".ljust(4)
@@ -104,12 +122,12 @@
res
end
- when RDoc::Markup::ListBase::LABELED
+ when :LABELED then
prefixer = proc do |li|
li.label
end
- when RDoc::Markup::ListBase::NOTE
+ when :NOTE then
longest = 0
list.contents.each do |item|
if item.kind_of?(RDoc::Markup::Flow::LI) && item.label.length > longest
@@ -122,8 +140,7 @@
end
else
- fail "unknown list type"
-
+ raise ArgumentError, "unknown list type #{list.type}"
end
list.contents.each do |item|
@@ -161,7 +178,7 @@
def display_verbatim_flow_item(item, prefix=@indent)
item.body.split(/\n/).each do |line|
- print @indent, conv_html(line), "\n"
+ @output.print @indent, conv_html(line), "\n"
end
blankline
end
@@ -171,19 +188,19 @@
case level
when 1
ul = "=" * text.length
- puts
- puts text.upcase
- puts ul
+ @output.puts
+ @output.puts text.upcase
+ @output.puts ul
# puts
when 2
ul = "-" * text.length
- puts
- puts text
- puts ul
+ @output.puts
+ @output.puts text
+ @output.puts ul
# puts
else
- print indent, text, "\n"
+ @output.print indent, text, "\n"
end
end
@@ -274,11 +291,11 @@
end
##
- # Overrides base class. Looks for <tt>...</tt> etc sequences
- # and generates an array of AttrChars. This array is then used
- # as the basis for the split
+ # Overrides base class. Looks for <tt>...</tt> etc sequences and generates
+ # an array of AttrChars. This array is then used as the basis for the
+ # split.
- def wrap(txt, prefix=@indent, linelen=@width)
+ def wrap(txt, prefix=@indent, linelen=@width)
return unless txt && !txt.empty?
txt = add_attributes_to(txt)
@@ -303,15 +320,15 @@
protected
def write_attribute_text(prefix, line)
- print prefix
+ @output.print prefix
line.each do |achar|
- print achar.char
+ @output.print achar.char
end
- puts
+ @output.puts
end
def bold_print(txt)
- print txt
+ @output.print txt
end
private
@@ -342,18 +359,18 @@
BS = "\C-h"
def write_attribute_text(prefix, line)
- print prefix
+ @output.print prefix
line.each do |achar|
attr = achar.attr
if (attr & (ITALIC+CODE)) != 0
- print "_", BS
+ @output.print "_", BS
end
if (attr & BOLD) != 0
- print achar.char, BS
+ @output.print achar.char, BS
end
- print achar.char
+ @output.print achar.char
end
- puts
+ @output.puts
end
##
@@ -361,7 +378,7 @@
def bold_print(text)
text.split(//).each do |ch|
- print ch, BS, ch
+ @output.print ch, BS, ch
end
end
@@ -374,12 +391,12 @@
class RDoc::RI::AnsiFormatter < RDoc::RI::AttributeFormatter
def initialize(*args)
- print "\033[0m"
super
+ @output.print "\033[0m"
end
def write_attribute_text(prefix, line)
- print prefix
+ @output.print prefix
curr_attr = 0
line.each do |achar|
attr = achar.attr
@@ -387,14 +404,14 @@
update_attributes(achar.attr)
curr_attr = achar.attr
end
- print achar.char
+ @output.print achar.char
end
update_attributes(0) unless curr_attr.zero?
- puts
+ @output.puts
end
def bold_print(txt)
- print "\033[1m#{txt}\033[m"
+ @output.print "\033[1m#{txt}\033[m"
end
HEADINGS = {
@@ -406,10 +423,10 @@
def display_heading(text, level, indent)
level = 3 if level > 3
heading = HEADINGS[level]
- print indent
- print heading[0]
- print strip_attributes(text)
- puts heading[1]
+ @output.print indent
+ @output.print heading[0]
+ @output.print strip_attributes(text)
+ @output.puts heading[1]
end
private
@@ -427,7 +444,7 @@
str << ATTR_MAP[quality]
end
end
- print str, "m"
+ @output.print str, "m"
end
end
@@ -445,7 +462,7 @@
update_attributes(curr_attr, achar.attr)
curr_attr = achar.attr
end
- print(escape(achar.char))
+ @output.print(escape(achar.char))
end
update_attributes(curr_attr, 0) unless curr_attr.zero?
end
@@ -454,7 +471,7 @@
if label != nil
bold_print(label)
end
- puts("<hr>")
+ @output.puts("<hr>")
end
def bold_print(txt)
@@ -462,38 +479,36 @@
end
def blankline()
- puts("<p>")
+ @output.puts("<p>")
end
def break_to_newline
- puts("<br>")
+ @output.puts("<br>")
end
def display_heading(text, level, indent)
level = 4 if level > 4
tag("h#{level}") { text }
- puts
+ @output.puts
end
def display_list(list)
case list.type
- when RDoc::Markup::ListBase::BULLET
+ when :BULLET then
list_type = "ul"
prefixer = proc { |ignored| "<li>" }
- when RDoc::Markup::ListBase::NUMBER,
- RDoc::Markup::ListBase::UPPERALPHA,
- RDoc::Markup::ListBase::LOWERALPHA
+ when :NUMBER, :UPPERALPHA, :LOWERALPHA then
list_type = "ol"
prefixer = proc { |ignored| "<li>" }
- when RDoc::Markup::ListBase::LABELED
+ when :LABELED then
list_type = "dl"
prefixer = proc do |li|
"<dt><b>" + escape(li.label) + "</b><dd>"
end
- when RDoc::Markup::ListBase::NOTE
+ when :NOTE then
list_type = "table"
prefixer = proc do |li|
%{<tr valign="top"><td>#{li.label.gsub(/ /, ' ')}</td><td>}
@@ -502,25 +517,25 @@
fail "unknown list type"
end
- print "<#{list_type}>"
+ @output.print "<#{list_type}>"
list.contents.each do |item|
if item.kind_of? RDoc::Markup::Flow::LI
prefix = prefixer.call(item)
- print prefix
+ @output.print prefix
display_flow_item(item, prefix)
else
display_flow_item(item)
end
end
- print "</#{list_type}>"
+ @output.print "</#{list_type}>"
end
def display_verbatim_flow_item(item, prefix=@indent)
- print("<pre>")
+ @output.print("<pre>")
item.body.split(/\n/).each do |line|
- puts conv_html(line)
+ @output.puts conv_html(line)
end
- puts("</pre>")
+ @output.puts("</pre>")
end
private
@@ -547,13 +562,13 @@
str << "<" << ATTR_MAP[quality]
end
end
- print str
+ @output.print str
end
def tag(code)
- print("<#{code}>")
- print(yield)
- print("</#{code}>")
+ @output.print("<#{code}>")
+ @output.print(yield)
+ @output.print("</#{code}>")
end
def escape(str)
@@ -584,7 +599,7 @@
def draw_line(label=nil)
unless label.nil? then
bold_print(label)
- puts
+ @output.puts
end
end
@@ -595,36 +610,18 @@
text = strip_attributes(text)
case level
when 1
- puts "= " + text.upcase
+ @output.puts "= " + text.upcase
when 2
- puts "-- " + text
+ @output.puts "-- " + text
else
- print indent, text, "\n"
+ @output.print indent, text, "\n"
end
end
end
-##
-# Finally, fill in the list of known formatters
-
-class RDoc::RI::Formatter
-
- FORMATTERS = {
- "plain" => RDoc::RI::Formatter,
- "simple" => RDoc::RI::SimpleFormatter,
- "bs" => RDoc::RI::OverstrikeFormatter,
- "ansi" => RDoc::RI::AnsiFormatter,
- "html" => RDoc::RI::HtmlFormatter,
- }
-
- def self.list
- FORMATTERS.keys.sort.join(", ")
- end
-
- def self.for(name)
- FORMATTERS[name.downcase]
- end
-
-end
-
+RDoc::RI::Formatter::FORMATTERS['plain'] = RDoc::RI::Formatter
+RDoc::RI::Formatter::FORMATTERS['simple'] = RDoc::RI::SimpleFormatter
+RDoc::RI::Formatter::FORMATTERS['bs'] = RDoc::RI::OverstrikeFormatter
+RDoc::RI::Formatter::FORMATTERS['ansi'] = RDoc::RI::AnsiFormatter
+RDoc::RI::Formatter::FORMATTERS['html'] = RDoc::RI::HtmlFormatter
Index: lib/rdoc/ri/display.rb
===================================================================
--- lib/rdoc/ri/display.rb (revision 15119)
+++ lib/rdoc/ri/display.rb (revision 15120)
@@ -34,7 +34,7 @@
def initialize(formatter, width, use_stdout)
@use_stdout = use_stdout
- @formatter = formatter.new width, " "
+ @formatter = formatter.new $stdout, width, " "
end
def display_method_info(method)
Index: test/rdoc/test_simple_markup_attribute_manager.rb
===================================================================
--- test/rdoc/test_simple_markup_attribute_manager.rb (revision 15119)
+++ test/rdoc/test_simple_markup_attribute_manager.rb (revision 15120)
@@ -1,153 +0,0 @@
-require "test/unit"
-require "rdoc/markup/simple_markup/inline"
-
-class TestSimpleMarkupAttributeManager < Test::Unit::TestCase
-
- def setup
- @am = SM::AttributeManager.new
-
- @bold_on = @am.changed_attribute_by_name([], [:BOLD])
- @bold_off = @am.changed_attribute_by_name([:BOLD], [])
-
- @tt_on = @am.changed_attribute_by_name([], [:TT])
- @tt_off = @am.changed_attribute_by_name([:TT], [])
-
- @em_on = @am.changed_attribute_by_name([], [:EM])
- @em_off = @am.changed_attribute_by_name([:EM], [])
-
- @bold_em_on = @am.changed_attribute_by_name([], [:BOLD] | [:EM])
- @bold_em_off = @am.changed_attribute_by_name([:BOLD] | [:EM], [])
-
- @em_then_bold = @am.changed_attribute_by_name([:EM], [:EM] | [:BOLD])
-
- @em_to_bold = @am.changed_attribute_by_name([:EM], [:BOLD])
-
- @am.add_word_pair("{", "}", :WOMBAT)
- @wombat_on = @am.changed_attribute_by_name([], [:WOMBAT])
- @wombat_off = @am.changed_attribute_by_name([:WOMBAT], [])
- end
-
- def crossref(text)
- crossref_bitmap = SM::Attribute.bitmap_for(:_SPECIAL_) |
- SM::Attribute.bitmap_for(:CROSSREF)
-
- [ @am.changed_attribute_by_name([], [:CROSSREF] | [:_SPECIAL_]),
- SM::Special.new(crossref_bitmap, text),
- @am.changed_attribute_by_name([:CROSSREF] | [:_SPECIAL_], [])
- ]
- end
-
- def test_adding
- assert_equal(["cat ", @wombat_on, "and", @wombat_off, " dog" ],
- @am.flow("cat {and} dog"))
- #assert_equal(["cat {and} dog" ], @am.flow("cat \\{and} dog"))
- end
-
- def test_basic
- assert_equal(["cat"], @am.flow("cat"))
-
- assert_equal(["cat ", @bold_on, "and", @bold_off, " dog"],
- @am.flow("cat *and* dog"))
-
- assert_equal(["cat ", @bold_on, "AND", @bold_off, " dog"],
- @am.flow("cat *AND* dog"))
-
- assert_equal(["cat ", @em_on, "And", @em_off, " dog"],
- @am.flow("cat _And_ dog"))
-
- assert_equal(["cat *and dog*"], @am.flow("cat *and dog*"))
-
- assert_equal(["*cat and* dog"], @am.flow("*cat and* dog"))
-
- assert_equal(["cat *and ", @bold_on, "dog", @bold_off],
- @am.flow("cat *and *dog*"))
-
- assert_equal(["cat ", @em_on, "and", @em_off, " dog"],
- @am.flow("cat _and_ dog"))
-
- assert_equal(["cat_and_dog"],
- @am.flow("cat_and_dog"))
-
- assert_equal(["cat ", @tt_on, "and", @tt_off, " dog"],
- @am.flow("cat +and+ dog"))
-
- assert_equal(["cat ", @bold_on, "a_b_c", @bold_off, " dog"],
- @am.flow("cat *a_b_c* dog"))
-
- assert_equal(["cat __ dog"],
- @am.flow("cat __ dog"))
-
- assert_equal(["cat ", @em_on, "_", @em_off, " dog"],
- @am.flow("cat ___ dog"))
-
- end
-
- def test_combined
- assert_equal(["cat ", @em_on, "and", @em_off, " ", @bold_on, "dog", @bold_off],
- @am.flow("cat _and_ *dog*"))
-
- assert_equal(["cat ", @em_on, "a__nd", @em_off, " ", @bold_on, "dog", @bold_off],
- @am.flow("cat _a__nd_ *dog*"))
- end
-
- def test_html_like
- assert_equal(["cat ", @tt_on, "dog", @tt_off], @am.flow("cat <tt>dog</Tt>"))
-
- assert_equal(["cat ", @em_on, "and", @em_off, " ", @bold_on, "dog", @bold_off],
- @am.flow("cat <i>and</i> <B>dog</b>"))
-
- assert_equal(["cat ", @em_on, "and ", @em_then_bold, "dog", @bold_em_off],
- @am.flow("cat <i>and <B>dog</B></I>"))
-
- assert_equal(["cat ", @em_on, "and ", @em_to_bold, "dog", @bold_off],
- @am.flow("cat <i>and </i><b>dog</b>"))
-
- assert_equal(["cat ", @em_on, "and ", @em_to_bold, "dog", @bold_off],
- @am.flow("cat <i>and <b></i>dog</b>"))
-
- assert_equal([@tt_on, "cat", @tt_off, " ", @em_on, "and ", @em_to_bold, "dog", @bold_off],
- @am.flow("<tt>cat</tt> <i>and <b></i>dog</b>"))
-
- assert_equal(["cat ", @em_on, "and ", @em_then_bold, "dog", @bold_em_off],
- @am.flow("cat <i>and <b>dog</b></i>"))
-
- assert_equal(["cat ", @bold_em_on, "and", @bold_em_off, " dog"],
- @am.flow("cat <i><b>and</b></i> dog"))
- end
-
- def test_protect
- assert_equal(['cat \\ dog'], @am.flow('cat \\ dog'))
-
- assert_equal(["cat <tt>dog</Tt>"], @am.flow("cat \\<tt>dog</Tt>"))
-
- assert_equal(["cat ", @em_on, "and", @em_off, " <B>dog</b>"],
- @am.flow("cat <i>and</i> \\<B>dog</b>"))
-
- assert_equal(["*word* or <b>text</b>"], @am.flow("\\*word* or \\<b>text</b>"))
-
- assert_equal(["_cat_", @em_on, "dog", @em_off],
- @am.flow("\\_cat_<i>dog</i>"))
- end
-
- def test_special
- # class names, variable names, file names, or instance variables
- @am.add_special(/(
- \b([A-Z]\w+(::\w+)*)
- | \#\w+[!?=]?
- | \b\w+([_\/\.]+\w+)+[!?=]?
- )/x,
- :CROSSREF)
-
- assert_equal(["cat"], @am.flow("cat"))
-
- assert_equal(["cat ", crossref("#fred"), " dog"].flatten,
- @am.flow("cat #fred dog"))
-
- assert_equal([crossref("#fred"), " dog"].flatten,
- @am.flow("#fred dog"))
-
- assert_equal(["cat ", crossref("#fred")].flatten, @am.flow("cat #fred"))
- end
-
-end
-
Index: test/rdoc/test_simple_markup.rb
===================================================================
--- test/rdoc/test_simple_markup.rb (revision 15119)
+++ test/rdoc/test_simple_markup.rb (revision 15120)
@@ -1,496 +0,0 @@
-require 'test/unit'
-require 'rdoc/markup/simple_markup'
-
-class TestSimpleMarkup < Test::Unit::TestCase
-
- class MockOutput
-
- def start_accepting
- @res = []
- end
-
- def end_accepting
- @res
- end
-
- def accept_paragraph(am, fragment)
- @res << fragment.to_s
- end
-
- def accept_verbatim(am, fragment)
- @res << fragment.to_s
- end
-
- def accept_list_start(am, fragment)
- @res << fragment.to_s
- end
-
- def accept_list_end(am, fragment)
- @res << fragment.to_s
- end
-
- def accept_list_item(am, fragment)
- @res << fragment.to_s
- end
-
- def accept_blank_line(am, fragment)
- @res << fragment.to_s
- end
-
- def accept_heading(am, fragment)
- @res << fragment.to_s
- end
-
- def accept_rule(am, fragment)
- @res << fragment.to_s
- end
-
- end
-
- def basic_conv(str)
- sm = SM::SimpleMarkup.new
- mock = MockOutput.new
- sm.convert(str, mock)
- sm.content
- end
-
- def line_groups(str, expected)
- p = SM::SimpleMarkup.new
- mock = MockOutput.new
-
- block = p.convert(str, mock)
-
- if block != expected
- rows = (0...([expected.size, block.size].max)).collect{|i|
- [expected[i]||"nil", block[i]||"nil"]
- }
- printf "\n\n%35s %35s\n", "Expected", "Got"
- rows.each {|e,g| printf "%35s %35s\n", e.dump, g.dump }
- end
-
- assert_equal(expected, block)
- end
-
- def line_types(str, expected)
- p = SM::SimpleMarkup.new
- mock = MockOutput.new
- p.convert(str, mock)
- assert_equal(expected, p.get_line_types.map{|type| type.to_s[0,1]}.join(''))
- end
-
- def test_groups
- str = "now is the time"
- line_groups(str, ["L0: Paragraph\nnow is the time"] )
-
- str = "now is the time\nfor all good men"
- line_groups(str, ["L0: Paragraph\nnow is the time for all good men"] )
-
- str = %{\
- now is the time
- code _line_ here
- for all good men}
-
- line_groups(str,
- [ "L0: Paragraph\nnow is the time",
- "L0: Verbatim\n code _line_ here\n",
- "L0: Paragraph\nfor all good men"
- ] )
-
- str = "now is the time\n code\n more code\nfor all good men"
- line_groups(str,
- [ "L0: Paragraph\nnow is the time",
- "L0: Verbatim\n code\n more code\n",
- "L0: Paragraph\nfor all good men"
- ] )
-
- str = %{\
- now is
- * l1
- * l2
- the time}
- line_groups(str,
- [ "L0: Paragraph\nnow is",
- "L1: ListStart\n",
- "L1: ListItem\nl1",
- "L1: ListItem\nl2",
- "L1: ListEnd\n",
- "L0: Paragraph\nthe time"
- ])
-
- str = %{\
- now is
- * l1
- l1+
- * l2
- the time}
- line_groups(str,
- [ "L0: Paragraph\nnow is",
- "L1: ListStart\n",
- "L1: ListItem\nl1 l1+",
- "L1: ListItem\nl2",
- "L1: ListEnd\n",
- "L0: Paragraph\nthe time"
- ])
-
- str = %{\
- now is
- * l1
- * l1.1
- * l2
- the time}
- line_groups(str,
- [ "L0: Paragraph\nnow is",
- "L1: ListStart\n",
- "L1: ListItem\nl1",
- "L2: ListStart\n",
- "L2: ListItem\nl1.1",
- "L2: ListEnd\n",
- "L1: ListItem\nl2",
- "L1: ListEnd\n",
- "L0: Paragraph\nthe time"
- ])
-
-
- str = %{\
- now is
- * l1
- * l1.1
- text
- code
- code
-
- text
- * l2
- the time}
- line_groups(str,
- [ "L0: Paragraph\nnow is",
- "L1: ListStart\n",
- "L1: ListItem\nl1",
- "L2: ListStart\n",
- "L2: ListItem\nl1.1 text",
- "L2: Verbatim\n code\n code\n",
- "L2: Paragraph\ntext",
- "L2: ListEnd\n",
- "L1: ListItem\nl2",
- "L1: ListEnd\n",
- "L0: Paragraph\nthe time"
- ])
-
-
- str = %{\
- now is
- 1. l1
- * l1.1
- 2. l2
- the time}
- line_groups(str,
- [ "L0: Paragraph\nnow is",
- "L1: ListStart\n",
- "L1: ListItem\nl1",
- "L2: ListStart\n",
- "L2: ListItem\nl1.1",
- "L2: ListEnd\n",
- "L1: ListItem\nl2",
- "L1: ListEnd\n",
- "L0: Paragraph\nthe time"
- ])
-
- str = %{\
- now is
- [cat] l1
- * l1.1
- [dog] l2
- the time}
- line_groups(str,
- [ "L0: Paragraph\nnow is",
- "L1: ListStart\n",
- "L1: ListItem\nl1",
- "L2: ListStart\n",
- "L2: ListItem\nl1.1",
- "L2: ListEnd\n",
- "L1: ListItem\nl2",
- "L1: ListEnd\n",
- "L0: Paragraph\nthe time"
- ])
-
- str = %{\
- now is
- [cat] l1
- continuation
- [dog] l2
- the time}
- line_groups(str,
- [ "L0: Paragraph\nnow is",
- "L1: ListStart\n",
- "L1: ListItem\nl1 continuation",
- "L1: ListItem\nl2",
- "L1: ListEnd\n",
- "L0: Paragraph\nthe time"
- ])
- end
-
- def test_headings
- str = "= heading one"
- line_groups(str,
- [ "L0: Heading\nheading one"
- ])
-
- str = "=== heading three"
- line_groups(str,
- [ "L0: Heading\nheading three"
- ])
-
- str = "text\n === heading three"
- line_groups(str,
- [ "L0: Paragraph\ntext",
- "L0: Verbatim\n === heading three\n"
- ])
-
- str = "text\n code\n === heading three"
- line_groups(str,
- [ "L0: Paragraph\ntext",
- "L0: Verbatim\n code\n === heading three\n"
- ])
-
- str = "text\n code\n=== heading three"
- line_groups(str,
- [ "L0: Paragraph\ntext",
- "L0: Verbatim\n code\n",
- "L0: Heading\nheading three"
- ])
-
- end
-
- def test_list_split
- str = %{\
- now is
- * l1
- 1. n1
- 2. n2
- * l2
- the time}
- line_groups(str,
- [ "L0: Paragraph\nnow is",
- "L1: ListStart\n",
- "L1: ListItem\nl1",
- "L1: ListEnd\n",
- "L1: ListStart\n",
- "L1: ListItem\nn1",
- "L1: ListItem\nn2",
- "L1: ListEnd\n",
- "L1: ListStart\n",
- "L1: ListItem\nl2",
- "L1: ListEnd\n",
- "L0: Paragraph\nthe time"
- ])
-
- end
-
- def test_tabs
- str = "hello\n dave"
- assert_equal(str, basic_conv(str))
- str = "hello\n\tdave"
- assert_equal("hello\n dave", basic_conv(str))
- str = "hello\n \tdave"
- assert_equal("hello\n dave", basic_conv(str))
- str = "hello\n \tdave"
- assert_equal("hello\n dave", basic_conv(str))
- str = "hello\n \tdave"
- assert_equal("hello\n dave", basic_conv(str))
- str = "hello\n \tdave"
- assert_equal("hello\n dave", basic_conv(str))
- str = "hello\n \tdave"
- assert_equal("hello\n dave", basic_conv(str))
- str = "hello\n \tdave"
- assert_equal("hello\n dave", basic_conv(str))
- str = "hello\n \tdave"
- assert_equal("hello\n dave", basic_conv(str))
- str = "hello\n \tdave"
- assert_equal("hello\n dave", basic_conv(str))
- str = ".\t\t."
- assert_equal(". .", basic_conv(str))
- end
-
- def test_types
- str = "now is the time"
- line_types(str, 'P')
-
- str = "now is the time\nfor all good men"
- line_types(str, 'PP')
-
- str = "now is the time\n code\nfor all good men"
- line_types(str, 'PVP')
-
- str = "now is the time\n code\n more code\nfor all good men"
- line_types(str, 'PVVP')
-
- str = "now is\n---\nthe time"
- line_types(str, 'PRP')
-
- str = %{\
- now is
- * l1
- * l2
- the time}
- line_types(str, 'PLLP')
-
- str = %{\
- now is
- * l1
- l1+
- * l2
- the time}
- line_types(str, 'PLPLP')
-
- str = %{\
- now is
- * l1
- * l1.1
- * l2
- the time}
- line_types(str, 'PLLLP')
-
- str = %{\
- now is
- * l1
- * l1.1
- text
- code
- code
-
- text
- * l2
- the time}
- line_types(str, 'PLLPVVBPLP')
-
- str = %{\
- now is
- 1. l1
- * l1.1
- 2. l2
- the time}
- line_types(str, 'PLLLP')
-
- str = %{\
- now is
- [cat] l1
- * l1.1
- [dog] l2
- the time}
- line_types(str, 'PLLLP')
-
- str = %{\
- now is
- [cat] l1
- continuation
- [dog] l2
- the time}
- line_types(str, 'PLPLP')
- end
-
- def test_verbatim_merge
- str = %{\
- now is
- code
- the time}
-
- line_groups(str,
- [ "L0: Paragraph\nnow is",
- "L0: Verbatim\n code\n",
- "L0: Paragraph\nthe time"
- ])
-
-
- str = %{\
- now is
- code
- code1
- the time}
-
- line_groups(str,
- [ "L0: Paragraph\nnow is",
- "L0: Verbatim\n code\n code1\n",
- "L0: Paragraph\nthe time"
- ])
-
-
- str = %{\
- now is
- code
-
- code1
- the time}
-
- line_groups(str,
- [ "L0: Paragraph\nnow is",
- "L0: Verbatim\n code\n\n code1\n",
- "L0: Paragraph\nthe time"
- ])
-
-
- str = %{\
- now is
- code
-
- code1
-
- the time}
-
- line_groups(str,
- [ "L0: Paragraph\nnow is",
- "L0: Verbatim\n code\n\n code1\n",
- "L0: Paragraph\nthe time"
- ])
-
-
- str = %{\
- now is
- code
-
- code1
-
- code2
- the time}
-
- line_groups(str,
- [ "L0: Paragraph\nnow is",
- "L0: Verbatim\n code\n\n code1\n\n code2\n",
- "L0: Paragraph\nthe time"
- ])
-
-
- # Folds multiple blank lines
- str = %{\
- now is
- code
-
-
- code1
-
- the time}
-
- line_groups(str,
- [ "L0: Paragraph\nnow is",
- "L0: Verbatim\n code\n\n code1\n",
- "L0: Paragraph\nthe time"
- ])
-
-
- end
-
- def test_whitespace
- assert_equal("hello", basic_conv("hello"))
- assert_equal("hello", basic_conv(" hello "))
- assert_equal("hello", basic_conv(" \t \t hello\t\t"))
-
- assert_equal("1\n 2\n 3", basic_conv("1\n 2\n 3"))
- assert_equal("1\n 2\n 3", basic_conv(" 1\n 2\n 3"))
-
- assert_equal("1\n 2\n 3\n1\n 2", basic_conv("1\n 2\n 3\n1\n 2"))
- assert_equal("1\n 2\n 3\n1\n 2", basic_conv(" 1\n 2\n 3\n 1\n 2"))
-
- assert_equal("1\n 2\n\n 3", basic_conv(" 1\n 2\n\n 3"))
- end
-
-end
-
Index: test/rdoc/parsers/test_parse_c.rb
===================================================================
--- test/rdoc/parsers/test_parse_c.rb (revision 15119)
+++ test/rdoc/parsers/test_parse_c.rb (revision 15120)
@@ -1,261 +0,0 @@
-require 'stringio'
-require 'tempfile'
-require 'test/unit'
-require 'rdoc/parsers/parse_c'
-
-class RDoc::C_Parser
- attr_accessor :classes
-
- public :do_classes, :do_constants
-end
-
-class TestRdocC_Parser < Test::Unit::TestCase
-
- def setup
- @tempfile = Tempfile.new self.class.name
- filename = @tempfile.path
-
- @top_level = RDoc::TopLevel.new filename
- @fn = filename
- @options = Options.instance
- @stats = RDoc::Stats.new
-
- @progress = StringIO.new
- end
-
- def teardown
- @tempfile.unlink
- end
-
- def test_do_classes_boot_class
- content = <<-EOF
-/* Document-class: Foo
- * this is the Foo boot class
- */
-VALUE cFoo = boot_defclass("Foo", 0);
- EOF
-
- klass = util_get_class content, 'cFoo'
- assert_equal " this is the Foo boot class\n ", klass.comment
- end
-
- def test_do_classes_class
- content = <<-EOF
-/* Document-class: Foo
- * this is the Foo class
- */
-VALUE cFoo = rb_define_class("Foo", rb_cObject);
- EOF
-
- klass = util_get_class content, 'cFoo'
- assert_equal " this is the Foo class\n ", klass.comment
- end
-
- def test_do_classes_class_under
- content = <<-EOF
-/* Document-class: Kernel::Foo
- * this is the Foo class under Kernel
- */
-VALUE cFoo = rb_define_class_under(rb_mKernel, "Foo", rb_cObject);
- EOF
-
- klass = util_get_class content, 'cFoo'
- assert_equal " this is the Foo class under Kernel\n ", klass.comment
- end
-
- def test_do_classes_module
- content = <<-EOF
-/* Document-module: Foo
- * this is the Foo module
- */
-VALUE mFoo = rb_define_module("Foo");
- EOF
-
- klass = util_get_class content, 'mFoo'
- assert_equal " this is the Foo module\n ", klass.comment
- end
-
- def test_do_classes_module_under
- content = <<-EOF
-/* Document-module: Kernel::Foo
- * this is the Foo module under Kernel
- */
-VALUE mFoo = rb_define_module_under(rb_mKernel, "Foo");
- EOF
-
- klass = util_get_class content, 'mFoo'
- assert_equal " this is the Foo module under Kernel\n ", klass.comment
- end
-
- def test_do_constants
- content = <<-EOF
-#include <ruby.h>
-
-void Init_foo(){
- VALUE cFoo = rb_define_class("Foo", rb_cObject);
-
- /* 300: The highest possible score in bowling */
- rb_define_const(cFoo, "PERFECT", INT2FIX(300));
-
- /* Huzzah!: What you cheer when you roll a perfect game */
- rb_define_const(cFoo, "CHEER", rb_str_new2("Huzzah!"));
-
- /* TEST\:TEST: Checking to see if escaped semicolon works */
- rb_define_const(cFoo, "TEST", rb_str_new2("TEST:TEST"));
-
- /* \\: The file separator on MS Windows */
- rb_define_const(cFoo, "MSEPARATOR", rb_str_new2("\\"));
-
- /* /: The file separator on Unix */
- rb_define_const(cFoo, "SEPARATOR", rb_str_new2("/"));
-
- /* C:\\Program Files\\Stuff: A directory on MS Windows */
- rb_define_const(cFoo, "STUFF", rb_str_new2("C:\\Program Files\\Stuff"));
-
- /* Default definition */
- rb_define_const(cFoo, "NOSEMI", INT2FIX(99));
-
- rb_define_const(cFoo, "NOCOMMENT", rb_str_new2("No comment"));
-
- /*
- * Multiline comment goes here because this comment spans multiple lines.
- * Multiline comment goes here because this comment spans multiple lines.
- */
- rb_define_const(cFoo, "MULTILINE", INT2FIX(1));
-
- /*
- * 1: Multiline comment goes here because this comment spans multiple lines.
- * Multiline comment goes here because this comment spans multiple lines.
- */
- rb_define_const(cFoo, "MULTILINE_VALUE", INT2FIX(1));
-
- /* Multiline comment goes here because this comment spans multiple lines.
- * Multiline comment goes here because this comment spans multiple lines.
- */
- rb_define_const(cFoo, "MULTILINE_NOT_EMPTY", INT2FIX(1));
-
-}
- EOF
-
- parser = util_parser content
-
- parser.do_classes
- parser.do_constants
-
- klass = parser.classes['cFoo']
- assert klass
-
- constants = klass.constants
- assert !klass.constants.empty?
-
- constants = constants.map { |c| [c.name, c.value, c.comment] }
-
- assert_equal ['PERFECT', '300',
- "\n The highest possible score in bowling \n "],
- constants.shift
- assert_equal ['CHEER', 'Huzzah!',
- "\n What you cheer when you roll a perfect game \n "],
- constants.shift
- assert_equal ['TEST', 'TEST:TEST',
- "\n Checking to see if escaped semicolon works \n "],
- constants.shift
- assert_equal ['MSEPARATOR', '\\',
- "\n The file separator on MS Windows \n "],
- constants.shift
- assert_equal ['SEPARATOR', '/',
- "\n The file separator on Unix \n "],
- constants.shift
- assert_equal ['STUFF', 'C:\\Program Files\\Stuff',
- "\n A directory on MS Windows \n "],
- constants.shift
- assert_equal ['NOSEMI', 'INT2FIX(99)',
- "\n Default definition \n "],
- constants.shift
- assert_equal ['NOCOMMENT', 'rb_str_new2("No comment")', nil],
- constants.shift
-
- comment = <<-EOF.chomp
-
-
- Multiline comment goes here because this comment spans multiple lines.
- Multiline comment goes here because this comment spans multiple lines.
-
-
- EOF
- assert_equal ['MULTILINE', 'INT2FIX(1)', comment], constants.shift
- assert_equal ['MULTILINE_VALUE', '1', comment], constants.shift
-
- comment = <<-EOF.chomp
-
- Multiline comment goes here because this comment spans multiple lines.
- Multiline comment goes here because this comment spans multiple lines.
-
-
- EOF
- assert_equal ['MULTILINE_NOT_EMPTY', 'INT2FIX(1)', comment], constants.shift
-
- assert constants.empty?, constants.inspect
- end
-
- def test_find_class_comment_init
- content = <<-EOF
-/*
- * a comment for class Foo
- */
-void
-Init_Foo(void) {
- VALUE foo = rb_define_class("Foo", rb_cObject);
-}
- EOF
-
- klass = util_get_class content, 'foo'
-
- assert_equal " \n a comment for class Foo\n \n", klass.comment
- end
-
- def test_find_class_comment_define_class
- content = <<-EOF
-/*
- * a comment for class Foo
- */
-VALUE foo = rb_define_class("Foo", rb_cObject);
- EOF
-
- klass = util_get_class content, 'foo'
-
- assert_equal " \n a comment for class Foo\n ", klass.comment
- end
-
- def test_find_class_comment_define_class
- content = <<-EOF
-/*
- * a comment for class Foo on Init
- */
-void
-Init_Foo(void) {
- /*
- * a comment for class Foo on rb_define_class
- */
- VALUE foo = rb_define_class("Foo", rb_cObject);
-}
- EOF
-
- klass = util_get_class content, 'foo'
-
- assert_equal " \n a comment for class Foo on Init\n \n", klass.comment
- end
-
- def util_get_class(content, name)
- parser = util_parser content
- parser.do_classes
- parser.classes[name]
- end
-
- def util_parser(content)
- parser = RDoc::C_Parser.new @top_level, @fn, content, @options, @stats
- parser.progress = @progress
- parser
- end
-
-end
-
Index: test/rdoc/test_rdoc_markup_attribute_manager.rb
===================================================================
--- test/rdoc/test_rdoc_markup_attribute_manager.rb (revision 0)
+++ test/rdoc/test_rdoc_markup_attribute_manager.rb (revision 15120)
@@ -0,0 +1,153 @@
+require "test/unit"
+require "rdoc/markup/inline"
+
+class TestRDocMarkupAttributeManager < Test::Unit::TestCase
+
+ def setup
+ @am = RDoc::Markup::AttributeManager.new
+
+ @bold_on = @am.changed_attribute_by_name([], [:BOLD])
+ @bold_off = @am.changed_attribute_by_name([:BOLD], [])
+
+ @tt_on = @am.changed_attribute_by_name([], [:TT])
+ @tt_off = @am.changed_attribute_by_name([:TT], [])
+
+ @em_on = @am.changed_attribute_by_name([], [:EM])
+ @em_off = @am.changed_attribute_by_name([:EM], [])
+
+ @bold_em_on = @am.changed_attribute_by_name([], [:BOLD] | [:EM])
+ @bold_em_off = @am.changed_attribute_by_name([:BOLD] | [:EM], [])
+
+ @em_then_bold = @am.changed_attribute_by_name([:EM], [:EM] | [:BOLD])
+
+ @em_to_bold = @am.changed_attribute_by_name([:EM], [:BOLD])
+
+ @am.add_word_pair("{", "}", :WOMBAT)
+ @wombat_on = @am.changed_attribute_by_name([], [:WOMBAT])
+ @wombat_off = @am.changed_attribute_by_name([:WOMBAT], [])
+ end
+
+ def crossref(text)
+ crossref_bitmap = RDoc::Markup::Attribute.bitmap_for(:_SPECIAL_) |
+ RDoc::Markup::Attribute.bitmap_for(:CROSSREF)
+
+ [ @am.changed_attribute_by_name([], [:CROSSREF] | [:_SPECIAL_]),
+ RDoc::Markup::Special.new(crossref_bitmap, text),
+ @am.changed_attribute_by_name([:CROSSREF] | [:_SPECIAL_], [])
+ ]
+ end
+
+ def test_adding
+ assert_equal(["cat ", @wombat_on, "and", @wombat_off, " dog" ],
+ @am.flow("cat {and} dog"))
+ #assert_equal(["cat {and} dog" ], @am.flow("cat \\{and} dog"))
+ end
+
+ def test_basic
+ assert_equal(["cat"], @am.flow("cat"))
+
+ assert_equal(["cat ", @bold_on, "and", @bold_off, " dog"],
+ @am.flow("cat *and* dog"))
+
+ assert_equal(["cat ", @bold_on, "AND", @bold_off, " dog"],
+ @am.flow("cat *AND* dog"))
+
+ assert_equal(["cat ", @em_on, "And", @em_off, " dog"],
+ @am.flow("cat _And_ dog"))
+
+ assert_equal(["cat *and dog*"], @am.flow("cat *and dog*"))
+
+ assert_equal(["*cat and* dog"], @am.flow("*cat and* dog"))
+
+ assert_equal(["cat *and ", @bold_on, "dog", @bold_off],
+ @am.flow("cat *and *dog*"))
+
+ assert_equal(["cat ", @em_on, "and", @em_off, " dog"],
+ @am.flow("cat _and_ dog"))
+
+ assert_equal(["cat_and_dog"],
+ @am.flow("cat_and_dog"))
+
+ assert_equal(["cat ", @tt_on, "and", @tt_off, " dog"],
+ @am.flow("cat +and+ dog"))
+
+ assert_equal(["cat ", @bold_on, "a_b_c", @bold_off, " dog"],
+ @am.flow("cat *a_b_c* dog"))
+
+ assert_equal(["cat __ dog"],
+ @am.flow("cat __ dog"))
+
+ assert_equal(["cat ", @em_on, "_", @em_off, " dog"],
+ @am.flow("cat ___ dog"))
+
+ end
+
+ def test_combined
+ assert_equal(["cat ", @em_on, "and", @em_off, " ", @bold_on, "dog", @bold_off],
+ @am.flow("cat _and_ *dog*"))
+
+ assert_equal(["cat ", @em_on, "a__nd", @em_off, " ", @bold_on, "dog", @bold_off],
+ @am.flow("cat _a__nd_ *dog*"))
+ end
+
+ def test_html_like
+ assert_equal(["cat ", @tt_on, "dog", @tt_off], @am.flow("cat <tt>dog</Tt>"))
+
+ assert_equal(["cat ", @em_on, "and", @em_off, " ", @bold_on, "dog", @bold_off],
+ @am.flow("cat <i>and</i> <B>dog</b>"))
+
+ assert_equal(["cat ", @em_on, "and ", @em_then_bold, "dog", @bold_em_off],
+ @am.flow("cat <i>and <B>dog</B></I>"))
+
+ assert_equal(["cat ", @em_on, "and ", @em_to_bold, "dog", @bold_off],
+ @am.flow("cat <i>and </i><b>dog</b>"))
+
+ assert_equal(["cat ", @em_on, "and ", @em_to_bold, "dog", @bold_off],
+ @am.flow("cat <i>and <b></i>dog</b>"))
+
+ assert_equal([@tt_on, "cat", @tt_off, " ", @em_on, "and ", @em_to_bold, "dog", @bold_off],
+ @am.flow("<tt>cat</tt> <i>and <b></i>dog</b>"))
+
+ assert_equal(["cat ", @em_on, "and ", @em_then_bold, "dog", @bold_em_off],
+ @am.flow("cat <i>and <b>dog</b></i>"))
+
+ assert_equal(["cat ", @bold_em_on, "and", @bold_em_off, " dog"],
+ @am.flow("cat <i><b>and</b></i> dog"))
+ end
+
+ def test_protect
+ assert_equal(['cat \\ dog'], @am.flow('cat \\ dog'))
+
+ assert_equal(["cat <tt>dog</Tt>"], @am.flow("cat \\<tt>dog</Tt>"))
+
+ assert_equal(["cat ", @em_on, "and", @em_off, " <B>dog</b>"],
+ @am.flow("cat <i>and</i> \\<B>dog</b>"))
+
+ assert_equal(["*word* or <b>text</b>"], @am.flow("\\*word* or \\<b>text</b>"))
+
+ assert_equal(["_cat_", @em_on, "dog", @em_off],
+ @am.flow("\\_cat_<i>dog</i>"))
+ end
+
+ def test_special
+ # class names, variable names, file names, or instance variables
+ @am.add_special(/(
+ \b([A-Z]\w+(::\w+)*)
+ | \#\w+[!?=]?
+ | \b\w+([_\/\.]+\w+)+[!?=]?
+ )/x,
+ :CROSSREF)
+
+ assert_equal(["cat"], @am.flow("cat"))
+
+ assert_equal(["cat ", crossref("#fred"), " dog"].flatten,
+ @am.flow("cat #fred dog"))
+
+ assert_equal([crossref("#fred"), " dog"].flatten,
+ @am.flow("#fred dog"))
+
+ assert_equal(["cat ", crossref("#fred")].flatten, @am.flow("cat #fred"))
+ end
+
+end
+
Property changes on: test/rdoc/test_rdoc_markup_attribute_manager.rb
___________________________________________________________________
Name: svn:eol-style
+ LF
Name: svn:keywords
+ Author Date Id Revision
Index: test/rdoc/test_rdoc_ri_formatter.rb
===================================================================
--- test/rdoc/test_rdoc_ri_formatter.rb (revision 0)
+++ test/rdoc/test_rdoc_ri_formatter.rb (revision 15120)
@@ -0,0 +1,124 @@
+require 'stringio'
+require 'test/unit'
+require 'rdoc/ri/formatter'
+require 'rdoc/markup/to_flow'
+
+class TestRDocRIFormatter < Test::Unit::TestCase
+
+ def setup
+ @output = StringIO.new
+ @width = 78
+ @indent = ' '
+
+ @f = RDoc::RI::Formatter.new @output, @width, @indent
+ @markup = RDoc::Markup.new
+ @flow = RDoc::Markup::ToFlow.new
+ end
+
+ def test_blankline
+ @f.blankline
+
+ assert_equal "\n", @output.string
+ end
+
+ def test_bold_print
+ @f.bold_print 'a b c'
+
+ assert_equal 'a b c', @output.string
+ end
+
+ def test_break_to_newline
+ @f.break_to_newline
+
+ assert_equal '', @output.string
+ end
+
+ def test_conv_html
+ assert_equal '> < " &', @f.conv_html('> < " &')
+ end
+
+ def test_conv_markup
+ text = '<tt>a</tt> <code>b</code> <b>c</b> <em>d</em>'
+
+ expected = '+a+ +b+ *c* _d_'
+
+ assert_equal expected, @f.conv_markup(text)
+ end
+
+ def test_display_list_bullet
+ list = util_convert('* a b c').first
+
+ @f.display_list list
+
+ assert_equal " * a b c\n\n", @output.string
+ end
+
+ def test_display_list_unknown
+ list = util_convert('* a b c').first
+ list.instance_variable_set :@type, :UNKNOWN
+
+ e = assert_raise ArgumentError do
+ @f.display_list list
+ end
+
+ assert_equal 'unknown list type UNKNOWN', e.message
+ end
+
+ def test_draw_line
+ @f.draw_line
+
+ expected = '-' * @width + "\n"
+ assert_equal expected, @output.string
+ end
+
+ def test_draw_line_label
+ @f.draw_line 'label'
+
+ expected = '-' * (@width - 6) + " label\n"
+ assert_equal expected, @output.string
+ end
+
+ def test_draw_line_label_long
+ @f.draw_line 'a' * @width
+
+ expected = '-' * @width + "\n" + ('a' * @width) + "\n"
+ assert_equal expected, @output.string
+ end
+
+ def test_raw_print_line
+ @f.raw_print_line 'a b c'
+
+ assert_equal "a b c\n", @output.string
+ end
+
+ def test_wrap_empty
+ @f.wrap ''
+ assert_equal '', @output.string
+ end
+
+ def test_wrap_long
+ @f.wrap 'a ' * (@width / 2)
+ assert_equal " a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a\n a \n",
+ @output.string
+ end
+
+ def test_wrap_markup
+ @f.wrap 'a <tt>b</tt> c'
+ assert_equal " a +b+ c\n", @output.string
+ end
+
+ def test_wrap_nil
+ @f.wrap nil
+ assert_equal '', @output.string
+ end
+
+ def test_wrap_short
+ @f.wrap 'a b c'
+ assert_equal " a b c\n", @output.string
+ end
+
+ def util_convert(text)
+ @markup.convert text, @flow
+ end
+end
+
Index: test/rdoc/test_rdoc_c_parser.rb
===================================================================
--- test/rdoc/test_rdoc_c_parser.rb (revision 0)
+++ test/rdoc/test_rdoc_c_parser.rb (revision 15120)
@@ -0,0 +1,261 @@
+require 'stringio'
+require 'tempfile'
+require 'test/unit'
+require 'rdoc/parsers/parse_c'
+
+class RDoc::C_Parser
+ attr_accessor :classes
+
+ public :do_classes, :do_constants
+end
+
+class TestRdocC_Parser < Test::Unit::TestCase
+
+ def setup
+ @tempfile = Tempfile.new self.class.name
+ filename = @tempfile.path
+
+ @top_level = RDoc::TopLevel.new filename
+ @fn = filename
+ @options = RDoc::Options.new Hash.new
+ @stats = RDoc::Stats.new
+
+ @progress = StringIO.new
+ end
+
+ def teardown
+ @tempfile.unlink
+ end
+
+ def test_do_classes_boot_class
+ content = <<-EOF
+/* Document-class: Foo
+ * this is the Foo boot class
+ */
+VALUE cFoo = boot_defclass("Foo", 0);
+ EOF
+
+ klass = util_get_class content, 'cFoo'
+ assert_equal " this is the Foo boot class\n ", klass.comment
+ end
+
+ def test_do_classes_class
+ content = <<-EOF
+/* Document-class: Foo
+ * this is the Foo class
+ */
+VALUE cFoo = rb_define_class("Foo", rb_cObject);
+ EOF
+
+ klass = util_get_class content, 'cFoo'
+ assert_equal " this is the Foo class\n ", klass.comment
+ end
+
+ def test_do_classes_class_under
+ content = <<-EOF
+/* Document-class: Kernel::Foo
+ * this is the Foo class under Kernel
+ */
+VALUE cFoo = rb_define_class_under(rb_mKernel, "Foo", rb_cObject);
+ EOF
+
+ klass = util_get_class content, 'cFoo'
+ assert_equal " this is the Foo class under Kernel\n ", klass.comment
+ end
+
+ def test_do_classes_module
+ content = <<-EOF
+/* Document-module: Foo
+ * this is the Foo module
+ */
+VALUE mFoo = rb_define_module("Foo");
+ EOF
+
+ klass = util_get_class content, 'mFoo'
+ assert_equal " this is the Foo module\n ", klass.comment
+ end
+
+ def test_do_classes_module_under
+ content = <<-EOF
+/* Document-module: Kernel::Foo
+ * this is the Foo module under Kernel
+ */
+VALUE mFoo = rb_define_module_under(rb_mKernel, "Foo");
+ EOF
+
+ klass = util_get_class content, 'mFoo'
+ assert_equal " this is the Foo module under Kernel\n ", klass.comment
+ end
+
+ def test_do_constants
+ content = <<-EOF
+#include <ruby.h>
+
+void Init_foo(){
+ VALUE cFoo = rb_define_class("Foo", rb_cObject);
+
+ /* 300: The highest possible score in bowling */
+ rb_define_const(cFoo, "PERFECT", INT2FIX(300));
+
+ /* Huzzah!: What you cheer when you roll a perfect game */
+ rb_define_const(cFoo, "CHEER", rb_str_new2("Huzzah!"));
+
+ /* TEST\:TEST: Checking to see if escaped semicolon works */
+ rb_define_const(cFoo, "TEST", rb_str_new2("TEST:TEST"));
+
+ /* \\: The file separator on MS Windows */
+ rb_define_const(cFoo, "MSEPARATOR", rb_str_new2("\\"));
+
+ /* /: The file separator on Unix */
+ rb_define_const(cFoo, "SEPARATOR", rb_str_new2("/"));
+
+ /* C:\\Program Files\\Stuff: A directory on MS Windows */
+ rb_define_const(cFoo, "STUFF", rb_str_new2("C:\\Program Files\\Stuff"));
+
+ /* Default definition */
+ rb_define_const(cFoo, "NOSEMI", INT2FIX(99));
+
+ rb_define_const(cFoo, "NOCOMMENT", rb_str_new2("No comment"));
+
+ /*
+ * Multiline comment goes here because this comment spans multiple lines.
+ * Multiline comment goes here because this comment spans multiple lines.
+ */
+ rb_define_const(cFoo, "MULTILINE", INT2FIX(1));
+
+ /*
+ * 1: Multiline comment goes here because this comment spans multiple lines.
+ * Multiline comment goes here because this comment spans multiple lines.
+ */
+ rb_define_const(cFoo, "MULTILINE_VALUE", INT2FIX(1));
+
+ /* Multiline comment goes here because this comment spans multiple lines.
+ * Multiline comment goes here because this comment spans multiple lines.
+ */
+ rb_define_const(cFoo, "MULTILINE_NOT_EMPTY", INT2FIX(1));
+
+}
+ EOF
+
+ parser = util_parser content
+
+ parser.do_classes
+ parser.do_constants
+
+ klass = parser.classes['cFoo']
+ assert klass
+
+ constants = klass.constants
+ assert !klass.constants.empty?
+
+ constants = constants.map { |c| [c.name, c.value, c.comment] }
+
+ assert_equal ['PERFECT', '300',
+ "\n The highest possible score in bowling \n "],
+ constants.shift
+ assert_equal ['CHEER', 'Huzzah!',
+ "\n What you cheer when you roll a perfect game \n "],
+ constants.shift
+ assert_equal ['TEST', 'TEST:TEST',
+ "\n Checking to see if escaped semicolon works \n "],
+ constants.shift
+ assert_equal ['MSEPARATOR', '\\',
+ "\n The file separator on MS Windows \n "],
+ constants.shift
+ assert_equal ['SEPARATOR', '/',
+ "\n The file separator on Unix \n "],
+ constants.shift
+ assert_equal ['STUFF', 'C:\\Program Files\\Stuff',
+ "\n A directory on MS Windows \n "],
+ constants.shift
+ assert_equal ['NOSEMI', 'INT2FIX(99)',
+ "\n Default definition \n "],
+ constants.shift
+ assert_equal ['NOCOMMENT', 'rb_str_new2("No comment")', nil],
+ constants.shift
+
+ comment = <<-EOF.chomp
+
+
+ Multiline comment goes here because this comment spans multiple lines.
+ Multiline comment goes here because this comment spans multiple lines.
+
+
+ EOF
+ assert_equal ['MULTILINE', 'INT2FIX(1)', comment], constants.shift
+ assert_equal ['MULTILINE_VALUE', '1', comment], constants.shift
+
+ comment = <<-EOF.chomp
+
+ Multiline comment goes here because this comment spans multiple lines.
+ Multiline comment goes here because this comment spans multiple lines.
+
+
+ EOF
+ assert_equal ['MULTILINE_NOT_EMPTY', 'INT2FIX(1)', comment], constants.shift
+
+ assert constants.empty?, constants.inspect
+ end
+
+ def test_find_class_comment_init
+ content = <<-EOF
+/*
+ * a comment for class Foo
+ */
+void
+Init_Foo(void) {
+ VALUE foo = rb_define_class("Foo", rb_cObject);
+}
+ EOF
+
+ klass = util_get_class content, 'foo'
+
+ assert_equal " \n a comment for class Foo\n \n", klass.comment
+ end
+
+ def test_find_class_comment_define_class
+ content = <<-EOF
+/*
+ * a comment for class Foo
+ */
+VALUE foo = rb_define_class("Foo", rb_cObject);
+ EOF
+
+ klass = util_get_class content, 'foo'
+
+ assert_equal " \n a comment for class Foo\n ", klass.comment
+ end
+
+ def test_find_class_comment_define_class
+ content = <<-EOF
+/*
+ * a comment for class Foo on Init
+ */
+void
+Init_Foo(void) {
+ /*
+ * a comment for class Foo on rb_define_class
+ */
+ VALUE foo = rb_define_class("Foo", rb_cObject);
+}
+ EOF
+
+ klass = util_get_class content, 'foo'
+
+ assert_equal " \n a comment for class Foo on Init\n \n", klass.comment
+ end
+
+ def util_get_class(content, name)
+ parser = util_parser content
+ parser.do_classes
+ parser.classes[name]
+ end
+
+ def util_parser(content)
+ parser = RDoc::C_Parser.new @top_level, @fn, content, @options, @stats
+ parser.progress = @progress
+ parser
+ end
+
+end
+
Property changes on: test/rdoc/test_rdoc_c_parser.rb
___________________________________________________________________
Name: svn:eol-style
+ LF
Name: svn:keywords
+ "Date Revision Author HeadURL Id"
Index: test/rdoc/test_rdoc_markup.rb
===================================================================
--- test/rdoc/test_rdoc_markup.rb (revision 0)
+++ test/rdoc/test_rdoc_markup.rb (revision 15120)
@@ -0,0 +1,453 @@
+require 'test/unit'
+require 'rdoc/markup'
+require 'rdoc/markup/to_test'
+
+class TestRDocMarkup < Test::Unit::TestCase
+
+ def basic_conv(str)
+ sm = RDoc::Markup.new
+ mock = RDoc::Markup::ToTest.new
+ sm.convert(str, mock)
+ sm.content
+ end
+
+ def line_groups(str, expected)
+ p = RDoc::Markup.new
+ mock = RDoc::Markup::ToTest.new
+
+ block = p.convert(str, mock)
+
+ if block != expected
+ rows = (0...([expected.size, block.size].max)).collect{|i|
+ [expected[i]||"nil", block[i]||"nil"]
+ }
+ printf "\n\n%35s %35s\n", "Expected", "Got"
+ rows.each {|e,g| printf "%35s %35s\n", e.dump, g.dump }
+ end
+
+ assert_equal(expected, block)
+ end
+
+ def line_types(str, expected)
+ p = RDoc::Markup.new
+ mock = RDoc::Markup::ToTest.new
+ p.convert(str, mock)
+ assert_equal(expected, p.get_line_types.map{|type| type.to_s[0,1]}.join(''))
+ end
+
+ def test_groups
+ str = "now is the time"
+ line_groups(str, ["L0: Paragraph\nnow is the time"] )
+
+ str = "now is the time\nfor all good men"
+ line_groups(str, ["L0: Paragraph\nnow is the time for all good men"] )
+
+ str = %{\
+ now is the time
+ code _line_ here
+ for all good men}
+
+ line_groups(str,
+ [ "L0: Paragraph\nnow is the time",
+ "L0: Verbatim\n code _line_ here\n",
+ "L0: Paragraph\nfor all good men"
+ ] )
+
+ str = "now is the time\n code\n more code\nfor all good men"
+ line_groups(str,
+ [ "L0: Paragraph\nnow is the time",
+ "L0: Verbatim\n code\n more code\n",
+ "L0: Paragraph\nfor all good men"
+ ] )
+
+ str = %{\
+ now is
+ * l1
+ * l2
+ the time}
+ line_groups(str,
+ [ "L0: Paragraph\nnow is",
+ "L1: ListStart\n",
+ "L1: ListItem\nl1",
+ "L1: ListItem\nl2",
+ "L1: ListEnd\n",
+ "L0: Paragraph\nthe time"
+ ])
+
+ str = %{\
+ now is
+ * l1
+ l1+
+ * l2
+ the time}
+ line_groups(str,
+ [ "L0: Paragraph\nnow is",
+ "L1: ListStart\n",
+ "L1: ListItem\nl1 l1+",
+ "L1: ListItem\nl2",
+ "L1: ListEnd\n",
+ "L0: Paragraph\nthe time"
+ ])
+
+ str = %{\
+ now is
+ * l1
+ * l1.1
+ * l2
+ the time}
+ line_groups(str,
+ [ "L0: Paragraph\nnow is",
+ "L1: ListStart\n",
+ "L1: ListItem\nl1",
+ "L2: ListStart\n",
+ "L2: ListItem\nl1.1",
+ "L2: ListEnd\n",
+ "L1: ListItem\nl2",
+ "L1: ListEnd\n",
+ "L0: Paragraph\nthe time"
+ ])
+
+
+ str = %{\
+ now is
+ * l1
+ * l1.1
+ text
+ code
+ code
+
+ text
+ * l2
+ the time}
+ line_groups(str,
+ [ "L0: Paragraph\nnow is",
+ "L1: ListStart\n",
+ "L1: ListItem\nl1",
+ "L2: ListStart\n",
+ "L2: ListItem\nl1.1 text",
+ "L2: Verbatim\n code\n code\n",
+ "L2: Paragraph\ntext",
+ "L2: ListEnd\n",
+ "L1: ListItem\nl2",
+ "L1: ListEnd\n",
+ "L0: Paragraph\nthe time"
+ ])
+
+
+ str = %{\
+ now is
+ 1. l1
+ * l1.1
+ 2. l2
+ the time}
+ line_groups(str,
+ [ "L0: Paragraph\nnow is",
+ "L1: ListStart\n",
+ "L1: ListItem\nl1",
+ "L2: ListStart\n",
+ "L2: ListItem\nl1.1",
+ "L2: ListEnd\n",
+ "L1: ListItem\nl2",
+ "L1: ListEnd\n",
+ "L0: Paragraph\nthe time"
+ ])
+
+ str = %{\
+ now is
+ [cat] l1
+ * l1.1
+ [dog] l2
+ the time}
+ line_groups(str,
+ [ "L0: Paragraph\nnow is",
+ "L1: ListStart\n",
+ "L1: ListItem\nl1",
+ "L2: ListStart\n",
+ "L2: ListItem\nl1.1",
+ "L2: ListEnd\n",
+ "L1: ListItem\nl2",
+ "L1: ListEnd\n",
+ "L0: Paragraph\nthe time"
+ ])
+
+ str = %{\
+ now is
+ [cat] l1
+ continuation
+ [dog] l2
+ the time}
+ line_groups(str,
+ [ "L0: Paragraph\nnow is",
+ "L1: ListStart\n",
+ "L1: ListItem\nl1 continuation",
+ "L1: ListItem\nl2",
+ "L1: ListEnd\n",
+ "L0: Paragraph\nthe time"
+ ])
+ end
+
+ def test_headings
+ str = "= heading one"
+ line_groups(str,
+ [ "L0: Heading\nheading one"
+ ])
+
+ str = "=== heading three"
+ line_groups(str,
+ [ "L0: Heading\nheading three"
+ ])
+
+ str = "text\n === heading three"
+ line_groups(str,
+ [ "L0: Paragraph\ntext",
+ "L0: Verbatim\n === heading three\n"
+ ])
+
+ str = "text\n code\n === heading three"
+ line_groups(str,
+ [ "L0: Paragraph\ntext",
+ "L0: Verbatim\n code\n === heading three\n"
+ ])
+
+ str = "text\n code\n=== heading three"
+ line_groups(str,
+ [ "L0: Paragraph\ntext",
+ "L0: Verbatim\n code\n",
+ "L0: Heading\nheading three"
+ ])
+
+ end
+
+ def test_list_split
+ str = %{\
+ now is
+ * l1
+ 1. n1
+ 2. n2
+ * l2
+ the time}
+ line_groups(str,
+ [ "L0: Paragraph\nnow is",
+ "L1: ListStart\n",
+ "L1: ListItem\nl1",
+ "L1: ListEnd\n",
+ "L1: ListStart\n",
+ "L1: ListItem\nn1",
+ "L1: ListItem\nn2",
+ "L1: ListEnd\n",
+ "L1: ListStart\n",
+ "L1: ListItem\nl2",
+ "L1: ListEnd\n",
+ "L0: Paragraph\nthe time"
+ ])
+
+ end
+
+ def test_tabs
+ str = "hello\n dave"
+ assert_equal(str, basic_conv(str))
+ str = "hello\n\tdave"
+ assert_equal("hello\n dave", basic_conv(str))
+ str = "hello\n \tdave"
+ assert_equal("hello\n dave", basic_conv(str))
+ str = "hello\n \tdave"
+ assert_equal("hello\n dave", basic_conv(str))
+ str = "hello\n \tdave"
+ assert_equal("hello\n dave", basic_conv(str))
+ str = "hello\n \tdave"
+ assert_equal("hello\n dave", basic_conv(str))
+ str = "hello\n \tdave"
+ assert_equal("hello\n dave", basic_conv(str))
+ str = "hello\n \tdave"
+ assert_equal("hello\n dave", basic_conv(str))
+ str = "hello\n \tdave"
+ assert_equal("hello\n dave", basic_conv(str))
+ str = "hello\n \tdave"
+ assert_equal("hello\n dave", basic_conv(str))
+ str = ".\t\t."
+ assert_equal(". .", basic_conv(str))
+ end
+
+ def test_types
+ str = "now is the time"
+ line_types(str, 'P')
+
+ str = "now is the time\nfor all good men"
+ line_types(str, 'PP')
+
+ str = "now is the time\n code\nfor all good men"
+ line_types(str, 'PVP')
+
+ str = "now is the time\n code\n more code\nfor all good men"
+ line_types(str, 'PVVP')
+
+ str = "now is\n---\nthe time"
+ line_types(str, 'PRP')
+
+ str = %{\
+ now is
+ * l1
+ * l2
+ the time}
+ line_types(str, 'PLLP')
+
+ str = %{\
+ now is
+ * l1
+ l1+
+ * l2
+ the time}
+ line_types(str, 'PLPLP')
+
+ str = %{\
+ now is
+ * l1
+ * l1.1
+ * l2
+ the time}
+ line_types(str, 'PLLLP')
+
+ str = %{\
+ now is
+ * l1
+ * l1.1
+ text
+ code
+ code
+
+ text
+ * l2
+ the time}
+ line_types(str, 'PLLPVVBPLP')
+
+ str = %{\
+ now is
+ 1. l1
+ * l1.1
+ 2. l2
+ the time}
+ line_types(str, 'PLLLP')
+
+ str = %{\
+ now is
+ [cat] l1
+ * l1.1
+ [dog] l2
+ the time}
+ line_types(str, 'PLLLP')
+
+ str = %{\
+ now is
+ [cat] l1
+ continuation
+ [dog] l2
+ the time}
+ line_types(str, 'PLPLP')
+ end
+
+ def test_verbatim_merge
+ str = %{\
+ now is
+ code
+ the time}
+
+ line_groups(str,
+ [ "L0: Paragraph\nnow is",
+ "L0: Verbatim\n code\n",
+ "L0: Paragraph\nthe time"
+ ])
+
+
+ str = %{\
+ now is
+ code
+ code1
+ the time}
+
+ line_groups(str,
+ [ "L0: Paragraph\nnow is",
+ "L0: Verbatim\n code\n code1\n",
+ "L0: Paragraph\nthe time"
+ ])
+
+
+ str = %{\
+ now is
+ code
+
+ code1
+ the time}
+
+ line_groups(str,
+ [ "L0: Paragraph\nnow is",
+ "L0: Verbatim\n code\n\n code1\n",
+ "L0: Paragraph\nthe time"
+ ])
+
+
+ str = %{\
+ now is
+ code
+
+ code1
+
+ the time}
+
+ line_groups(str,
+ [ "L0: Paragraph\nnow is",
+ "L0: Verbatim\n code\n\n code1\n",
+ "L0: Paragraph\nthe time"
+ ])
+
+
+ str = %{\
+ now is
+ code
+
+ code1
+
+ code2
+ the time}
+
+ line_groups(str,
+ [ "L0: Paragraph\nnow is",
+ "L0: Verbatim\n code\n\n code1\n\n code2\n",
+ "L0: Paragraph\nthe time"
+ ])
+
+
+ # Folds multiple blank lines
+ str = %{\
+ now is
+ code
+
+
+ code1
+
+ the time}
+
+ line_groups(str,
+ [ "L0: Paragraph\nnow is",
+ "L0: Verbatim\n code\n\n code1\n",
+ "L0: Paragraph\nthe time"
+ ])
+
+
+ end
+
+ def test_whitespace
+ assert_equal("hello", basic_conv("hello"))
+ assert_equal("hello", basic_conv(" hello "))
+ assert_equal("hello", basic_conv(" \t \t hello\t\t"))
+
+ assert_equal("1\n 2\n 3", basic_conv("1\n 2\n 3"))
+ assert_equal("1\n 2\n 3", basic_conv(" 1\n 2\n 3"))
+
+ assert_equal("1\n 2\n 3\n1\n 2", basic_conv("1\n 2\n 3\n1\n 2"))
+ assert_equal("1\n 2\n 3\n1\n 2", basic_conv(" 1\n 2\n 3\n 1\n 2"))
+
+ assert_equal("1\n 2\n\n 3", basic_conv(" 1\n 2\n\n 3"))
+ end
+
+end
+
Property changes on: test/rdoc/test_rdoc_markup.rb
___________________________________________________________________
Name: svn:eol-style
+ LF
Name: svn:keywords
+ Author Date Id Revision
Index: test/rdoc/test_rdoc_ri_attribute_formatter.rb
===================================================================
--- test/rdoc/test_rdoc_ri_attribute_formatter.rb (revision 0)
+++ test/rdoc/test_rdoc_ri_attribute_formatter.rb (revision 15120)
@@ -0,0 +1,42 @@
+require 'stringio'
+require 'test/unit'
+require 'rdoc/ri/formatter'
+
+class TestRDocRIAttributeFormatter < Test::Unit::TestCase
+
+ def setup
+ @output = StringIO.new
+ @width = 78
+ @indent = ' '
+
+ @f = RDoc::RI::AttributeFormatter.new @output, @width, @indent
+ end
+
+ def test_wrap_empty
+ @f.wrap ''
+ assert_equal '', @output.string
+ end
+
+ def test_wrap_long
+ @f.wrap 'a ' * (@width / 2)
+ assert_equal " a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a \n a \n",
+ @output.string
+ end
+
+ def test_wrap_markup
+ @f.wrap 'a <tt>b</tt> c'
+ assert_equal " a b c\n", @output.string
+ end
+
+ def test_wrap_nil
+ @f.wrap nil
+ assert_equal '', @output.string
+ end
+
+ def test_wrap_short
+ @f.wrap 'a b c'
+ assert_equal " a b c\n", @output.string
+ end
+
+end
+
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/