# frozen_string_literal: true require File.expand_path '../xref_test_case', __FILE__ class TestRDocMarkupToHtmlCrossref < XrefTestCase def setup super @options.hyperlink_all = true @to = RDoc::Markup::ToHtmlCrossref.new @options, 'index.html', @c1 end def test_convert_CROSSREF result = @to.convert 'C1' assert_equal para("C1"), result end def test_convert_CROSSREF_label result = @to.convert 'C1@foo' assert_equal para("foo at C1"), result result = @to.convert 'C1#m@foo' assert_equal para("foo at C1#m"), result end def test_convert_CROSSREF_label_period result = @to.convert 'C1@foo.' assert_equal para("foo at C1."), result end def test_convert_CROSSREF_label_space result = @to.convert 'C1@foo+bar' assert_equal para("foo bar at C1"), result end def test_convert_CROSSREF_section @c1.add_section 'Section' result = @to.convert 'C1@Section' assert_equal para("Section at C1"), result end def test_convert_CROSSREF_constant result = @to.convert 'C1::CONST' assert_equal para("C1::CONST"), result end def test_convert_RDOCLINK_rdoc_ref result = @to.convert 'rdoc-ref:C1' assert_equal para("C1"), result end def test_convert_RDOCLINK_rdoc_ref_method result = @to.convert 'rdoc-ref:C1#m' assert_equal para("#m"), result end def test_convert_RDOCLINK_rdoc_ref_method_label result = @to.convert 'rdoc-ref:C1#m@foo' assert_equal para("foo at C1#m"), result, 'rdoc-ref:C1#m@foo' end def test_convert_RDOCLINK_rdoc_ref_method_percent m = @c1.add_method RDoc::AnyMethod.new nil, '%' m.singleton = false result = @to.convert 'rdoc-ref:C1#%' assert_equal para("#%"), result m.singleton = true result = @to.convert 'rdoc-ref:C1::%' assert_equal para("::%"), result end def test_convert_RDOCLINK_rdoc_ref_method_percent_label m = @c1.add_method RDoc::AnyMethod.new nil, '%' m.singleton = false result = @to.convert 'rdoc-ref:C1#%@f' assert_equal para("f at C1#%"), result m.singleton = true result = @to.convert 'rdoc-ref:C1::%@f' assert_equal para("f at C1::%"), result end def test_convert_RDOCLINK_rdoc_ref_label result = @to.convert 'rdoc-ref:C1@foo' assert_equal para("foo at C1"), result, 'rdoc-ref:C1@foo' end def test_gen_url assert_equal 'Some class', @to.gen_url('rdoc-ref:C1', 'Some class') assert_equal 'HTTP example', @to.gen_url('http://example', 'HTTP example') end def test_handle_special_CROSSREF assert_equal "C2::C3", SPECIAL('C2::C3') end def test_handle_special_CROSSREF_label assert_equal "foo at C1#m", SPECIAL('C1#m@foo') end def test_handle_special_CROSSREF_show_hash_false @to.show_hash = false assert_equal "m", SPECIAL('#m') end def test_handle_special_HYPERLINK_rdoc readme = @store.add_file 'README.txt' readme.parser = RDoc::Parser::Simple @to = RDoc::Markup::ToHtmlCrossref.new @options, 'C2.html', @c2 link = @to.handle_special_HYPERLINK hyper 'C2::C3' assert_equal 'C2::C3', link link = @to.handle_special_HYPERLINK hyper 'C4' assert_equal 'C4', link link = @to.handle_special_HYPERLINK hyper 'README.txt' assert_equal 'README.txt', link end def test_handle_special_TIDYLINK_rdoc readme = @store.add_file 'README.txt' readme.parser = RDoc::Parser::Simple @to = RDoc::Markup::ToHtmlCrossref.new @options, 'C2.html', @c2 link = @to.handle_special_TIDYLINK tidy 'C2::C3' assert_equal 'tidy', link link = @to.handle_special_TIDYLINK tidy 'C4' assert_equal 'tidy', link link = @to.handle_special_TIDYLINK tidy 'C1#m' assert_equal 'tidy', link link = @to.handle_special_TIDYLINK tidy 'README.txt' assert_equal 'tidy', link end def test_handle_special_TIDYLINK_label link = @to.handle_special_TIDYLINK tidy 'C1#m@foo' assert_equal "tidy", link, 'C1#m@foo' end def test_to_html_CROSSREF_email @options.hyperlink_all = false @to = RDoc::Markup::ToHtmlCrossref.new @options, 'index.html', @c1 result = @to.to_html 'first.last@example.com' assert_equal 'first.last@example.com', result end def test_to_html_CROSSREF_email_hyperlink_all result = @to.to_html 'first.last@example.com' assert_equal 'first.last@example.com', result end def test_link assert_equal 'n', @to.link('n', 'n') assert_equal '::m', @to.link('m', 'm') end def test_link_class_method_full assert_equal 'Parent.m', @to.link('Parent::m', 'Parent::m') end def para text "\n
#{text}
\n" end def SPECIAL text @to.handle_special_CROSSREF special text end def hyper reference RDoc::Markup::Special.new 0, "rdoc-ref:#{reference}" end def special text RDoc::Markup::Special.new 0, text end def tidy reference RDoc::Markup::Special.new 0, "{tidy}[rdoc-ref:#{reference}]" end end