Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix C const comment #1062

Merged
merged 3 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lib/rdoc/parser/c.rb
Original file line number Diff line number Diff line change
Expand Up @@ -938,14 +938,13 @@ def handle_constants(type, var_name, const_name, definition)
# "/* definition: comment */" form. The literal ':' and '\' characters
# can be escaped with a backslash.
if type.downcase == 'const' then
no_match, new_definition, new_comment = comment.text.split(/(\A.*):/)
if /\A(.+?)?:(?!\S)/ =~ comment.text
new_definition, new_comment = $1, $'

if no_match and no_match.empty? then
if new_definition.empty? then # Default to literal C definition
if !new_definition # Default to literal C definition
new_definition = definition
else
new_definition = new_definition.gsub("\:", ":")
new_definition = new_definition.gsub("\\", '\\')
new_definition = new_definition.gsub(/\\([\\:])/, '\1')
end

new_definition.sub!(/\A(\s+)/, '')
Expand Down
8 changes: 7 additions & 1 deletion test/rdoc/test_rdoc_parser_c.rb
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def test_do_classes_module_under
end

def test_do_constants
content = <<-EOF
content = <<-'EOF'
#include <ruby.h>

void Init_foo(){
Expand All @@ -475,6 +475,9 @@ def test_do_constants
/* TEST\:TEST: Checking to see if escaped colon works */
rb_define_const(cFoo, "TEST", rb_str_new2("TEST:TEST"));

/* TEST: TEST:Checking to see if only word-ending colon works */
rb_define_const(cFoo, "TEST2", rb_str_new2("TEST:TEST"));

/* \\: The file separator on MS Windows */
rb_define_const(cFoo, "MSEPARATOR", rb_str_new2("\\"));

Expand Down Expand Up @@ -538,6 +541,9 @@ def test_do_constants
assert_equal ['TEST', 'TEST:TEST',
'Checking to see if escaped colon works '],
constants.shift
assert_equal ['TEST2', 'TEST',
'TEST:Checking to see if only word-ending colon works '],
constants.shift
assert_equal ['MSEPARATOR', '\\',
'The file separator on MS Windows '],
constants.shift
Expand Down