* lib/rdoc.rb: Updated VERSION.

* lib/rdoc/markup/attribute_manager.rb:  Removed useless empty check.

	* lib/rdoc/markup/to_markdown.rb:  Support links from other formats.
	* lib/rdoc/markup/formatter.rb:  ditto.
	* lib/rdoc/markup/to_html.rb:  ditto.
	* test/rdoc/test_rdoc_markup_formatter.rb:  Test for above.
	* test/rdoc/test_rdoc_markup_to_html.rb:  ditto.
	* test/rdoc/test_rdoc_markup_to_markdown.rb:  ditto.

	* lib/rdoc/rd/block_parser.rb:  Improved footnote display.  Worked
	  around bug in footnote conversion to Markdown.
	* test/rdoc/test_rdoc_rd_block_parser.rb:  Test for above.

	* lib/rdoc/rd/inline_parser.rb:  Fixed bug with emphasis inside
	  verbatim.
	* test/rdoc/test_rdoc_rd_inline_parser.rb:  Test for above.

	* test/rdoc/test_rdoc_parser_rd.rb:  Use mu_pp, use shortcut methods.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38418 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
drbrain 2012-12-16 23:07:49 +00:00
Родитель 10295ab2ff
Коммит 810008293f
13 изменённых файлов: 422 добавлений и 208 удалений

Просмотреть файл

@ -64,7 +64,7 @@ module RDoc
##
# RDoc version you are using
VERSION = '4.0.0.preview2'
VERSION = '4.0.0.preview2.1'
##
# Method visibilities

Просмотреть файл

@ -168,15 +168,13 @@ class RDoc::Markup::AttributeManager
# Converts special sequences to RDoc attributes
def convert_specials str, attrs
unless @special.empty?
@special.each do |regexp, attribute|
str.scan(regexp) do
capture = $~.size == 1 ? 0 : 1
@special.each do |regexp, attribute|
str.scan(regexp) do
capture = $~.size == 1 ? 0 : 1
s, e = $~.offset capture
s, e = $~.offset capture
attrs.set_attrs s, e - s, attribute | @attributes.special
end
attrs.set_attrs s, e - s, attribute | @attributes.special
end
end
end

Просмотреть файл

@ -17,6 +17,30 @@ class RDoc::Markup::Formatter
InlineTag = Struct.new(:bit, :on, :off)
##
# Converts a target url to one that is relative to a given path
def self.gen_relative_url path, target
from = File.dirname path
to, to_file = File.split target
from = from.split "/"
to = to.split "/"
from.delete '.'
to.delete '.'
while from.size > 0 and to.size > 0 and from[0] == to[0] do
from.shift
to.shift
end
from.fill ".."
from.concat to
from << to_file
File.join(*from)
end
##
# Creates a new Formatter
@ -35,6 +59,7 @@ class RDoc::Markup::Formatter
@tt_bit = @attributes.bitmap_for :TT
@hard_break = ''
@from_path = '.'
end
##
@ -51,6 +76,26 @@ class RDoc::Markup::Formatter
end
end
##
# Adds a special for links of the form rdoc-...:
def add_special_RDOCLINK
@markup.add_special(/rdoc-[a-z]+:\S+/, :RDOCLINK)
end
##
# Adds a special for links of the form {<text>}[<url>] and <word>[<url>]
def add_special_TIDYLINK
@markup.add_special(/(?:
\{.*?\} | # multi-word label
\b[^\s{}]+? # single-word label
)
\[\S+?\] # link target
/x, :TIDYLINK)
end
##
# Add a new set of tags for an attribute. We allow separate start and end
# tags for flexibility
@ -178,6 +223,36 @@ class RDoc::Markup::Formatter
end
end
##
# Extracts and a scheme, url and an anchor id from +url+ and returns them.
def parse_url url
case url
when /^rdoc-label:([^:]*)(?::(.*))?/ then
scheme = 'link'
path = "##{$1}"
id = " id=\"#{$2}\"" if $2
when /([A-Za-z]+):(.*)/ then
scheme = $1.downcase
path = $2
when /^#/ then
else
scheme = 'http'
path = url
url = "http://#{url}"
end
if scheme == 'link' then
url = if path[0, 1] == '#' then # is this meaningful?
path
else
self.class.gen_relative_url @from_path, path
end
end
[scheme, url, id]
end
##
# Is +tag+ a tt tag?

Просмотреть файл

@ -36,30 +36,6 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
attr_accessor :from_path
##
# Converts a target url to one that is relative to a given path
def self.gen_relative_url(path, target)
from = File.dirname path
to, to_file = File.split target
from = from.split "/"
to = to.split "/"
from.delete '.'
to.delete '.'
while from.size > 0 and to.size > 0 and from[0] == to[0] do
from.shift
to.shift
end
from.fill ".."
from.concat to
from << to_file
File.join(*from)
end
# :section:
##
@ -79,17 +55,8 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
@markup.add_special(/(?:link:|https?:|mailto:|ftp:|irc:|www\.)\S+\w/,
:HYPERLINK)
# internal links
@markup.add_special(/rdoc-[a-z]+:\S+/, :RDOCLINK)
# and links of the form <text>[<url>]
@markup.add_special(/(?:
\{.*?\} | # multi-word label
\b[^\s{}]+? # single-word label
)
\[\S+?\] # link target
/x, :TIDYLINK)
add_special_RDOCLINK
add_special_TIDYLINK
init_tags
end
@ -325,32 +292,13 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
# for img: and link: described under handle_special_HYPERLINK
def gen_url url, text
if url =~ /^rdoc-label:([^:]*)(?::(.*))?/ then
type = "link"
path = "##{$1}"
id = " id=\"#{$2}\"" if $2
elsif url =~ /([A-Za-z]+):(.*)/ then
type = $1
path = $2
else
type = "http"
path = url
url = "http://#{url}"
end
scheme, url, id = parse_url url
if type == "link" then
url = if path[0, 1] == '#' then # is this meaningful?
path
else
self.class.gen_relative_url @from_path, path
end
end
if (type == "http" or type == "https" or type == "link") and
if %w[http https link].include?(scheme) and
url =~ /\.(gif|png|jpg|jpeg|bmp)$/ then
"<img src=\"#{url}\" />"
else
"<a#{id} href=\"#{url}\">#{text.sub(%r{^#{type}:/*}, '')}</a>"
"<a#{id} href=\"#{url}\">#{text.sub(%r{^#{scheme}:/*}i, '')}</a>"
end
end

Просмотреть файл

@ -18,6 +18,9 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
@headings[5] = ['##### ', '']
@headings[6] = ['###### ', '']
add_special_RDOCLINK
add_special_TIDYLINK
@hard_break = " \n"
end
@ -130,5 +133,57 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
@res << "\n" unless @res =~ /\n\z/
end
##
# Creates a Markdown-style URL from +url+ with +text+.
def gen_url url, text
scheme, url, = parse_url url
"[#{text.sub(%r{^#{scheme}:/*}i, '')}](#{url})"
end
##
# Handles <tt>rdoc-</tt> type links for footnotes.
def handle_rdoc_link url
case url
when /\Ardoc-ref:/ then
$'
when /\Ardoc-label:footmark-(\d+)/ then
"[^#{$1}]:"
when /\Ardoc-label:foottext-(\d+)/ then
"[^#{$1}]"
when /\Ardoc-label:label-/ then
gen_url url, $'
when /\Ardoc-[a-z]+:/ then
$'
end
end
##
# Converts the RDoc markup tidylink into a Markdown.style link.
def handle_special_TIDYLINK special
text = special.text
return text unless text =~ /\{(.*?)\}\[(.*?)\]/ or text =~ /(\S+)\[(.*?)\]/
label = $1
url = $2
if url =~ /^rdoc-label:foot/ then
handle_rdoc_link url
else
gen_url url, label
end
end
##
# Converts the rdoc-...: links into a Markdown.style links.
def handle_special_RDOCLINK special
handle_rdoc_link special.text
end
end

Просмотреть файл

@ -394,11 +394,12 @@ end
# Adds footnote +content+ to the document
def add_footnote content
index = @footnotes.length + 1
index = @footnotes.length / 2 + 1
footmark_link = "{^#{index}}[rdoc-label:footmark-#{index}:foottext-#{index}]"
@footnotes << RDoc::Markup::Paragraph.new(footmark_link, *content)
@footnotes << RDoc::Markup::Paragraph.new(footmark_link, ' ', *content)
@footnotes << RDoc::Markup::BlankLine.new
index
end

Просмотреть файл

@ -1104,7 +1104,7 @@ def _reduce_101(val, _values, result)
end
def _reduce_102(val, _values, result)
result = "<tt>#{val[1]}</tt>"
result = inline "<tt>#{val[1]}</tt>", val[1]
result
end

Просмотреть файл

@ -48,6 +48,97 @@ class TestRDocMarkupFormatter < RDoc::TestCase
@tt = @attributes.bitmap_for :TT
end
def test_class_gen_relative_url
def gen(from, to)
RDoc::Markup::ToHtml.gen_relative_url from, to
end
assert_equal 'a.html', gen('a.html', 'a.html')
assert_equal 'b.html', gen('a.html', 'b.html')
assert_equal 'd.html', gen('a/c.html', 'a/d.html')
assert_equal '../a.html', gen('a/c.html', 'a.html')
assert_equal 'a/c.html', gen('a.html', 'a/c.html')
end
def special_names
@attribute_manager.special.map do |_, mask|
@attributes.as_string mask
end
end
def test_add_special_RDOCLINK
@to.add_special_RDOCLINK
assert_includes special_names, 'RDOCLINK'
end
def test_add_special_TIDYLINK
@to.add_special_TIDYLINK
assert_includes special_names, 'TIDYLINK'
end
def test_parse_url
scheme, url, id = @to.parse_url 'example/foo'
assert_equal 'http', scheme
assert_equal 'http://example/foo', url
assert_equal nil, id
end
def test_parse_url_anchor
scheme, url, id = @to.parse_url '#foottext-1'
assert_equal nil, scheme
assert_equal '#foottext-1', url
assert_equal nil, id
end
def test_parse_url_link
scheme, url, id = @to.parse_url 'link:README.txt'
assert_equal 'link', scheme
assert_equal 'README.txt', url
assert_equal nil, id
end
def test_parse_url_link_id
scheme, url, id = @to.parse_url 'link:README.txt#label-foo'
assert_equal 'link', scheme
assert_equal 'README.txt#label-foo', url
assert_equal nil, id
end
def test_parse_url_rdoc_label
scheme, url, id = @to.parse_url 'rdoc-label:foo'
assert_equal 'link', scheme
assert_equal '#foo', url
assert_equal nil, id
scheme, url, id = @to.parse_url 'rdoc-label:foo:bar'
assert_equal 'link', scheme
assert_equal '#foo', url
assert_equal ' id="bar"', id
end
def test_parse_url_scheme
scheme, url, id = @to.parse_url 'http://example/foo'
assert_equal 'http', scheme
assert_equal 'http://example/foo', url
assert_equal nil, id
scheme, url, id = @to.parse_url 'https://example/foo'
assert_equal 'https', scheme
assert_equal 'https://example/foo', url
assert_equal nil, id
end
def test_convert_tt_special
converted = @to.convert '<code>AAA</code>'

Просмотреть файл

@ -10,19 +10,6 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase
@to = RDoc::Markup::ToHtml.new @options
end
def test_class_gen_relative_url
def gen(from, to)
RDoc::Markup::ToHtml.gen_relative_url from, to
end
assert_equal 'a.html', gen('a.html', 'a.html')
assert_equal 'b.html', gen('a.html', 'b.html')
assert_equal 'd.html', gen('a/c.html', 'a/d.html')
assert_equal '../a.html', gen('a/c.html', 'a.html')
assert_equal 'a/c.html', gen('a.html', 'a/c.html')
end
def accept_blank_line
assert_empty @to.res.join
end

Просмотреть файл

@ -348,5 +348,36 @@ words words words words
assert_equal expected, @to.end_accepting
end
def test_convert_RDOCLINK
result = @to.convert 'rdoc-garbage:C'
assert_equal "C\n", result
end
def test_convert_TIDYLINK
result = @to.convert \
'{DSL}[http://en.wikipedia.org/wiki/Domain-specific_language]'
expected = "[DSL](http://en.wikipedia.org/wiki/Domain-specific_language)\n"
assert_equal expected, result
end
def test_handle_rdoc_link_label_footmark
assert_equal '[^1]:', @to.handle_rdoc_link('rdoc-label:footmark-1:x')
end
def test_handle_rdoc_link_label_foottext
assert_equal '[^1]', @to.handle_rdoc_link('rdoc-label:foottext-1:x')
end
def test_handle_rdoc_link_label_label
assert_equal '[x](#label-x)', @to.handle_rdoc_link('rdoc-label:label-x')
end
def test_handle_rdoc_link_ref
assert_equal 'x', @to.handle_rdoc_link('rdoc-ref:x')
end
end

Просмотреть файл

@ -22,6 +22,13 @@ class TestRDocParserRd < RDoc::TestCase
@tempfile.close
end
def mu_pp obj
s = ''
s = PP.pp obj, s
s = s.force_encoding Encoding.default_external if defined? Encoding
s.chomp
end
def test_file
assert_kind_of RDoc::Parser::Text, util_parser('')
end
@ -34,9 +41,7 @@ class TestRDocParserRd < RDoc::TestCase
def test_scan
parser = util_parser 'it ((*really*)) works'
expected =
@RM::Document.new(
@RM::Paragraph.new('it <em>really</em> works'))
expected = doc(para('it <em>really</em> works'))
expected.file = @top_level
parser.scan

Просмотреть файл

@ -15,6 +15,23 @@ class TestRDocRdBlockParser < RDoc::TestCase
s.chomp
end
def test_add_footnote
index = @block_parser.add_footnote 'context'
assert_equal 1, index
expected = [
para('{^1}[rdoc-label:footmark-1:foottext-1]', ' ', 'context'),
blank_line,
]
assert_equal expected, @block_parser.footnotes
index = @block_parser.add_footnote 'other'
assert_equal 2, index
end
def test_parse_desclist
list = <<-LIST
:one
@ -25,9 +42,9 @@ class TestRDocRdBlockParser < RDoc::TestCase
expected =
doc(
@RM::List.new(:NOTE,
@RM::ListItem.new("one", @RM::Paragraph.new("desc one")),
@RM::ListItem.new("two", @RM::Paragraph.new("desc two"))))
list(:NOTE,
item("one", para("desc one")),
item("two", para("desc two"))))
assert_equal expected, parse(list)
end
@ -40,9 +57,9 @@ class TestRDocRdBlockParser < RDoc::TestCase
expected =
doc(
@RM::List.new(:NUMBER,
@RM::ListItem.new(nil, @RM::Paragraph.new("one")),
@RM::ListItem.new(nil, @RM::Paragraph.new("two"))))
list(:NUMBER,
item(nil, para("one")),
item(nil, para("two"))))
assert_equal expected, parse(list)
end
@ -56,10 +73,10 @@ class TestRDocRdBlockParser < RDoc::TestCase
expected =
doc(
@RM::List.new(:NUMBER,
@RM::ListItem.new(nil,
@RM::Paragraph.new("one"),
@RM::Paragraph.new("two"))))
list(:NUMBER,
item(nil,
para("one"),
para("two"))))
assert_equal expected, parse(list)
end
@ -74,8 +91,8 @@ class TestRDocRdBlockParser < RDoc::TestCase
expected =
doc(
@RM::List.new(:NUMBER,
@RM::ListItem.new(nil, @RM::Paragraph.new(*contents))))
list(:NUMBER,
item(nil, para(*contents))))
assert_equal expected, parse(list)
end
@ -88,10 +105,10 @@ class TestRDocRdBlockParser < RDoc::TestCase
expected =
doc(
@RM::List.new(:NUMBER,
@RM::ListItem.new(nil,
@RM::Paragraph.new("item"),
@RM::Verbatim.new("verbatim\n"))))
list(:NUMBER,
item(nil,
para("item"),
verb("verbatim\n"))))
assert_equal expected, parse(list)
end
@ -105,11 +122,11 @@ class TestRDocRdBlockParser < RDoc::TestCase
expected =
doc(
@RM::List.new(:NUMBER,
@RM::ListItem.new(nil,
@RM::Paragraph.new("one"),
@RM::Verbatim.new("verbatim\n"),
@RM::Paragraph.new("two"))))
list(:NUMBER,
item(nil,
para("one"),
verb("verbatim\n"),
para("two"))))
assert_equal expected, parse(list)
end
@ -117,9 +134,10 @@ class TestRDocRdBlockParser < RDoc::TestCase
def test_parse_footnote
expected =
doc(
@RM::Paragraph.new("{*1}[rdoc-label:foottext-1:footmark-1]"),
@RM::Rule.new(1),
@RM::Paragraph.new("{^1}[rdoc-label:footmark-1:foottext-1]", "text"))
para("{*1}[rdoc-label:foottext-1:footmark-1]"),
rule(1),
para("{^1}[rdoc-label:footmark-1:foottext-1]", " ", "text"),
blank_line)
assert_equal expected, parse("((-text-))")
end
@ -137,10 +155,10 @@ class TestRDocRdBlockParser < RDoc::TestCase
expected =
doc(
@RM::BlankLine.new,
@RM::Paragraph.new("include <em>worked</em>"),
@RM::BlankLine.new,
@RM::BlankLine.new)
blank_line,
para("include <em>worked</em>"),
blank_line,
blank_line)
Tempfile.open %w[parse_include .rd] do |io|
io.puts "=begin\ninclude ((*worked*))\n=end"
@ -155,12 +173,12 @@ class TestRDocRdBlockParser < RDoc::TestCase
end
def test_parse_heading
assert_equal doc(@RM::Heading.new(1, "H")), parse("= H")
assert_equal doc(@RM::Heading.new(2, "H")), parse("== H")
assert_equal doc(@RM::Heading.new(3, "H")), parse("=== H")
assert_equal doc(@RM::Heading.new(4, "H")), parse("==== H")
assert_equal doc(@RM::Heading.new(5, "H")), parse("+ H")
assert_equal doc(@RM::Heading.new(6, "H")), parse("++ H")
assert_equal doc(head(1, "H")), parse("= H")
assert_equal doc(head(2, "H")), parse("== H")
assert_equal doc(head(3, "H")), parse("=== H")
assert_equal doc(head(4, "H")), parse("==== H")
assert_equal doc(head(5, "H")), parse("+ H")
assert_equal doc(head(6, "H")), parse("++ H")
end
def test_parse_itemlist
@ -171,9 +189,9 @@ class TestRDocRdBlockParser < RDoc::TestCase
expected =
doc(
@RM::List.new(:BULLET,
@RM::ListItem.new(nil, @RM::Paragraph.new("one")),
@RM::ListItem.new(nil, @RM::Paragraph.new("two"))))
list(:BULLET,
item(nil, para("one")),
item(nil, para("two"))))
assert_equal expected, parse(list)
end
@ -188,8 +206,8 @@ class TestRDocRdBlockParser < RDoc::TestCase
expected =
doc(
@RM::List.new(:BULLET,
@RM::ListItem.new(nil, @RM::Paragraph.new(*contents))))
list(:BULLET,
item(nil, para(*contents))))
assert_equal expected, parse(list)
end
@ -203,13 +221,13 @@ class TestRDocRdBlockParser < RDoc::TestCase
expected =
doc(
@RM::List.new(:BULLET,
@RM::ListItem.new(nil,
@RM::Paragraph.new("one"),
@RM::List.new(:BULLET,
@RM::ListItem.new(nil, @RM::Paragraph.new("inner")))),
@RM::ListItem.new(nil,
@RM::Paragraph.new("two"))))
list(:BULLET,
item(nil,
para("one"),
list(:BULLET,
item(nil, para("inner")))),
item(nil,
para("two"))))
assert_equal expected, parse(list)
end
@ -223,10 +241,10 @@ class TestRDocRdBlockParser < RDoc::TestCase
expected =
doc(
@RM::List.new(:BULLET,
@RM::ListItem.new(nil,
@RM::Paragraph.new("one"),
@RM::Paragraph.new("two"))))
list(:BULLET,
item(nil,
para("one"),
para("two"))))
assert_equal expected, parse(list)
end
@ -239,10 +257,10 @@ class TestRDocRdBlockParser < RDoc::TestCase
expected =
doc(
@RM::List.new(:BULLET,
@RM::ListItem.new(nil,
@RM::Paragraph.new("item"),
@RM::Verbatim.new("verbatim\n"))))
list(:BULLET,
item(nil,
para("item"),
verb("verbatim\n"))))
assert_equal expected, parse(list)
end
@ -256,11 +274,11 @@ class TestRDocRdBlockParser < RDoc::TestCase
expected =
doc(
@RM::List.new(:BULLET,
@RM::ListItem.new(nil,
@RM::Paragraph.new("one"),
@RM::Verbatim.new("verbatim\n"),
@RM::Paragraph.new("two"))))
list(:BULLET,
item(nil,
para("one"),
verb("verbatim\n"),
para("two"))))
assert_equal expected, parse(list)
end
@ -277,15 +295,15 @@ class TestRDocRdBlockParser < RDoc::TestCase
expected =
doc(
@RM::List.new(:NUMBER,
@RM::ListItem.new(nil, @RM::Paragraph.new("one")),
@RM::ListItem.new(nil, @RM::Paragraph.new("two"))),
@RM::List.new(:BULLET,
@RM::ListItem.new(nil, @RM::Paragraph.new("three")),
@RM::ListItem.new(nil, @RM::Paragraph.new("four"))),
@RM::List.new(:NUMBER,
@RM::ListItem.new(nil, @RM::Paragraph.new("five")),
@RM::ListItem.new(nil, @RM::Paragraph.new("six"))))
list(:NUMBER,
item(nil, para("one")),
item(nil, para("two"))),
list(:BULLET,
item(nil, para("three")),
item(nil, para("four"))),
list(:NUMBER,
item(nil, para("five")),
item(nil, para("six"))))
assert_equal expected, parse(list)
end
@ -302,15 +320,15 @@ class TestRDocRdBlockParser < RDoc::TestCase
expected =
doc(
@RM::List.new(:NUMBER,
@RM::ListItem.new(nil, @RM::Paragraph.new("one")),
@RM::ListItem.new(nil,
@RM::Paragraph.new("two"),
@RM::List.new(:BULLET,
@RM::ListItem.new(nil, @RM::Paragraph.new("three")),
@RM::ListItem.new(nil, @RM::Paragraph.new("four")))),
@RM::ListItem.new(nil, @RM::Paragraph.new("five")),
@RM::ListItem.new(nil, @RM::Paragraph.new("six"))))
list(:NUMBER,
item(nil, para("one")),
item(nil,
para("two"),
list(:BULLET,
item(nil, para("three")),
item(nil, para("four")))),
item(nil, para("five")),
item(nil, para("six"))))
assert_equal expected, parse(list)
end
@ -328,16 +346,16 @@ class TestRDocRdBlockParser < RDoc::TestCase
expected =
doc(
@RM::List.new(:NUMBER,
@RM::ListItem.new(nil, @RM::Paragraph.new("one")),
@RM::ListItem.new(nil,
@RM::Paragraph.new("two"),
@RM::List.new(:BULLET,
@RM::ListItem.new(nil, @RM::Paragraph.new("three")),
@RM::ListItem.new(nil, @RM::Paragraph.new("four"))),
@RM::Verbatim.new("verbatim\n")),
@RM::ListItem.new(nil, @RM::Paragraph.new("five")),
@RM::ListItem.new(nil, @RM::Paragraph.new("six"))))
list(:NUMBER,
item(nil, para("one")),
item(nil,
para("two"),
list(:BULLET,
item(nil, para("three")),
item(nil, para("four"))),
verb("verbatim\n")),
item(nil, para("five")),
item(nil, para("six"))))
assert_equal expected, parse(list)
end
@ -355,16 +373,16 @@ class TestRDocRdBlockParser < RDoc::TestCase
expected =
doc(
@RM::List.new(:NUMBER,
@RM::ListItem.new(nil, @RM::Paragraph.new("one")),
@RM::ListItem.new(nil,
@RM::Paragraph.new("two"),
@RM::List.new(:BULLET,
@RM::ListItem.new(nil, @RM::Paragraph.new("three")),
@RM::ListItem.new(nil, @RM::Paragraph.new("four"))),
@RM::Verbatim.new("verbatim\n")),
@RM::ListItem.new(nil, @RM::Paragraph.new("five")),
@RM::ListItem.new(nil, @RM::Paragraph.new("six"))))
list(:NUMBER,
item(nil, para("one")),
item(nil,
para("two"),
list(:BULLET,
item(nil, para("three")),
item(nil, para("four"))),
verb("verbatim\n")),
item(nil, para("five")),
item(nil, para("six"))))
assert_equal expected, parse(list)
end
@ -380,13 +398,13 @@ class TestRDocRdBlockParser < RDoc::TestCase
expected =
doc(
@RM::List.new(:LABEL,
@RM::ListItem.new(
list(:LABEL,
item(
"<tt>Array#each {|i| ... }</tt>",
@RM::Paragraph.new("yield block for each item.")),
@RM::ListItem.new(
para("yield block for each item.")),
item(
"<tt>Array#index(val)</tt>",
@RM::Paragraph.new("return index of first item which equals with val. if it hasn't same item, return nil."))))
para("return index of first item which equals with val. if it hasn't same item, return nil."))))
assert_equal expected, parse(list)
end
@ -399,8 +417,8 @@ class TestRDocRdBlockParser < RDoc::TestCase
expected =
doc(
@RM::List.new(:LABEL,
@RM::ListItem.new("<tt>A#b</tt>")))
list(:LABEL,
item("<tt>A#b</tt>")))
assert_equal expected, parse(list)
end
@ -414,10 +432,10 @@ class TestRDocRdBlockParser < RDoc::TestCase
expected =
doc(
@RM::List.new(:LABEL,
@RM::ListItem.new(
list(:LABEL,
item(
"<tt>A#b</tt>",
@RM::Paragraph.new("one"))))
para("one"))))
assert_equal expected, parse(list)
end
@ -432,11 +450,11 @@ two
expected =
doc(
@RM::List.new(:LABEL,
@RM::ListItem.new(
list(:LABEL,
item(
"<tt>A#b</tt>",
@RM::Paragraph.new("one"))),
@RM::Paragraph.new("two"))
para("one"))),
para("two"))
assert_equal expected, parse(list)
end
@ -451,21 +469,21 @@ two
expected =
doc(
@RM::List.new(:LABEL,
@RM::ListItem.new(
list(:LABEL,
item(
"<tt>A#b</tt>",
@RM::Paragraph.new("text"),
@RM::Verbatim.new("verbatim\n"))))
para("text"),
verb("verbatim\n"))))
assert_equal expected, parse(list)
end
def test_parse_verbatim
assert_equal doc(@RM::Verbatim.new("verbatim\n")), parse(" verbatim")
assert_equal doc(verb("verbatim\n")), parse(" verbatim")
end
def test_parse_verbatim_blankline
expected = doc(@RM::Verbatim.new("one\n", "\n", "two\n"))
expected = doc(verb("one\n", "\n", "two\n"))
verbatim = <<-VERBATIM
one
@ -477,7 +495,7 @@ two
end
def test_parse_verbatim_indent
expected = doc(@RM::Verbatim.new("one\n", " two\n"))
expected = doc(verb("one\n", " two\n"))
verbatim = <<-VERBATIM
one
@ -488,7 +506,7 @@ two
end
def test_parse_verbatim_multi
expected = doc(@RM::Verbatim.new("one\n", "two\n"))
expected = doc(verb("one\n", "two\n"))
verbatim = <<-VERBATIM
one
@ -499,11 +517,11 @@ two
end
def test_parse_textblock
assert_equal doc(@RM::Paragraph.new("text")), parse("text")
assert_equal doc(para("text")), parse("text")
end
def test_parse_textblock_multi
expected = doc(@RM::Paragraph.new("one two"))
expected = doc(para("one two"))
assert_equal expected, parse("one\ntwo")
end
@ -513,8 +531,8 @@ two
doc = @block_parser.parse text.lines.to_a
assert_equal @RM::BlankLine.new, doc.parts.shift, "=begin blankline"
assert_equal @RM::BlankLine.new, doc.parts.pop, "=end blankline"
assert_equal blank_line, doc.parts.shift, "=begin blankline"
assert_equal blank_line, doc.parts.pop, "=end blankline"
doc
end

Просмотреть файл

@ -26,7 +26,8 @@ class TestRDocRdInlineParser < RDoc::TestCase
assert_equal '{*1}[rdoc-label:foottext-1:footmark-1]', parse('((-text-))')
expected = [
@RM::Paragraph.new('{^1}[rdoc-label:footmark-1:foottext-1]', 'text')
@RM::Paragraph.new('{^1}[rdoc-label:footmark-1:foottext-1]', ' ', 'text'),
blank_line,
]
assert_equal expected, @block_parser.footnotes
@ -161,6 +162,10 @@ class TestRDocRdInlineParser < RDoc::TestCase
assert_equal '<tt>text "</tt>', parse("(('text \\\"'))")
end
def test_parse_verb_emphasis
assert_equal '<tt>((*emphasis*))</tt>', parse("(('((*emphasis*))'))")
end
def test_parse_verb_multiple
assert_equal '<tt>((*text*))</tt>', parse("(('((*text*))'))")
end