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

Add tests to document behavior of Codec.nullableField and Code.maybeField #17

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
48 changes: 48 additions & 0 deletions tests/CodecBaseTests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,30 @@ objectTests =
Err _ ->
Expect.pass
)
, test "a nullableField returns the value" <|
\_ ->
"""{ "f": 1 }"""
|> decodeString nullableCodec
|> (\r ->
case r of
Ok { f } ->
Expect.equal (Just 1) f

Err _ ->
Expect.fail "Should have suceeded"
)
, test "a nullableField hides decoder errors" <|
\_ ->
"""{ "f": "string" }"""
|> decodeString nullableCodec
|> (\r ->
case r of
Ok _ ->
Expect.pass

Err _ ->
Expect.fail "Functionality has changed"
)
, test "a nullableField produces a field with a null value on encoding Nothing" <|
\_ ->
{ f = Nothing }
Expand All @@ -206,6 +230,30 @@ objectTests =
"{}"
|> decodeString maybeCodec
|> Expect.equal (Ok { f = Nothing })
, test "a maybeField returns the value" <|
\_ ->
"""{ "f": 1 }"""
|> decodeString maybeCodec
|> (\r ->
case r of
Ok { f } ->
Expect.equal (Just 1) f

Err _ ->
Expect.fail "Should have succeeded"
)
, test "a maybeField hides decoder errors" <|
\_ ->
"""{ "f": "string" }"""
|> decodeString maybeCodec
|> (\r ->
case r of
Ok _ ->
Expect.pass

Err _ ->
Expect.fail "Functionality has changed"
)
, test "a maybeField doesn't produce a field on encoding Nothing" <|
\_ ->
{ f = Nothing }
Expand Down