Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In the bool case we can just put the expected and actual values inside the string #159

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading