Elm Exactly
Results / elm-regex /

RegexFromStringTest

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
`Regex.fromString` returns `Just` for a valid pattern and `Nothing` for an invalid one.

`[0-9]+` compiles. `[invalid` has an unclosed character class and is rejected.

Results

elm-0.19.1

passran in 60 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
from_string: True
invalid: False

elm-0.19.2

passran in 82 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
from_string: True
invalid: False

elm-0.19.3

passran in 68 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
from_string: True
invalid: False

lamdera-1.5.0

passran in 83 ms
Output
from_string: True
invalid: False

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module RegexFromStringTest exposing (main)
{-| `Regex.fromString` returns `Just` for a valid pattern and `Nothing` for an invalid one.
`[0-9]+` compiles. `[invalid` has an unclosed character class and is rejected.
-}
-- CHECK: from_string: True
-- CHECK: invalid: False
import Html exposing (text)
import Regex
main =
let
maybeRegex = Regex.fromString "[0-9]+"
_ = Debug.log "from_string" (maybeRegex /= Nothing)
invalid = Regex.fromString "[invalid"
_ = Debug.log "invalid" (invalid /= Nothing)
in
text "done"