1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
# frozen_string_literal: true
require_relative 'helper'
class TestRDocMarkupFormatter < RDoc::TestCase
class ToTest < RDoc::Markup::Formatter
def initialize markup
super nil, markup
add_tag :TT, '<code>', '</code>'
end
def accept_paragraph paragraph
@res += attributes(paragraph.text)
end
def attributes text
convert_flow @am.flow text.dup
end
def handle_regexp_CAPS target
"handled #{target.text}"
end
def start_accepting
@res = ""
end
def end_accepting
@res
end
end
def setup
super
@markup = @RM.new
@markup.add_regexp_handling(/[A-Z]+/, :CAPS)
@attribute_manager = @markup.attribute_manager
@attributes = @attribute_manager.attributes
@to = ToTest.new @markup
@caps = @attributes.bitmap_for :CAPS
@regexp_handling = @attributes.bitmap_for :_REGEXP_HANDLING_
@tt = @attributes.bitmap_for :TT
end
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
def regexp_handling_names
@attribute_manager.regexp_handlings.map do |_, mask|
@attributes.as_string mask
end
end
def test_add_regexp_handling_RDOCLINK
@to.add_regexp_handling_RDOCLINK
assert_includes regexp_handling_names, 'RDOCLINK'
def @to.handle_regexp_RDOCLINK target
"<#{target.text}>"
end
document = doc(para('{foo}[rdoc-label:bar].'))
formatted = document.accept @to
assert_equal '{foo}[<rdoc-label:bar>].', formatted
end
def test_add_regexp_handling_TIDYLINK
@to.add_regexp_handling_TIDYLINK
assert_includes regexp_handling_names, 'TIDYLINK'
def @to.handle_regexp_TIDYLINK target
"<#{target.text}>"
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
end
def test_parse_url
scheme, url, id = @to.parse_url 'example/foo'
assert_equal 'http', scheme
assert_equal 'example/foo', url
assert_nil id
end
def test_parse_url_anchor
scheme, url, id = @to.parse_url '#foottext-1'
assert_nil scheme
assert_equal '#foottext-1', url
assert_nil id
end
def test_parse_url_link
scheme, url, id = @to.parse_url 'link:README.txt'
assert_equal 'link', scheme
assert_equal 'README.txt', url
assert_nil id
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
assert_nil id
end
def test_parse_url_rdoc_label
scheme, url, id = @to.parse_url 'rdoc-label:foo'
assert_equal 'link', scheme
assert_equal '#foo', url
assert_nil id
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
assert_nil id
scheme, url, id = @to.parse_url 'https://example/foo'
assert_equal 'https', scheme
assert_equal 'https://example/foo', url
assert_nil id
end
def test_convert_tt_regexp_handling
converted = @to.convert '<code>AAA</code>'
assert_equal '<code>AAA</code>', converted
end
end
|