Class: RDoc::Markup::FormatterTestCase

Inherits:
TestCase
  • Object
show all
Defined in:
lib/rdoc/markup/formatter_test_case.rb

Overview

Test case for creating new RDoc::Markup formatters. See test/test_rdoc_markup_to_*.rb for examples.

This test case adds a variety of tests to your subclass when #add_visitor_tests is called. Most tests set up a scenario then call a method you will provide to perform the assertion on the output.

Your subclass must instantiate a visitor and assign it to @to.

For example, test_accept_blank_line sets up a RDoc::Markup::BlockLine then calls accept_blank_line on your visitor. You are responsible for asserting that the output is correct.

Example:

class TestRDocMarkupToNewFormat < RDoc::Markup::FormatterTestCase

  add_visitor_tests

  def setup
    super

    @to = RDoc::Markup::ToNewFormat.new
  end

  def accept_blank_line
    assert_equal :junk, @to.res.join
  end

  # ...

end

Direct Known Subclasses

TextFormatterTestCase

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TestCase

#assert_directory, #assert_file, #blank_line, #block, #comment, #doc, #hard_break, #head, #item, #list, #mu_pp, #para, #raw, #refute_file, #rule, #temp_dir, #verb, #verbose_capture_io

Class Method Details

.add_visitor_testsObject

Call to add the visitor tests to your test case


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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
# File 'lib/rdoc/markup/formatter_test_case.rb', line 88

def self.add_visitor_tests
  class_eval do

    ##
    # Calls start_accepting which needs to verify startup state

    def test_start_accepting
      @to.start_accepting

      start_accepting
    end

    ##
    # Calls end_accepting on your test case which needs to call
    # <tt>@to.end_accepting</tt> and verify document generation

    def test_end_accepting
      @to.start_accepting
      @to.res << 'hi'

      end_accepting
    end

    ##
    # Calls accept_blank_line

    def test_accept_blank_line
      @to.start_accepting

      @to.accept_blank_line @RM::BlankLine.new

      accept_blank_line
    end

    ##
    # Calls accept_block_quote

    def test_accept_block_quote
      @to.start_accepting

      @to.accept_block_quote block para 'quote'

      accept_block_quote
    end
    ##
    # Test case that calls <tt>@to.accept_document</tt>

    def test_accept_document
      @to.start_accepting
      @to.accept_document @RM::Document.new @RM::Paragraph.new 'hello'

      accept_document
    end

    ##
    # Calls accept_heading with a level 5 RDoc::Markup::Heading

    def test_accept_heading
      @to.start_accepting

      @to.accept_heading @RM::Heading.new(5, 'Hello')

      accept_heading
    end

    ##
    # Calls accept_heading_1 with a level 1 RDoc::Markup::Heading

    def test_accept_heading_1
      @to.start_accepting

      @to.accept_heading @RM::Heading.new(1, 'Hello')

      accept_heading_1
    end

    ##
    # Calls accept_heading_2 with a level 2 RDoc::Markup::Heading

    def test_accept_heading_2
      @to.start_accepting

      @to.accept_heading @RM::Heading.new(2, 'Hello')

      accept_heading_2
    end

    ##
    # Calls accept_heading_3 with a level 3 RDoc::Markup::Heading

    def test_accept_heading_3
      # HACK this doesn't belong here
      skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars

      @to.start_accepting

      @to.accept_heading @RM::Heading.new(3, 'Hello')

      accept_heading_3
    end

    ##
    # Calls accept_heading_4 with a level 4 RDoc::Markup::Heading

    def test_accept_heading_4
      @to.start_accepting

      @to.accept_heading @RM::Heading.new(4, 'Hello')

      accept_heading_4
    end

    ##
    # Calls accept_heading_b with a bold level 1 RDoc::Markup::Heading

    def test_accept_heading_b
      @to.start_accepting

      @to.accept_heading @RM::Heading.new(1, '*Hello*')

      accept_heading_b
    end

    ##
    # Calls accept_heading_suppressed_crossref with a level 1
    # RDoc::Markup::Heading containing a suppressed crossref

    def test_accept_heading_suppressed_crossref # HACK to_html_crossref test
      @to.start_accepting

      @to.accept_heading @RM::Heading.new(1, '\\Hello')

      accept_heading_suppressed_crossref
    end

    ##
    # Calls accept_paragraph

    def test_accept_paragraph
      @to.start_accepting

      @to.accept_paragraph @RM::Paragraph.new('hi')

      accept_paragraph
    end

    ##
    # Calls accept_paragraph_b with a RDoc::Markup::Paragraph containing
    # bold words

    def test_accept_paragraph_b
      @to.start_accepting

      @to.accept_paragraph @RM::Paragraph.new('reg <b>bold words</b> reg')

      accept_paragraph_b
    end

    ##
    # Calls accept_paragraph_br with a RDoc::Markup::Paragraph containing
    # a \<br>

    def test_accept_paragraph_br
      @to.start_accepting

      @to.accept_paragraph para 'one<br>two'

      accept_paragraph_br
    end

    ##
    # Calls accept_paragraph with a Paragraph containing a hard break

    def test_accept_paragraph_break
      @to.start_accepting

      @to.accept_paragraph para('hello', hard_break, 'world')

      accept_paragraph_break
    end

    ##
    # Calls accept_paragraph_i with a RDoc::Markup::Paragraph containing
    # emphasized words

    def test_accept_paragraph_i
      @to.start_accepting

      @to.accept_paragraph @RM::Paragraph.new('reg <em>italic words</em> reg')

      accept_paragraph_i
    end

    ##
    # Calls accept_paragraph_plus with a RDoc::Markup::Paragraph containing
    # teletype words

    def test_accept_paragraph_plus
      @to.start_accepting

      @to.accept_paragraph @RM::Paragraph.new('reg +teletype+ reg')

      accept_paragraph_plus
    end

    ##
    # Calls accept_paragraph_star with a RDoc::Markup::Paragraph containing
    # bold words

    def test_accept_paragraph_star
      @to.start_accepting

      @to.accept_paragraph @RM::Paragraph.new('reg *bold* reg')

      accept_paragraph_star
    end

    ##
    # Calls accept_paragraph_underscore with a RDoc::Markup::Paragraph
    # containing emphasized words

    def test_accept_paragraph_underscore
      @to.start_accepting

      @to.accept_paragraph @RM::Paragraph.new('reg _italic_ reg')

      accept_paragraph_underscore
    end

    ##
    # Calls accept_verbatim with a RDoc::Markup::Verbatim

    def test_accept_verbatim
      @to.start_accepting

      @to.accept_verbatim @RM::Verbatim.new("hi\n", "  world\n")

      accept_verbatim
    end

    ##
    # Calls accept_raw with a RDoc::Markup::Raw

    def test_accept_raw
      @to.start_accepting

      @to.accept_raw @RM::Raw.new("<table>",
                                  "<tr><th>Name<th>Count",
                                  "<tr><td>a<td>1",
                                  "<tr><td>b<td>2",
                                  "</table>")

      accept_raw
    end

    ##
    # Calls accept_rule with a RDoc::Markup::Rule

    def test_accept_rule
      @to.start_accepting

      @to.accept_rule @RM::Rule.new(4)

      accept_rule
    end

    ##
    # Calls accept_list_item_start_bullet

    def test_accept_list_item_start_bullet
      @to.start_accepting

      @to.accept_list_start @bullet_list

      @to.accept_list_item_start @bullet_list.items.first

      accept_list_item_start_bullet
    end

    ##
    # Calls accept_list_item_start_label

    def test_accept_list_item_start_label
      @to.start_accepting

      @to.accept_list_start @label_list

      @to.accept_list_item_start @label_list.items.first

      accept_list_item_start_label
    end

    ##
    # Calls accept_list_item_start_lalpha

    def test_accept_list_item_start_lalpha
      @to.start_accepting

      @to.accept_list_start @lalpha_list

      @to.accept_list_item_start @lalpha_list.items.first

      accept_list_item_start_lalpha
    end

    ##
    # Calls accept_list_item_start_note

    def test_accept_list_item_start_note
      @to.start_accepting

      @to.accept_list_start @note_list

      @to.accept_list_item_start @note_list.items.first

      accept_list_item_start_note
    end

    ##
    # Calls accept_list_item_start_note_2

    def test_accept_list_item_start_note_2
      list = list(:NOTE,
               item('<tt>teletype</tt>',
                 para('teletype description')))

      @to.start_accepting

      list.accept @to

      @to.end_accepting

      accept_list_item_start_note_2
    end

    ##
    # Calls accept_list_item_start_note_multi_description

    def test_accept_list_item_start_note_multi_description
      list = list(:NOTE,
               item(%w[label],
                 para('description one')),
               item(nil, para('description two')))

      @to.start_accepting

      list.accept @to

      @to.end_accepting

      accept_list_item_start_note_multi_description
    end

    ##
    # Calls accept_list_item_start_note_multi_label

    def test_accept_list_item_start_note_multi_label
      list = list(:NOTE,
               item(%w[one two],
                 para('two headers')))

      @to.start_accepting

      list.accept @to

      @to.end_accepting

      accept_list_item_start_note_multi_label
    end

    ##
    # Calls accept_list_item_start_number

    def test_accept_list_item_start_number
      @to.start_accepting

      @to.accept_list_start @number_list

      @to.accept_list_item_start @number_list.items.first

      accept_list_item_start_number
    end

    ##
    # Calls accept_list_item_start_ualpha

    def test_accept_list_item_start_ualpha
      @to.start_accepting

      @to.accept_list_start @ualpha_list

      @to.accept_list_item_start @ualpha_list.items.first

      accept_list_item_start_ualpha
    end

    ##
    # Calls accept_list_item_end_bullet

    def test_accept_list_item_end_bullet
      @to.start_accepting

      @to.accept_list_start @bullet_list

      @to.accept_list_item_start @bullet_list.items.first

      @to.accept_list_item_end @bullet_list.items.first

      accept_list_item_end_bullet
    end

    ##
    # Calls accept_list_item_end_label

    def test_accept_list_item_end_label
      @to.start_accepting

      @to.accept_list_start @label_list

      @to.accept_list_item_start @label_list.items.first

      @to.accept_list_item_end @label_list.items.first

      accept_list_item_end_label
    end

    ##
    # Calls accept_list_item_end_lalpha

    def test_accept_list_item_end_lalpha
      @to.start_accepting

      @to.accept_list_start @lalpha_list

      @to.accept_list_item_start @lalpha_list.items.first

      @to.accept_list_item_end @lalpha_list.items.first

      accept_list_item_end_lalpha
    end

    ##
    # Calls accept_list_item_end_note

    def test_accept_list_item_end_note
      @to.start_accepting

      @to.accept_list_start @note_list

      @to.accept_list_item_start @note_list.items.first

      @to.accept_list_item_end @note_list.items.first

      accept_list_item_end_note
    end

    ##
    # Calls accept_list_item_end_number

    def test_accept_list_item_end_number
      @to.start_accepting

      @to.accept_list_start @number_list

      @to.accept_list_item_start @number_list.items.first

      @to.accept_list_item_end @number_list.items.first

      accept_list_item_end_number
    end

    ##
    # Calls accept_list_item_end_ualpha

    def test_accept_list_item_end_ualpha
      @to.start_accepting

      @to.accept_list_start @ualpha_list

      @to.accept_list_item_start @ualpha_list.items.first

      @to.accept_list_item_end @ualpha_list.items.first

      accept_list_item_end_ualpha
    end

    ##
    # Calls accept_list_start_bullet

    def test_accept_list_start_bullet
      @to.start_accepting

      @to.accept_list_start @bullet_list

      accept_list_start_bullet
    end

    ##
    # Calls accept_list_start_label

    def test_accept_list_start_label
      @to.start_accepting

      @to.accept_list_start @label_list

      accept_list_start_label
    end

    ##
    # Calls accept_list_start_lalpha

    def test_accept_list_start_lalpha
      @to.start_accepting

      @to.accept_list_start @lalpha_list

      accept_list_start_lalpha
    end

    ##
    # Calls accept_list_start_note

    def test_accept_list_start_note
      @to.start_accepting

      @to.accept_list_start @note_list

      accept_list_start_note
    end

    ##
    # Calls accept_list_start_number

    def test_accept_list_start_number
      @to.start_accepting

      @to.accept_list_start @number_list

      accept_list_start_number
    end

    ##
    # Calls accept_list_start_ualpha

    def test_accept_list_start_ualpha
      @to.start_accepting

      @to.accept_list_start @ualpha_list

      accept_list_start_ualpha
    end

    ##
    # Calls accept_list_end_bullet

    def test_accept_list_end_bullet
      @to.start_accepting

      @to.accept_list_start @bullet_list

      @to.accept_list_end @bullet_list

      accept_list_end_bullet
    end

    ##
    # Calls accept_list_end_label

    def test_accept_list_end_label
      @to.start_accepting

      @to.accept_list_start @label_list

      @to.accept_list_end @label_list

      accept_list_end_label
    end

    ##
    # Calls accept_list_end_lalpha

    def test_accept_list_end_lalpha
      @to.start_accepting

      @to.accept_list_start @lalpha_list

      @to.accept_list_end @lalpha_list

      accept_list_end_lalpha
    end

    ##
    # Calls accept_list_end_number

    def test_accept_list_end_number
      @to.start_accepting

      @to.accept_list_start @number_list

      @to.accept_list_end @number_list

      accept_list_end_number
    end

    ##
    # Calls accept_list_end_note

    def test_accept_list_end_note
      @to.start_accepting

      @to.accept_list_start @note_list

      @to.accept_list_end @note_list

      accept_list_end_note
    end

    ##
    # Calls accept_list_end_ualpha

    def test_accept_list_end_ualpha
      @to.start_accepting

      @to.accept_list_start @ualpha_list

      @to.accept_list_end @ualpha_list

      accept_list_end_ualpha
    end

    ##
    # Calls list_nested with a two-level list

    def test_list_nested
      doc = @RM::Document.new(
              @RM::List.new(:BULLET,
                @RM::ListItem.new(nil,
                  @RM::Paragraph.new('l1'),
                  @RM::List.new(:BULLET,
                    @RM::ListItem.new(nil,
                      @RM::Paragraph.new('l1.1')))),
                @RM::ListItem.new(nil,
                  @RM::Paragraph.new('l2'))))

      doc.accept @to

      list_nested
    end

    ##
    # Calls list_verbatim with a list containing a verbatim block

    def test_list_verbatim # HACK overblown
      doc =
        doc(
          list(:BULLET,
            item(nil,
              para('list stuff'),
              blank_line,
              verb("* list\n",
                   "  with\n",
                   "\n",
                   "  second\n",
                   "\n",
                   "  1. indented\n",
                   "  2. numbered\n",
                   "\n",
                   "  third\n",
                   "\n",
                   "* second\n"))))

      doc.accept @to

      list_verbatim
    end
  end
end

Instance Method Details

#setupObject

Call #setup when inheriting from this test case.

Provides the following instance variables:

@m

RDoc::Markup.new

@RM

RDoc::Markup # to reduce typing

@bullet_list

@RM::List.new :BULLET, # …

@label_list

@RM::List.new :LABEL, # …

@lalpha_list

@RM::List.new :LALPHA, # …

@note_list

@RM::List.new :NOTE, # …

@number_list

@RM::List.new :NUMBER, # …

@ualpha_list

@RM::List.new :UALPHA, # …


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
# File 'lib/rdoc/markup/formatter_test_case.rb', line 53

def setup
  super

  @options = RDoc::Options.new

  @m = @RM.new

  @bullet_list = @RM::List.new(:BULLET,
    @RM::ListItem.new(nil, @RM::Paragraph.new('l1')),
    @RM::ListItem.new(nil, @RM::Paragraph.new('l2')))

  @label_list = @RM::List.new(:LABEL,
    @RM::ListItem.new('cat', @RM::Paragraph.new('cats are cool')),
    @RM::ListItem.new('dog', @RM::Paragraph.new('dogs are cool too')))

  @lalpha_list = @RM::List.new(:LALPHA,
    @RM::ListItem.new(nil, @RM::Paragraph.new('l1')),
    @RM::ListItem.new(nil, @RM::Paragraph.new('l2')))

  @note_list = @RM::List.new(:NOTE,
    @RM::ListItem.new('cat', @RM::Paragraph.new('cats are cool')),
    @RM::ListItem.new('dog', @RM::Paragraph.new('dogs are cool too')))

  @number_list = @RM::List.new(:NUMBER,
    @RM::ListItem.new(nil, @RM::Paragraph.new('l1')),
    @RM::ListItem.new(nil, @RM::Paragraph.new('l2')))

  @ualpha_list = @RM::List.new(:UALPHA,
    @RM::ListItem.new(nil, @RM::Paragraph.new('l1')),
    @RM::ListItem.new(nil, @RM::Paragraph.new('l2')))
end