Elm Exactly
Results / elm /

PortPipeValueRejectsBytesTest

Tags:elm-spec

XFAIL Expected to fail: no compiler the suite runs represents a byte sequence at the host; Elm/JS passes the driver's Uint8Array through a Value port

Checks, in A Standard Definition of Elm?:rule e-dec-valuerule e-enc-valuerule p-in-rejectrule p-in-acceptrule e-enc-tuple

Translated into Lean for the mechanisation of the book: see its Lean translation.

elm-0.19.1 failelm-0.19.2 failelm-0.19.3 faillamdera-1.5.0 fail
A byte sequence sent to a `Json.Encode.Value` port is rejected, alone or inside an object.

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 numbers the values it receives, from 1,
and sends each out with its number, so a rejected value shows as a number not used.

A Standard Definition of Elm?, rule e-dec-value (ruling A92): every JSON value decodes at
`Value`, and a boundary value in which a byte sequence occurs is not a JSON value, so it does not
decode there and is rejected. `null` after them is the first value the program receives.
<https://elm-test-suite.netlify.app/standard/rules/e-dec-value>

The program's types hold no `Bytes`, so Elm 0.19.1 compiles it, but no compiler the suite runs
has a representation for a byte sequence at the host (Appendix E: Elm/JS has none). To Elm/JS the
driver's `Uint8Array` is a JavaScript value that is not a boundary value, which is outside the
definition, and a `Value` port passes it through; so the test is expected to fail on all of them.

Results

elm-0.19.1

failran in 61 ms
Missing pattern: valueOut sent: [1,null]
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
valueOut sent: [1,bytes(01)]
valueOut sent: [2,{"a":bytes(02)}]
valueOut sent: [3,null]

elm-0.19.2

failran in 61 ms
Missing pattern: valueOut sent: [1,null]
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
valueOut sent: [1,bytes(01)]
valueOut sent: [2,{"a":bytes(02)}]
valueOut sent: [3,null]

elm-0.19.3

failran in 63 ms
Missing pattern: valueOut sent: [1,null]
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
valueOut sent: [1,bytes(01)]
valueOut sent: [2,{"a":bytes(02)}]
valueOut sent: [3,null]

lamdera-1.5.0

failran in 52 ms
Missing pattern: valueOut sent: [1,null]
--- output ---
valueOut sent: [1,bytes(01)]
valueOut sent: [2,{"a":bytes(02)}]
valueOut sent: [3,null]

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

port module PortPipeValueRejectsBytesTest exposing (main)
{-| A byte sequence sent to a `Json.Encode.Value` port is rejected, alone or inside an object.
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 numbers the values it receives, from 1,
and sends each out with its number, so a rejected value shows as a number not used.
A Standard Definition of Elm?, rule e-dec-value (ruling A92): every JSON value decodes at
`Value`, and a boundary value in which a byte sequence occurs is not a JSON value, so it does not
decode there and is rejected. `null` after them is the first value the program receives.
<https://elm-test-suite.netlify.app/standard/rules/e-dec-value>
The program's types hold no `Bytes`, so Elm 0.19.1 compiles it, but no compiler the suite runs
has a representation for a byte sequence at the host (Appendix E: Elm/JS has none). To Elm/JS the
driver's `Uint8Array` is a JavaScript value that is not a boundary value, which is outside the
definition, and a `Value` port passes it through; so the test is expected to fail on all of them.
-}
-- TAGS: elm-spec, e-dec-value, e-enc-value, p-in-reject, p-in-accept, e-enc-tuple
-- XFAIL: no compiler the suite runs represents a byte sequence at the host; Elm/JS passes the driver's Uint8Array through a Value port
-- HOST-SEND: valueIn bytes(01)
-- HOST-SEND: valueIn {"a":bytes(02)}
-- HOST-SEND: valueIn null
-- CHECK: valueOut sent: [1,null]
import Json.Encode exposing (Value)
import Platform
port valueIn : (Value -> msg) -> Sub msg
port valueOut : ( Int, Value ) -> Cmd msg
type Msg
= Got Value
init : () -> ( Int, Cmd Msg )
init _ =
( 0, Cmd.none )
update : Msg -> Int -> ( Int, Cmd Msg )
update (Got v) model =
( model + 1, valueOut ( model + 1, v ) )
subscriptions : Int -> Sub Msg
subscriptions _ =
valueIn Got
main : Program () Int 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_PortPipeValueRejectsBytesTest, 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.

CheckExpected (CHECK)Lean evaluatorProved by
valueOut sent[1,null][1,null]t_elm_PortPipeValueRejectsBytesTest
/-- tests/elm/src/PortPipeValueRejectsBytesTest.elm -/
def g_elm_PortPipeValueRejectsBytesTest : Program := {
  name := "PortPipeValueRejectsBytesTest", 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, (.tuple2 .int .value))],
  defs := [
    .fn "init" [pw] (tup2 (i 0) (qv "Cmd" "none")),
    .fn "update" [.paren (pcon "Got" [pv "v"]), pv "model"] (tup2 (bin "+" (v "model") (i 1)) (ap (v "valueOut") [tup2 (bin "+" (v "model") (i 1)) (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 PortPipeValueRejectsBytesTest. -/
def w_elm_PortPipeValueRejectsBytesTest : Prog.WorkerTest := {
  prog := g_elm_PortPipeValueRejectsBytesTest,
  flagsType := .unit,
  flags := .null,
  host := .feed "valueIn" [(.bytes [1]), (Eff.BVal.mkObj [("a", (.bytes [2]))]), .null],
  sent := [("valueOut", (Eff.BVal.array [(.num (Eff.jnum (1) (0))), .null]))],
  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_PortPipeValueRejectsBytesTest 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_PortPipeValueRejectsBytesTest 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_PortPipeValueRejectsBytesTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_PortPipeValueRejectsBytesTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.