2017-11-27 13:45:24 +03:00
|
|
|
# frozen_string_literal: true
|
2019-08-08 17:09:24 +03:00
|
|
|
require_relative 'helper'
|
2011-08-24 03:53:49 +04:00
|
|
|
|
2012-11-27 08:28:14 +04:00
|
|
|
class TestRDocMarkupFormatter < RDoc::TestCase
|
2011-08-24 03:53:49 +04:00
|
|
|
|
|
|
|
class ToTest < RDoc::Markup::Formatter
|
|
|
|
|
|
|
|
def initialize markup
|
2012-11-27 08:28:14 +04:00
|
|
|
super nil, markup
|
2011-08-24 03:53:49 +04:00
|
|
|
|
2012-11-27 08:28:14 +04:00
|
|
|
add_tag :TT, '<code>', '</code>'
|
2011-08-24 03:53:49 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def accept_paragraph paragraph
|
2017-11-27 13:45:24 +03:00
|
|
|
@res += attributes(paragraph.text)
|
2011-08-24 03:53:49 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def attributes text
|
|
|
|
convert_flow @am.flow text.dup
|
|
|
|
end
|
|
|
|
|
2018-10-17 09:28:20 +03:00
|
|
|
def handle_regexp_CAPS target
|
|
|
|
"handled #{target.text}"
|
2011-08-24 03:53:49 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def start_accepting
|
|
|
|
@res = ""
|
|
|
|
end
|
|
|
|
|
|
|
|
def end_accepting
|
|
|
|
@res
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def setup
|
2012-11-27 08:28:14 +04:00
|
|
|
super
|
|
|
|
|
|
|
|
@markup = @RM.new
|
2018-10-17 09:28:20 +03:00
|
|
|
@markup.add_regexp_handling(/[A-Z]+/, :CAPS)
|
2011-08-24 03:53:49 +04:00
|
|
|
|
2012-11-27 08:28:14 +04:00
|
|
|
@attribute_manager = @markup.attribute_manager
|
|
|
|
@attributes = @attribute_manager.attributes
|
|
|
|
|
2011-08-24 03:53:49 +04:00
|
|
|
@to = ToTest.new @markup
|
|
|
|
|
2018-10-17 09:28:20 +03:00
|
|
|
@caps = @attributes.bitmap_for :CAPS
|
|
|
|
@regexp_handling = @attributes.bitmap_for :_REGEXP_HANDLING_
|
|
|
|
@tt = @attributes.bitmap_for :TT
|
2011-08-24 03:53:49 +04:00
|
|
|
end
|
|
|
|
|
2012-12-17 03:07:49 +04:00
|
|
|
def test_class_gen_relative_url
|
|
|
|
def gen(from, to)
|
|
|
|
RDoc::Markup::ToHtml.gen_relative_url from, to
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal 'a.html', gen('a.html', 'a.html')
|
|
|
|
assert_equal 'b.html', gen('a.html', 'b.html')
|
|
|
|
|
|
|
|
assert_equal 'd.html', gen('a/c.html', 'a/d.html')
|
|
|
|
assert_equal '../a.html', gen('a/c.html', 'a.html')
|
|
|
|
assert_equal 'a/c.html', gen('a.html', 'a/c.html')
|
|
|
|
end
|
|
|
|
|
2018-10-17 09:28:20 +03:00
|
|
|
def regexp_handling_names
|
|
|
|
@attribute_manager.regexp_handlings.map do |_, mask|
|
2012-12-17 03:07:49 +04:00
|
|
|
@attributes.as_string mask
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-10-17 09:28:20 +03:00
|
|
|
def test_add_regexp_handling_RDOCLINK
|
|
|
|
@to.add_regexp_handling_RDOCLINK
|
2012-12-17 03:07:49 +04:00
|
|
|
|
2018-10-17 09:28:20 +03:00
|
|
|
assert_includes regexp_handling_names, 'RDOCLINK'
|
2013-09-19 03:33:36 +04:00
|
|
|
|
2018-10-17 09:28:20 +03:00
|
|
|
def @to.handle_regexp_RDOCLINK target
|
|
|
|
"<#{target.text}>"
|
2013-09-19 03:33:36 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
document = doc(para('{foo}[rdoc-label:bar].'))
|
|
|
|
|
|
|
|
formatted = document.accept @to
|
|
|
|
|
|
|
|
assert_equal '{foo}[<rdoc-label:bar>].', formatted
|
2012-12-17 03:07:49 +04:00
|
|
|
end
|
|
|
|
|
2018-10-17 09:28:20 +03:00
|
|
|
def test_add_regexp_handling_TIDYLINK
|
|
|
|
@to.add_regexp_handling_TIDYLINK
|
2012-12-17 03:07:49 +04:00
|
|
|
|
2018-10-17 09:28:20 +03:00
|
|
|
assert_includes regexp_handling_names, 'TIDYLINK'
|
2013-09-19 03:33:36 +04:00
|
|
|
|
2018-10-17 09:28:20 +03:00
|
|
|
def @to.handle_regexp_TIDYLINK target
|
|
|
|
"<#{target.text}>"
|
2013-09-19 03:33:36 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
document = doc(para('foo[rdoc-label:bar].'))
|
|
|
|
|
|
|
|
formatted = document.accept @to
|
|
|
|
|
|
|
|
assert_equal '<foo[rdoc-label:bar]>.', formatted
|
|
|
|
|
|
|
|
document = doc(para('{foo}[rdoc-label:bar].'))
|
|
|
|
|
|
|
|
formatted = document.accept @to
|
|
|
|
|
|
|
|
assert_equal '<{foo}[rdoc-label:bar]>.', formatted
|
2012-12-17 03:07:49 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_parse_url
|
|
|
|
scheme, url, id = @to.parse_url 'example/foo'
|
|
|
|
|
2013-09-19 03:33:36 +04:00
|
|
|
assert_equal 'http', scheme
|
|
|
|
assert_equal 'example/foo', url
|
2018-03-26 08:56:26 +03:00
|
|
|
assert_nil id
|
2012-12-17 03:07:49 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_parse_url_anchor
|
|
|
|
scheme, url, id = @to.parse_url '#foottext-1'
|
|
|
|
|
2018-03-26 08:56:26 +03:00
|
|
|
assert_nil scheme
|
2012-12-17 03:07:49 +04:00
|
|
|
assert_equal '#foottext-1', url
|
2018-03-26 08:56:26 +03:00
|
|
|
assert_nil id
|
2012-12-17 03:07:49 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_parse_url_link
|
|
|
|
scheme, url, id = @to.parse_url 'link:README.txt'
|
|
|
|
|
|
|
|
assert_equal 'link', scheme
|
|
|
|
assert_equal 'README.txt', url
|
2018-03-26 08:56:26 +03:00
|
|
|
assert_nil id
|
2012-12-17 03:07:49 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_parse_url_link_id
|
|
|
|
scheme, url, id = @to.parse_url 'link:README.txt#label-foo'
|
|
|
|
|
|
|
|
assert_equal 'link', scheme
|
|
|
|
assert_equal 'README.txt#label-foo', url
|
2018-03-26 08:56:26 +03:00
|
|
|
assert_nil id
|
2012-12-17 03:07:49 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_parse_url_rdoc_label
|
|
|
|
scheme, url, id = @to.parse_url 'rdoc-label:foo'
|
|
|
|
|
|
|
|
assert_equal 'link', scheme
|
|
|
|
assert_equal '#foo', url
|
2018-03-26 08:56:26 +03:00
|
|
|
assert_nil id
|
2012-12-17 03:07:49 +04:00
|
|
|
|
|
|
|
scheme, url, id = @to.parse_url 'rdoc-label:foo:bar'
|
|
|
|
|
|
|
|
assert_equal 'link', scheme
|
|
|
|
assert_equal '#foo', url
|
|
|
|
assert_equal ' id="bar"', id
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_parse_url_scheme
|
|
|
|
scheme, url, id = @to.parse_url 'http://example/foo'
|
|
|
|
|
|
|
|
assert_equal 'http', scheme
|
|
|
|
assert_equal 'http://example/foo', url
|
2018-03-26 08:56:26 +03:00
|
|
|
assert_nil id
|
2012-12-17 03:07:49 +04:00
|
|
|
|
|
|
|
scheme, url, id = @to.parse_url 'https://example/foo'
|
|
|
|
|
|
|
|
assert_equal 'https', scheme
|
|
|
|
assert_equal 'https://example/foo', url
|
2018-03-26 08:56:26 +03:00
|
|
|
assert_nil id
|
2012-12-17 03:07:49 +04:00
|
|
|
end
|
|
|
|
|
2018-10-17 09:28:20 +03:00
|
|
|
def test_convert_tt_regexp_handling
|
2012-11-27 08:28:14 +04:00
|
|
|
converted = @to.convert '<code>AAA</code>'
|
2011-08-24 03:53:49 +04:00
|
|
|
|
2012-11-27 08:28:14 +04:00
|
|
|
assert_equal '<code>AAA</code>', converted
|
2011-08-24 03:53:49 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|