RegexFromStringTest
`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 msOutput
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 msOutput
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 msOutput
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 msOutput
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"