Results / elm-parser /
ParserChompIfTest
`Parser.chompIf` succeeds when the predicate accepts the next character and fails when it does not. With `Char.isDigit` as the predicate, `digit_ok` runs on `"5"` and checks for `Ok`; `alpha_fail` runs on `"a"` and checks for `Err`.
Results
elm-0.19.1
passran in 45 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. digit_ok: True alpha_fail: True
elm-0.19.2
passran in 48 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. digit_ok: True alpha_fail: True
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. digit_ok: True alpha_fail: True
lamdera-1.5.0
passran in 58 msOutput
digit_ok: True alpha_fail: True
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-parser/ParserChompIfTest] in its title.
Source
The -- CHECK: lines give the expected output.
module ParserChompIfTest exposing (main)
{-| `Parser.chompIf` succeeds when the predicate accepts the next character and fails when it does not.
With `Char.isDigit` as the predicate, `digit_ok` runs on `"5"` and checks for
`Ok`; `alpha_fail` runs on `"a"` and checks for `Err`.
-}
-- CHECK: digit_ok: True
-- CHECK: alpha_fail: True
import Char
import Html exposing (text)
import Parser
digitP : Parser.Parser ()
digitP =
Parser.chompIf Char.isDigit
main =
let
ok_ = Parser.run digitP "5"
_ = Debug.log "digit_ok"
(case ok_ of
Ok _ -> True
Err _ -> False
)
bad = Parser.run digitP "a"
_ = Debug.log "alpha_fail"
(case bad of
Err _ -> True
Ok _ -> False
)
in
text "done"