2017-11-27 05:45:24 -05:00
|
|
|
# frozen_string_literal: true
|
2010-04-01 03:45:16 -04:00
|
|
|
require File.expand_path '../xref_test_case', __FILE__
|
|
|
|
|
|
|
|
class TestRDocMarkupToHtmlCrossref < XrefTestCase
|
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
@options.hyperlink_all = true
|
|
|
|
|
|
|
|
@to = RDoc::Markup::ToHtmlCrossref.new @options, 'index.html', @c1
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
def test_convert_CROSSREF
|
|
|
|
result = @to.convert 'C1'
|
2008-07-17 20:46:16 -04:00
|
|
|
|
2018-10-29 02:23:21 -04:00
|
|
|
assert_equal para("<a href=\"C1.html\"><code>C1</code></a>"), result
|
2012-11-26 23:28:14 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_convert_CROSSREF_label
|
|
|
|
result = @to.convert 'C1@foo'
|
2018-10-29 02:23:21 -04:00
|
|
|
assert_equal para("<a href=\"C1.html#label-foo\">foo at <code>C1</code></a>"), result
|
2012-11-26 23:28:14 -05:00
|
|
|
|
|
|
|
result = @to.convert 'C1#m@foo'
|
2018-10-29 02:23:21 -04:00
|
|
|
assert_equal para("<a href=\"C1.html#method-i-m-label-foo\">foo at <code>C1#m</code></a>"),
|
2012-11-26 23:28:14 -05:00
|
|
|
result
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
def test_convert_CROSSREF_label_period
|
|
|
|
result = @to.convert 'C1@foo.'
|
2018-10-29 02:23:21 -04:00
|
|
|
assert_equal para("<a href=\"C1.html#label-foo\">foo at <code>C1</code></a>."), result
|
2012-11-26 23:28:14 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_convert_CROSSREF_label_space
|
|
|
|
result = @to.convert 'C1@foo+bar'
|
2018-10-29 02:23:21 -04:00
|
|
|
assert_equal para("<a href=\"C1.html#label-foo+bar\">foo bar at <code>C1</code></a>"),
|
2012-11-26 23:28:14 -05:00
|
|
|
result
|
|
|
|
end
|
|
|
|
|
2013-09-18 19:33:36 -04:00
|
|
|
def test_convert_CROSSREF_section
|
|
|
|
@c1.add_section 'Section'
|
|
|
|
|
|
|
|
result = @to.convert 'C1@Section'
|
2018-10-29 02:23:21 -04:00
|
|
|
assert_equal para("<a href=\"C1.html#Section\">Section at <code>C1</code></a>"), result
|
2013-09-18 19:33:36 -04:00
|
|
|
end
|
|
|
|
|
2016-09-05 06:35:30 -04:00
|
|
|
def test_convert_CROSSREF_constant
|
|
|
|
result = @to.convert 'C1::CONST'
|
|
|
|
|
2018-10-29 02:23:21 -04:00
|
|
|
assert_equal para("<a href=\"C1.html#CONST\"><code>C1::CONST</code></a>"), result
|
2016-09-05 06:35:30 -04:00
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
def test_convert_RDOCLINK_rdoc_ref
|
2011-07-30 20:19:00 -04:00
|
|
|
result = @to.convert 'rdoc-ref:C1'
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2018-10-29 02:23:21 -04:00
|
|
|
assert_equal para("<a href=\"C1.html\"><code>C1</code></a>"), result
|
2012-11-26 23:28:14 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_convert_RDOCLINK_rdoc_ref_method
|
|
|
|
result = @to.convert 'rdoc-ref:C1#m'
|
|
|
|
|
2018-10-29 02:23:21 -04:00
|
|
|
assert_equal para("<a href=\"C1.html#method-i-m\"><code>C1#m</code></a>"), result
|
2008-07-17 20:46:16 -04:00
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
def test_convert_RDOCLINK_rdoc_ref_method_label
|
|
|
|
result = @to.convert 'rdoc-ref:C1#m@foo'
|
|
|
|
|
2018-10-29 02:23:21 -04:00
|
|
|
assert_equal para("<a href=\"C1.html#method-i-m-label-foo\">foo at <code>C1#m</code></a>"),
|
2012-11-26 23:28:14 -05:00
|
|
|
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#%'
|
|
|
|
|
2018-10-29 02:23:21 -04:00
|
|
|
assert_equal para("<a href=\"C1.html#method-i-25\"><code>C1#%</code></a>"), result
|
2012-11-26 23:28:14 -05:00
|
|
|
|
|
|
|
m.singleton = true
|
|
|
|
|
|
|
|
result = @to.convert 'rdoc-ref:C1::%'
|
|
|
|
|
2018-10-29 02:23:21 -04:00
|
|
|
assert_equal para("<a href=\"C1.html#method-c-25\"><code>C1::%</code></a>"), result
|
2012-11-26 23:28:14 -05:00
|
|
|
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'
|
|
|
|
|
2018-10-29 02:23:21 -04:00
|
|
|
assert_equal para("<a href=\"C1.html#method-i-25-label-f\">f at <code>C1#%</code></a>"),
|
2012-11-26 23:28:14 -05:00
|
|
|
result
|
|
|
|
|
|
|
|
m.singleton = true
|
|
|
|
|
|
|
|
result = @to.convert 'rdoc-ref:C1::%@f'
|
2011-08-11 14:31:49 -04:00
|
|
|
|
2018-10-29 02:23:21 -04:00
|
|
|
assert_equal para("<a href=\"C1.html#method-c-25-label-f\">f at <code>C1::%</code></a>"),
|
2012-11-26 23:28:14 -05:00
|
|
|
result
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_convert_RDOCLINK_rdoc_ref_label
|
|
|
|
result = @to.convert 'rdoc-ref:C1@foo'
|
|
|
|
|
2018-10-29 02:23:21 -04:00
|
|
|
assert_equal para("<a href=\"C1.html#label-foo\">foo at <code>C1</code></a>"), result,
|
2012-11-26 23:28:14 -05:00
|
|
|
'rdoc-ref:C1@foo'
|
2011-08-11 14:31:49 -04:00
|
|
|
end
|
|
|
|
|
2011-08-01 01:25:13 -04:00
|
|
|
def test_gen_url
|
|
|
|
assert_equal '<a href="C1.html">Some class</a>',
|
|
|
|
@to.gen_url('rdoc-ref:C1', 'Some class')
|
|
|
|
|
|
|
|
assert_equal '<a href="http://example">HTTP example</a>',
|
|
|
|
@to.gen_url('http://example', 'HTTP example')
|
|
|
|
end
|
|
|
|
|
2018-10-17 02:28:20 -04:00
|
|
|
def test_handle_regexp_CROSSREF
|
2018-10-29 02:23:21 -04:00
|
|
|
assert_equal "<a href=\"C2/C3.html\"><code>C2::C3</code></a>", REGEXP_HANDLING('C2::C3')
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
2018-10-17 02:28:20 -04:00
|
|
|
def test_handle_regexp_CROSSREF_label
|
2018-10-29 02:23:21 -04:00
|
|
|
assert_equal "<a href=\"C1.html#method-i-m-label-foo\">foo at <code>C1#m</code></a>",
|
2018-10-17 02:28:20 -04:00
|
|
|
REGEXP_HANDLING('C1#m@foo')
|
2012-11-26 23:28:14 -05:00
|
|
|
end
|
|
|
|
|
2018-10-17 02:28:20 -04:00
|
|
|
def test_handle_regexp_CROSSREF_show_hash_false
|
2011-07-30 20:19:00 -04:00
|
|
|
@to.show_hash = false
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2018-10-29 02:23:21 -04:00
|
|
|
assert_equal "<a href=\"C1.html#method-i-m\"><code>m</code></a>",
|
2018-10-17 02:28:20 -04:00
|
|
|
REGEXP_HANDLING('#m')
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2018-10-17 02:28:20 -04:00
|
|
|
def test_handle_regexp_HYPERLINK_rdoc
|
2012-11-26 23:28:14 -05:00
|
|
|
readme = @store.add_file 'README.txt'
|
|
|
|
readme.parser = RDoc::Parser::Simple
|
|
|
|
|
|
|
|
@to = RDoc::Markup::ToHtmlCrossref.new @options, 'C2.html', @c2
|
2008-09-24 22:43:03 -04:00
|
|
|
|
2018-10-17 02:28:20 -04:00
|
|
|
link = @to.handle_regexp_HYPERLINK hyper 'C2::C3'
|
2008-07-17 20:46:16 -04:00
|
|
|
|
2018-10-29 02:23:21 -04:00
|
|
|
assert_equal '<a href="C2/C3.html"><code>C2::C3</code></a>', link
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2018-10-17 02:28:20 -04:00
|
|
|
link = @to.handle_regexp_HYPERLINK hyper 'C4'
|
2008-09-24 22:43:03 -04:00
|
|
|
|
2018-10-29 02:23:21 -04:00
|
|
|
assert_equal '<a href="C4.html"><code>C4</code></a>', link
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2018-10-17 02:28:20 -04:00
|
|
|
link = @to.handle_regexp_HYPERLINK hyper 'README.txt'
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
assert_equal '<a href="README_txt.html">README.txt</a>', link
|
2008-09-24 22:43:03 -04:00
|
|
|
end
|
|
|
|
|
2018-10-17 02:28:20 -04:00
|
|
|
def test_handle_regexp_TIDYLINK_rdoc
|
2012-11-26 23:28:14 -05:00
|
|
|
readme = @store.add_file 'README.txt'
|
|
|
|
readme.parser = RDoc::Parser::Simple
|
|
|
|
|
|
|
|
@to = RDoc::Markup::ToHtmlCrossref.new @options, 'C2.html', @c2
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2018-10-17 02:28:20 -04:00
|
|
|
link = @to.handle_regexp_TIDYLINK tidy 'C2::C3'
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
assert_equal '<a href="C2/C3.html">tidy</a>', link
|
2008-09-24 22:43:03 -04:00
|
|
|
|
2018-10-17 02:28:20 -04:00
|
|
|
link = @to.handle_regexp_TIDYLINK tidy 'C4'
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
assert_equal '<a href="C4.html">tidy</a>', link
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2018-10-17 02:28:20 -04:00
|
|
|
link = @to.handle_regexp_TIDYLINK tidy 'C1#m'
|
2012-11-26 23:28:14 -05:00
|
|
|
|
|
|
|
assert_equal '<a href="C1.html#method-i-m">tidy</a>', link
|
|
|
|
|
2018-10-17 02:28:20 -04:00
|
|
|
link = @to.handle_regexp_TIDYLINK tidy 'README.txt'
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
assert_equal '<a href="README_txt.html">tidy</a>', link
|
2008-09-24 22:43:03 -04:00
|
|
|
end
|
|
|
|
|
2018-10-17 02:28:20 -04:00
|
|
|
def test_handle_regexp_TIDYLINK_label
|
|
|
|
link = @to.handle_regexp_TIDYLINK tidy 'C1#m@foo'
|
2012-11-26 23:28:14 -05:00
|
|
|
|
|
|
|
assert_equal "<a href=\"C1.html#method-i-m-label-foo\">tidy</a>",
|
|
|
|
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
|
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
def test_link
|
|
|
|
assert_equal 'n', @to.link('n', 'n')
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2018-10-29 02:23:21 -04:00
|
|
|
assert_equal '<a href="C1.html#method-c-m"><code>m</code></a>', @to.link('m', 'm')
|
2018-08-26 21:30:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_link_for_method_traverse
|
|
|
|
@to = RDoc::Markup::ToHtmlCrossref.new @options, 'C2.html', @c9
|
2018-10-29 02:23:21 -04:00
|
|
|
assert_equal '<a href="C9/A.html#method-i-foo"><code>C9::B#foo</code></a>', @to.link('C9::B#foo', 'C9::B#foo')
|
2012-11-26 23:28:14 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_link_class_method_full
|
2018-10-29 02:23:21 -04:00
|
|
|
assert_equal '<a href="Parent.html#method-c-m"><code>Parent::m</code></a>',
|
2012-11-26 23:28:14 -05:00
|
|
|
@to.link('Parent::m', 'Parent::m')
|
|
|
|
end
|
|
|
|
|
|
|
|
def para text
|
|
|
|
"\n<p>#{text}</p>\n"
|
2011-07-30 20:19:00 -04:00
|
|
|
end
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2018-10-17 02:28:20 -04:00
|
|
|
def REGEXP_HANDLING text
|
|
|
|
@to.handle_regexp_CROSSREF regexp_handling text
|
2008-09-24 22:43:03 -04:00
|
|
|
end
|
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
def hyper reference
|
2018-10-17 02:28:20 -04:00
|
|
|
RDoc::Markup::RegexpHandling.new 0, "rdoc-ref:#{reference}"
|
2011-07-30 20:19:00 -04:00
|
|
|
end
|
2010-12-19 22:22:49 -05:00
|
|
|
|
2018-10-17 02:28:20 -04:00
|
|
|
def regexp_handling text
|
|
|
|
RDoc::Markup::RegexpHandling.new 0, text
|
2010-12-19 22:22:49 -05:00
|
|
|
end
|
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
def tidy reference
|
2018-10-17 02:28:20 -04:00
|
|
|
RDoc::Markup::RegexpHandling.new 0, "{tidy}[rdoc-ref:#{reference}]"
|
2008-09-24 22:43:03 -04:00
|
|
|
end
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2008-09-24 22:43:03 -04:00
|
|
|
end
|
2008-10-24 19:05:28 -04:00
|
|
|
|