Skip to content

Commit 5491f83

Browse files
author
Zachary Scott
committed
Merge pull request #381 from sho-h/fix-rb_attr
parse rb_intern_const correctly.
2 parents 382e6ed + c1379a5 commit 5491f83

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

lib/rdoc/parser/c.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ def handle_attr(var_name, attr_name, read, write)
840840
comment = find_attr_comment var_name, attr_name
841841
comment.normalize
842842

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

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

test/test_rdoc_parser_c.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,50 @@ def test_do_attr_rb_attr
175175
assert_equal 'This is a writer', writer.comment.text
176176
end
177177

178+
def test_do_attr_rb_attr_2
179+
content = <<-EOF
180+
void Init_Blah(void) {
181+
cBlah = rb_define_class("Blah", rb_cObject);
182+
183+
/*
184+
* This is an accessor
185+
*/
186+
rb_attr(cBlah, rb_intern_const("accessor"), 1, 1, Qfalse);
187+
188+
/*
189+
* This is a reader
190+
*/
191+
rb_attr(cBlah, rb_intern_const("reader"), 1, 0, Qfalse);
192+
193+
/*
194+
* This is a writer
195+
*/
196+
rb_attr(cBlah, rb_intern_const("writer"), 0, 1, Qfalse);
197+
}
198+
EOF
199+
200+
klass = util_get_class content, 'cBlah'
201+
202+
attrs = klass.attributes
203+
assert_equal 3, attrs.length, attrs.inspect
204+
205+
accessor = attrs.shift
206+
assert_equal 'accessor', accessor.name
207+
assert_equal 'RW', accessor.rw
208+
assert_equal 'This is an accessor', accessor.comment.text
209+
assert_equal @top_level, accessor.file
210+
211+
reader = attrs.shift
212+
assert_equal 'reader', reader.name
213+
assert_equal 'R', reader.rw
214+
assert_equal 'This is a reader', reader.comment.text
215+
216+
writer = attrs.shift
217+
assert_equal 'writer', writer.name
218+
assert_equal 'W', writer.rw
219+
assert_equal 'This is a writer', writer.comment.text
220+
end
221+
178222
def test_do_attr_rb_define_attr
179223
content = <<-EOF
180224
void Init_Blah(void) {

0 commit comments

Comments
 (0)