Skip to content

Commit

Permalink
Merge pull request #381 from sho-h/fix-rb_attr
Browse files Browse the repository at this point in the history
parse rb_intern_const correctly.
  • Loading branch information
Zachary Scott committed Mar 19, 2016
2 parents 382e6ed + c1379a5 commit 5491f83
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rdoc/parser/c.rb
Expand Up @@ -840,7 +840,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 @@ -175,6 +175,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

0 comments on commit 5491f83

Please sign in to comment.