Skip to content

Commit 78d5754

Browse files
committed
Create ToHtmlSnippet correctly in Text#snippet
While ToHtmlSnippet was updated to pass an Options instance in, Text#snippet was not. This has been corrected by adding RDoc::CodeObject#options which uses the store's options or creates a default RDoc::Options instance. This bug was missed in part due to commented-out tests for Text#snippet.
1 parent 6c532d2 commit 78d5754

File tree

5 files changed

+54
-38
lines changed

5 files changed

+54
-38
lines changed

History.rdoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#204 by Erik Hollensbe
2525
* Code objects with nodoc are no longer included in the ri store. Bug #177
2626
by Thomas Leitner.
27+
* Text#snippet now creates a RDoc::Markup::ToHtmlSnippet correctly.
2728

2829
=== 4.0.0 / 2013-02-24
2930

lib/rdoc/code_object.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,20 @@ def ignored?
275275
@ignored
276276
end
277277

278+
##
279+
# The options instance from the store this CodeObject is attached to, or a
280+
# default options instance if the CodeObject is not attached.
281+
#
282+
# This is used by Text#snippet
283+
284+
def options
285+
if @store then
286+
@store.rdoc.options
287+
else
288+
RDoc::Options.new
289+
end
290+
end
291+
278292
##
279293
# Our parent CodeObject. The parent may be missing for classes loaded from
280294
# legacy RI data stores.

lib/rdoc/text.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def parse text, format = 'rdoc'
140140
def snippet text, limit = 100
141141
document = parse text
142142

143-
RDoc::Markup::ToHtmlSnippet.new(limit).convert document
143+
RDoc::Markup::ToHtmlSnippet.new(options, limit).convert document
144144
end
145145

146146
##

test/test_rdoc_code_object.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,14 @@ def test_offset
229229
assert_equal 5, @c1_m.offset
230230
end
231231

232+
def test_options
233+
assert_kind_of RDoc::Options, @co.options
234+
235+
@co.store = @store
236+
237+
assert_same @options, @co.options
238+
end
239+
232240
def test_parent_file_name
233241
assert_equal '(unknown)', @co.parent_file_name
234242
assert_equal 'xref_data.rb', @c1.parent_file_name

test/test_rdoc_text.rb

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -261,42 +261,31 @@ def test_parse_newline
261261
assert_equal RDoc::Markup::Document.new, parse("\n")
262262
end
263263

264-
# def test_snippet
265-
# text = <<-TEXT
266-
#This is one-hundred characters or more of text in a single paragraph. This
267-
#paragraph will be cut off some point after the one-hundredth character.
268-
# TEXT
269-
#
270-
# expected = text.gsub(/\r?\n/, ' ').sub(/ some point.*/, '')
271-
#
272-
# assert_equal expected, snippet(text)
273-
# end
274-
#
275-
# def test_snippet_comment
276-
# c = comment 'This is a comment'
277-
#
278-
# assert_equal 'This is a comment', snippet(c)
279-
# end
280-
#
281-
# def test_snippet_no_space
282-
# text = <<-TEXT.strip
283-
#This is one-hundred characters or more of text in a single paragraph. This
284-
#paragraph will not be cut
285-
# TEXT
286-
#
287-
# expected = <<-EXPECTED.strip.gsub(/\r?\n/, ' ')
288-
#This is one-hundred characters or more of text in a single paragraph. This
289-
#paragraph will not be cut
290-
# EXPECTED
291-
#
292-
# assert_equal expected, snippet(text)
293-
# end
294-
#
295-
# def test_snippet_short
296-
# text = 'This is a comment'
297-
#
298-
# assert_equal text.dup, snippet(text)
299-
# end
264+
def test_snippet
265+
text = <<-TEXT
266+
This is one-hundred characters or more of text in a single paragraph. This
267+
paragraph will be cut off some point after the one-hundredth character.
268+
TEXT
269+
270+
expected = <<-EXPECTED
271+
<p>This is one-hundred characters or more of text in a single paragraph. This
272+
paragraph will be cut off \u2026
273+
EXPECTED
274+
275+
assert_equal expected, snippet(text)
276+
end
277+
278+
def test_snippet_comment
279+
c = comment 'This is a comment'
280+
281+
assert_equal "<p>This is a comment\n", snippet(c)
282+
end
283+
284+
def test_snippet_short
285+
text = 'This is a comment'
286+
287+
assert_equal "<p>#{text}\n", snippet(text)
288+
end
300289

301290
def test_strip_hashes
302291
text = <<-TEXT
@@ -560,9 +549,13 @@ def test_to_html_tt_tag_mismatch
560549
assert_equal "mismatched <tt> tag\n", err
561550
end
562551

563-
def formatter()
552+
def formatter
564553
RDoc::Markup::ToHtml.new @options
565554
end
566555

556+
def options
557+
@options
558+
end
559+
567560
end
568561

0 commit comments

Comments
 (0)