Elm Exactly
Results / elm-parser /

ParserChompIfTest

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
`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 ms
Output
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 ms
Output
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 ms
Output
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 ms
Output
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"