2
require 'rdoc/markup/formatter_test_case'
3
require 'rdoc/markup/to_rdoc'
4
require 'minitest/autorun'
6
class TestRDocMarkupToRdoc < RDoc::Markup::FormatterTestCase
13
@to = RDoc::Markup::ToRdoc.new
17
assert_equal "\n", @to.res.join
21
assert_equal "===== Hello\n", @to.res.join
24
def accept_list_end_bullet
25
assert_empty @to.list_index
26
assert_empty @to.list_type
27
assert_empty @to.list_width
30
def accept_list_end_label
31
assert_empty @to.list_index
32
assert_empty @to.list_type
33
assert_empty @to.list_width
36
def accept_list_end_lalpha
37
assert_empty @to.list_index
38
assert_empty @to.list_type
39
assert_empty @to.list_width
42
def accept_list_end_note
43
assert_empty @to.list_index
44
assert_empty @to.list_type
45
assert_empty @to.list_width
48
def accept_list_end_number
49
assert_empty @to.list_index
50
assert_empty @to.list_type
51
assert_empty @to.list_width
54
def accept_list_end_ualpha
55
assert_empty @to.list_index
56
assert_empty @to.list_type
57
assert_empty @to.list_width
60
def accept_list_item_end_bullet
61
assert_equal 0, @to.indent, 'indent'
64
def accept_list_item_end_label
65
assert_equal "\n", @to.res.join
66
assert_equal 0, @to.indent, 'indent'
69
def accept_list_item_end_lalpha
70
assert_equal 0, @to.indent, 'indent'
71
assert_equal 'b', @to.list_index.last
74
def accept_list_item_end_note
75
assert_equal "\n", @to.res.join
76
assert_equal 0, @to.indent, 'indent'
79
def accept_list_item_end_number
80
assert_equal 0, @to.indent, 'indent'
81
assert_equal 2, @to.list_index.last
84
def accept_list_item_end_ualpha
85
assert_equal 0, @to.indent, 'indent'
86
assert_equal 'B', @to.list_index.last
89
def accept_list_item_start_bullet
90
assert_equal [""], @to.res
91
assert_equal '* ', @to.prefix
94
def accept_list_item_start_label
95
assert_equal [""], @to.res
96
assert_equal "cat:\n ", @to.prefix
98
assert_equal 2, @to.indent
101
def accept_list_item_start_lalpha
102
assert_equal [""], @to.res
103
assert_equal 'a. ', @to.prefix
105
assert_equal 'a', @to.list_index.last
106
assert_equal 3, @to.indent
109
def accept_list_item_start_note
110
assert_equal [""], @to.res
111
assert_equal "cat:\n ", @to.prefix
113
assert_equal 2, @to.indent
116
def accept_list_item_start_number
117
assert_equal [""], @to.res
118
assert_equal '1. ', @to.prefix
120
assert_equal 1, @to.list_index.last
121
assert_equal 3, @to.indent
124
def accept_list_item_start_ualpha
125
assert_equal [""], @to.res
126
assert_equal 'A. ', @to.prefix
128
assert_equal 'A', @to.list_index.last
129
assert_equal 3, @to.indent
132
def accept_list_start_bullet
133
assert_equal "", @to.res.join
134
assert_equal [nil], @to.list_index
135
assert_equal [:BULLET], @to.list_type
136
assert_equal [1], @to.list_width
139
def accept_list_start_label
140
assert_equal "", @to.res.join
141
assert_equal [nil], @to.list_index
142
assert_equal [:LABEL], @to.list_type
143
assert_equal [2], @to.list_width
146
def accept_list_start_lalpha
147
assert_equal "", @to.res.join
148
assert_equal ['a'], @to.list_index
149
assert_equal [:LALPHA], @to.list_type
150
assert_equal [1], @to.list_width
153
def accept_list_start_note
154
assert_equal "", @to.res.join
155
assert_equal [nil], @to.list_index
156
assert_equal [:NOTE], @to.list_type
157
assert_equal [2], @to.list_width
160
def accept_list_start_number
161
assert_equal "", @to.res.join
162
assert_equal [1], @to.list_index
163
assert_equal [:NUMBER], @to.list_type
164
assert_equal [1], @to.list_width
167
def accept_list_start_ualpha
168
assert_equal "", @to.res.join
169
assert_equal ['A'], @to.list_index
170
assert_equal [:UALPHA], @to.list_type
171
assert_equal [1], @to.list_width
175
assert_equal "hi\n", @to.res.join
181
<tr><th>Name<th>Count
187
assert_equal raw, @to.res.join
191
assert_equal "#{'-' * 78}\n", @to.res.join
194
def accept_verbatim # FormatterTestCase doesn't set indent for ToAnsi
195
assert_equal " hi\n world\n\n", @to.res.join
199
assert_equal "hi", @to.end_accepting
203
assert_equal 0, @to.indent
204
assert_equal [""], @to.res
205
assert_empty @to.list_index
206
assert_empty @to.list_type
207
assert_empty @to.list_width
210
def test_accept_heading_1
212
@to.accept_heading @RM::Heading.new(1, 'Hello')
214
assert_equal "= Hello\n", @to.end_accepting
217
def test_accept_heading_2
219
@to.accept_heading @RM::Heading.new(2, 'Hello')
221
assert_equal "== Hello\n", @to.end_accepting
224
def test_accept_heading_3
226
@to.accept_heading @RM::Heading.new(3, 'Hello')
228
assert_equal "=== Hello\n", @to.end_accepting
231
def test_accept_heading_4
233
@to.accept_heading @RM::Heading.new(4, 'Hello')
235
assert_equal "==== Hello\n", @to.end_accepting
238
def test_accept_heading_indent
241
@to.accept_heading @RM::Heading.new(1, 'Hello')
243
assert_equal " = Hello\n", @to.end_accepting
246
def test_accept_heading_b
249
@to.accept_heading @RM::Heading.new(1, '*Hello*')
251
assert_equal " = <b>Hello</b>\n", @to.end_accepting
254
def test_accept_list_item_start_note_2
255
list = @RM::List.new(:NOTE,
256
@RM::ListItem.new('<tt>teletype</tt>',
257
@RM::Paragraph.new('teletype description')))
263
expected = "<tt>teletype</tt>:\n teletype description\n\n"
265
assert_equal expected, @to.end_accepting
268
def test_accept_paragraph_b
270
@to.accept_paragraph @RM::Paragraph.new('reg <b>bold words</b> reg')
272
expected = "reg <b>bold words</b> reg\n"
274
assert_equal expected, @to.end_accepting
277
def test_accept_paragraph_i
279
@to.accept_paragraph @RM::Paragraph.new('reg <em>italic words</em> reg')
281
expected = "reg <em>italic words</em> reg\n"
283
assert_equal expected, @to.end_accepting
286
def test_accept_paragraph_indent
289
@to.accept_paragraph @RM::Paragraph.new('words ' * 30)
291
expected = <<-EXPECTED
292
words words words words words words words words words words words words
293
words words words words words words words words words words words words
294
words words words words words words
297
assert_equal expected, @to.end_accepting
300
def test_accept_paragraph_plus
302
@to.accept_paragraph @RM::Paragraph.new('regular +teletype+ regular')
304
expected = "regular <tt>teletype</tt> regular\n"
306
assert_equal expected, @to.end_accepting
309
def test_accept_paragraph_star
311
@to.accept_paragraph @RM::Paragraph.new('regular *bold* regular')
313
expected = "regular <b>bold</b> regular\n"
315
assert_equal expected, @to.end_accepting
318
def test_accept_paragraph_underscore
320
@to.accept_paragraph @RM::Paragraph.new('regular _italic_ regular')
322
expected = "regular <em>italic</em> regular\n"
324
assert_equal expected, @to.end_accepting
327
def test_accept_paragraph_wrap
329
@to.accept_paragraph @RM::Paragraph.new('words ' * 30)
331
expected = <<-EXPECTED
332
words words words words words words words words words words words words words
333
words words words words words words words words words words words words words
334
words words words words
337
assert_equal expected, @to.end_accepting
340
def test_accept_rule_indent
344
@to.accept_rule @RM::Rule.new(1)
346
assert_equal " #{'-' * 75}\n", @to.end_accepting
349
def test_accept_verbatim_indent
354
@to.accept_verbatim @RM::Verbatim.new(' ', 'hi', "\n",
357
assert_equal " hi\n world\n\n", @to.end_accepting
360
def test_accept_verbatim_big_indent
365
@to.accept_verbatim @RM::Verbatim.new(' ', 'hi', "\n",
368
assert_equal " hi\n world\n\n", @to.end_accepting
372
assert_equal 'Dog', @to.attributes("\\Dog")
376
doc = @RM::Document.new(
377
@RM::List.new(:BULLET,
378
@RM::ListItem.new(nil,
379
@RM::Paragraph.new('l1'),
380
@RM::List.new(:BULLET,
381
@RM::ListItem.new(nil,
382
@RM::Paragraph.new('l1.1')))),
383
@RM::ListItem.new(nil,
384
@RM::Paragraph.new('l2'))))
386
output = doc.accept @to
388
expected = <<-EXPECTED
394
assert_equal expected, output
397
def test_list_verbatim # HACK overblown
398
doc = @RM::Document.new(
399
@RM::List.new(:BULLET,
400
@RM::ListItem.new(nil,
401
@RM::Paragraph.new('list', 'stuff'),
402
@RM::BlankLine.new(),
403
@RM::Verbatim.new(' ', '*', ' ', 'list', "\n",
408
' ', '1.', ' ', 'indented', "\n",
409
' ', '2.', ' ', 'numbered', "\n",
413
' ', '*', ' ', 'second', "\n"))))
415
output = doc.accept @to
417
expected = <<-EXPECTED
434
assert_equal expected, output