DecodeSucceedTest
Bytes.Decode.succeed produces its value without reading the input. `succeed 42` is run on a one-byte input, and the logged result is 42. A failed decode would log -1.
Results
elm-0.19.1
passran in 45 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. DecodeSucceedTest: 42
elm-0.19.2
passran in 57 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. DecodeSucceedTest: 42
elm-0.19.3
passran in 54 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. DecodeSucceedTest: 42
lamdera-1.5.0
passran in 41 msOutput
DecodeSucceedTest: 42
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-bytes/DecodeSucceedTest] in its title.
Source
The -- CHECK: lines give the expected output.
module DecodeSucceedTest exposing (main)
{-| Bytes.Decode.succeed produces its value without reading the input.
`succeed 42` is run on a one-byte input, and the logged result is 42. A failed
decode would log -1.
-}
-- CHECK: DecodeSucceedTest: 42
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.succeed 42
result =
D.decode decoder bytes
|> Maybe.withDefault -1
_ =
Debug.log "DecodeSucceedTest" result
in
text (String.fromInt result)