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

Added YARD::Parser::CParser#find_override_comments #177

Closed
wants to merge 1 commit into from
Closed
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
19 changes: 15 additions & 4 deletions lib/yard/parser/c_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ def find_method_body(object, func_name, content = @content)
# distinct (for example Kernel.hash and Kernel.object_id share the same
# implementation

# override_comment = find_override_comment(object)
# comment = override_comment if override_comment
override_comment = find_override_comment(object)
comment = override_comment if override_comment

object.docstring = parse_comments(object, comment) if comment
object.source = body_text
Expand All @@ -168,11 +168,22 @@ def find_method_body(object, func_name, content = @content)
find_method_body(object, $2, content)
else
# No body, but might still have an override comment
# comment = find_override_comment(object)
comment = nil
comment = find_override_comment(object)
object.docstring = parse_comments(object, comment) if comment
end
end

def find_override_comment(object, content = @content)
name = Regexp.escape(object.name.to_s)
class_name = object.parent.path
if content =~ %r{Document-method:\s+#{class_name}(?:\.|::|#)#{name}\s*?\n((?>.*?\*/))}m then
$1
elsif content =~ %r{Document-method:\s#{name}\s*?\n((?>.*?\*/))}m then
$1
else
nil
end
end

def parse_comments(object, comments)
spaces = nil
Expand Down
38 changes: 38 additions & 0 deletions spec/parser/c_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
before(:all) do
file = File.join(File.dirname(__FILE__), 'examples', 'array.c.txt')
@parser = Parser::CParser.new(IO.read(file)).parse

override_file = File.join(File.dirname(__FILE__), 'examples', 'override.c.txt')
@override_parser = Parser::CParser.new(IO.read(override_file)).parse
end

describe '#parse' do
Expand All @@ -20,4 +23,39 @@
obj.tags(:overload).size.should > 1
end
end

describe '#find_override_comment' do
it "should parse GMP::Z class" do
z = YARD::Registry.at('GMP::Z')
z.should_not be_nil
z.docstring.should_not be_blank
end

it "should parse GMP::Z methods w/ bodies" do
add = YARD::Registry.at('GMP::Z#+')
add.docstring.should_not be_blank
add.source.should_not be_nil
add.source.should_not be_empty

add_self = YARD::Registry.at('GMP::Z#+')
add_self.docstring.should_not be_blank
add_self.source.should_not be_nil
add_self.source.should_not be_empty

sqrtrem = YARD::Registry.at('GMP::Z#+')
sqrtrem.docstring.should_not be_blank
sqrtrem.source.should_not be_nil
sqrtrem.source.should_not be_empty
end

it "should parse GMP::Z methods w/o bodies" do
neg = YARD::Registry.at('GMP::Z#neg')
neg.docstring.should_not be_blank
neg.source.should be_nil

neg_self = YARD::Registry.at('GMP::Z#neg')
neg_self.docstring.should_not be_blank
neg_self.source.should be_nil
end
end
end
Loading