1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/rdoc] Support attributes defined by rb_struct_define

https://github.com/ruby/rdoc/commit/854b370763
This commit is contained in:
Nobuyoshi Nakada 2022-06-28 19:40:27 +09:00 committed by git
parent 98bf8c83fa
commit 131422ceea
2 changed files with 23 additions and 1 deletions

View file

@ -372,12 +372,20 @@ class RDoc::Parser::C < RDoc::Parser
next next
end end
var_name = $~[:var_name]
type = $~[:module] ? :module : :class type = $~[:module] ? :module : :class
class_name = $~[:class_name] class_name = $~[:class_name]
parent_name = $~[:parent_name] || $~[:path] parent_name = $~[:parent_name] || $~[:path]
under = $~[:under] under = $~[:under]
attributes = $~[:attributes]
handle_class_module($~[:var_name], type, class_name, parent_name, under) handle_class_module(var_name, type, class_name, parent_name, under)
if attributes and !parent_name # rb_struct_define *not* without_accessor
true_flag = 'Qtrue'
attributes.scan(/"\K\w+(?=")/) do |attr_name|
handle_attr var_name, attr_name, true_flag, true_flag
end
end
end end
end end

View file

@ -311,6 +311,12 @@ VALUE cFoo = rb_struct_define(
klass = util_get_class content, 'cFoo' klass = util_get_class content, 'cFoo'
assert_equal "this is the Foo class", klass.comment.text assert_equal "this is the Foo class", klass.comment.text
attributes = klass.attributes
assert_equal 3, attributes.size, -> {attributes}
["some", "various", "fields"].zip(attributes) do |name, attr|
assert_equal RDoc::Attr.new("", name, "RW", ""), attr
end
end end
def test_do_classes_struct_under def test_do_classes_struct_under
@ -326,6 +332,12 @@ VALUE cFoo = rb_struct_define_under(
klass = util_get_class content, 'cFoo' klass = util_get_class content, 'cFoo'
assert_equal 'Kernel::Foo', klass.full_name assert_equal 'Kernel::Foo', klass.full_name
assert_equal "this is the Foo class under Kernel", klass.comment.text assert_equal "this is the Foo class under Kernel", klass.comment.text
attributes = klass.attributes
assert_equal 3, attributes.size, -> {attributes}
["some", "various", "fields"].zip(attributes) do |name, attr|
assert_equal RDoc::Attr.new("", name, "RW", ""), attr
end
end end
def test_do_classes_struct_without_accessor def test_do_classes_struct_without_accessor
@ -340,6 +352,7 @@ VALUE cFoo = rb_struct_define_without_accessor(
klass = util_get_class content, 'cFoo' klass = util_get_class content, 'cFoo'
assert_equal "this is the Foo class", klass.comment.text assert_equal "this is the Foo class", klass.comment.text
assert_empty klass.attributes
end end
def test_do_classes_struct_without_accessor_under def test_do_classes_struct_without_accessor_under
@ -355,6 +368,7 @@ VALUE cFoo = rb_struct_define_without_accessor_under(
klass = util_get_class content, 'cFoo' klass = util_get_class content, 'cFoo'
assert_equal 'Kernel::Foo', klass.full_name assert_equal 'Kernel::Foo', klass.full_name
assert_equal "this is the Foo class under Kernel", klass.comment.text assert_equal "this is the Foo class under Kernel", klass.comment.text
assert_empty klass.attributes
end end
def test_do_classes_class_under def test_do_classes_class_under