Skip to content

Commit

Permalink
Put strip_stars in the right place
Browse files Browse the repository at this point in the history
  • Loading branch information
drbrain committed Mar 30, 2010
1 parent 675a211 commit 2809c74
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 18 deletions.
1 change: 1 addition & 0 deletions Manifest.txt
Expand Up @@ -131,6 +131,7 @@ test/test_rdoc_parser.rb
test/test_rdoc_parser_c.rb
test/test_rdoc_parser_perl.rb
test/test_rdoc_parser_ruby.rb
test/test_rdoc_parser_simple.rb
test/test_rdoc_rdoc.rb
test/test_rdoc_require.rb
test/test_rdoc_ri_driver.rb
Expand Down
22 changes: 11 additions & 11 deletions lib/rdoc/parser/c.rb
Expand Up @@ -176,19 +176,17 @@ def do_classes

def do_constants
@content.scan(%r{\Wrb_define_
(
variable |
readonly_variable |
const |
global_const |
)
( variable |
readonly_variable |
const |
global_const | )
\s*\(
(?:\s*(\w+),)?
\s*"(\w+)",
\s*(.*?)\s*\)\s*;
}xm) do |type, var_name, const_name, definition|
var_name = "rb_cObject" if !var_name or var_name == "rb_mKernel"
handle_constants(type, var_name, const_name, definition)
handle_constants type, var_name, const_name, definition
end
end

Expand Down Expand Up @@ -311,7 +309,7 @@ def find_body(class_name, meth_name, meth_obj, body, quiet = false)
tk = RDoc::RubyToken::Token.new nil, 1, 1
tk.set_text body_text
meth_obj.add_token tk
meth_obj.comment = comment
meth_obj.comment = strip_stars comment
when %r{((?>/\*.*?\*/\s*))^\s*(\#\s*define\s+#{meth_name}\s+(\w+))}m
comment = $1
body_text = $2
Expand All @@ -322,7 +320,7 @@ def find_body(class_name, meth_name, meth_obj, body, quiet = false)
tk = RDoc::RubyToken::Token.new nil, 1, 1
tk.set_text body_text
meth_obj.add_token tk
meth_obj.comment = comment + meth_obj.comment.to_s
meth_obj.comment = strip_stars(comment) + meth_obj.comment.to_s
when %r{^\s*\#\s*define\s+#{meth_name}\s+(\w+)}m
unless find_body(class_name, $1, meth_obj, body, true)
warn "No definition for #{meth_name}" unless @options.quiet
Expand All @@ -334,7 +332,7 @@ def find_body(class_name, meth_name, meth_obj, body, quiet = false)

if comment
find_modifiers(comment, meth_obj)
meth_obj.comment = comment
meth_obj.comment = strip_stars comment
else
warn "No definition for #{meth_name}" unless @options.quiet
return false
Expand Down Expand Up @@ -399,7 +397,7 @@ def find_class_comment(class_name, class_mod)
comment = $1
end

class_mod.comment = comment if comment
class_mod.comment = strip_stars comment if comment
end

##
Expand Down Expand Up @@ -461,6 +459,7 @@ def handle_attr(var_name, attr_name, reader, writer)

if class_obj
comment = find_attr_comment(attr_name)
comment = strip_stars comment
att = RDoc::Attr.new '', attr_name, rw, comment
@stats.add_method att
class_obj.add_attribute(att)
Expand Down Expand Up @@ -539,6 +538,7 @@ def handle_constants(type, var_name, const_name, definition)
end

comment = find_const_comment type, const_name
comment = strip_stars comment
comment = normalize_comment comment

# In the case of rb_define_const, the definition and comment are in
Expand Down
9 changes: 4 additions & 5 deletions lib/rdoc/text.rb
Expand Up @@ -60,7 +60,6 @@ def markup text
def normalize_comment text
return text if text.empty?

text = strip_stars text
text = strip_hashes text
text = expand_tabs text
text = flush_left text
Expand Down Expand Up @@ -120,10 +119,10 @@ def strip_newlines text
# Strips /* */ style comments

def strip_stars text
text = text.gsub %r{Document-method:\s+[\w:.#]+}, ''
text.sub!(%r%/\*+%) { " " * $&.length }
text.sub!(%r%\*+/%) { " " * $&.length }
text.gsub!(/^[ \t]*\*/m) { " " * $&.length }
text = text.gsub %r%Document-method:\s+[\w:.#]+%, ''
text.sub! %r%/\*+% do " " * $&.length end
text.sub! %r%\*+/% do " " * $&.length end
text.gsub! %r%^[ \t]*\*%m do " " * $&.length end
text
end

Expand Down
4 changes: 2 additions & 2 deletions test/test_rdoc_class_module.rb
Expand Up @@ -18,9 +18,9 @@ def test_comment_equals

assert_equal "comment 1\n---\ncomment 2", cm.comment

cm.comment = "/*\n * comment 3\n */"
cm.comment = "# * comment 3"

assert_equal "comment 1\n---\ncomment 2\n---\ncomment 3", cm.comment
assert_equal "comment 1\n---\ncomment 2\n---\n* comment 3", cm.comment
end

# handle making a short module alias of yourself
Expand Down
48 changes: 48 additions & 0 deletions test/test_rdoc_parser_simple.rb
@@ -0,0 +1,48 @@
require 'tempfile'
require 'rubygems'
require 'minitest/autorun'
require 'rdoc/options'
require 'rdoc/parser'

class TestRDocParserSimple < MiniTest::Unit::TestCase

def setup
@tempfile = Tempfile.new self.class.name
filename = @tempfile.path

@top_level = RDoc::TopLevel.new filename
@fn = filename
@options = RDoc::Options.new
@stats = RDoc::Stats.new 0

RDoc::TopLevel.reset
end

def teardown
@tempfile.close
end

def test_remove_private_comments
parser = util_parser ''
text = "foo\n\n--\nbar\n++\n\nbaz\n"

expected = "foo\n\n\n\nbaz\n"

assert_equal expected, parser.remove_private_comments(text)
end

def test_remove_private_comments_star
parser = util_parser ''

text = "* foo\n* bar\n"
expected = text.dup

assert_equal expected, parser.remove_private_comments(text)
end

def util_parser(content)
RDoc::Parser::Simple.new @top_level, @fn, content, @options, @stats
end

end

20 changes: 20 additions & 0 deletions test/test_rdoc_text.rb
Expand Up @@ -133,5 +133,25 @@ def test_strip_newlines
assert_equal 'hi', strip_newlines("\n\nhi\n\n")
end

def test_strip_stars
text = <<-TEXT
/*
* * we don't worry too much.
*
* The comments associated with
*/
TEXT

expected = <<-EXPECTED
* we don't worry too much.
The comments associated with
EXPECTED

assert_equal expected, strip_stars(text)
end

end

0 comments on commit 2809c74

Please sign in to comment.