Skip to content

Commit

Permalink
Fix syntax error and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
dirceu committed Feb 23, 2023
1 parent 9e77566 commit 9da4b32
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/tapioca/dsl/compilers/protobuf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def gather_constants
T.cast(desc, Google::Protobuf::EnumDescriptor).enummodule
end

results = if :Google::Protobuf.const_defined?(:AbstractMessage)
results = if Google::Protobuf.const_defined?(:AbstractMessage)
abstract_message_const = ::Google::Protobuf.const_get(:AbstractMessage)
descendants_of(abstract_message_const) - [abstract_message_const]
else
Expand All @@ -171,7 +171,7 @@ def gather_constants
T::Array[Module],
)
end

results = results.concat(enum_modules)
results.any? ? results + [Google::Protobuf::RepeatedField, Google::Protobuf::Map] : []
end
Expand Down
18 changes: 18 additions & 0 deletions spec/tapioca/dsl/compilers/protobuf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ class ProtobufSpec < ::DslSpec
assert_includes(gathered_constants, "Google::Protobuf::Map")
assert_includes(gathered_constants, "Google::Protobuf::RepeatedField")
end

it "skips AbstractMessage" do
add_ruby_file("content.rb", <<~RUBY)
Google::Protobuf::DescriptorPool.generated_pool.build do
add_file("cart.proto", :syntax => :proto3) do
add_message "MyCart" do
optional :shop_id, :int32, 1
optional :customer_id, :int32, 2
end
end
end
Cart = Google::Protobuf::DescriptorPool.generated_pool.lookup("MyCart").msgclass
RUBY

assert_equal(["Cart"], gathered_constants.reject { |constant| constant.start_with?("Google::Protobuf") })
refute_includes(gathered_constants, "Google::Protobuf::AbstractMessage")
end
end

describe "decorate" do
Expand Down

0 comments on commit 9da4b32

Please sign in to comment.