Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for 'Raises' lines in TomDoc parser #611

Merged
merged 1 commit into from
May 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
  • Loading branch information
nbeyer committed May 8, 2018
commit 54f6e5bd5dd4e1d0687880d369ad54891be5b1ab
12 changes: 9 additions & 3 deletions lib/rdoc/tom_doc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,19 @@ def build_paragraph margin

case type
when :TEXT then
@section = 'Returns' if data =~ /\AReturns/
@section = 'Returns' if data =~ /\A(Returns|Raises)/

paragraph << data
when :NEWLINE then
if :TEXT == peek_token[0] then
paragraph << ' '
# Lines beginning with 'Raises' in the Returns section should not be
# treated as multiline text
if 'Returns' == @section and
peek_token[1].start_with?('Raises') then
break
else
paragraph << ' '
end
else
break
end
Expand Down Expand Up @@ -255,4 +262,3 @@ def tokenize text
end

end

60 changes: 59 additions & 1 deletion test/test_rdoc_tom_doc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,44 @@ def test_parse_returns
assert_equal expected, @TD.parse(text)
end

def test_parse_returns_with_raises
text = <<-TEXT
Do some stuff

Returns a thing
Raises ArgumentError when stuff
Raises StandardError when stuff
TEXT
expected =
doc(
para('Do some stuff'),
blank_line,
head(3, 'Returns'),
blank_line,
para('Returns a thing'),
para('Raises ArgumentError when stuff'),
para('Raises StandardError when stuff'))

assert_equal expected, @TD.parse(text)
end

def test_parse_raises_without_returns
text = <<-TEXT
Do some stuff

Raises ArgumentError when stuff
TEXT
expected =
doc(
para('Do some stuff'),
blank_line,
head(3, 'Returns'),
blank_line,
para('Raises ArgumentError when stuff'))

assert_equal expected, @TD.parse(text)
end

def test_parse_returns_multiline
text = <<-TEXT
Do some stuff
Expand All @@ -320,6 +358,27 @@ def test_parse_returns_multiline
assert_equal expected, @TD.parse(text)
end

def test_parse_returns_multiline_and_raises
text = <<-TEXT
Do some stuff

Returns a thing
that is multiline
Raises ArgumentError
TEXT

expected =
doc(
para('Do some stuff'),
blank_line,
head(3, 'Returns'),
blank_line,
para('Returns a thing', ' ', 'that is multiline'),
para('Raises ArgumentError'))

assert_equal expected, @TD.parse(text)
end

def test_parse_signature
text = <<-TEXT
Do some stuff
Expand Down Expand Up @@ -518,4 +577,3 @@ def test_tokenize_returns_multiline
end

end