Elm Exactly
Results / elm-parser /

ParserOneOfTest

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
Checks that `Parser.oneOf` falls through to a later alternative when an earlier one fails.

`boolP` tries `keyword "true"` and then `keyword "false"`; `"true"` gives
`Ok True` and `"false"` gives `Ok False`.

Results

elm-0.19.1

passran in 93 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
true_: Ok True
false_: Ok False

elm-0.19.2

passran in 53 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
true_: Ok True
false_: Ok False

elm-0.19.3

passran in 49 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
true_: Ok True
false_: Ok False

lamdera-1.5.0

passran in 76 ms
Output
true_: Ok True
false_: Ok False

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module ParserOneOfTest exposing (main)
{-| Checks that `Parser.oneOf` falls through to a later alternative when an earlier one fails.
`boolP` tries `keyword "true"` and then `keyword "false"`; `"true"` gives
`Ok True` and `"false"` gives `Ok False`.
-}
-- CHECK: true_: Ok True
-- CHECK: false_: Ok False
import Html exposing (text)
import Parser
boolP : Parser.Parser Bool
boolP =
Parser.oneOf
[ Parser.map (\_ -> True) (Parser.keyword "true")
, Parser.map (\_ -> False) (Parser.keyword "false")
]
main =
let
t = Parser.run boolP "true"
_ = Debug.log "true_" t
f = Parser.run boolP "false"
_ = Debug.log "false_" f
in
text "done"