Elm Exactly
Results / elm /

PortEchoArrayStringTest

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
An `Array String` sent out through a port comes back unchanged through an incoming
port, for each of two sample values.

The program assumes a host that passes every value sent out on the `echoOut`
port straight back in on the `echoIn` port; without one, nothing after `init`
is logged. It sends the values in `values` one at a time, sending the next only
after the previous one has come back, logs each value received, logs
`"done"` after the last one, and then drops its subscription.

The values are an empty array and a three-element array.

The arrays are built by the program with `Array.empty` and `Array.fromList`, library functions
outside A Standard Definition of Elm? (Appendix C, Library functions), so this test is not
tagged `elm-spec`: it needs only the port echo, not flags. `PortEchoArrayStringFlagsTest` checks
the same round trip with arrays received as flags.

Results

elm-0.19.1

passran in 74 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
PortEchoArrayStringTest got: Array.fromList []
PortEchoArrayStringTest got: Array.fromList ["a","b","c"]
PortEchoArrayStringTest: "done"

elm-0.19.2

passran in 47 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
PortEchoArrayStringTest got: Array.fromList []
PortEchoArrayStringTest got: Array.fromList ["a","b","c"]
PortEchoArrayStringTest: "done"

elm-0.19.3

passran in 73 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
PortEchoArrayStringTest got: Array.fromList []
PortEchoArrayStringTest got: Array.fromList ["a","b","c"]
PortEchoArrayStringTest: "done"

lamdera-1.5.0

passran in 55 ms
Output
PortEchoArrayStringTest got: Array.fromList []
PortEchoArrayStringTest got: Array.fromList ["a","b","c"]
PortEchoArrayStringTest: "done"

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

port module PortEchoArrayStringTest exposing (main)
{-| An `Array String` sent out through a port comes back unchanged through an incoming
port, for each of two sample values.
The program assumes a host that passes every value sent out on the `echoOut`
port straight back in on the `echoIn` port; without one, nothing after `init`
is logged. It sends the values in `values` one at a time, sending the next only
after the previous one has come back, logs each value received, logs
`"done"` after the last one, and then drops its subscription.
The values are an empty array and a three-element array.
The arrays are built by the program with `Array.empty` and `Array.fromList`, library functions
outside A Standard Definition of Elm? (Appendix C, Library functions), so this test is not
tagged `elm-spec`: it needs only the port echo, not flags. `PortEchoArrayStringFlagsTest` checks
the same round trip with arrays received as flags.
-}
-- CHECK: PortEchoArrayStringTest got: Array.fromList []
-- CHECK: PortEchoArrayStringTest got: Array.fromList ["a","b","c"]
-- CHECK: PortEchoArrayStringTest: "done"
import Array exposing (Array)
import Platform
port echoOut : Array String -> Cmd msg
port echoIn : (Array String -> msg) -> Sub msg
values : List (Array String)
values =
[ Array.empty
, Array.fromList [ "a", "b", "c" ]
]
type Msg
= Got (Array String)
type alias Model =
{ remaining : List (Array String), done : Bool }
init : () -> ( Model, Cmd Msg )
init _ =
case values of
first :: rest ->
( { remaining = rest, done = False }, echoOut first )
[] ->
( { remaining = [], done = True }, Cmd.none )
update : Msg -> Model -> ( Model, Cmd Msg )
update (Got v) model =
let
_ =
Debug.log "PortEchoArrayStringTest got" (v)
in
case model.remaining of
next :: rest ->
( { model | remaining = rest }, echoOut next )
[] ->
let
_ =
Debug.log "PortEchoArrayStringTest" "done"
in
( { model | done = True }, Cmd.none )
subscriptions : Model -> Sub Msg
subscriptions model =
if model.done then
Sub.none
else
echoIn Got
main : Program () Model Msg
main =
Platform.worker
{ init = init
, update = update
, subscriptions = subscriptions
}