3 require 'rdoc/ri/formatter'
4 require 'rdoc/markup/to_flow'
6 class TestRDocRIFormatter < Test::Unit::TestCase
13 @f = RDoc::RI::Formatter.new @output, @width, @indent
14 @markup = RDoc::Markup.new
15 @flow = RDoc::Markup::ToFlow.new
21 assert_equal "\n", @output.string
27 assert_equal 'a b c', @output.string
30 def test_break_to_newline
33 assert_equal '', @output.string
37 assert_equal '> < " &', @f.conv_html('> < " &')
41 text = '<tt>a</tt> <code>b</code> <b>c</b> <em>d</em>'
43 expected = '+a+ +b+ *c* _d_'
45 assert_equal expected, @f.conv_markup(text)
50 RDoc::Markup::Flow::H.new(1, 'heading'),
51 RDoc::Markup::Flow::P.new('paragraph'),
56 assert_equal "\nHEADING\n=======\n\n paragraph\n\n", @output.string
59 def test_display_flow_item_h
60 item = RDoc::Markup::Flow::H.new 1, 'heading'
62 @f.display_flow_item item
64 assert_equal "\nHEADING\n=======\n\n", @output.string
67 def test_display_flow_item_li
68 item = RDoc::Markup::Flow::LI.new nil, 'paragraph'
70 @f.display_flow_item item
72 assert_equal " paragraph\n\n", @output.string
75 def test_display_flow_item_list
76 item = RDoc::Markup::Flow::LIST.new :NUMBER
78 @f.display_flow_item item
80 assert_equal "", @output.string
83 def test_display_flow_item_p
84 item = RDoc::Markup::Flow::P.new 'paragraph'
86 @f.display_flow_item item
88 assert_equal " paragraph\n\n", @output.string
91 def test_display_flow_item_rule
92 item = RDoc::Markup::Flow::RULE.new 1
94 @f.display_flow_item item
96 assert_equal "#{'-' * 78}\n", @output.string
99 def test_display_flow_item_unknown
100 e = assert_raise RDoc::Error do
101 @f.display_flow_item Object.new
104 assert_equal "Unknown flow element: Object", e.message
107 def test_display_flow_item_verb
108 item = RDoc::Markup::Flow::VERB.new 'a b c'
110 @f.display_flow_item item
112 assert_equal " a b c\n\n", @output.string
115 def test_display_heading_1
116 @f.display_heading 'heading', 1, ' '
118 assert_equal "\nHEADING\n=======\n\n", @output.string
121 def test_display_heading_2
122 @f.display_heading 'heading', 2, ' '
124 assert_equal "\nheading\n-------\n\n", @output.string
127 def test_display_heading_3
128 @f.display_heading 'heading', 3, ' '
130 assert_equal " heading\n\n", @output.string
133 def test_display_list
134 list = RDoc::Markup::Flow::LIST.new :NUMBER
135 list << RDoc::Markup::Flow::LI.new(nil, 'a b c')
136 list << RDoc::Markup::Flow::LI.new(nil, 'd e f')
140 assert_equal " 1. a b c\n\n 2. d e f\n\n", @output.string
143 def test_display_list_bullet
144 list = RDoc::Markup::Flow::LIST.new :BULLET
145 list << RDoc::Markup::Flow::LI.new(nil, 'a b c')
149 assert_equal " * a b c\n\n", @output.string
152 def test_display_list_labeled
153 list = RDoc::Markup::Flow::LIST.new :LABELED
154 list << RDoc::Markup::Flow::LI.new('label', 'a b c')
158 assert_equal " label a b c\n\n", @output.string
161 def test_display_list_lower_alpha
162 list = RDoc::Markup::Flow::LIST.new :LOWERALPHA
163 list << RDoc::Markup::Flow::LI.new(nil, 'a b c')
167 assert_equal " a. a b c\n\n", @output.string
170 def test_display_list_note
171 list = RDoc::Markup::Flow::LIST.new :NOTE
172 list << RDoc::Markup::Flow::LI.new('note:', 'a b c')
176 assert_equal " note: a b c\n\n", @output.string
179 def test_display_list_number
180 list = RDoc::Markup::Flow::LIST.new :NUMBER
181 list << RDoc::Markup::Flow::LI.new(nil, 'a b c')
185 assert_equal " 1. a b c\n\n", @output.string
188 def test_display_list_unknown
189 list = RDoc::Markup::Flow::LIST.new :UNKNOWN
190 list << RDoc::Markup::Flow::LI.new(nil, 'a b c')
192 e = assert_raise ArgumentError do
196 assert_equal 'unknown list type UNKNOWN', e.message
199 def test_display_list_upper_alpha
200 list = RDoc::Markup::Flow::LIST.new :UPPERALPHA
201 list << RDoc::Markup::Flow::LI.new(nil, 'a b c')
205 assert_equal " A. a b c\n\n", @output.string
208 def test_display_verbatim_flow_item
209 verbatim = RDoc::Markup::Flow::VERB.new "a b c\nd e f"
211 @f.display_verbatim_flow_item verbatim
213 assert_equal " a b c\n d e f\n\n", @output.string
216 def test_display_verbatim_flow_item_bold
217 verbatim = RDoc::Markup::Flow::VERB.new "*a* b c"
219 @f.display_verbatim_flow_item verbatim
221 assert_equal " *a* b c\n\n", @output.string
227 expected = '-' * @width + "\n"
228 assert_equal expected, @output.string
231 def test_draw_line_label
234 expected = '-' * (@width - 6) + " label\n"
235 assert_equal expected, @output.string
238 def test_draw_line_label_long
239 @f.draw_line 'a' * @width
241 expected = '-' * @width + "\n" + ('a' * @width) + "\n"
242 assert_equal expected, @output.string
245 def test_raw_print_line
246 @f.raw_print_line 'a b c'
248 assert_equal "a b c\n", @output.string
251 def test_strip_attributes_b
252 text = @f.strip_attributes 'hello <b>world</b>'
254 expected = 'hello world'
256 assert_equal expected, text
259 def test_strip_attributes_code
260 text = @f.strip_attributes 'hello <code>world</code>'
262 expected = 'hello world'
264 assert_equal expected, text
267 def test_strip_attributes_em
268 text = @f.strip_attributes 'hello <em>world</em>'
270 expected = 'hello world'
272 assert_equal expected, text
275 def test_strip_attributes_i
276 text = @f.strip_attributes 'hello <i>world</i>'
278 expected = 'hello world'
280 assert_equal expected, text
283 def test_strip_attributes_tt
284 text = @f.strip_attributes 'hello <tt>world</tt>'
286 expected = 'hello world'
288 assert_equal expected, text
293 assert_equal '', @output.string
297 @f.wrap 'a ' * (@width / 2)
298 assert_equal " a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a\n a \n",
303 @f.wrap 'a <tt>b</tt> c'
304 assert_equal " a +b+ c\n", @output.string
309 assert_equal '', @output.string
314 assert_equal " a b c\n", @output.string