1require 'rdoc/test_case'
2
3class TestRDocMarkupToAnsi < RDoc::Markup::TextFormatterTestCase
4
5  add_visitor_tests
6  add_text_tests
7
8  def setup
9    super
10
11    @to = RDoc::Markup::ToAnsi.new
12  end
13
14  def accept_blank_line
15    assert_equal "\e[0m\n", @to.res.join
16  end
17
18  def accept_block_quote
19    assert_equal "\e[0m> quote\n", @to.res.join
20  end
21
22  def accept_document
23    assert_equal "\e[0mhello\n", @to.res.join
24  end
25
26  def accept_heading
27    assert_equal "\e[0mHello\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 "\e[0mcat:\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 'b', @to.list_index.last
78  end
79
80  def accept_list_item_end_note
81    assert_equal "\e[0mcat:\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 'B', @to.list_index.last
93  end
94
95  def accept_list_item_start_bullet
96    assert_equal %W"\e[0m", @to.res
97    assert_equal '* ', @to.prefix
98  end
99
100  def accept_list_item_start_label
101    assert_equal %W"\e[0m", @to.res
102    assert_equal "cat:\n  ", @to.prefix
103
104    assert_equal 2, @to.indent
105  end
106
107  def accept_list_item_start_lalpha
108    assert_equal %W"\e[0m", @to.res
109    assert_equal 'a. ', @to.prefix
110
111    assert_equal 'a', @to.list_index.last
112    assert_equal 3, @to.indent
113  end
114
115  def accept_list_item_start_note
116    assert_equal %W"\e[0m", @to.res
117    assert_equal "cat:\n  ", @to.prefix
118
119    assert_equal 2, @to.indent
120  end
121
122  def accept_list_item_start_number
123    assert_equal %W"\e[0m", @to.res
124    assert_equal '1. ', @to.prefix
125
126    assert_equal 1, @to.list_index.last
127    assert_equal 3, @to.indent
128  end
129
130  def accept_list_item_start_ualpha
131    assert_equal %W"\e[0m", @to.res
132    assert_equal 'A. ', @to.prefix
133
134    assert_equal 'A', @to.list_index.last
135    assert_equal 3, @to.indent
136  end
137
138  def accept_list_start_bullet
139    assert_equal "\e[0m",   @to.res.join
140    assert_equal [nil],     @to.list_index
141    assert_equal [:BULLET], @to.list_type
142    assert_equal [1],       @to.list_width
143  end
144
145  def accept_list_start_label
146    assert_equal "\e[0m",  @to.res.join
147    assert_equal [nil],    @to.list_index
148    assert_equal [:LABEL], @to.list_type
149    assert_equal [2],      @to.list_width
150  end
151
152  def accept_list_start_lalpha
153    assert_equal "\e[0m",   @to.res.join
154    assert_equal ['a'],     @to.list_index
155    assert_equal [:LALPHA], @to.list_type
156    assert_equal [1],       @to.list_width
157  end
158
159  def accept_list_start_note
160    assert_equal "\e[0m", @to.res.join
161    assert_equal [nil],   @to.list_index
162    assert_equal [:NOTE], @to.list_type
163    assert_equal [2],     @to.list_width
164  end
165
166  def accept_list_start_number
167    assert_equal "\e[0m",   @to.res.join
168    assert_equal [1],       @to.list_index
169    assert_equal [:NUMBER], @to.list_type
170    assert_equal [1],       @to.list_width
171  end
172
173  def accept_list_start_ualpha
174    assert_equal "\e[0m",   @to.res.join
175    assert_equal ['A'],     @to.list_index
176    assert_equal [:UALPHA], @to.list_type
177    assert_equal [1],       @to.list_width
178  end
179
180  def accept_paragraph
181    assert_equal "\e[0mhi\n", @to.res.join
182  end
183
184  def accept_raw
185    raw = <<-RAW.rstrip
186\e[0m<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 "\e[0m#{'-' * 78}\n", @to.res.join
198  end
199
200  def accept_verbatim
201    assert_equal "\e[0m  hi\n    world\n\n", @to.res.join
202  end
203
204  def end_accepting
205    assert_equal "\e[0mhi", @to.end_accepting
206  end
207
208  def start_accepting
209    assert_equal 0, @to.indent
210    assert_equal %W"\e[0m", @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 "\e[0m\e[1;32mHello\e[m\n", @to.end_accepting
218  end
219
220  def accept_heading_2
221    assert_equal "\e[0m\e[4;32mHello\e[m\n", @to.end_accepting
222  end
223
224  def accept_heading_3
225    assert_equal "\e[0m\e[32mHello\e[m\n", @to.end_accepting
226  end
227
228  def accept_heading_4
229    assert_equal "\e[0mHello\n", @to.end_accepting
230  end
231
232  def accept_heading_indent
233    assert_equal "\e[0m   \e[1;32mHello\e[m\n", @to.end_accepting
234  end
235
236  def accept_heading_b
237    assert_equal "\e[0m\e[1;32m\e[1mHello\e[m\e[m\n", @to.end_accepting
238  end
239
240  def accept_heading_suppressed_crossref
241    assert_equal "\e[0m\e[1;32mHello\e[m\n", @to.end_accepting
242  end
243
244  def accept_list_item_start_note_2
245    assert_equal "\e[0m\e[7mteletype\e[m:\n  teletype description\n\n",
246                 @to.res.join
247  end
248
249  def accept_list_item_start_note_multi_description
250    assert_equal "\e[0mlabel:\n  description one\n\n  description two\n\n",
251                 @to.res.join
252  end
253
254  def accept_list_item_start_note_multi_label
255    assert_equal "\e[0mone\ntwo:\n  two headers\n\n",
256                 @to.res.join
257  end
258
259  def accept_paragraph_b
260    assert_equal "\e[0mreg \e[1mbold words\e[m reg\n", @to.end_accepting
261  end
262
263  def accept_paragraph_br
264    assert_equal "\e[0mone\ntwo\n", @to.end_accepting
265  end
266
267  def accept_paragraph_break
268    assert_equal "\e[0mhello\nworld\n", @to.end_accepting
269  end
270
271  def accept_paragraph_i
272    assert_equal "\e[0mreg \e[4mitalic words\e[m reg\n", @to.end_accepting
273  end
274
275  def accept_paragraph_indent
276    expected = <<-EXPECTED
277\e[0m   words words words words words words words words words words words words
278   words words words words words words words words words words words words
279   words words words words words words
280    EXPECTED
281
282    assert_equal expected, @to.end_accepting
283  end
284
285  def accept_paragraph_plus
286    assert_equal "\e[0mreg \e[7mteletype\e[m reg\n", @to.end_accepting
287  end
288
289  def accept_paragraph_star
290    assert_equal "\e[0mreg \e[1mbold\e[m reg\n", @to.end_accepting
291  end
292
293  def accept_paragraph_underscore
294    assert_equal "\e[0mreg \e[4mitalic\e[m reg\n", @to.end_accepting
295  end
296
297  def accept_paragraph_wrap
298    expected = <<-EXPECTED
299\e[0mwords words words words words words words words words words words words words
300words words words words words words words words words words words words words
301words words words words
302    EXPECTED
303
304    assert_equal expected, @to.end_accepting
305  end
306
307  def accept_rule_indent
308    assert_equal "\e[0m   #{'-' * 75}\n", @to.end_accepting
309  end
310
311  def accept_verbatim_indent
312    assert_equal "\e[0m    hi\n     world\n\n", @to.end_accepting
313  end
314
315  def accept_verbatim_big_indent
316    assert_equal "\e[0m    hi\n    world\n\n", @to.end_accepting
317  end
318
319  def list_nested
320    expected = <<-EXPECTED
321\e[0m* l1
322  * l1.1
323* l2
324    EXPECTED
325
326    assert_equal expected, @to.end_accepting
327  end
328
329  def list_verbatim
330    expected = <<-EXPECTED # HACK overblown
331\e[0m* 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    EXPECTED
346
347    assert_equal expected, @to.end_accepting
348  end
349
350  # functional test
351  def test_convert_list_note
352    note_list = <<-NOTE_LIST
353foo ::
354bar ::
355  hi
356    NOTE_LIST
357
358    expected = <<-EXPECTED
359\e[0mfoo
360bar:
361  hi
362
363    EXPECTED
364
365    assert_equal expected, @to.convert(note_list)
366  end
367
368end
369
370