Elm Exactly
Results / elm-parser /

ParserProblemTest

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
Checks that `Parser.problem` makes a parse fail and that `Parser.deadEndsToString` renders the failure.

The parser matches `"a"` and then fails with a custom problem. The test checks
that the result is an `Err` and that the rendered dead ends are a non-empty
string; it does not check the text.

Results

elm-0.19.1

passran in 102 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
has_problem: True
render_nonempty: True

elm-0.19.2

passran in 49 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
has_problem: True
render_nonempty: True

elm-0.19.3

passran in 63 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
has_problem: True
render_nonempty: True

lamdera-1.5.0

passran in 59 ms
Output
has_problem: True
render_nonempty: True

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module ParserProblemTest exposing (main)
{-| Checks that `Parser.problem` makes a parse fail and that `Parser.deadEndsToString` renders the failure.
The parser matches `"a"` and then fails with a custom problem. The test checks
that the result is an `Err` and that the rendered dead ends are a non-empty
string; it does not check the text.
-}
-- CHECK: has_problem: True
-- CHECK: render_nonempty: True
import Html exposing (text)
import Parser exposing ((|.))
import String
p : Parser.Parser ()
p =
Parser.succeed ()
|. Parser.symbol "a"
|. Parser.problem "intentional failure"
main =
let
result = Parser.run p "a"
_ = Debug.log "has_problem"
(case result of
Err _ -> True
Ok _ -> False
)
msg =
case result of
Err deadEnds -> Parser.deadEndsToString deadEnds
Ok _ -> ""
_ = Debug.log "render_nonempty" (String.length msg > 0)
in
text "done"