Results / elm-parser /
ParserVariableTest
Checks that `Parser.variable` accepts an identifier and rejects a reserved word. `"foo"` gives `Ok "foo"`; `"if"`, which is in the reserved set, gives an `Err`.
Results
elm-0.19.1
passran in 54 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. name: Ok "foo" reserved: True
elm-0.19.2
passran in 40 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. name: Ok "foo" reserved: True
elm-0.19.3
passran in 44 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. name: Ok "foo" reserved: True
lamdera-1.5.0
passran in 39 msOutput
name: Ok "foo" reserved: True
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-parser/ParserVariableTest] in its title.
Source
The -- CHECK: lines give the expected output.
module ParserVariableTest exposing (main)
{-| Checks that `Parser.variable` accepts an identifier and rejects a reserved word.
`"foo"` gives `Ok "foo"`; `"if"`, which is in the reserved set, gives an
`Err`.
-}
-- CHECK: name: Ok "foo"
-- CHECK: reserved: True
import Char
import Html exposing (text)
import Parser
import Set
variable : Parser.Parser String
variable =
Parser.variable
{ start = Char.isLower
, inner = \c -> Char.isAlphaNum c || c == '_'
, reserved = Set.fromList [ "if", "then", "else" ]
}
main =
let
ok_ = Parser.run variable "foo"
_ = Debug.log "name" ok_
bad = Parser.run variable "if"
_ = Debug.log "reserved"
(case bad of
Err _ -> True
Ok _ -> False
)
in
text "done"