Fix JSON comparison bug for non-comparable types

3-room
Bram 2024-04-26 15:26:52 +02:00
parent df71779620
commit 2ff381d7f5
2 changed files with 15 additions and 5 deletions

View File

@ -434,12 +434,16 @@ field =
, description = description , description = description
, encoder = , encoder =
\o -> \o ->
let
v =
encoder o
in
-- If the value matches the default, do not record -- If the value matches the default, do not record
if o == Tuple.first default then if E.encode 0 v == E.encode 0 (encoder (Tuple.first default)) then
Nothing Nothing
else else
Maybe.Just (encoder o) Maybe.Just v
, decoder = D.opFieldWithDefault fieldName default decoder , decoder = D.opFieldWithDefault fieldName default decoder
, docs = docs , docs = docs
, requiredness = , requiredness =

View File

@ -89,11 +89,17 @@ suite =
, fuzz fuzzer , fuzz fuzzer
"Room -> JSON -> Room is equal" "Room -> JSON -> Room is equal"
(\room -> (\room ->
room let
|> Room.encode value : E.Value
value =
Room.encode room
in
value
|> D.decodeValue Room.decode |> D.decodeValue Room.decode
|> Result.toMaybe |> Result.toMaybe
|> Maybe.map Tuple.first |> Maybe.map Tuple.first
|> Expect.equal (Just room) |> Maybe.map Room.encode
|> Maybe.map (E.encode 0)
|> Expect.equal (Just <| E.encode 0 value)
) )
] ]