Skip to content

Commit 4e8c140

Browse files
committed
Impl should_generate_struct?
1 parent 4b896ce commit 4e8c140

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

_tools/ruby_h_to_go/lib/ruby_header_parser/data.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,14 @@ def should_generate_function?(function_name)
3232

3333
data["function"]["allow_name"].any? { |format| format === function_name }
3434
end
35+
36+
# Whether generate C struct to go
37+
# @param struct_name [String]
38+
# @return [Boolean]
39+
def should_generate_struct?(struct_name)
40+
struct_name = struct_name.downcase
41+
42+
data["struct"]["allow_name"].any? { |format| format === struct_name }
43+
end
3544
end
3645
end

_tools/ruby_h_to_go/lib/ruby_header_parser/data.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ function:
3434
3: array
3535
rb_funcallv_public:
3636
3: array
37+
38+
struct:
39+
allow_name:
40+
- !ruby/regexp /^rb_/

_tools/ruby_h_to_go/spec/ruby_header_parser/data_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,20 @@
4242
it { should eq false }
4343
end
4444
end
45+
46+
describe "#should_generate_struct?" do
47+
subject { data.should_generate_struct?(struct_name) }
48+
49+
context "rb struct" do
50+
let(:struct_name) { "rb_random_struct" }
51+
52+
it { should eq true }
53+
end
54+
55+
context "non rb struct" do
56+
let(:struct_name) { "fuga" }
57+
58+
it { should eq false }
59+
end
60+
end
4561
end

0 commit comments

Comments
 (0)