Skip to content

Commit 2eb2d98

Browse files
committed
Impl go_function_name
1 parent 4df9fde commit 2eb2d98

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

_tools/ruby_h_to_go/lib/ruby_h_to_go/function_definition.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ def write_go_file(dist_dir)
3838

3939
# @return [String]
4040
def generate_go_content
41-
go_function_name = snake_to_camel(name)
4241
go_function_args = args.map(&:go_function_arg)
4342

4443
go_function_typeref = typeref.go_function_typeref
@@ -119,5 +118,12 @@ def generate_go_content
119118

120119
go_function_lines.join("\n")
121120
end
121+
122+
# @return [String]
123+
def go_function_name
124+
return name if name.match?(/^[A-Z0-9_]+$/)
125+
126+
snake_to_camel(name)
127+
end
122128
end
123129
end

_tools/ruby_h_to_go/spec/ruby_h_to_go/function_definition_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,28 @@
199199
it { should eq go_content }
200200
end
201201
end
202+
203+
describe "#go_function_name" do
204+
subject { RubyHToGo::FunctionDefinition.new(definition:).go_function_name }
205+
206+
let(:definition) do
207+
RubyHeaderParser::FunctionDefinition.new(
208+
name: name,
209+
definition: "",
210+
typeref: typedef(type: "void"),
211+
args: [],
212+
)
213+
end
214+
215+
using RSpec::Parameterized::TableSyntax
216+
217+
where(:name, :expected) do
218+
"RB_FIX2INT" | "RB_FIX2INT"
219+
"rb_fix2int" | "RbFix2Int"
220+
end
221+
222+
with_them do
223+
it { should eq expected }
224+
end
225+
end
202226
end

0 commit comments

Comments
 (0)