summaryrefslogtreecommitdiff
path: root/lambda-calcul/haskell/test/Minilang/Lambda/ParserSpec.hs
blob: c1eab27c84e11ed81fb8f6a35df5ad4541168748 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
module Minilang.Lambda.ParserSpec where

import Data.Text (Text, pack)
import Minilang.Lambda.Parser (AST (..), initialChars, parse, restChars)
import Test.Hspec (Spec, parallel, shouldBe)
import Test.Hspec.QuickCheck (prop)
import Test.QuickCheck (Arbitrary (..), elements, listOf)

spec :: Spec
spec = parallel $ do
  prop "parses an identifier as a variable" $ \(Identifier ident) ->
    parse ident `shouldBe` Right (Sym ident)
  prop "parses a lambda-expression as an abstraction" $ \(Identifier ident) (Identifier body) ->
    parse ("(lam (" <> ident <> ") " <> body <> ")") `shouldBe` Right (Abs ident (Sym body))

newtype Identifier = Identifier Text
  deriving (Eq, Show)

instance Arbitrary Identifier where
  arbitrary =
    Identifier . pack
      <$> ((:) <$> elements initialChars <*> listOf (elements restChars))