Skip to content

Commit 9a97672

Browse files
authored
Keep same alphabetical order on options_to_str/1 (#377)
1 parent df12118 commit 9a97672

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/protobuf/protoc/generator/util.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ defmodule Protobuf.Protoc.Generator.Util do
4747
def options_to_str(opts) when is_map(opts) do
4848
opts
4949
|> Enum.reject(fn {_key, val} -> val in [nil, false] end)
50+
|> Enum.sort()
5051
|> Enum.map_join(", ", fn {key, val} -> "#{key}: #{print(val)}" end)
5152
end
5253

test/protobuf/protoc/generator/util_test.exs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,20 @@ defmodule Protobuf.Protoc.Generator.UtilTest do
5050
assert options_to_str(%{default: "42", enum: false}) == "default: 42"
5151
assert options_to_str(%{json_name: "\"theFieldName\""}) == "json_name: \"theFieldName\""
5252
end
53+
54+
test "keep options string in alphabetical order" do
55+
opts = %{
56+
syntax: :proto3,
57+
map: true,
58+
deprecated: true,
59+
protoc_gen_elixir_version: "1.2.3"
60+
}
61+
62+
sorted_str =
63+
"deprecated: true, map: true, protoc_gen_elixir_version: 1.2.3, syntax: :proto3"
64+
65+
assert options_to_str(opts) == sorted_str
66+
end
5367
end
5468

5569
describe "type_from_type_name/2" do

0 commit comments

Comments
 (0)