Skip to content

Commit 54f6e5b

Browse files
committed
Add support for 'Raises' lines in TomDoc parser
* For the special case of 'initialize', handle 'Raises' as the indicator of the Returns section. * Stop treating Raises lines as multine text and let them be their own paragraphs
1 parent 9d453c6 commit 54f6e5b

File tree

2 files changed

+68
-4
lines changed

2 files changed

+68
-4
lines changed

lib/rdoc/tom_doc.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,19 @@ def build_paragraph margin
180180

181181
case type
182182
when :TEXT then
183-
@section = 'Returns' if data =~ /\AReturns/
183+
@section = 'Returns' if data =~ /\A(Returns|Raises)/
184184

185185
paragraph << data
186186
when :NEWLINE then
187187
if :TEXT == peek_token[0] then
188-
paragraph << ' '
188+
# Lines beginning with 'Raises' in the Returns section should not be
189+
# treated as multiline text
190+
if 'Returns' == @section and
191+
peek_token[1].start_with?('Raises') then
192+
break
193+
else
194+
paragraph << ' '
195+
end
189196
else
190197
break
191198
end
@@ -255,4 +262,3 @@ def tokenize text
255262
end
256263

257264
end
258-

test/test_rdoc_tom_doc.rb

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,44 @@ def test_parse_returns
301301
assert_equal expected, @TD.parse(text)
302302
end
303303

304+
def test_parse_returns_with_raises
305+
text = <<-TEXT
306+
Do some stuff
307+
308+
Returns a thing
309+
Raises ArgumentError when stuff
310+
Raises StandardError when stuff
311+
TEXT
312+
expected =
313+
doc(
314+
para('Do some stuff'),
315+
blank_line,
316+
head(3, 'Returns'),
317+
blank_line,
318+
para('Returns a thing'),
319+
para('Raises ArgumentError when stuff'),
320+
para('Raises StandardError when stuff'))
321+
322+
assert_equal expected, @TD.parse(text)
323+
end
324+
325+
def test_parse_raises_without_returns
326+
text = <<-TEXT
327+
Do some stuff
328+
329+
Raises ArgumentError when stuff
330+
TEXT
331+
expected =
332+
doc(
333+
para('Do some stuff'),
334+
blank_line,
335+
head(3, 'Returns'),
336+
blank_line,
337+
para('Raises ArgumentError when stuff'))
338+
339+
assert_equal expected, @TD.parse(text)
340+
end
341+
304342
def test_parse_returns_multiline
305343
text = <<-TEXT
306344
Do some stuff
@@ -320,6 +358,27 @@ def test_parse_returns_multiline
320358
assert_equal expected, @TD.parse(text)
321359
end
322360

361+
def test_parse_returns_multiline_and_raises
362+
text = <<-TEXT
363+
Do some stuff
364+
365+
Returns a thing
366+
that is multiline
367+
Raises ArgumentError
368+
TEXT
369+
370+
expected =
371+
doc(
372+
para('Do some stuff'),
373+
blank_line,
374+
head(3, 'Returns'),
375+
blank_line,
376+
para('Returns a thing', ' ', 'that is multiline'),
377+
para('Raises ArgumentError'))
378+
379+
assert_equal expected, @TD.parse(text)
380+
end
381+
323382
def test_parse_signature
324383
text = <<-TEXT
325384
Do some stuff
@@ -518,4 +577,3 @@ def test_tokenize_returns_multiline
518577
end
519578

520579
end
521-

0 commit comments

Comments
 (0)