require 'rdoc/test_case'
class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase
add_visitor_tests
def setup
super
@to = RDoc::Markup::ToHtml.new @options
end
def accept_blank_line
assert_empty @to.res.join
end
def accept_block_quote
assert_equal "\n
\nquote
\n
\n", @to.res.join
end
def accept_document
assert_equal "\nhello
\n", @to.res.join
end
def accept_heading
links = '¶ ' +
'↑'
expected = "\nHello#{links}
\n"
assert_equal expected, @to.res.join
end
def accept_heading_1
links = '¶ ' +
'↑'
assert_equal "\nHello#{links}
\n", @to.res.join
end
def accept_heading_2
links = '¶ ' +
'↑'
assert_equal "\nHello#{links}
\n", @to.res.join
end
def accept_heading_3
links = '¶ ' +
'↑'
assert_equal "\nHello#{links}
\n", @to.res.join
end
def accept_heading_4
links = '¶ ' +
'↑'
assert_equal "\nHello#{links}
\n", @to.res.join
end
def accept_heading_b
links = '¶ ' +
'↑'
inner = "Hello"
assert_equal "\n#{inner}#{links}
\n",
@to.res.join
end
def accept_heading_suppressed_crossref
links = '¶ ' +
'↑'
assert_equal "\nHello#{links}
\n", @to.res.join
end
def accept_list_end_bullet
assert_equal [], @to.list
assert_equal [], @to.in_list_entry
assert_equal "\n", @to.res.join
end
def accept_list_end_label
assert_equal [], @to.list
assert_equal [], @to.in_list_entry
assert_equal "
\n", @to.res.join
end
def accept_list_end_lalpha
assert_equal [], @to.list
assert_equal [], @to.in_list_entry
assert_equal "
\n", @to.res.join
end
def accept_list_end_number
assert_equal [], @to.list
assert_equal [], @to.in_list_entry
assert_equal "
\n", @to.res.join
end
def accept_list_end_note
assert_equal [], @to.list
assert_equal [], @to.in_list_entry
assert_equal "
\n", @to.res.join
end
def accept_list_end_ualpha
assert_equal [], @to.list
assert_equal [], @to.in_list_entry
assert_equal "
\n", @to.res.join
end
def accept_list_item_end_bullet
assert_equal %w[], @to.in_list_entry
end
def accept_list_item_end_label
assert_equal %w[], @to.in_list_entry
end
def accept_list_item_end_lalpha
assert_equal %w[], @to.in_list_entry
end
def accept_list_item_end_note
assert_equal %w[], @to.in_list_entry
end
def accept_list_item_end_number
assert_equal %w[], @to.in_list_entry
end
def accept_list_item_end_ualpha
assert_equal %w[], @to.in_list_entry
end
def accept_list_item_start_bullet
assert_equal "- ", @to.res.join
end
def accept_list_item_start_label
assert_equal "
- cat\n
- ", @to.res.join
end
def accept_list_item_start_lalpha
assert_equal "
- ", @to.res.join
end
def accept_list_item_start_note
assert_equal "
- cat\n
- ",
@to.res.join
end
def accept_list_item_start_note_2
expected = <<-EXPECTED
teletype
-
teletype description
EXPECTED
assert_equal expected, @to.res.join
end
def accept_list_item_start_note_multi_description
expected = <<-EXPECTED
- label
-
description one
-
description two
EXPECTED
assert_equal expected, @to.res.join
end
def accept_list_item_start_note_multi_label
expected = <<-EXPECTED
- one
- two
-
two headers
EXPECTED
assert_equal expected, @to.res.join
end
def accept_list_item_start_number
assert_equal "- ", @to.res.join
end
def accept_list_item_start_ualpha
assert_equal "
- ", @to.res.join
end
def accept_list_start_bullet
assert_equal [:BULLET], @to.list
assert_equal [false], @to.in_list_entry
assert_equal "
", @to.res.join
end
def accept_list_start_label
assert_equal [:LABEL], @to.list
assert_equal [false], @to.in_list_entry
assert_equal '', @to.res.join
end
def accept_list_start_lalpha
assert_equal [:LALPHA], @to.list
assert_equal [false], @to.in_list_entry
assert_equal "", @to.res.join
end
def accept_list_start_note
assert_equal [:NOTE], @to.list
assert_equal [false], @to.in_list_entry
assert_equal "", @to.res.join
end
def accept_list_start_number
assert_equal [:NUMBER], @to.list
assert_equal [false], @to.in_list_entry
assert_equal "", @to.res.join
end
def accept_list_start_ualpha
assert_equal [:UALPHA], @to.list
assert_equal [false], @to.in_list_entry
assert_equal "", @to.res.join
end
def accept_paragraph
assert_equal "\nhi
\n", @to.res.join
end
def accept_paragraph_b
assert_equal "\nreg bold words reg
\n", @to.res.join
end
def accept_paragraph_br
assert_equal "\none
two
\n", @to.res.join
end
def accept_paragraph_break
assert_equal "\nhello
world
\n", @to.res.join
end
def accept_paragraph_i
assert_equal "\nreg italic words reg
\n", @to.res.join
end
def accept_paragraph_plus
assert_equal "\nreg teletype
reg
\n", @to.res.join
end
def accept_paragraph_star
assert_equal "\nreg bold reg
\n", @to.res.join
end
def accept_paragraph_underscore
assert_equal "\nreg italic reg
\n", @to.res.join
end
def accept_raw
raw = <<-RAW.rstrip
RAW
assert_equal raw, @to.res.join
end
def accept_rule
assert_equal "
\n", @to.res.join
end
def accept_verbatim
assert_equal "\nhi\n world\n
\n", @to.res.join
end
def end_accepting
assert_equal 'hi', @to.end_accepting
end
def start_accepting
assert_equal [], @to.res
assert_equal [], @to.in_list_entry
assert_equal [], @to.list
end
def list_nested
expected = <<-EXPECTED
EXPECTED
assert_equal expected, @to.res.join
end
def list_verbatim
expected = <<-EXPECTED
EXPECTED
assert_equal expected, @to.end_accepting
end
def test_accept_heading_7
@to.start_accepting
@to.accept_heading @RM::Heading.new(7, 'Hello')
links = '¶ ' +
'↑'
assert_equal "\nHello#{links}
\n", @to.res.join
end
def test_accept_heading_aref_class
@to.code_object = RDoc::NormalClass.new 'Foo'
@to.start_accepting
@to.accept_heading head(1, 'Hello')
links = '¶ ' +
'↑'
assert_equal "\nHello#{links}
\n",
@to.res.join
end
def test_accept_heading_aref_method
@to.code_object = RDoc::AnyMethod.new nil, 'foo'
@to.start_accepting
@to.accept_heading @RM::Heading.new(1, 'Hello')
links = '¶ ' +
'↑'
assert_equal "\nHello#{links}
\n",
@to.res.join
end
def test_accept_heading_pipe
@options.pipe = true
@to.start_accepting
@to.accept_heading @RM::Heading.new(1, 'Hello')
assert_equal "\nHello
\n", @to.res.join
end
def test_accept_paragraph_newline
@to.start_accepting
@to.accept_paragraph para("hello\n", "world\n")
assert_equal "\nhello world
\n", @to.res.join
end
def test_accept_heading_output_decoration
@options.output_decoration = false
@to.start_accepting
@to.accept_heading @RM::Heading.new(1, 'Hello')
assert_equal "\nHello¶ ↑
\n", @to.res.join
end
def test_accept_heading_output_decoration_with_pipe
@options.pipe = true
@options.output_decoration = false
@to.start_accepting
@to.accept_heading @RM::Heading.new(1, 'Hello')
assert_equal "\nHello
\n", @to.res.join
end
def test_accept_verbatim_parseable
verb = @RM::Verbatim.new("class C\n", "end\n")
@to.start_accepting
@to.accept_verbatim verb
expected = <<-EXPECTED
class C
end
EXPECTED
assert_equal expected, @to.res.join
end
def test_accept_verbatim_parseable_error
verb = @RM::Verbatim.new("a % 09 # => blah\n")
@to.start_accepting
@to.accept_verbatim verb
inner = CGI.escapeHTML "a % 09 # => blah"
expected = <<-EXPECTED
#{inner}
EXPECTED
assert_equal expected, @to.res.join
end
def test_accept_verbatim_pipe
@options.pipe = true
verb = @RM::Verbatim.new("1 + 1\n")
verb.format = :ruby
@to.start_accepting
@to.accept_verbatim verb
expected = <<-EXPECTED
1 + 1
EXPECTED
assert_equal expected, @to.res.join
end
def test_accept_verbatim_ruby
verb = @RM::Verbatim.new("1 + 1\n")
verb.format = :ruby
@to.start_accepting
@to.accept_verbatim verb
expected = <<-EXPECTED
1 + 1
EXPECTED
assert_equal expected, @to.res.join
end
def test_convert_string
assert_equal '<>', @to.convert_string('<>')
end
def test_convert_HYPERLINK_irc
result = @to.convert 'irc://irc.freenode.net/#ruby-lang'
assert_equal "\nirc.freenode.net/#ruby-lang
\n", result
end
def test_convert_RDOCLINK_label_label
result = @to.convert 'rdoc-label:label-One'
assert_equal "\nOne
\n", result
end
def test_convert_RDOCLINK_label_foottext
result = @to.convert 'rdoc-label:foottext-1'
assert_equal "\n1
\n", result
end
def test_convert_RDOCLINK_label_footmark
result = @to.convert 'rdoc-label:footmark-1'
assert_equal "\n1
\n", result
end
def test_convert_RDOCLINK_ref
result = @to.convert 'rdoc-ref:C'
assert_equal "\nC
\n", result
end
def test_convert_TIDYLINK_footnote
result = @to.convert 'text{*1}[rdoc-label:foottext-1:footmark-1]'
assert_equal "\ntext
\n", result
end
def test_convert_TIDYLINK_multiple
result = @to.convert '{a}[http://example] {b}[http://example]'
expected = <<-EXPECTED
a b
EXPECTED
assert_equal expected, result
end
def test_convert_TIDYLINK_image
result =
@to.convert '{rdoc-image:path/to/image.jpg}[http://example.com]'
expected =
"\n
\n"
assert_equal expected, result
end
def test_convert_TIDYLINK_rdoc_label
result = @to.convert '{foo}[rdoc-label:foottext-1]'
assert_equal "\nfoo
\n", result
end
def test_convert_TIDYLINK_irc
result = @to.convert '{ruby-lang}[irc://irc.freenode.net/#ruby-lang]'
assert_equal "\nruby-lang
\n", result
end
def test_gen_url
assert_equal 'example',
@to.gen_url('link:example', 'example')
end
def test_gen_url_rdoc_label
assert_equal 'example',
@to.gen_url('rdoc-label:foottext-1', 'example')
end
def test_gen_url_rdoc_label_id
assert_equal '',
@to.gen_url('rdoc-label:foottext-1:footmark-1', 'example')
end
def test_gen_url_image_url
assert_equal '', @to.gen_url('http://example.com/image.png', 'ignored')
end
def test_gen_url_ssl_image_url
assert_equal '', @to.gen_url('https://example.com/image.png', 'ignored')
end
def test_handle_special_HYPERLINK_link
special = RDoc::Markup::Special.new 0, 'link:README.txt'
link = @to.handle_special_HYPERLINK special
assert_equal 'README.txt', link
end
def test_handle_special_HYPERLINK_irc
special = RDoc::Markup::Special.new 0, 'irc://irc.freenode.net/#ruby-lang'
link = @to.handle_special_HYPERLINK special
assert_equal 'irc.freenode.net/#ruby-lang', link
end
def test_list_verbatim_2
str = "* one\n verb1\n verb2\n* two\n"
expected = <<-EXPECTED
EXPECTED
assert_equal expected, @m.convert(str, @to)
end
def test_parseable_eh
valid_syntax = [
'def x() end',
'def x; end',
'class C; end',
"module M end",
'a # => blah',
'x { |y| nil }',
'x do |y| nil end',
'# only a comment',
'require "foo"',
'cls="foo"'
]
invalid_syntax = [
'def x end',
'class C end',
'class C < end',
'module M < C end',
'a=># blah',
'x { |y| ... }',
'x do |y| ... end',
'// only a comment',
'<% require "foo" %>',
'class="foo"'
]
valid_syntax.each do |t|
assert @to.parseable?(t), "valid syntax considered invalid: #{t}"
end
invalid_syntax.each do |t|
refute @to.parseable?(t), "invalid syntax considered valid: #{t}"
end
end
def test_to_html
assert_equal "\n--
\n", util_format("--")
end
def util_format text
paragraph = RDoc::Markup::Paragraph.new text
@to.start_accepting
@to.accept_paragraph paragraph
@to.end_accepting
end
end