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

* 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
parent 10295ab2ff
commit 810008293f
13 changed files with 422 additions and 208 deletions

View file

@ -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