BytesHostEndiannessTest
`Bytes.getHostEndianness` is a `Task` that succeeds with an `Endianness`, `LE` on a little-endian machine. The program performs the task once at start-up and logs the result as `"LE"` or `"BE"`. The expected output is `"LE"`, so the test assumes a little-endian host; on a big-endian machine it would fail although `BE` is the correct answer there.
Results
elm-0.19.1
passran in 43 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. host endianness: "LE"
elm-0.19.2
passran in 51 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. host endianness: "LE"
elm-0.19.3
passran in 59 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. host endianness: "LE"
lamdera-1.5.0
passran in 69 msOutput
host endianness: "LE"
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-bytes/BytesHostEndiannessTest] in its title.
Source
The -- CHECK: lines give the expected output.
module BytesHostEndiannessTest exposing (main)
{-| `Bytes.getHostEndianness` is a `Task` that succeeds with an `Endianness`, `LE` on a
little-endian machine.
The program performs the task once at start-up and logs the result as `"LE"` or `"BE"`. The
expected output is `"LE"`, so the test assumes a little-endian host; on a big-endian machine it
would fail although `BE` is the correct answer there.
-}
-- MODE-GUARD: a Char equality must give the same answer as under --optimize
-- NO-SKIP: an edge case every compiler must run
-- CHECK: host endianness: "LE"
import Bytes exposing (Endianness(..))
import Task
type Msg
= Got Endianness
main : Program () () Msg
main =
Platform.worker
{ init = \_ -> ( (), Task.perform Got Bytes.getHostEndianness )
, update =
\(Got e) model ->
let
_ =
Debug.log "host endianness"
(case e of
LE ->
"LE"
BE ->
"BE"
)
in
( model, Cmd.none )
, subscriptions = \_ -> Sub.none
}