diff --git a/lib/langue/formatter/json/parser.ex b/lib/langue/formatter/json/parser.ex index a7d751d6..4e63f796 100644 --- a/lib/langue/formatter/json/parser.ex +++ b/lib/langue/formatter/json/parser.ex @@ -19,5 +19,6 @@ defmodule Langue.Formatter.Json.Parser do |> :jsone.decode(object_format: :tuple) |> elem(0) |> NestedParserHelper.parse() + |> Enum.uniq_by(& &1.key) end end diff --git a/lib/langue/utils/parser.ex b/lib/langue/utils/parser.ex index e65cb4de..0456a194 100644 --- a/lib/langue/utils/parser.ex +++ b/lib/langue/utils/parser.ex @@ -3,7 +3,5 @@ defmodule Langue.Formatter.Parser do alias Langue.Formatter.ParserResult, as: Output alias Langue.Formatter.SerializerResult, as: Input - @type result :: {:ok, Output.t()} | {:error, any()} - - @callback parse(Input.t()) :: result + @callback parse(Input.t()) :: Output.t() end diff --git a/lib/langue/utils/serializer.ex b/lib/langue/utils/serializer.ex index 88a28530..4328d173 100644 --- a/lib/langue/utils/serializer.ex +++ b/lib/langue/utils/serializer.ex @@ -3,7 +3,5 @@ defmodule Langue.Formatter.Serializer do alias Langue.Formatter.ParserResult, as: Input alias Langue.Formatter.SerializerResult, as: Output - @type result :: {:ok, Output.t()} | {:error, any()} - - @callback serialize(Input.t()) :: result + @callback serialize(Input.t()) :: Output.t() end diff --git a/test/langue/json/exceptions_test.exs b/test/langue/json/exceptions_test.exs index 2a18b200..23920be6 100644 --- a/test/langue/json/exceptions_test.exs +++ b/test/langue/json/exceptions_test.exs @@ -2,20 +2,28 @@ defmodule LangueTest.Formatter.Json.Exception do @moduledoc false use ExUnit.Case, async: true + alias Accent.FormatterTestHelper alias Langue.Formatter.Json + alias LangueTest.Formatter.Json.Expectation.DuplicateKey alias LangueTest.Formatter.Json.Expectation.InvalidFloatValue alias LangueTest.Formatter.Json.Expectation.InvalidIntegerValue Code.require_file("expectation_test.exs", __DIR__) test "invalid integer value" do - {expected_parse, result_parse} = Accent.FormatterTestHelper.test_serialize(InvalidIntegerValue, Json) + {expected_parse, result_parse} = FormatterTestHelper.test_serialize(InvalidIntegerValue, Json) assert expected_parse == result_parse end test "invalid float value" do - {expected_parse, result_parse} = Accent.FormatterTestHelper.test_serialize(InvalidFloatValue, Json) + {expected_parse, result_parse} = FormatterTestHelper.test_serialize(InvalidFloatValue, Json) + + assert expected_parse == result_parse + end + + test "duplicate key" do + {expected_parse, result_parse} = FormatterTestHelper.test_parse(DuplicateKey, Json) assert expected_parse == result_parse end diff --git a/test/langue/json/expectation_test.exs b/test/langue/json/expectation_test.exs index 5d039246..d2a4e3cf 100644 --- a/test/langue/json/expectation_test.exs +++ b/test/langue/json/expectation_test.exs @@ -126,6 +126,27 @@ defmodule LangueTest.Formatter.Json.Expectation do end end + defmodule DuplicateKey do + @moduledoc false + use Langue.Expectation.Case + + def render do + """ + { + "test": "foo", + "test": "bar", + "test": "baz" + } + """ + end + + def entries do + [ + %Entry{index: 1, key: "test", value: "foo", value_type: "string"} + ] + end + end + defmodule InvalidFloatValue do @moduledoc false use Langue.Expectation.Case