Elm Exactly
Results / elm-parser /

ParserIssue44FloatCommitsOnLeadingETest

Tags:elm19-bug

elm-0.19.1 failelm-0.19.2 failelm-0.19.3 faillamdera-1.5.0 fail

Issue: elm/parser#44

`Parser.float` commits on input that starts with `e`, so `oneOf` cannot fall back.

<https://github.com/elm/parser/issues/44>

`oneOf [ float |> map ..., chompUntilEndOr "\n" |> getChompedString ]` on "e should be text" fails
with ExpectingFloat in Elm 0.19.1 (elm/parser 1.1.0), while "not starting with e" works. Text
without a digit is not a float: `float` must fail without consuming.

Results

elm-0.19.1

failran in 63 ms
Missing pattern: e: Ok "e should be text"
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
e: Err [{ col = 2, problem = ExpectingFloat, row = 1 }]
n: Ok "not starting with e"

elm-0.19.2

failran in 56 ms
Missing pattern: e: Ok "e should be text"
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
e: Err [{ col = 2, problem = ExpectingFloat, row = 1 }]
n: Ok "not starting with e"

elm-0.19.3

failran in 45 ms
Missing pattern: e: Ok "e should be text"
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
e: Err [{ col = 2, row = 1, problem = ExpectingFloat }]
n: Ok "not starting with e"

lamdera-1.5.0

failran in 51 ms
Missing pattern: e: Ok "e should be text"
--- output ---
e: Err [{ col = 2, row = 1, problem = ExpectingFloat }]
n: Ok "not starting with e"

Discussions

Discuss this test·Search the discussions on GitHub

Discussions are on GitHub; one about this test has [t:elm-parser/ParserIssue44FloatCommitsOnLeadingETest] in its title.

Source

The -- CHECK: lines give the expected output.

module ParserIssue44FloatCommitsOnLeadingETest exposing (main)
{-| `Parser.float` commits on input that starts with `e`, so `oneOf` cannot fall back.
<https://github.com/elm/parser/issues/44>
`oneOf [ float |> map ..., chompUntilEndOr "\n" |> getChompedString ]` on "e should be text" fails
with ExpectingFloat in Elm 0.19.1 (elm/parser 1.1.0), while "not starting with e" works. Text
without a digit is not a float: `float` must fail without consuming.
-}
-- TAGS: elm19-bug
-- CHECK: e: Ok "e should be text"
-- CHECK: n: Ok "not starting with e"
import Html exposing (text)
import Parser
floatOrText : Parser.Parser String
floatOrText =
Parser.oneOf
[ Parser.float |> Parser.map (\n -> "Number: " ++ String.fromFloat n)
, Parser.chompUntilEndOr "\n" |> Parser.getChompedString
]
main =
let
_ =
Debug.log "e" (Parser.run floatOrText "e should be text")
_ =
Debug.log "n" (Parser.run floatOrText "not starting with e")
in
text "done"