Skip to content
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
1 change: 1 addition & 0 deletions lib/protobuf/protoc/generator/util.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ defmodule Protobuf.Protoc.Generator.Util do
def options_to_str(opts) when is_map(opts) do
opts
|> Enum.reject(fn {_key, val} -> val in [nil, false] end)
|> Enum.sort()
|> Enum.map_join(", ", fn {key, val} -> "#{key}: #{print(val)}" end)
end

Expand Down
14 changes: 14 additions & 0 deletions test/protobuf/protoc/generator/util_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ defmodule Protobuf.Protoc.Generator.UtilTest do
assert options_to_str(%{default: "42", enum: false}) == "default: 42"
assert options_to_str(%{json_name: "\"theFieldName\""}) == "json_name: \"theFieldName\""
end

test "keep options string in alphabetical order" do
opts = %{
syntax: :proto3,
map: true,
deprecated: true,
protoc_gen_elixir_version: "1.2.3"
}

sorted_str =
"deprecated: true, map: true, protoc_gen_elixir_version: 1.2.3, syntax: :proto3"

assert options_to_str(opts) == sorted_str
end
end

describe "type_from_type_name/2" do
Expand Down