PortPipeValueTest
Tags:elm-spec
Checks, in A Standard Definition of Elm?:rule e-dec-valuerule e-enc-valuerule p-in-acceptrule p-out
Translated into Lean for the mechanisation of the book: see its Lean translation.
A JSON value received at `Json.Encode.Value` goes out again as the same JSON value. The test driver sends each `HOST-SEND` value in on the incoming port and prints each value the program sends out (plans/host-pipe-tests.md); the program passes every value it receives straight back out. No library function and no `Debug.log` is involved: the driver sees `Enc(Dec(j))`. A Standard Definition of Elm?, rules e-dec-value and e-enc-value: every JSON value decodes at `Value` as itself, and a `Value` is sent as the JSON value it is. Objects have no order, so the driver prints keys in increasing order; the array `[1,true,null]`, which no other Elm type decodes, passes through unchanged. <https://elm-test-suite.netlify.app/standard/rules/e-dec-value>
Results
elm-0.19.1
passran in 60 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
valueOut sent: {"a":"x","b":[1,true,null],"c":{}}
valueOut sent: "plain"
valueOut sent: -2.5
valueOut sent: null
valueOut sent: [[],{"k":[{}]}]
elm-0.19.2
passran in 60 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
valueOut sent: {"a":"x","b":[1,true,null],"c":{}}
valueOut sent: "plain"
valueOut sent: -2.5
valueOut sent: null
valueOut sent: [[],{"k":[{}]}]
elm-0.19.3
passran in 64 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
valueOut sent: {"a":"x","b":[1,true,null],"c":{}}
valueOut sent: "plain"
valueOut sent: -2.5
valueOut sent: null
valueOut sent: [[],{"k":[{}]}]
lamdera-1.5.0
passran in 63 msOutput
valueOut sent: {"a":"x","b":[1,true,null],"c":{}}
valueOut sent: "plain"
valueOut sent: -2.5
valueOut sent: null
valueOut sent: [[],{"k":[{}]}]
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm/PortPipeValueTest] in its title.
Source
The -- CHECK: lines give the expected output.
port module PortPipeValueTest exposing (main)
{-| A JSON value received at `Json.Encode.Value` goes out again as the same JSON value.
The test driver sends each `HOST-SEND` value in on the incoming port and prints each value the
program sends out (plans/host-pipe-tests.md); the program passes every value it receives straight
back out. No library function and no `Debug.log` is involved: the driver sees `Enc(Dec(j))`.
A Standard Definition of Elm?, rules e-dec-value and e-enc-value: every JSON value decodes at
`Value` as itself, and a `Value` is sent as the JSON value it is. Objects have no order, so the
driver prints keys in increasing order; the array `[1,true,null]`, which no other Elm type decodes,
passes through unchanged. <https://elm-test-suite.netlify.app/standard/rules/e-dec-value>
-}
-- TAGS: elm-spec, e-dec-value, e-enc-value, p-in-accept, p-out
-- HOST-SEND: valueIn {"b":[1,true,null],"a":"x","c":{}}
-- HOST-SEND: valueIn "plain"
-- HOST-SEND: valueIn -2.5
-- HOST-SEND: valueIn null
-- HOST-SEND: valueIn [[],{"k":[{}]}]
-- CHECK: valueOut sent: {"a":"x","b":[1,true,null],"c":{}}
-- CHECK: valueOut sent: "plain"
-- CHECK: valueOut sent: -2.5
-- CHECK: valueOut sent: null
-- CHECK: valueOut sent: [[],{"k":[{}]}]
import Json.Encode exposing (Value)
import Platform
port valueIn : (Value -> msg) -> Sub msg
port valueOut : Value -> Cmd msg
type Msg
= Got Value
init : () -> ( (), Cmd Msg )
init _ =
( (), Cmd.none )
update : Msg -> () -> ( (), Cmd Msg )
update (Got v) model =
( model, valueOut v )
subscriptions : () -> Sub Msg
subscriptions _ =
valueIn Got
main : Program () () Msg
main =
Platform.worker
{ init = init
, update = update
, subscriptions = subscriptions
}
Lean translation
This worker program is translated into Lean by the translator of the Lean mechanisation of A Standard Definition of Elm? (g_elm_PortPipeValueTest, in StandardElmMech/Generated/Worker01.lean). Lean evaluates its modules by the rules of Chapter 7, starts it by r:p-init with no flags (null, A72), and runs it by the transitions of Chapter 9 under the test driver of a pipe test, which sends the test's HOST-SEND values on its incoming port, in order, and takes every value sent out. Its checks become one generated theorem: some execution the book allows, under that host, has a log (the modules', then the start's, then each step's) that meets every check, and sends out the values of the CHECK lines “<port> sent: <value>”, in the order written. The theorem trusts the parser and the translator's elaboration ([parse] [elab]), the test basis ([harness]) and the parameters of the basis ([params]), and is proved by the kernel.
Out of date. The test, or a module it imports, has changed since this translation was made; the translation, and so its theorems, describe the program as it was until the mechanisation is rebuilt.
| Check | Expected (CHECK) | Lean evaluator | Proved by |
|---|---|---|---|
valueOut sent | {"a":"x","b":[1,true,null],"c":{}} (the test now says [[],{"k":[{}]}]) | {"a":"x","b":[1,true,null],"c":{}} or "plain" or -2.5 or null or [[],{"k":[{}]}] | t_elm_PortPipeValueTest |
valueOut sent | "plain" (the test now says [[],{"k":[{}]}]) | {"a":"x","b":[1,true,null],"c":{}} or "plain" or -2.5 or null or [[],{"k":[{}]}] | t_elm_PortPipeValueTest |
valueOut sent | -2.5 (the test now says [[],{"k":[{}]}]) | {"a":"x","b":[1,true,null],"c":{}} or "plain" or -2.5 or null or [[],{"k":[{}]}] | t_elm_PortPipeValueTest |
valueOut sent | null (the test now says [[],{"k":[{}]}]) | {"a":"x","b":[1,true,null],"c":{}} or "plain" or -2.5 or null or [[],{"k":[{}]}] | t_elm_PortPipeValueTest |
valueOut sent | [[],{"k":[{}]}] | {"a":"x","b":[1,true,null],"c":{}} or "plain" or -2.5 or null or [[],{"k":[{}]}] | t_elm_PortPipeValueTest |
/-- tests/elm/src/PortPipeValueTest.elm -/
def g_elm_PortPipeValueTest : Program := {
name := "PortPipeValueTest", source := "tests/elm/src",
exposing := (.items [.var "main"]), imports := [⟨"Json.Encode", "Json.Encode", some (.items [.tycon "Value"])⟩, ⟨"Platform", "Platform", none⟩],
types := [("Msg", [("Got", 1)])],
aliases := [],
ports := [("valueIn", .inn, .value), ("valueOut", .out, .value)],
defs := [
.fn "init" [pw] (tup2 (.atexp .unit) (qv "Cmd" "none")),
.fn "update" [.paren (pcon "Got" [pv "v"]), pv "model"] (tup2 (v "model") (ap (v "valueOut") [v "v"])),
.fn "subscriptions" [pw] (ap (v "valueIn") [c "Got"]),
.fn "main" [] (ap (qv "Platform" "worker") [recE [("init", v "init"), ("update", v "update"), ("subscriptions", v "subscriptions")]]) ],
checks := [ ] }
/-- The worker test of PortPipeValueTest. -/
def w_elm_PortPipeValueTest : Prog.WorkerTest := {
prog := g_elm_PortPipeValueTest,
flagsType := .unit,
flags := .null,
host := .feed "valueIn" [(Eff.BVal.mkObj [("b", (Eff.BVal.array [(.num (Eff.jnum (1) (0))), .tru, .null])), ("a", (.str "x")), ("c", (Eff.BVal.mkObj []))]), (.str "plain"), (.num (Eff.jnum (-25) (-1))), .null, (Eff.BVal.array [(Eff.BVal.array []), (Eff.BVal.mkObj [("k", (Eff.BVal.array [(Eff.BVal.mkObj [])]))])])],
sent := [("valueOut", (Eff.BVal.mkObj [("a", (.str "x")), ("b", (Eff.BVal.array [(.num (Eff.jnum (1) (0))), .tru, .null])), ("c", (Eff.BVal.mkObj []))])), ("valueOut", (.str "plain")), ("valueOut", (.num (Eff.jnum (-25) (-1)))), ("valueOut", .null), ("valueOut", (Eff.BVal.array [(Eff.BVal.array []), (Eff.BVal.mkObj [("k", (Eff.BVal.array [(Eff.BVal.mkObj [])]))])]))],
checks := [] }Reading the translation: v "x" is the variable x, c "K" the constructor K, i 42 the integer 42 at Int, .scon (.intF 2) the integer 2 at Float, and str "s" a string; ap f [a, b] applies f to a and then b, and bin "+" a b is a + b. lams, caseOf, ifte, listE, tup2 and recE build lambdas, case, if, lists, pairs and records by the book's derived forms; pv, pw and pcon are variable, wildcard and constructor patterns. defs are the program's top-level definitions and locals the other declarations of main's let, placed in a let around each check; ckk label value kind exp is one check. A name with $ (incF$Float) is a copy number specialisation made.
Static semantics (Chapters 4, 5 and 9): legal_elm_PortPipeValueTest states that the program as written is legal, with no hypothesis: the proved inference W gives each module a principal derivation, which meets the syntactic restrictions and the further restrictions, with a type of main Chapter 9 allows. End to end: spec_elm_PortPipeValueTest states that Lean computes the reduced program above from the source (derived forms, inference, the proved checker, number specialisation, type erasure), so the theorems about it do not trust the translator's elaboration ([elab]); mean_elm_PortPipeValueTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_PortPipeValueTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.