Skip to content

Commit c1379a5

Browse files
committed
parse rb_intern_const correctly.
1 parent 0737e39 commit c1379a5

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
@@ -650,7 +650,7 @@ def handle_attr(var_name, attr_name, read, write)
650650
comment = find_attr_comment var_name, attr_name
651651
comment.normalize
652652

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

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

test/test_rdoc_parser_c.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,50 @@ def test_do_attr_rb_attr
126126
assert_equal 'This is a writer', writer.comment.text
127127
end
128128

129+
def test_do_attr_rb_attr_2
130+
content = <<-EOF
131+
void Init_Blah(void) {
132+
cBlah = rb_define_class("Blah", rb_cObject);
133+
134+
/*
135+
* This is an accessor
136+
*/
137+
rb_attr(cBlah, rb_intern_const("accessor"), 1, 1, Qfalse);
138+
139+
/*
140+
* This is a reader
141+
*/
142+
rb_attr(cBlah, rb_intern_const("reader"), 1, 0, Qfalse);
143+
144+
/*
145+
* This is a writer
146+
*/
147+
rb_attr(cBlah, rb_intern_const("writer"), 0, 1, Qfalse);
148+
}
149+
EOF
150+
151+
klass = util_get_class content, 'cBlah'
152+
153+
attrs = klass.attributes
154+
assert_equal 3, attrs.length, attrs.inspect
155+
156+
accessor = attrs.shift
157+
assert_equal 'accessor', accessor.name
158+
assert_equal 'RW', accessor.rw
159+
assert_equal 'This is an accessor', accessor.comment.text
160+
assert_equal @top_level, accessor.file
161+
162+
reader = attrs.shift
163+
assert_equal 'reader', reader.name
164+
assert_equal 'R', reader.rw
165+
assert_equal 'This is a reader', reader.comment.text
166+
167+
writer = attrs.shift
168+
assert_equal 'writer', writer.name
169+
assert_equal 'W', writer.rw
170+
assert_equal 'This is a writer', writer.comment.text
171+
end
172+
129173
def test_do_attr_rb_define_attr
130174
content = <<-EOF
131175
void Init_Blah(void) {

0 commit comments

Comments
 (0)