# frozen_string_literal: true require_relative '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_RDOCLINK_escape_image assert_escaped '"' end def test_convert_RDOCLINK_escape_label_id assert_escaped '"' end def test_convert_RDOCLINK_escape_label_path assert_escaped '"' end def test_convert_RDOCLINK_escape_ref assert_escaped '"' end def test_convert_RDOCLINK_escape_xxx assert_escaped '"' 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 result = @to.convert '{rdoc-image:}[http://example.com]' assert_not_include result, "}[a]' assert_escaped '[[]' end def test_convert_TIDYLINK_escape_javascript assert_not_include '{click}[javascript:alert`javascript_scheme`]', 'aaa
[:symbol]\n", @to.convert('+aaa+[:symbol]')
assert_equal "\naaa[:symbol]
https:
-foobar
aaa
_
\u{2018}i386-mswin32_
MSRTVERSION\u{2019}
one
verb1 verb2
two
BlockQuote
>>>EXPECTED assert_equal expected, @m.convert(str, @to).gsub(/^\n/, "") str = "BlockQuote\n >>> word\n" expected = <<-EXPECTED
BlockQuote
>>> wordEXPECTED assert_equal expected, @m.convert(str, @to).gsub(/^\n/, "") 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', '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
--