summaryrefslogtreecommitdiff
path: root/lambda-calcul/haskell/test
diff options
context:
space:
mode:
Diffstat (limited to 'lambda-calcul/haskell/test')
-rw-r--r--lambda-calcul/haskell/test/Minilang/Lambda/ParserSpec.hs15
1 files changed, 11 insertions, 4 deletions
diff --git a/lambda-calcul/haskell/test/Minilang/Lambda/ParserSpec.hs b/lambda-calcul/haskell/test/Minilang/Lambda/ParserSpec.hs
index b52017a..13279e9 100644
--- a/lambda-calcul/haskell/test/Minilang/Lambda/ParserSpec.hs
+++ b/lambda-calcul/haskell/test/Minilang/Lambda/ParserSpec.hs
@@ -5,7 +5,7 @@ import qualified Data.Text as Text
import Minilang.Lambda.Parser (AST (..), initialChars, parse, restChars)
import Test.Hspec (Spec, parallel, shouldBe)
import Test.Hspec.QuickCheck (prop)
-import Test.QuickCheck (Arbitrary (..), NonEmptyList (..), elements, listOf)
+import Test.QuickCheck (Arbitrary (..), NonEmptyList (..), elements, listOf, (==>))
spec :: Spec
spec = parallel $ do
@@ -17,11 +17,18 @@ spec = parallel $ do
prop "parses a lambda-expression with multiple bindings as an abstraction" $ \(NonEmpty idents) (Identifier body) ->
let vars = unIdent <$> idents
- nestedAbs = Abs vars (Sym body)
- in parse ("(lam (" <> Text.unwords vars <> ") " <> body <> ")") `shouldBe` Right nestedAbs
+ abs = Abs vars (Sym body)
+ in parse ("(lam (" <> Text.unwords vars <> ") " <> body <> ")") `shouldBe` Right abs
prop "parses an application" $ \(Identifier ident1) (Identifier ident2) ->
- parse ("(" <> ident1 <> " " <> ident2 <> ")") `shouldBe` Right (App (Sym ident1) (Sym ident2))
+ parse ("(" <> ident1 <> " " <> ident2 <> ")") `shouldBe` Right (App (Sym ident1) (Sym ident2) [])
+
+ prop "parses multiple applications" $ \(NonEmpty idents) ->
+ (length idents >= 2) ==>
+ let vars = unIdent <$> idents
+ (a : b : rest) = vars
+ app = App (Sym a) (Sym b) (Sym <$> rest)
+ in parse ("(" <> Text.unwords vars <> ")") `shouldBe` Right app
newtype Identifier = Identifier {unIdent :: Text}
deriving (Eq, Show)