1require 'rdoc/test_case'
2
3class TestRDocMarkupToMarkdown < RDoc::Markup::TextFormatterTestCase
4
5  add_visitor_tests
6  add_text_tests
7
8  def setup
9    super
10
11    @to = RDoc::Markup::ToMarkdown.new
12  end
13
14  def accept_blank_line
15    assert_equal "\n", @to.res.join
16  end
17
18  def accept_block_quote
19    assert_equal "> quote\n", @to.res.join
20  end
21
22  def accept_document
23    assert_equal "hello\n", @to.res.join
24  end
25
26  def accept_heading
27    assert_equal "##### Hello\n", @to.res.join
28  end
29
30  def accept_list_end_bullet
31    assert_empty @to.list_index
32    assert_empty @to.list_type
33    assert_empty @to.list_width
34  end
35
36  def accept_list_end_label
37    assert_empty @to.list_index
38    assert_empty @to.list_type
39    assert_empty @to.list_width
40  end
41
42  def accept_list_end_lalpha
43    assert_empty @to.list_index
44    assert_empty @to.list_type
45    assert_empty @to.list_width
46  end
47
48  def accept_list_end_note
49    assert_empty @to.list_index
50    assert_empty @to.list_type
51    assert_empty @to.list_width
52  end
53
54  def accept_list_end_number
55    assert_empty @to.list_index
56    assert_empty @to.list_type
57    assert_empty @to.list_width
58  end
59
60  def accept_list_end_ualpha
61    assert_empty @to.list_index
62    assert_empty @to.list_type
63    assert_empty @to.list_width
64  end
65
66  def accept_list_item_end_bullet
67    assert_equal 0, @to.indent, 'indent'
68  end
69
70  def accept_list_item_end_label
71    assert_equal "cat\n:   ", @to.res.join
72    assert_equal 0, @to.indent, 'indent'
73  end
74
75  def accept_list_item_end_lalpha
76    assert_equal 0, @to.indent, 'indent'
77    assert_equal 2, @to.list_index.last
78  end
79
80  def accept_list_item_end_note
81    assert_equal "cat\n:   ", @to.res.join
82    assert_equal 0, @to.indent, 'indent'
83  end
84
85  def accept_list_item_end_number
86    assert_equal 0, @to.indent, 'indent'
87    assert_equal 2, @to.list_index.last
88  end
89
90  def accept_list_item_end_ualpha
91    assert_equal 0, @to.indent, 'indent'
92    assert_equal 2, @to.list_index.last
93  end
94
95  def accept_list_item_start_bullet
96    assert_equal [""], @to.res
97    assert_equal '*   ', @to.prefix
98  end
99
100  def accept_list_item_start_label
101    assert_equal [""], @to.res
102    assert_equal "cat\n:   ", @to.prefix
103
104    assert_equal 4, @to.indent
105  end
106
107  def accept_list_item_start_lalpha
108    assert_equal [""], @to.res
109    assert_equal '1.  ', @to.prefix
110
111    assert_equal 1, @to.list_index.last
112    assert_equal 4, @to.indent
113  end
114
115  def accept_list_item_start_note
116    assert_equal [""], @to.res
117    assert_equal "cat\n:   ", @to.prefix
118
119    assert_equal 4, @to.indent
120  end
121
122  def accept_list_item_start_number
123    assert_equal [""], @to.res
124    assert_equal '1.  ', @to.prefix
125
126    assert_equal 1, @to.list_index.last
127    assert_equal 4, @to.indent
128  end
129
130  def accept_list_item_start_ualpha
131    assert_equal [""], @to.res
132    assert_equal '1.  ', @to.prefix
133
134    assert_equal 1, @to.list_index.last
135    assert_equal 4, @to.indent
136  end
137
138  def accept_list_start_bullet
139    assert_equal "",   @to.res.join
140    assert_equal [nil],     @to.list_index
141    assert_equal [:BULLET], @to.list_type
142    assert_equal [4],       @to.list_width
143  end
144
145  def accept_list_start_label
146    assert_equal "",  @to.res.join
147    assert_equal [nil],    @to.list_index
148    assert_equal [:LABEL], @to.list_type
149    assert_equal [4],      @to.list_width
150  end
151
152  def accept_list_start_lalpha
153    assert_equal "",   @to.res.join
154    assert_equal [1],     @to.list_index
155    assert_equal [:LALPHA], @to.list_type
156    assert_equal [4],       @to.list_width
157  end
158
159  def accept_list_start_note
160    assert_equal "", @to.res.join
161    assert_equal [nil],   @to.list_index
162    assert_equal [:NOTE], @to.list_type
163    assert_equal [4],     @to.list_width
164  end
165
166  def accept_list_start_number
167    assert_equal "",   @to.res.join
168    assert_equal [1],       @to.list_index
169    assert_equal [:NUMBER], @to.list_type
170    assert_equal [4],       @to.list_width
171  end
172
173  def accept_list_start_ualpha
174    assert_equal "",   @to.res.join
175    assert_equal [1],     @to.list_index
176    assert_equal [:UALPHA], @to.list_type
177    assert_equal [4],       @to.list_width
178  end
179
180  def accept_paragraph
181    assert_equal "hi\n", @to.res.join
182  end
183
184  def accept_raw
185    raw = <<-RAW.rstrip
186<table>
187<tr><th>Name<th>Count
188<tr><td>a<td>1
189<tr><td>b<td>2
190</table>
191    RAW
192
193    assert_equal raw, @to.res.join
194  end
195
196  def accept_rule
197    assert_equal "---\n", @to.res.join
198  end
199
200  def accept_verbatim
201    assert_equal "    hi\n      world\n\n", @to.res.join
202  end
203
204  def end_accepting
205    assert_equal "hi", @to.end_accepting
206  end
207
208  def start_accepting
209    assert_equal 0, @to.indent
210    assert_equal [""], @to.res
211    assert_empty @to.list_index
212    assert_empty @to.list_type
213    assert_empty @to.list_width
214  end
215
216  def accept_heading_1
217    assert_equal "# Hello\n", @to.end_accepting
218  end
219
220  def accept_heading_2
221    assert_equal "## Hello\n", @to.end_accepting
222  end
223
224  def accept_heading_3
225    assert_equal "### Hello\n", @to.end_accepting
226  end
227
228  def accept_heading_4
229    assert_equal "#### Hello\n", @to.end_accepting
230  end
231
232  def accept_heading_indent
233    assert_equal "   # Hello\n", @to.end_accepting
234  end
235
236  def accept_heading_b
237    assert_equal "# **Hello**\n", @to.end_accepting
238  end
239
240  def accept_heading_suppressed_crossref
241    assert_equal "# Hello\n", @to.end_accepting
242  end
243
244  def accept_list_item_start_note_2
245    assert_equal "`teletype`\n:   teletype description\n\n", @to.res.join
246  end
247
248  def accept_list_item_start_note_multi_description
249    assert_equal "label\n:   description one\n\n:   description two\n\n",
250                 @to.res.join
251  end
252
253  def accept_list_item_start_note_multi_label
254    assert_equal "one\ntwo\n:   two headers\n\n", @to.res.join
255  end
256
257  def accept_paragraph_b
258    assert_equal "reg **bold words** reg\n", @to.end_accepting
259  end
260
261  def accept_paragraph_br
262    assert_equal "one  \ntwo\n", @to.end_accepting
263  end
264
265  def accept_paragraph_break
266    assert_equal "hello  \nworld\n", @to.end_accepting
267  end
268
269  def accept_paragraph_i
270    assert_equal "reg *italic words* reg\n", @to.end_accepting
271  end
272
273  def accept_paragraph_indent
274    expected = <<-EXPECTED
275   words words words words words words words words words words words words
276   words words words words words words words words words words words words
277   words words words words words words
278    EXPECTED
279
280    assert_equal expected, @to.end_accepting
281  end
282
283  def accept_paragraph_plus
284    assert_equal "reg `teletype` reg\n", @to.end_accepting
285  end
286
287  def accept_paragraph_star
288    assert_equal "reg **bold** reg\n", @to.end_accepting
289  end
290
291  def accept_paragraph_underscore
292    assert_equal "reg *italic* reg\n", @to.end_accepting
293  end
294
295  def accept_paragraph_wrap
296    expected = <<-EXPECTED
297words words words words words words words words words words words words words
298words words words words words words words words words words words words words
299words words words words
300    EXPECTED
301
302    assert_equal expected, @to.end_accepting
303  end
304
305  def accept_rule_indent
306    assert_equal "   ---\n", @to.end_accepting
307  end
308
309  def accept_verbatim_indent
310    assert_equal "      hi\n       world\n\n", @to.end_accepting
311  end
312
313  def accept_verbatim_big_indent
314    assert_equal "      hi\n      world\n\n", @to.end_accepting
315  end
316
317  def list_nested
318    expected = <<-EXPECTED
319*   l1
320    *   l1.1
321
322*   l2
323
324    EXPECTED
325
326    assert_equal expected, @to.end_accepting
327  end
328
329  def list_verbatim
330    expected = <<-EXPECTED # HACK overblown
331*   list stuff
332
333        * list
334          with
335
336          second
337
338          1. indented
339          2. numbered
340
341          third
342
343        * second
344
345
346    EXPECTED
347
348    assert_equal expected, @to.end_accepting
349  end
350
351  def test_convert_RDOCLINK
352    result = @to.convert 'rdoc-garbage:C'
353
354    assert_equal "C\n", result
355  end
356
357  def test_convert_TIDYLINK
358    result = @to.convert \
359      '{DSL}[http://en.wikipedia.org/wiki/Domain-specific_language]'
360
361    expected = "[DSL](http://en.wikipedia.org/wiki/Domain-specific_language)\n"
362
363    assert_equal expected, result
364  end
365
366  def test_handle_rdoc_link_label_footmark
367    assert_equal '[^1]:', @to.handle_rdoc_link('rdoc-label:footmark-1:x')
368  end
369
370  def test_handle_rdoc_link_label_foottext
371    assert_equal '[^1]',   @to.handle_rdoc_link('rdoc-label:foottext-1:x')
372  end
373
374  def test_handle_rdoc_link_label_label
375    assert_equal '[x](#label-x)', @to.handle_rdoc_link('rdoc-label:label-x')
376  end
377
378  def test_handle_rdoc_link_ref
379    assert_equal 'x', @to.handle_rdoc_link('rdoc-ref:x')
380  end
381
382end
383
384