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

parse rb_intern_const correctly. #381

Merged
merged 1 commit into from Mar 19, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rdoc/parser/c.rb
Expand Up @@ -650,7 +650,7 @@ def handle_attr(var_name, attr_name, read, write)
comment = find_attr_comment var_name, attr_name
comment.normalize

name = attr_name.gsub(/rb_intern\("([^"]+)"\)/, '\1')
name = attr_name.gsub(/rb_intern(?:_const)?\("([^"]+)"\)/, '\1')

attr = RDoc::Attr.new '', name, rw, comment

Expand Down
44 changes: 44 additions & 0 deletions test/test_rdoc_parser_c.rb
Expand Up @@ -126,6 +126,50 @@ def test_do_attr_rb_attr
assert_equal 'This is a writer', writer.comment.text
end

def test_do_attr_rb_attr_2
content = <<-EOF
void Init_Blah(void) {
cBlah = rb_define_class("Blah", rb_cObject);

/*
* This is an accessor
*/
rb_attr(cBlah, rb_intern_const("accessor"), 1, 1, Qfalse);

/*
* This is a reader
*/
rb_attr(cBlah, rb_intern_const("reader"), 1, 0, Qfalse);

/*
* This is a writer
*/
rb_attr(cBlah, rb_intern_const("writer"), 0, 1, Qfalse);
}
EOF

klass = util_get_class content, 'cBlah'

attrs = klass.attributes
assert_equal 3, attrs.length, attrs.inspect

accessor = attrs.shift
assert_equal 'accessor', accessor.name
assert_equal 'RW', accessor.rw
assert_equal 'This is an accessor', accessor.comment.text
assert_equal @top_level, accessor.file

reader = attrs.shift
assert_equal 'reader', reader.name
assert_equal 'R', reader.rw
assert_equal 'This is a reader', reader.comment.text

writer = attrs.shift
assert_equal 'writer', writer.name
assert_equal 'W', writer.rw
assert_equal 'This is a writer', writer.comment.text
end

def test_do_attr_rb_define_attr
content = <<-EOF
void Init_Blah(void) {
Expand Down