Skip to content

Commit

Permalink
In the bool case we can just put the expected and actual values insid…
Browse files Browse the repository at this point in the history
…e the string
  • Loading branch information
miniBill committed Nov 5, 2024
1 parent e721bb8 commit 2749a92
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions src/SchemaUtils.elm
Original file line number Diff line number Diff line change
Expand Up @@ -1112,21 +1112,38 @@ typeToDecoder qualify type_ =
base Elm.float String.fromFloat Gen.String.call_.fromFloat const Gen.Json.Decode.float

Common.Bool { const } ->
base Elm.bool
(\b ->
let
boolToString : Bool -> String
boolToString b =
if b then
"true"

else
"false"
)
(\s ->
Elm.ifThen s
(Elm.string "true")
(Elm.string "false")
)
const
Gen.Json.Decode.bool
in
(case const of
Nothing ->
Gen.Json.Decode.bool

Just expected ->
Gen.Json.Decode.bool
|> Gen.Json.Decode.andThen
(\actual ->
Elm.ifThen
(Elm.Op.equal actual (Elm.bool expected))
(Gen.Json.Decode.succeed actual)
(Gen.Json.Decode.call_.fail
(Elm.string
("Unexpected value: expected "
++ boolToString expected
++ " got "
++ boolToString (not expected)
)
)
)
)
)
|> CliMonad.succeed

Common.Null ->
CliMonad.succeed (Gen.Json.Decode.null Elm.unit)
Expand Down

0 comments on commit 2749a92

Please sign in to comment.