49 lines
1.5 KiB
Haskell
49 lines
1.5 KiB
Haskell
module ParserSpec (spec) where
|
|
|
|
import Parser (Expr (Abstraction, Application, Variable), parse)
|
|
import Test.Hspec
|
|
|
|
spec :: Spec
|
|
spec = do
|
|
describe "Parser" $ do
|
|
it "can parse variable" $
|
|
(parse "x") `shouldBe` Right (Variable "x")
|
|
it "can parse identity abstraction" $
|
|
(parse "λx.x") `shouldBe` Right (Abstraction ("x", Variable "x"))
|
|
it "can parse mockingbird of identity" $
|
|
(parse "(λx.x x) (λx.x)") -- (λx.x) (λx.x) -> (λx.x)
|
|
`shouldBe` Right
|
|
( Application
|
|
( Abstraction
|
|
( "x",
|
|
Application
|
|
( Variable "x",
|
|
Variable "x"
|
|
)
|
|
),
|
|
Abstraction ("x", Variable "x")
|
|
)
|
|
)
|
|
it "it can parse successor" $
|
|
(parse "λn.λf.λx.f (n f x)")
|
|
`shouldBe` Right
|
|
( Abstraction
|
|
( "n",
|
|
Abstraction
|
|
( "f",
|
|
Abstraction
|
|
( "x",
|
|
Application
|
|
( Variable "f",
|
|
Application
|
|
( Application
|
|
( Variable "n",
|
|
Variable "f"
|
|
),
|
|
Variable "x"
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|