rdoc 6.1.2.1 → 6.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rdoc might be problematic. Click here for more details.

@@ -1,764 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'minitest/unit'
3
-
4
- ##
5
- # Test case for creating new RDoc::Markup formatters. See
6
- # test/test_rdoc_markup_to_*.rb for examples.
7
- #
8
- # This test case adds a variety of tests to your subclass when
9
- # #add_visitor_tests is called. Most tests set up a scenario then call a
10
- # method you will provide to perform the assertion on the output.
11
- #
12
- # Your subclass must instantiate a visitor and assign it to <tt>@to</tt>.
13
- #
14
- # For example, test_accept_blank_line sets up a RDoc::Markup::BlockLine then
15
- # calls accept_blank_line on your visitor. You are responsible for asserting
16
- # that the output is correct.
17
- #
18
- # Example:
19
- #
20
- # class TestRDocMarkupToNewFormat < RDoc::Markup::FormatterTestCase
21
- #
22
- # add_visitor_tests
23
- #
24
- # def setup
25
- # super
26
- #
27
- # @to = RDoc::Markup::ToNewFormat.new
28
- # end
29
- #
30
- # def accept_blank_line
31
- # assert_equal :junk, @to.res.join
32
- # end
33
- #
34
- # # ...
35
- #
36
- # end
37
-
38
- class RDoc::Markup::FormatterTestCase < RDoc::TestCase
39
-
40
- ##
41
- # Call #setup when inheriting from this test case.
42
- #
43
- # Provides the following instance variables:
44
- #
45
- # +@m+:: RDoc::Markup.new
46
- # +@RM+:: RDoc::Markup # to reduce typing
47
- # +@bullet_list+:: @RM::List.new :BULLET, # ...
48
- # +@label_list+:: @RM::List.new :LABEL, # ...
49
- # +@lalpha_list+:: @RM::List.new :LALPHA, # ...
50
- # +@note_list+:: @RM::List.new :NOTE, # ...
51
- # +@number_list+:: @RM::List.new :NUMBER, # ...
52
- # +@ualpha_list+:: @RM::List.new :UALPHA, # ...
53
-
54
- def setup
55
- super
56
-
57
- @options = RDoc::Options.new
58
-
59
- @m = @RM.new
60
-
61
- @bullet_list = @RM::List.new(:BULLET,
62
- @RM::ListItem.new(nil, @RM::Paragraph.new('l1')),
63
- @RM::ListItem.new(nil, @RM::Paragraph.new('l2')))
64
-
65
- @label_list = @RM::List.new(:LABEL,
66
- @RM::ListItem.new('cat', @RM::Paragraph.new('cats are cool')),
67
- @RM::ListItem.new('dog', @RM::Paragraph.new('dogs are cool too')))
68
-
69
- @lalpha_list = @RM::List.new(:LALPHA,
70
- @RM::ListItem.new(nil, @RM::Paragraph.new('l1')),
71
- @RM::ListItem.new(nil, @RM::Paragraph.new('l2')))
72
-
73
- @note_list = @RM::List.new(:NOTE,
74
- @RM::ListItem.new('cat', @RM::Paragraph.new('cats are cool')),
75
- @RM::ListItem.new('dog', @RM::Paragraph.new('dogs are cool too')))
76
-
77
- @number_list = @RM::List.new(:NUMBER,
78
- @RM::ListItem.new(nil, @RM::Paragraph.new('l1')),
79
- @RM::ListItem.new(nil, @RM::Paragraph.new('l2')))
80
-
81
- @ualpha_list = @RM::List.new(:UALPHA,
82
- @RM::ListItem.new(nil, @RM::Paragraph.new('l1')),
83
- @RM::ListItem.new(nil, @RM::Paragraph.new('l2')))
84
- end
85
-
86
- ##
87
- # Call to add the visitor tests to your test case
88
-
89
- def self.add_visitor_tests
90
- class_eval do
91
-
92
- ##
93
- # Calls start_accepting which needs to verify startup state
94
-
95
- def test_start_accepting
96
- @to.start_accepting
97
-
98
- start_accepting
99
- end
100
-
101
- ##
102
- # Calls end_accepting on your test case which needs to call
103
- # <tt>@to.end_accepting</tt> and verify document generation
104
-
105
- def test_end_accepting
106
- @to.start_accepting
107
- @to.res << 'hi'
108
-
109
- end_accepting
110
- end
111
-
112
- ##
113
- # Calls accept_blank_line
114
-
115
- def test_accept_blank_line
116
- @to.start_accepting
117
-
118
- @to.accept_blank_line @RM::BlankLine.new
119
-
120
- accept_blank_line
121
- end
122
-
123
- ##
124
- # Calls accept_block_quote
125
-
126
- def test_accept_block_quote
127
- @to.start_accepting
128
-
129
- @to.accept_block_quote block para 'quote'
130
-
131
- accept_block_quote
132
- end
133
- ##
134
- # Test case that calls <tt>@to.accept_document</tt>
135
-
136
- def test_accept_document
137
- @to.start_accepting
138
- @to.accept_document @RM::Document.new @RM::Paragraph.new 'hello'
139
-
140
- accept_document
141
- end
142
-
143
- ##
144
- # Calls accept_heading with a level 5 RDoc::Markup::Heading
145
-
146
- def test_accept_heading
147
- @to.start_accepting
148
-
149
- @to.accept_heading @RM::Heading.new(5, 'Hello')
150
-
151
- accept_heading
152
- end
153
-
154
- ##
155
- # Calls accept_heading_1 with a level 1 RDoc::Markup::Heading
156
-
157
- def test_accept_heading_1
158
- @to.start_accepting
159
-
160
- @to.accept_heading @RM::Heading.new(1, 'Hello')
161
-
162
- accept_heading_1
163
- end
164
-
165
- ##
166
- # Calls accept_heading_2 with a level 2 RDoc::Markup::Heading
167
-
168
- def test_accept_heading_2
169
- @to.start_accepting
170
-
171
- @to.accept_heading @RM::Heading.new(2, 'Hello')
172
-
173
- accept_heading_2
174
- end
175
-
176
- ##
177
- # Calls accept_heading_3 with a level 3 RDoc::Markup::Heading
178
-
179
- def test_accept_heading_3
180
- @to.start_accepting
181
-
182
- @to.accept_heading @RM::Heading.new(3, 'Hello')
183
-
184
- accept_heading_3
185
- end
186
-
187
- ##
188
- # Calls accept_heading_4 with a level 4 RDoc::Markup::Heading
189
-
190
- def test_accept_heading_4
191
- @to.start_accepting
192
-
193
- @to.accept_heading @RM::Heading.new(4, 'Hello')
194
-
195
- accept_heading_4
196
- end
197
-
198
- ##
199
- # Calls accept_heading_b with a bold level 1 RDoc::Markup::Heading
200
-
201
- def test_accept_heading_b
202
- @to.start_accepting
203
-
204
- @to.accept_heading @RM::Heading.new(1, '*Hello*')
205
-
206
- accept_heading_b
207
- end
208
-
209
- ##
210
- # Calls accept_heading_suppressed_crossref with a level 1
211
- # RDoc::Markup::Heading containing a suppressed crossref
212
-
213
- def test_accept_heading_suppressed_crossref # HACK to_html_crossref test
214
- @to.start_accepting
215
-
216
- @to.accept_heading @RM::Heading.new(1, '\\Hello')
217
-
218
- accept_heading_suppressed_crossref
219
- end
220
-
221
- ##
222
- # Calls accept_paragraph
223
-
224
- def test_accept_paragraph
225
- @to.start_accepting
226
-
227
- @to.accept_paragraph @RM::Paragraph.new('hi')
228
-
229
- accept_paragraph
230
- end
231
-
232
- ##
233
- # Calls accept_paragraph_b with a RDoc::Markup::Paragraph containing
234
- # bold words
235
-
236
- def test_accept_paragraph_b
237
- @to.start_accepting
238
-
239
- @to.accept_paragraph @RM::Paragraph.new('reg <b>bold words</b> reg')
240
-
241
- accept_paragraph_b
242
- end
243
-
244
- ##
245
- # Calls accept_paragraph_br with a RDoc::Markup::Paragraph containing
246
- # a \<br>
247
-
248
- def test_accept_paragraph_br
249
- @to.start_accepting
250
-
251
- @to.accept_paragraph para 'one<br>two'
252
-
253
- accept_paragraph_br
254
- end
255
-
256
- ##
257
- # Calls accept_paragraph with a Paragraph containing a hard break
258
-
259
- def test_accept_paragraph_break
260
- @to.start_accepting
261
-
262
- @to.accept_paragraph para('hello', hard_break, 'world')
263
-
264
- accept_paragraph_break
265
- end
266
-
267
- ##
268
- # Calls accept_paragraph_i with a RDoc::Markup::Paragraph containing
269
- # emphasized words
270
-
271
- def test_accept_paragraph_i
272
- @to.start_accepting
273
-
274
- @to.accept_paragraph @RM::Paragraph.new('reg <em>italic words</em> reg')
275
-
276
- accept_paragraph_i
277
- end
278
-
279
- ##
280
- # Calls accept_paragraph_plus with a RDoc::Markup::Paragraph containing
281
- # teletype words
282
-
283
- def test_accept_paragraph_plus
284
- @to.start_accepting
285
-
286
- @to.accept_paragraph @RM::Paragraph.new('reg +teletype+ reg')
287
-
288
- accept_paragraph_plus
289
- end
290
-
291
- ##
292
- # Calls accept_paragraph_star with a RDoc::Markup::Paragraph containing
293
- # bold words
294
-
295
- def test_accept_paragraph_star
296
- @to.start_accepting
297
-
298
- @to.accept_paragraph @RM::Paragraph.new('reg *bold* reg')
299
-
300
- accept_paragraph_star
301
- end
302
-
303
- ##
304
- # Calls accept_paragraph_underscore with a RDoc::Markup::Paragraph
305
- # containing emphasized words
306
-
307
- def test_accept_paragraph_underscore
308
- @to.start_accepting
309
-
310
- @to.accept_paragraph @RM::Paragraph.new('reg _italic_ reg')
311
-
312
- accept_paragraph_underscore
313
- end
314
-
315
- ##
316
- # Calls accept_verbatim with a RDoc::Markup::Verbatim
317
-
318
- def test_accept_verbatim
319
- @to.start_accepting
320
-
321
- @to.accept_verbatim @RM::Verbatim.new("hi\n", " world\n")
322
-
323
- accept_verbatim
324
- end
325
-
326
- ##
327
- # Calls accept_raw with a RDoc::Markup::Raw
328
-
329
- def test_accept_raw
330
- @to.start_accepting
331
-
332
- @to.accept_raw @RM::Raw.new("<table>",
333
- "<tr><th>Name<th>Count",
334
- "<tr><td>a<td>1",
335
- "<tr><td>b<td>2",
336
- "</table>")
337
-
338
- accept_raw
339
- end
340
-
341
- ##
342
- # Calls accept_rule with a RDoc::Markup::Rule
343
-
344
- def test_accept_rule
345
- @to.start_accepting
346
-
347
- @to.accept_rule @RM::Rule.new(4)
348
-
349
- accept_rule
350
- end
351
-
352
- ##
353
- # Calls accept_list_item_start_bullet
354
-
355
- def test_accept_list_item_start_bullet
356
- @to.start_accepting
357
-
358
- @to.accept_list_start @bullet_list
359
-
360
- @to.accept_list_item_start @bullet_list.items.first
361
-
362
- accept_list_item_start_bullet
363
- end
364
-
365
- ##
366
- # Calls accept_list_item_start_label
367
-
368
- def test_accept_list_item_start_label
369
- @to.start_accepting
370
-
371
- @to.accept_list_start @label_list
372
-
373
- @to.accept_list_item_start @label_list.items.first
374
-
375
- accept_list_item_start_label
376
- end
377
-
378
- ##
379
- # Calls accept_list_item_start_lalpha
380
-
381
- def test_accept_list_item_start_lalpha
382
- @to.start_accepting
383
-
384
- @to.accept_list_start @lalpha_list
385
-
386
- @to.accept_list_item_start @lalpha_list.items.first
387
-
388
- accept_list_item_start_lalpha
389
- end
390
-
391
- ##
392
- # Calls accept_list_item_start_note
393
-
394
- def test_accept_list_item_start_note
395
- @to.start_accepting
396
-
397
- @to.accept_list_start @note_list
398
-
399
- @to.accept_list_item_start @note_list.items.first
400
-
401
- accept_list_item_start_note
402
- end
403
-
404
- ##
405
- # Calls accept_list_item_start_note_2
406
-
407
- def test_accept_list_item_start_note_2
408
- list = list(:NOTE,
409
- item('<tt>teletype</tt>',
410
- para('teletype description')))
411
-
412
- @to.start_accepting
413
-
414
- list.accept @to
415
-
416
- @to.end_accepting
417
-
418
- accept_list_item_start_note_2
419
- end
420
-
421
- ##
422
- # Calls accept_list_item_start_note_multi_description
423
-
424
- def test_accept_list_item_start_note_multi_description
425
- list = list(:NOTE,
426
- item(%w[label],
427
- para('description one')),
428
- item(nil, para('description two')))
429
-
430
- @to.start_accepting
431
-
432
- list.accept @to
433
-
434
- @to.end_accepting
435
-
436
- accept_list_item_start_note_multi_description
437
- end
438
-
439
- ##
440
- # Calls accept_list_item_start_note_multi_label
441
-
442
- def test_accept_list_item_start_note_multi_label
443
- list = list(:NOTE,
444
- item(%w[one two],
445
- para('two headers')))
446
-
447
- @to.start_accepting
448
-
449
- list.accept @to
450
-
451
- @to.end_accepting
452
-
453
- accept_list_item_start_note_multi_label
454
- end
455
-
456
- ##
457
- # Calls accept_list_item_start_number
458
-
459
- def test_accept_list_item_start_number
460
- @to.start_accepting
461
-
462
- @to.accept_list_start @number_list
463
-
464
- @to.accept_list_item_start @number_list.items.first
465
-
466
- accept_list_item_start_number
467
- end
468
-
469
- ##
470
- # Calls accept_list_item_start_ualpha
471
-
472
- def test_accept_list_item_start_ualpha
473
- @to.start_accepting
474
-
475
- @to.accept_list_start @ualpha_list
476
-
477
- @to.accept_list_item_start @ualpha_list.items.first
478
-
479
- accept_list_item_start_ualpha
480
- end
481
-
482
- ##
483
- # Calls accept_list_item_end_bullet
484
-
485
- def test_accept_list_item_end_bullet
486
- @to.start_accepting
487
-
488
- @to.accept_list_start @bullet_list
489
-
490
- @to.accept_list_item_start @bullet_list.items.first
491
-
492
- @to.accept_list_item_end @bullet_list.items.first
493
-
494
- accept_list_item_end_bullet
495
- end
496
-
497
- ##
498
- # Calls accept_list_item_end_label
499
-
500
- def test_accept_list_item_end_label
501
- @to.start_accepting
502
-
503
- @to.accept_list_start @label_list
504
-
505
- @to.accept_list_item_start @label_list.items.first
506
-
507
- @to.accept_list_item_end @label_list.items.first
508
-
509
- accept_list_item_end_label
510
- end
511
-
512
- ##
513
- # Calls accept_list_item_end_lalpha
514
-
515
- def test_accept_list_item_end_lalpha
516
- @to.start_accepting
517
-
518
- @to.accept_list_start @lalpha_list
519
-
520
- @to.accept_list_item_start @lalpha_list.items.first
521
-
522
- @to.accept_list_item_end @lalpha_list.items.first
523
-
524
- accept_list_item_end_lalpha
525
- end
526
-
527
- ##
528
- # Calls accept_list_item_end_note
529
-
530
- def test_accept_list_item_end_note
531
- @to.start_accepting
532
-
533
- @to.accept_list_start @note_list
534
-
535
- @to.accept_list_item_start @note_list.items.first
536
-
537
- @to.accept_list_item_end @note_list.items.first
538
-
539
- accept_list_item_end_note
540
- end
541
-
542
- ##
543
- # Calls accept_list_item_end_number
544
-
545
- def test_accept_list_item_end_number
546
- @to.start_accepting
547
-
548
- @to.accept_list_start @number_list
549
-
550
- @to.accept_list_item_start @number_list.items.first
551
-
552
- @to.accept_list_item_end @number_list.items.first
553
-
554
- accept_list_item_end_number
555
- end
556
-
557
- ##
558
- # Calls accept_list_item_end_ualpha
559
-
560
- def test_accept_list_item_end_ualpha
561
- @to.start_accepting
562
-
563
- @to.accept_list_start @ualpha_list
564
-
565
- @to.accept_list_item_start @ualpha_list.items.first
566
-
567
- @to.accept_list_item_end @ualpha_list.items.first
568
-
569
- accept_list_item_end_ualpha
570
- end
571
-
572
- ##
573
- # Calls accept_list_start_bullet
574
-
575
- def test_accept_list_start_bullet
576
- @to.start_accepting
577
-
578
- @to.accept_list_start @bullet_list
579
-
580
- accept_list_start_bullet
581
- end
582
-
583
- ##
584
- # Calls accept_list_start_label
585
-
586
- def test_accept_list_start_label
587
- @to.start_accepting
588
-
589
- @to.accept_list_start @label_list
590
-
591
- accept_list_start_label
592
- end
593
-
594
- ##
595
- # Calls accept_list_start_lalpha
596
-
597
- def test_accept_list_start_lalpha
598
- @to.start_accepting
599
-
600
- @to.accept_list_start @lalpha_list
601
-
602
- accept_list_start_lalpha
603
- end
604
-
605
- ##
606
- # Calls accept_list_start_note
607
-
608
- def test_accept_list_start_note
609
- @to.start_accepting
610
-
611
- @to.accept_list_start @note_list
612
-
613
- accept_list_start_note
614
- end
615
-
616
- ##
617
- # Calls accept_list_start_number
618
-
619
- def test_accept_list_start_number
620
- @to.start_accepting
621
-
622
- @to.accept_list_start @number_list
623
-
624
- accept_list_start_number
625
- end
626
-
627
- ##
628
- # Calls accept_list_start_ualpha
629
-
630
- def test_accept_list_start_ualpha
631
- @to.start_accepting
632
-
633
- @to.accept_list_start @ualpha_list
634
-
635
- accept_list_start_ualpha
636
- end
637
-
638
- ##
639
- # Calls accept_list_end_bullet
640
-
641
- def test_accept_list_end_bullet
642
- @to.start_accepting
643
-
644
- @to.accept_list_start @bullet_list
645
-
646
- @to.accept_list_end @bullet_list
647
-
648
- accept_list_end_bullet
649
- end
650
-
651
- ##
652
- # Calls accept_list_end_label
653
-
654
- def test_accept_list_end_label
655
- @to.start_accepting
656
-
657
- @to.accept_list_start @label_list
658
-
659
- @to.accept_list_end @label_list
660
-
661
- accept_list_end_label
662
- end
663
-
664
- ##
665
- # Calls accept_list_end_lalpha
666
-
667
- def test_accept_list_end_lalpha
668
- @to.start_accepting
669
-
670
- @to.accept_list_start @lalpha_list
671
-
672
- @to.accept_list_end @lalpha_list
673
-
674
- accept_list_end_lalpha
675
- end
676
-
677
- ##
678
- # Calls accept_list_end_number
679
-
680
- def test_accept_list_end_number
681
- @to.start_accepting
682
-
683
- @to.accept_list_start @number_list
684
-
685
- @to.accept_list_end @number_list
686
-
687
- accept_list_end_number
688
- end
689
-
690
- ##
691
- # Calls accept_list_end_note
692
-
693
- def test_accept_list_end_note
694
- @to.start_accepting
695
-
696
- @to.accept_list_start @note_list
697
-
698
- @to.accept_list_end @note_list
699
-
700
- accept_list_end_note
701
- end
702
-
703
- ##
704
- # Calls accept_list_end_ualpha
705
-
706
- def test_accept_list_end_ualpha
707
- @to.start_accepting
708
-
709
- @to.accept_list_start @ualpha_list
710
-
711
- @to.accept_list_end @ualpha_list
712
-
713
- accept_list_end_ualpha
714
- end
715
-
716
- ##
717
- # Calls list_nested with a two-level list
718
-
719
- def test_list_nested
720
- doc = @RM::Document.new(
721
- @RM::List.new(:BULLET,
722
- @RM::ListItem.new(nil,
723
- @RM::Paragraph.new('l1'),
724
- @RM::List.new(:BULLET,
725
- @RM::ListItem.new(nil,
726
- @RM::Paragraph.new('l1.1')))),
727
- @RM::ListItem.new(nil,
728
- @RM::Paragraph.new('l2'))))
729
-
730
- doc.accept @to
731
-
732
- list_nested
733
- end
734
-
735
- ##
736
- # Calls list_verbatim with a list containing a verbatim block
737
-
738
- def test_list_verbatim # HACK overblown
739
- doc =
740
- doc(
741
- list(:BULLET,
742
- item(nil,
743
- para('list stuff'),
744
- blank_line,
745
- verb("* list\n",
746
- " with\n",
747
- "\n",
748
- " second\n",
749
- "\n",
750
- " 1. indented\n",
751
- " 2. numbered\n",
752
- "\n",
753
- " third\n",
754
- "\n",
755
- "* second\n"))))
756
-
757
- doc.accept @to
758
-
759
- list_verbatim
760
- end
761
- end
762
- end
763
-
764
- end