Results / elm-parser /
ParserCommitTest
`Parser.oneOf` does not try a later alternative once an earlier one has consumed input and committed. The first alternative parses `"a"`, calls `commit`, then expects `"b"`; the second parses `"a"` alone. Run on `"ax"`, the first alternative fails at `"x"` and the result is `Err`, not `Ok 1` from the second. Having parsed `"a"`, the first alternative has already consumed input, so the test does not separate the effect of `commit` from that of consuming.
Results
elm-0.19.1
passran in 84 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. committed: True
elm-0.19.2
passran in 53 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. committed: True
elm-0.19.3
passran in 68 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. committed: True
lamdera-1.5.0
passran in 42 msOutput
committed: True
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-parser/ParserCommitTest] in its title.
Source
The -- CHECK: lines give the expected output.
module ParserCommitTest exposing (main)
{-| `Parser.oneOf` does not try a later alternative once an earlier one has consumed input and committed.
The first alternative parses `"a"`, calls `commit`, then expects `"b"`; the
second parses `"a"` alone. Run on `"ax"`, the first alternative fails at
`"x"` and the result is `Err`, not `Ok 1` from the second.
Having parsed `"a"`, the first alternative has already consumed input, so the
test does not separate the effect of `commit` from that of consuming.
-}
-- CHECK: committed: True
import Html exposing (text)
import Parser exposing ((|.))
{-| Returns 0 for `"ab"`, committing after the `"a"`, or 1 for `"a"` alone.
-}
p : Parser.Parser Int
p =
Parser.oneOf
[ Parser.succeed 0
|. Parser.symbol "a"
|. Parser.commit ()
|. Parser.symbol "b"
, Parser.succeed 1 |. Parser.symbol "a"
]
main =
let
result = Parser.run p "ax"
_ = Debug.log "committed"
(case result of
Err _ -> True
Ok _ -> False
)
in
text "done"