Skip to content

Commit 854b370

Browse files
committed
Support attributes defined by rb_struct_define
1 parent 41da9d0 commit 854b370

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/rdoc/parser/c.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,12 +372,20 @@ def do_classes_and_modules
372372
next
373373
end
374374

375+
var_name = $~[:var_name]
375376
type = $~[:module] ? :module : :class
376377
class_name = $~[:class_name]
377378
parent_name = $~[:parent_name] || $~[:path]
378379
under = $~[:under]
380+
attributes = $~[:attributes]
379381

380-
handle_class_module($~[:var_name], type, class_name, parent_name, under)
382+
handle_class_module(var_name, type, class_name, parent_name, under)
383+
if attributes and !parent_name # rb_struct_define *not* without_accessor
384+
true_flag = 'Qtrue'
385+
attributes.scan(/"\K\w+(?=")/) do |attr_name|
386+
handle_attr var_name, attr_name, true_flag, true_flag
387+
end
388+
end
381389
end
382390
end
383391

test/rdoc/test_rdoc_parser_c.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,12 @@ def test_do_classes_struct
311311

312312
klass = util_get_class content, 'cFoo'
313313
assert_equal "this is the Foo class", klass.comment.text
314+
315+
attributes = klass.attributes
316+
assert_equal 3, attributes.size, -> {attributes}
317+
["some", "various", "fields"].zip(attributes) do |name, attr|
318+
assert_equal RDoc::Attr.new("", name, "RW", ""), attr
319+
end
314320
end
315321

316322
def test_do_classes_struct_under
@@ -326,6 +332,12 @@ def test_do_classes_struct_under
326332
klass = util_get_class content, 'cFoo'
327333
assert_equal 'Kernel::Foo', klass.full_name
328334
assert_equal "this is the Foo class under Kernel", klass.comment.text
335+
336+
attributes = klass.attributes
337+
assert_equal 3, attributes.size, -> {attributes}
338+
["some", "various", "fields"].zip(attributes) do |name, attr|
339+
assert_equal RDoc::Attr.new("", name, "RW", ""), attr
340+
end
329341
end
330342

331343
def test_do_classes_struct_without_accessor
@@ -340,6 +352,7 @@ def test_do_classes_struct_without_accessor
340352

341353
klass = util_get_class content, 'cFoo'
342354
assert_equal "this is the Foo class", klass.comment.text
355+
assert_empty klass.attributes
343356
end
344357

345358
def test_do_classes_struct_without_accessor_under
@@ -355,6 +368,7 @@ def test_do_classes_struct_without_accessor_under
355368
klass = util_get_class content, 'cFoo'
356369
assert_equal 'Kernel::Foo', klass.full_name
357370
assert_equal "this is the Foo class under Kernel", klass.comment.text
371+
assert_empty klass.attributes
358372
end
359373

360374
def test_do_classes_class_under

0 commit comments

Comments
 (0)