Skip to content

Commit

Permalink
Generate typespecs for messages with no fields (protocolbuffers#41)
Browse files Browse the repository at this point in the history
* Generate type for messages with no fields

* Add assertions for typespec for messages with no fields
  • Loading branch information
JayH5 authored and tony612 committed Nov 20, 2018
1 parent a9023ca commit 25598a2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/protobuf/protoc/generator/message.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ defmodule Protobuf.Protoc.Generator.Message do
Enum.map_join(struct.oneof_decl ++ fields, ", ", fn f -> ":#{f.name}" end)
end

def typespec_str([], []), do: ""
def typespec_str([], []), do: " @type t :: %__MODULE__{}\n"

def typespec_str(fields, oneofs) do
longest_field = fields |> Enum.max_by(&String.length(&1[:name]))
Expand Down
2 changes: 2 additions & 0 deletions test/protobuf/protoc/generator/message_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defmodule Protobuf.Protoc.Generator.MessageTest do
[msg] = Generator.generate(ctx, desc)
assert msg =~ "defmodule Foo do\n"
assert msg =~ "use Protobuf\n"
assert msg =~ "@type t :: %__MODULE__{}\n"
end

test "generate/2 has right syntax" do
Expand All @@ -18,6 +19,7 @@ defmodule Protobuf.Protoc.Generator.MessageTest do
[msg] = Generator.generate(ctx, desc)
assert msg =~ "defmodule Foo do\n"
assert msg =~ "use Protobuf, syntax: :proto3\n"
assert msg =~ "@type t :: %__MODULE__{}\n"
end

test "generate/2 has right name with package" do
Expand Down

0 comments on commit 25598a2

Please sign in to comment.