Skip to content

Commit 9762de4

Browse files
committed
Merge remote-tracking branch 'upstream/master' into fix-regexp-literal-in-oneliner
2 parents 90f73be + 71b01e3 commit 9762de4

File tree

3 files changed

+85
-11
lines changed

3 files changed

+85
-11
lines changed

lib/rdoc/ruby_lex.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,15 +457,18 @@ def lex_init()
457457
proc{|op, io| @prev_char_no == 0 && peek(0) =~ /\s/}) do
458458
|op, io|
459459
@ltype = "="
460-
res = ''
461-
nil until getc == "\n"
460+
res = op
461+
until (ch = getc) == "\n" do
462+
res << ch
463+
end
464+
res << ch
462465

463466
until ( peek_equal?("=end") && peek(4) =~ /\s/ ) do
464467
(ch = getc)
465468
res << ch
466469
end
467470

468-
gets # consume =end
471+
res << gets # consume =end
469472

470473
@ltype = nil
471474
Token(TkRD_COMMENT, res)

lib/rdoc/token_stream.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,18 @@ def self.to_html token_stream
4444
when RDoc::RubyToken::TkVal then 'ruby-value'
4545
end
4646

47-
text = CGI.escapeHTML t.text
47+
comment_with_nl = false
48+
case t
49+
when RDoc::RubyToken::TkRD_COMMENT, RDoc::RubyToken::TkHEREDOCEND
50+
comment_with_nl = true if t.text =~ /\n$/
51+
text = t.text.rstrip
52+
else
53+
text = t.text
54+
end
55+
text = CGI.escapeHTML text
4856

4957
if style then
50-
"<span class=\"#{style}\">#{text}</span>"
58+
"<span class=\"#{style}\">#{text}</span>#{"\n" if comment_with_nl}"
5159
else
5260
text
5361
end

test/test_rdoc_parser_ruby.rb

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class C; end
7474

7575
comment = parser.collect_first_comment
7676

77-
assert_equal RDoc::Comment.new("first\n\n", @top_level), comment
77+
assert_equal RDoc::Comment.new("=begin\nfirst\n=end\n\n", @top_level), comment
7878
end
7979

8080
def test_get_class_or_module
@@ -2499,6 +2499,35 @@ def blah()
24992499
assert_equal markup_code, expected
25002500
end
25012501

2502+
def test_parse_statements_postfix_if_after_heredocbeg
2503+
@filename = 'file.rb'
2504+
util_parser <<RUBY
2505+
class Foo
2506+
def blah()
2507+
<<~EOM if true
2508+
EOM
2509+
end
2510+
end
2511+
RUBY
2512+
2513+
expected = <<EXPTECTED
2514+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">blah</span>()
2515+
<span class="ruby-identifier">&lt;&lt;~EOM</span> <span class="ruby-keyword">if</span> <span class="ruby-keyword">true</span>
2516+
<span class="ruby-value"></span><span class="ruby-identifier"> EOM</span>
2517+
<span class="ruby-keyword">end</span>
2518+
EXPTECTED
2519+
expected = expected.rstrip
2520+
2521+
@parser.scan
2522+
2523+
foo = @top_level.classes.first
2524+
assert_equal 'Foo', foo.full_name
2525+
2526+
blah = foo.method_list.first
2527+
markup_code = blah.markup_code.sub(/^.*\n/, '')
2528+
assert_equal markup_code, expected
2529+
end
2530+
25022531
def test_parse_statements_method_oneliner_with_regexp
25032532
util_parser <<RUBY
25042533
class Foo
@@ -2521,6 +2550,40 @@ def blah() /bar/ end
25212550
assert_equal expected, markup_code
25222551
end
25232552

2553+
def test_parse_statements_embdoc_in_document
2554+
@filename = 'file.rb'
2555+
util_parser <<RUBY
2556+
class Foo
2557+
# doc
2558+
#
2559+
# =begin
2560+
# test embdoc
2561+
# =end
2562+
#
2563+
def blah
2564+
end
2565+
end
2566+
RUBY
2567+
2568+
expected = <<EXPTECTED
2569+
<p>doc
2570+
2571+
<pre class="ruby"><span class="ruby-comment">=begin
2572+
test embdoc
2573+
=end</span>
2574+
</pre>
2575+
EXPTECTED
2576+
2577+
@parser.scan
2578+
2579+
foo = @top_level.classes.first
2580+
assert_equal 'Foo', foo.full_name
2581+
2582+
blah = foo.method_list.first
2583+
markup_comment = blah.search_record[6]
2584+
assert_equal markup_comment, expected
2585+
end
2586+
25242587
def test_parse_require_dynamic_string
25252588
content = <<-RUBY
25262589
prefix = 'path'
@@ -2995,11 +3058,11 @@ def m() end
29953058

29963059
foo = @top_level.classes.first
29973060

2998-
assert_equal 'Foo comment', foo.comment.text
3061+
assert_equal "=begin rdoc\nFoo comment\n=end", foo.comment.text
29993062

30003063
m = foo.method_list.first
30013064

3002-
assert_equal 'm comment', m.comment.text
3065+
assert_equal "=begin\nm comment\n=end", m.comment.text
30033066
end
30043067

30053068
def test_scan_block_comment_nested # Issue #41
@@ -3021,7 +3084,7 @@ class Bar
30213084
foo = @top_level.modules.first
30223085

30233086
assert_equal 'Foo', foo.full_name
3024-
assert_equal 'findmeindoc', foo.comment.text
3087+
assert_equal "=begin rdoc\nfindmeindoc\n=end", foo.comment.text
30253088

30263089
bar = foo.classes.first
30273090

@@ -3068,12 +3131,12 @@ def lauren
30683131

30693132
foo = @top_level.classes.first
30703133

3071-
assert_equal "= DESCRIPTION\n\nThis is a simple test class\n\n= RUMPUS\n\nIs a silly word",
3134+
assert_equal "=begin rdoc\n\n= DESCRIPTION\n\nThis is a simple test class\n\n= RUMPUS\n\nIs a silly word\n\n=end",
30723135
foo.comment.text
30733136

30743137
m = foo.method_list.first
30753138

3076-
assert_equal 'A nice girl', m.comment.text
3139+
assert_equal "=begin rdoc\nA nice girl\n=end", m.comment.text
30773140
end
30783141

30793142
def test_scan_class_nested_nodoc

0 commit comments

Comments
 (0)