summaryrefslogtreecommitdiff
path: root/lambda-calcul/haskell/test/Minilang/Lambda
diff options
context:
space:
mode:
Diffstat (limited to 'lambda-calcul/haskell/test/Minilang/Lambda')
-rw-r--r--lambda-calcul/haskell/test/Minilang/Lambda/ParserSpec.hs20
1 files changed, 19 insertions, 1 deletions
diff --git a/lambda-calcul/haskell/test/Minilang/Lambda/ParserSpec.hs b/lambda-calcul/haskell/test/Minilang/Lambda/ParserSpec.hs
index e6f05b9..932eff6 100644
--- a/lambda-calcul/haskell/test/Minilang/Lambda/ParserSpec.hs
+++ b/lambda-calcul/haskell/test/Minilang/Lambda/ParserSpec.hs
@@ -10,7 +10,7 @@ import Data.Text (Text, pack)
import qualified Data.Text as Text
import Minilang.Lambda.Eval (Term (Lam))
import qualified Minilang.Lambda.Eval as Eval
-import Minilang.Lambda.Parser (AST (..), desugar, initialChars, parse, pretty, restChars)
+import Minilang.Lambda.Parser (AST (..), desugar, initialChars, parse, parseProgram, pretty, restChars)
import Test.Hspec (Spec, it, parallel, shouldBe, shouldSatisfy)
import Test.Hspec.QuickCheck (prop)
import Test.QuickCheck
@@ -103,6 +103,24 @@ spec = parallel $ do
let text = pretty ast
in parse text `shouldBe` Right ast
+ it "parses multiline program with blank lines" $ do
+ let program =
+ "(def id (lam (x) x))\n\
+ \\n\
+ \(def const (lam (x y) x))\n\
+ \(def apply (lam (f x) (f x)))\n\
+ \(apply id const)"
+ expected =
+ [ Def "id" (Abs ["x"] (Sym "x")),
+ Def "const" (Abs ["x", "y"] (Sym "x")),
+ Def "apply" (Abs ["f", "x"] (App (Sym "f") (Sym "x") [])),
+ App
+ (Sym "apply")
+ (Sym "id")
+ [Sym "const"]
+ ]
+ parseProgram program `shouldBe` Right expected
+
spine :: AST -> Int
spine = \case
App x _ rest -> 1 + spine x + length rest