mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/rdoc/code_objects.rb: Make some attributes accessible for reuse.
* lib/rdoc/generator/html.rb: Pull out ContextUser classes and related methods for reuse. * lib/rdoc/generator.rb: Move ContextUser classes to RDoc::Generator::Context for reuse. * lib/rdoc/rdoc.rb: Make RDoc::RDoc initialization a little easier. * lib/rdoc/options.rb: Make RDoc::Options easier to use without parsing an ARGV. * lib/rdoc/markup/to_*.rb: Subclass RDoc::Markup::Formatter. * lib/rdoc/markup/formatter.rb: Add RDoc::Markup::Formatter to make RDoc markup conversion easier. * lib/rdoc/markup/fragments.rb: Make RDoc::Markup::ListItem easier to test. * lib/rdoc/markup/to_html_hyperlink.rb: Pulled out of the HTML generator for easier reusability. * lib/rdoc/markup.rb: Fix bug with labeled lists containing bullet lists. * lib/rdoc/generators/html/html.rb: Fix Constant display. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15421 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d44f24c47c
commit
455b051a00
21 changed files with 1839 additions and 1588 deletions
|
@ -12,10 +12,10 @@ class TestRDocMarkup < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def line_groups(str, expected)
|
||||
p = RDoc::Markup.new
|
||||
m = RDoc::Markup.new
|
||||
mock = RDoc::Markup::ToTest.new
|
||||
|
||||
block = p.convert(str, mock)
|
||||
block = m.convert(str, mock)
|
||||
|
||||
if block != expected
|
||||
rows = (0...([expected.size, block.size].max)).collect{|i|
|
||||
|
@ -29,10 +29,10 @@ class TestRDocMarkup < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def line_types(str, expected)
|
||||
p = RDoc::Markup.new
|
||||
m = 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(''))
|
||||
m.convert(str, mock)
|
||||
assert_equal(expected, m.get_line_types.map{|type| type.to_s[0,1]}.join(''))
|
||||
end
|
||||
|
||||
def test_groups
|
||||
|
@ -68,8 +68,8 @@ class TestRDocMarkup < Test::Unit::TestCase
|
|||
line_groups(str,
|
||||
[ "L0: Paragraph\nnow is",
|
||||
"L1: ListStart\n",
|
||||
"L1: ListItem\nl1",
|
||||
"L1: ListItem\nl2",
|
||||
"L1: BULLET ListItem\nl1",
|
||||
"L1: BULLET ListItem\nl2",
|
||||
"L1: ListEnd\n",
|
||||
"L0: Paragraph\nthe time"
|
||||
])
|
||||
|
@ -83,8 +83,8 @@ class TestRDocMarkup < Test::Unit::TestCase
|
|||
line_groups(str,
|
||||
[ "L0: Paragraph\nnow is",
|
||||
"L1: ListStart\n",
|
||||
"L1: ListItem\nl1 l1+",
|
||||
"L1: ListItem\nl2",
|
||||
"L1: BULLET ListItem\nl1 l1+",
|
||||
"L1: BULLET ListItem\nl2",
|
||||
"L1: ListEnd\n",
|
||||
"L0: Paragraph\nthe time"
|
||||
])
|
||||
|
@ -98,11 +98,11 @@ class TestRDocMarkup < Test::Unit::TestCase
|
|||
line_groups(str,
|
||||
[ "L0: Paragraph\nnow is",
|
||||
"L1: ListStart\n",
|
||||
"L1: ListItem\nl1",
|
||||
"L1: BULLET ListItem\nl1",
|
||||
"L2: ListStart\n",
|
||||
"L2: ListItem\nl1.1",
|
||||
"L2: BULLET ListItem\nl1.1",
|
||||
"L2: ListEnd\n",
|
||||
"L1: ListItem\nl2",
|
||||
"L1: BULLET ListItem\nl2",
|
||||
"L1: ListEnd\n",
|
||||
"L0: Paragraph\nthe time"
|
||||
])
|
||||
|
@ -122,13 +122,13 @@ class TestRDocMarkup < Test::Unit::TestCase
|
|||
line_groups(str,
|
||||
[ "L0: Paragraph\nnow is",
|
||||
"L1: ListStart\n",
|
||||
"L1: ListItem\nl1",
|
||||
"L1: BULLET ListItem\nl1",
|
||||
"L2: ListStart\n",
|
||||
"L2: ListItem\nl1.1 text",
|
||||
"L2: BULLET ListItem\nl1.1 text",
|
||||
"L2: Verbatim\n code\n code\n",
|
||||
"L2: Paragraph\ntext",
|
||||
"L2: ListEnd\n",
|
||||
"L1: ListItem\nl2",
|
||||
"L1: BULLET ListItem\nl2",
|
||||
"L1: ListEnd\n",
|
||||
"L0: Paragraph\nthe time"
|
||||
])
|
||||
|
@ -143,11 +143,11 @@ class TestRDocMarkup < Test::Unit::TestCase
|
|||
line_groups(str,
|
||||
[ "L0: Paragraph\nnow is",
|
||||
"L1: ListStart\n",
|
||||
"L1: ListItem\nl1",
|
||||
"L1: NUMBER ListItem\nl1",
|
||||
"L2: ListStart\n",
|
||||
"L2: ListItem\nl1.1",
|
||||
"L2: BULLET ListItem\nl1.1",
|
||||
"L2: ListEnd\n",
|
||||
"L1: ListItem\nl2",
|
||||
"L1: NUMBER ListItem\nl2",
|
||||
"L1: ListEnd\n",
|
||||
"L0: Paragraph\nthe time"
|
||||
])
|
||||
|
@ -161,11 +161,11 @@ class TestRDocMarkup < Test::Unit::TestCase
|
|||
line_groups(str,
|
||||
[ "L0: Paragraph\nnow is",
|
||||
"L1: ListStart\n",
|
||||
"L1: ListItem\nl1",
|
||||
"L1: LABELED ListItem\ncat: l1",
|
||||
"L2: ListStart\n",
|
||||
"L2: ListItem\nl1.1",
|
||||
"L2: BULLET ListItem\nl1.1",
|
||||
"L2: ListEnd\n",
|
||||
"L1: ListItem\nl2",
|
||||
"L1: LABELED ListItem\ndog: l2",
|
||||
"L1: ListEnd\n",
|
||||
"L0: Paragraph\nthe time"
|
||||
])
|
||||
|
@ -179,8 +179,8 @@ class TestRDocMarkup < Test::Unit::TestCase
|
|||
line_groups(str,
|
||||
[ "L0: Paragraph\nnow is",
|
||||
"L1: ListStart\n",
|
||||
"L1: ListItem\nl1 continuation",
|
||||
"L1: ListItem\nl2",
|
||||
"L1: LABELED ListItem\ncat: l1 continuation",
|
||||
"L1: LABELED ListItem\ndog: l2",
|
||||
"L1: ListEnd\n",
|
||||
"L0: Paragraph\nthe time"
|
||||
])
|
||||
|
@ -218,6 +218,133 @@ class TestRDocMarkup < Test::Unit::TestCase
|
|||
|
||||
end
|
||||
|
||||
def test_list_alpha
|
||||
str = "a. alpha\nb. baker\nB. ALPHA\nA. BAKER"
|
||||
|
||||
line_groups(str,
|
||||
[ "L1: ListStart\n",
|
||||
"L1: LOWERALPHA ListItem\nalpha",
|
||||
"L1: LOWERALPHA ListItem\nbaker",
|
||||
"L1: ListEnd\n",
|
||||
"L1: ListStart\n",
|
||||
"L1: UPPERALPHA ListItem\nALPHA",
|
||||
"L1: UPPERALPHA ListItem\nBAKER",
|
||||
"L1: ListEnd\n" ])
|
||||
end
|
||||
|
||||
def test_list_bullet_dash
|
||||
str = "- one\n- two\n"
|
||||
|
||||
line_groups(str,
|
||||
[ "L1: ListStart\n",
|
||||
"L1: BULLET ListItem\none",
|
||||
"L1: BULLET ListItem\ntwo",
|
||||
"L1: ListEnd\n" ])
|
||||
end
|
||||
|
||||
def test_list_bullet_star
|
||||
str = "* one\n* two\n"
|
||||
|
||||
line_groups(str,
|
||||
[ "L1: ListStart\n",
|
||||
"L1: BULLET ListItem\none",
|
||||
"L1: BULLET ListItem\ntwo",
|
||||
"L1: ListEnd\n" ])
|
||||
end
|
||||
|
||||
def test_list_labeled_bracket
|
||||
str = "[one] item one\n[two] item two"
|
||||
|
||||
line_groups(str,
|
||||
[ "L1: ListStart\n",
|
||||
"L1: LABELED ListItem\none: item one",
|
||||
"L1: LABELED ListItem\ntwo: item two",
|
||||
"L1: ListEnd\n" ])
|
||||
end
|
||||
|
||||
def test_list_labeled_bracket_continued
|
||||
str = "[one]\n item one\n[two]\n item two"
|
||||
|
||||
line_groups(str,
|
||||
[ "L1: ListStart\n",
|
||||
"L1: LABELED ListItem\none: item one",
|
||||
"L1: LABELED ListItem\ntwo: item two",
|
||||
"L1: ListEnd\n" ])
|
||||
end
|
||||
|
||||
def test_list_labeled_colon
|
||||
str = "one:: item one\ntwo:: item two"
|
||||
|
||||
line_groups(str,
|
||||
[ "L1: ListStart\n",
|
||||
"L1: NOTE ListItem\none:: item one",
|
||||
"L1: NOTE ListItem\ntwo:: item two",
|
||||
"L1: ListEnd\n" ])
|
||||
end
|
||||
|
||||
def test_list_labeled_colon_continued
|
||||
str = "one::\n item one\ntwo::\n item two"
|
||||
|
||||
line_groups(str,
|
||||
[ "L1: ListStart\n",
|
||||
"L1: NOTE ListItem\none:: item one",
|
||||
"L1: NOTE ListItem\ntwo:: item two",
|
||||
"L1: ListEnd\n" ])
|
||||
end
|
||||
|
||||
def test_list_nested_bullet_bullet
|
||||
str = "* one\n* two\n * cat\n * dog"
|
||||
|
||||
line_groups(str,
|
||||
[ "L1: ListStart\n",
|
||||
"L1: BULLET ListItem\none",
|
||||
"L1: BULLET ListItem\ntwo",
|
||||
"L2: ListStart\n",
|
||||
"L2: BULLET ListItem\ncat",
|
||||
"L2: BULLET ListItem\ndog",
|
||||
"L2: ListEnd\n",
|
||||
"L1: ListEnd\n" ])
|
||||
end
|
||||
|
||||
def test_list_nested_labeled_bullet
|
||||
str = "[one]\n * cat\n * dog"
|
||||
|
||||
line_groups(str,
|
||||
[ "L1: ListStart\n",
|
||||
"L1: LABELED ListItem\none: ",
|
||||
"L2: ListStart\n",
|
||||
"L2: BULLET ListItem\ncat",
|
||||
"L2: BULLET ListItem\ndog",
|
||||
"L2: ListEnd\n",
|
||||
"L1: ListEnd\n" ])
|
||||
end
|
||||
|
||||
def test_list_nested_labeled_bullet_bullet
|
||||
str = "[one]\n * cat\n * dog"
|
||||
|
||||
line_groups(str,
|
||||
[ "L1: ListStart\n",
|
||||
"L1: LABELED ListItem\none: ",
|
||||
"L2: ListStart\n",
|
||||
"L2: BULLET ListItem\ncat",
|
||||
"L3: ListStart\n",
|
||||
"L3: BULLET ListItem\ndog",
|
||||
"L3: ListEnd\n",
|
||||
"L2: ListEnd\n",
|
||||
"L1: ListEnd\n" ])
|
||||
end
|
||||
|
||||
def test_list_number
|
||||
str = "1. one\n2. two\n1. three"
|
||||
|
||||
line_groups(str,
|
||||
[ "L1: ListStart\n",
|
||||
"L1: NUMBER ListItem\none",
|
||||
"L1: NUMBER ListItem\ntwo",
|
||||
"L1: NUMBER ListItem\nthree",
|
||||
"L1: ListEnd\n" ])
|
||||
end
|
||||
|
||||
def test_list_split
|
||||
str = %{\
|
||||
now is
|
||||
|
@ -229,20 +356,30 @@ class TestRDocMarkup < Test::Unit::TestCase
|
|||
line_groups(str,
|
||||
[ "L0: Paragraph\nnow is",
|
||||
"L1: ListStart\n",
|
||||
"L1: ListItem\nl1",
|
||||
"L1: BULLET ListItem\nl1",
|
||||
"L1: ListEnd\n",
|
||||
"L1: ListStart\n",
|
||||
"L1: ListItem\nn1",
|
||||
"L1: ListItem\nn2",
|
||||
"L1: NUMBER ListItem\nn1",
|
||||
"L1: NUMBER ListItem\nn2",
|
||||
"L1: ListEnd\n",
|
||||
"L1: ListStart\n",
|
||||
"L1: ListItem\nl2",
|
||||
"L1: BULLET ListItem\nl2",
|
||||
"L1: ListEnd\n",
|
||||
"L0: Paragraph\nthe time"
|
||||
])
|
||||
|
||||
end
|
||||
|
||||
def test_paragraph
|
||||
str = "paragraph\n\n*bold* paragraph\n"
|
||||
|
||||
line_groups str, [
|
||||
"L0: Paragraph\nparagraph",
|
||||
"L0: BlankLine\n",
|
||||
"L0: Paragraph\n*bold* paragraph"
|
||||
]
|
||||
end
|
||||
|
||||
def test_tabs
|
||||
str = "hello\n dave"
|
||||
assert_equal(str, basic_conv(str))
|
||||
|
@ -345,6 +482,15 @@ class TestRDocMarkup < Test::Unit::TestCase
|
|||
line_types(str, 'PLPLP')
|
||||
end
|
||||
|
||||
def test_verbatim
|
||||
str = "paragraph\n *bold* verbatim\n"
|
||||
|
||||
line_groups str, [
|
||||
"L0: Paragraph\nparagraph",
|
||||
"L0: Verbatim\n *bold* verbatim\n"
|
||||
]
|
||||
end
|
||||
|
||||
def test_verbatim_merge
|
||||
str = %{\
|
||||
now is
|
||||
|
|
|
@ -31,9 +31,9 @@ class TestRDocMarkupAttributeManager < Test::Unit::TestCase
|
|||
crossref_bitmap = RDoc::Markup::Attribute.bitmap_for(:_SPECIAL_) |
|
||||
RDoc::Markup::Attribute.bitmap_for(:CROSSREF)
|
||||
|
||||
[ @am.changed_attribute_by_name([], [:CROSSREF] | [:_SPECIAL_]),
|
||||
[ @am.changed_attribute_by_name([], [:CROSSREF, :_SPECIAL_]),
|
||||
RDoc::Markup::Special.new(crossref_bitmap, text),
|
||||
@am.changed_attribute_by_name([:CROSSREF] | [:_SPECIAL_], [])
|
||||
@am.changed_attribute_by_name([:CROSSREF, :_SPECIAL_], [])
|
||||
]
|
||||
end
|
||||
|
||||
|
@ -90,31 +90,46 @@ class TestRDocMarkupAttributeManager < Test::Unit::TestCase
|
|||
@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>"))
|
||||
def test_html_like_em_bold
|
||||
assert_equal ["cat ", @em_on, "and ", @em_to_bold, "dog", @bold_off],
|
||||
@am.flow("cat <i>and </i><b>dog</b>")
|
||||
end
|
||||
|
||||
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>"))
|
||||
def test_html_like_em_bold_SGML
|
||||
assert_equal ["cat ", @em_on, "and ", @em_to_bold, "dog", @bold_off],
|
||||
@am.flow("cat <i>and <b></i>dog</b>")
|
||||
end
|
||||
|
||||
def test_html_like_em_bold_nested_1
|
||||
assert_equal(["cat ", @bold_em_on, "and", @bold_em_off, " dog"],
|
||||
@am.flow("cat <i><b>and</b></i> dog"))
|
||||
end
|
||||
|
||||
def test_html_like_em_bold_nested_2
|
||||
assert_equal ["cat ", @em_on, "and ", @em_then_bold, "dog", @bold_em_off],
|
||||
@am.flow("cat <i>and <b>dog</b></i>")
|
||||
end
|
||||
|
||||
def test_html_like_em_bold_nested_mixed_case
|
||||
assert_equal ["cat ", @em_on, "and ", @em_then_bold, "dog", @bold_em_off],
|
||||
@am.flow("cat <i>and <B>dog</B></I>")
|
||||
end
|
||||
|
||||
def test_html_like_em_bold_mixed_case
|
||||
assert_equal ["cat ", @em_on, "and", @em_off, " ", @bold_on, "dog", @bold_off],
|
||||
@am.flow("cat <i>and</i> <B>dog</b>")
|
||||
end
|
||||
|
||||
def test_html_like_teletype
|
||||
assert_equal ["cat ", @tt_on, "dog", @tt_off],
|
||||
@am.flow("cat <tt>dog</Tt>")
|
||||
end
|
||||
|
||||
def test_html_like_teletype_em_bold_SGML
|
||||
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>")
|
||||
end
|
||||
|
||||
def test_protect
|
||||
assert_equal(['cat \\ dog'], @am.flow('cat \\ dog'))
|
||||
|
||||
|
|
|
@ -250,6 +250,14 @@ class TestRDocRIFormatter < Test::Unit::TestCase
|
|||
assert_equal " a b c\n d e f\n\n", @output.string
|
||||
end
|
||||
|
||||
def test_display_verbatim_flow_item_bold
|
||||
verbatim = RDoc::Markup::Flow::VERB.new "*a* b c"
|
||||
|
||||
@f.display_verbatim_flow_item verbatim
|
||||
|
||||
assert_equal " *a* b c\n\n", @output.string
|
||||
end
|
||||
|
||||
def test_draw_line
|
||||
@f.draw_line
|
||||
|
||||
|
|
|
@ -18,6 +18,14 @@ class TestRDocRIOverstrikeFormatter < Test::Unit::TestCase
|
|||
@af = RDoc::RI::AttributeFormatter
|
||||
end
|
||||
|
||||
def test_display_verbatim_flow_item_bold
|
||||
verbatim = RDoc::Markup::Flow::VERB.new "*a* b c"
|
||||
|
||||
@f.display_verbatim_flow_item verbatim
|
||||
|
||||
assert_equal " *a* b c\n\n", @output.string
|
||||
end
|
||||
|
||||
def test_write_attribute_text_bold
|
||||
line = [RDoc::RI::AttributeFormatter::AttrChar.new('b', @af::BOLD)]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue