1##
2# Test case for creating new plain-text RDoc::Markup formatters.  See also
3# RDoc::Markup::FormatterTestCase
4#
5# See test_rdoc_markup_to_rdoc.rb for a complete example.
6#
7# Example:
8#
9#  class TestRDocMarkupToNewTextFormat < RDoc::Markup::TextFormatterTestCase
10#
11#    add_visitor_tests
12#    add_text_tests
13#
14#    def setup
15#      super
16#
17#      @to = RDoc::Markup::ToNewTextFormat.new
18#    end
19#
20#    def accept_blank_line
21#      assert_equal :junk, @to.res.join
22#    end
23#
24#    # ...
25#
26#  end
27
28class RDoc::Markup::TextFormatterTestCase < RDoc::Markup::FormatterTestCase
29
30  ##
31  # Adds test cases to the calling TestCase.
32
33  def self.add_text_tests
34    self.class_eval do
35
36      ##
37      # Test case that calls <tt>@to.accept_heading</tt>
38
39      def test_accept_heading_indent
40        @to.start_accepting
41        @to.indent = 3
42        @to.accept_heading @RM::Heading.new(1, 'Hello')
43
44        accept_heading_indent
45      end
46
47      ##
48      # Test case that calls <tt>@to.accept_rule</tt>
49
50      def test_accept_rule_indent
51        @to.start_accepting
52        @to.indent = 3
53        @to.accept_rule @RM::Rule.new(1)
54
55        accept_rule_indent
56      end
57
58      ##
59      # Test case that calls <tt>@to.accept_verbatim</tt>
60
61      def test_accept_verbatim_indent
62        @to.start_accepting
63        @to.indent = 2
64        @to.accept_verbatim @RM::Verbatim.new("hi\n", " world\n")
65
66        accept_verbatim_indent
67      end
68
69      ##
70      # Test case that calls <tt>@to.accept_verbatim</tt> with a big indent
71
72      def test_accept_verbatim_big_indent
73        @to.start_accepting
74        @to.indent = 2
75        @to.accept_verbatim @RM::Verbatim.new("hi\n", "world\n")
76
77        accept_verbatim_big_indent
78      end
79
80      ##
81      # Test case that calls <tt>@to.accept_paragraph</tt> with an indent
82
83      def test_accept_paragraph_indent
84        @to.start_accepting
85        @to.indent = 3
86        @to.accept_paragraph @RM::Paragraph.new(('words ' * 30).strip)
87
88        accept_paragraph_indent
89      end
90
91      ##
92      # Test case that calls <tt>@to.accept_paragraph</tt> with a long line
93
94      def test_accept_paragraph_wrap
95        @to.start_accepting
96        @to.accept_paragraph @RM::Paragraph.new(('words ' * 30).strip)
97
98        accept_paragraph_wrap
99      end
100
101      ##
102      # Test case that calls <tt>@to.attributes</tt> with an escaped
103      # cross-reference.  If this test doesn't pass something may be very
104      # wrong.
105
106      def test_attributes
107        assert_equal 'Dog', @to.attributes("\\Dog")
108      end
109
110    end
111  end
112
113end
114
115