# frozen_string_literal: true require 'minitest_helper' 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
\n\n", @to.res.join end def accept_document assert_equal "\nquote
\n
hello
\n", @to.res.join end def accept_heading links = '¶ ' + '↑' expected = "\nteletype
teletype description
description one
description two
two headers
hi
\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
hello
world
reg italic words reg
\n", @to.res.join end def accept_paragraph_plus assert_equal "\nreg teletype
reg
reg 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.rstripName | Count |
---|---|
a | 1 |
b | 2 |
hi\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
l1
l1.1
l2
list stuff
* list with second 1. indented 2. numbered third * second
hello 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 "\nclass C endEXPECTED 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_nl_after_backslash verb = @RM::Verbatim.new("a = 1 if first_flag_var and \\\n", " this_is_flag_var\n") @to.start_accepting @to.accept_verbatim verb expected = <<-EXPECTED
a = 1 if first_flag_var and \\ this_is_flag_varEXPECTED 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_escape_in_string
code = <<-'RUBY'
def foo
[
'\\',
'\'',
"'",
"\'\"\`",
"\#",
"\#{}",
"#",
"#{}",
/'"/,
/\'\"/,
/\//,
/\\/,
/\#/,
/\#{}/,
/#/,
/#{}/
]
end
def bar
end
RUBY
verb = @RM::Verbatim.new(*code.split(/(?<=\n)/))
@to.start_accepting
@to.accept_verbatim verb
expected = <<-'EXPECTED'
def foo [ '\\', '\'', "'", "\'\"\`", "\#", "\#{}", "#", "#{}", /'"/, /\'\"/, /\//, /\\/, /\#/, /\#{}/, /#/, /#{}/ ] end def bar endEXPECTED assert_equal expected, @to.res.join end def test_accept_verbatim_escape_in_backtick code = <<-'RUBY' def foo [ `\\`, `\'\"\``, `\#`, `\#{}`, `#`, `#{}` ] end def bar end RUBY verb = @RM::Verbatim.new(*code.split(/(?<=\n)/)) @to.start_accepting @to.accept_verbatim verb expected = <<-'EXPECTED'
def foo [ `\\`, `\'\"\``, `\#`, `\#{}`, `#`, `#{}` ] end def bar endEXPECTED 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 + 1EXPECTED assert_equal expected, @to.res.join end def test_accept_verbatim_redefinable_operators functions = %w[| ^ & <=> == === =~ > >= < <= << >> + - * / % ** ~ +@ -@ [] []= ` ! != !~].map { |redefinable_op| ["def #{redefinable_op}\n", "end\n"] }.flatten verb = @RM::Verbatim.new(*functions) @to.start_accepting @to.accept_verbatim verb expected = <<-EXPECTED
EXPECTED expected = expected.rstrip %w[| ^ & <=> == === =~ > >= < <= << >> + - * / % ** ~ +@ -@ [] []= ` ! != !~].each do |html_escaped_op| expected += <<-EXPECTED def #{html_escaped_op} end EXPECTED end expected += <<-EXPECTEDEXPECTED 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 "\n\n", result end def test_convert_RDOCLINK_label_label result = @to.convert 'rdoc-label:label-One' assert_equal "\n\n", result end def test_convert_RDOCLINK_label_foottext result = @to.convert 'rdoc-label:foottext-1' assert_equal "\n\n", result end def test_convert_RDOCLINK_label_footmark result = @to.convert 'rdoc-label:footmark-1' assert_equal "\n\n", result end def test_convert_RDOCLINK_ref result = @to.convert 'rdoc-ref:C' assert_equal "\n
C
\n", result end def test_convert_TIDYLINK_footnote result = @to.convert 'text{*1}[rdoc-label:foottext-1:footmark-1]' assert_equal "\ntext1
\n", result end def test_convert_TIDYLINK_multiple result = @to.convert '{a}[http://example] {b}[http://example]' expected = <<-EXPECTED 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 "\n\n", result end def test_convert_TIDYLINK_irc result = @to.convert '{ruby-lang}[irc://irc.freenode.net/#ruby-lang]' assert_equal "\n\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 'example', @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 = <<-EXPECTEDone
verb1 verb2
two
--