Elm Exactly
Results / elm-bytes /

DecodeFailTest

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
`Bytes.Decode.fail` makes `decode` return `Nothing` even when there are bytes left to read.

Results

elm-0.19.1

passran in 61 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
DecodeFailTest: "Nothing"

elm-0.19.2

passran in 42 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
DecodeFailTest: "Nothing"

elm-0.19.3

passran in 46 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
DecodeFailTest: "Nothing"

lamdera-1.5.0

passran in 59 ms
Output
DecodeFailTest: "Nothing"

Discussions

Discuss this test·Search the discussions on GitHub

Discussions are on GitHub; one about this test has [t:elm-bytes/DecodeFailTest] in its title.

Source

The -- CHECK: lines give the expected output.

module DecodeFailTest exposing (main)
{-| `Bytes.Decode.fail` makes `decode` return `Nothing` even when there are bytes left to read.
-}
-- CHECK: DecodeFailTest: "Nothing"
import Bytes exposing (Bytes)
import Bytes.Decode as D
import Bytes.Encode as E
import Html exposing (text)
main =
let
bytes =
E.encode (E.unsignedInt8 0)
decoder =
D.fail
result =
D.decode decoder bytes
output =
case result of
Nothing ->
"Nothing"
Just _ ->
"FAIL"
_ =
Debug.log "DecodeFailTest" output
in
text output