yard
yard copied to clipboard
@!group directives not working for constants defined in C/C++ source
@!group and !endgroup directives in C/C++ source is ignored. When the statement for // @!group Foos is processed it's relegated to the YARD::Handlers::C::OverrideCommentHandler handler. In its process method it all short circuits early at return if statement.overrides.empty?
I'm not sure if this should be handled by another handler. Any advice would be appreciated. I'm trying to figure out a PR for this.
Steps to reproduce
Add to c_parser_spec.rb:
describe "Group directives" do
it "groups constants" do
parse <<-eof
void Init_Mask(void)
{
rb_cExample = rb_define_class("Example", rb_cObject);
// @!group Foos
/* 1: Foobar description. */
rb_define_const(rb_cExample, "FOOBAR", INT2NUM(1));
/* 2: Foobiz description. */
rb_define_const(rb_cExample, "FOOBIZ", INT2NUM(2));
// @!endgroup
/* 3: Hello description. */
rb_define_const(rb_cExample, "HELLO", INT2NUM(3));
}
eof
constant = Registry.at('Example::FOOBAR')
expect(constant.value).to eq '1'
expect(constant.docstring).to eq "Foobar description."
expect(constant.group).to eq "Foos"
constant = Registry.at('Example::FOOBIZ')
expect(constant.value).to eq '2'
expect(constant.docstring).to eq "Foobiz description."
expect(constant.group).to eq "Foos"
constant = Registry.at('Example::HELLO')
expect(constant.value).to eq '3'
expect(constant.docstring).to eq "Hello description."
end
end
Actual Output
constant.group will return nil for all constants parsed with the C parser.
Expected Output
constant.group should yield the name of the last processed @!group directive.
Environment details:
- OS: Windows 10
- Ruby version (
ruby -v): ruby 2.5.1p57 (2018-03-29 revision 63029) [x64-mingw32] - YARD version (
yard -v): yard 0.9.19
I have read the Contributing Guide.
A kludgy workaround:
describe "Group directives" do
it "groups constants" do
parse <<-eof
void Init_Mask(void)
{
rb_cExample = rb_define_class("Example", rb_cObject);
/* 1: @!group Foos
* Foobar description. */
rb_define_const(rb_cExample, "FOOBAR", INT2NUM(1));
/* 2: Foobiz description. */
rb_define_const(rb_cExample, "FOOBIZ", INT2NUM(2));
/* 3: @!endgroup
* Hello description. */
rb_define_const(rb_cExample, "HELLO", INT2NUM(3));
}
eof
constant = Registry.at('Example::FOOBAR')
expect(constant.value).to eq '1'
expect(constant.docstring).to eq "Foobar description."
expect(constant.group).to eq "Foos"
constant = Registry.at('Example::FOOBIZ')
expect(constant.value).to eq '2'
expect(constant.docstring).to eq "Foobiz description."
expect(constant.group).to eq "Foos"
constant = Registry.at('Example::HELLO')
expect(constant.value).to eq '3'
expect(constant.docstring).to eq "Hello description."
expect(constant.group).to eq nil
end