arowM / elm-parser-test / Parser.Test

Helper functions to develop/test your own parser using elm/parser.

Core

run : Parser a -> String -> ( Result (List Parser.DeadEnd) a, Basics.Bool )

Check if a parser is backtrackable or not.

import Parser

run (Parser.keyword "import") "imp" |> Tuple.mapFirst (Result.mapError (\_ -> ()))
--> (Err (), True)

run (Parser.keyword "import") "import"
--> (Ok (), False)

run Parser.spaces "  "
--> (Ok (), False)

run (Parser.backtrackable Parser.spaces) "  "
--> (Ok (), True)

run_ : Parser a -> String -> ( Maybe a, Basics.Bool )

Same as run but returns Maybe a instead. This is useful to implement tests for your own parsers.

import Parser

run_ (Parser.keyword "import") "imp"
--> (Nothing, True)

run_ (Parser.keyword "import") "import"
--> (Just (), False)