Skip to content

Behaviour of "string" parser does not match example in docs #42

@ktonon

Description

@ktonon

Doc for function (</>) shows:

    parsePath (s "search" </> string) location
    -- /search/cats/  ==>  Just "cats"
    -- /search/frog   ==>  Just "frog"
    -- /search/       ==>  Nothing
    -- /cats/         ==>  Nothing

But parsePath (s "search" </> string) location returns Just "" because the implementation of string is

string : Parser (String -> a) a
string =
    custom "STRING" Ok

Not sure which is correct. Assuming the docs are the desired behaviour:

{-| Parse a segment of the path as a `String`.
    parsePath string location
    -- /alice/  ==>  Just "alice"
    -- /bob     ==>  Just "bob"
    -- /42/     ==>  Just "42"
    -- /        ==> Nothing
-}
string : Parser (String -> a) a
string =
    custom "STRING" <|
        \segment ->
            if String.isEmpty segment then
                Err "string does not match empty segment"
            else
                Ok segment

Using elm-doc-test would catch this earlier.

Caught the issue while working on a PR to add doc tests. Using elm 0.18.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions