mirror of
https://github.com/mirego/accent.git
synced 2024-08-16 22:40:36 +03:00
Fix duplicate key in json parse
This commit is contained in:
parent
e3fcf4fed8
commit
adc0c1a90e
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user