summaryrefslogtreecommitdiff
path: root/lambda-calcul/haskell/test/Minilang/REPLSpec.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lambda-calcul/haskell/test/Minilang/REPLSpec.hs')
-rw-r--r--lambda-calcul/haskell/test/Minilang/REPLSpec.hs68
1 files changed, 33 insertions, 35 deletions
diff --git a/lambda-calcul/haskell/test/Minilang/REPLSpec.hs b/lambda-calcul/haskell/test/Minilang/REPLSpec.hs
index e382df4..1754cdb 100644
--- a/lambda-calcul/haskell/test/Minilang/REPLSpec.hs
+++ b/lambda-calcul/haskell/test/Minilang/REPLSpec.hs
@@ -1,11 +1,9 @@
module Minilang.REPLSpec where
import Control.Exception (bracket)
-import Data.Either (isRight)
import Data.Text.IO
import Minilang.Lambda.Eval (Term (Lam, Var))
import Minilang.Lambda.Parser (AST (..))
-import Minilang.Lambda.Unify (Type (TyVar))
import Minilang.REPL
import Minilang.REPL.Purer (PurerEnv (..))
import Minilang.REPL.Run (loadProgramInEnv)
@@ -26,8 +24,8 @@ spec = parallel $
["((lam (x) x) y)"]
out
- `shouldBe` [ "Bye!",
- "y : <?>"
+ `shouldBe` [ "Bye!"
+ , "y"
]
it "evaluates untyped MiniLang terms with definitions" $ do
@@ -36,24 +34,24 @@ spec = parallel $
["(def id (lam (x) x))", "(id y)"]
out
- `shouldBe` [ "Bye!",
- "y : <?>",
- "id : <?>"
+ `shouldBe` [ "Bye!"
+ , "y"
+ , "id"
]
it "evaluates typed MiniLang terms with definitions" $ do
let out =
withInput
- [ ":lang Typed",
- "(def id (lam (x) x))",
- "(id y)"
+ [ ":lang Typed"
+ , "(def id (lam (x) x))"
+ , "(id y)"
]
out
- `shouldBe` [ "Bye!",
- "y : a",
- "id : a -> a",
- "Language set to Typed"
+ `shouldBe` [ "Bye!"
+ , "y : a"
+ , "id : a -> a"
+ , "Language set to Typed"
]
it "defaults untyped terms" $ do
@@ -65,58 +63,58 @@ spec = parallel $
]
out
- `shouldBe` [ "Bye!",
- "(lam (z s) (s (lam (z s) (s (lam (z s) z))))) : <?>"
+ `shouldBe` [ "Bye!"
+ , "(lam (z s) (s (lam (z s) (s (lam (z s) z)))))"
]
it "do typecheck term when language is set to 'Typed'" $ do
let out =
withInput
- [ ":lang Typed",
- "(let ((Succ (lam (n z s) (s n))) \
+ [ ":lang Typed"
+ , "(let ((Succ (lam (n z s) (s n))) \
\ (Zero (lam (z s) z))) \
\ (Succ (Succ Zero)))"
]
out
- `shouldBe` [ "Bye!",
- "(lam (z s) (s (lam (z s) (s (lam (z s) z))))) : a -> ((c -> ((e -> f -> e) -> g) -> g) -> h) -> h",
- "Language set to Typed"
+ `shouldBe` [ "Bye!"
+ , "(lam (z s) (s (lam (z s) (s (lam (z s) z))))) : a -> ((c -> ((e -> f -> e) -> g) -> g) -> h) -> h"
+ , "Language set to Typed"
]
it "shows error when trying to load a non-existent file" $ do
withInput [":load foo"]
- `shouldBe` [ "Bye!",
- "REPLError \"cannot load file foo in Pure interpreter\""
+ `shouldBe` [ "Bye!"
+ , "REPLError \"cannot load file foo in Pure interpreter\""
]
it "can load 'bool-prog.lisp'" $ do
boolProg <- readFile "bool-prog.lisp"
- let PurerEnv {outputs} = runProgram (loadProgramInEnv boolProg)
+ let PurerEnv{outputs} = runProgram (loadProgramInEnv boolProg)
outputs
- `shouldBe` [ Evaluated (Abs ["f", "t"] (Sym "t")) (Lam "f" (Lam "t" (Var "t"))) (TyVar "<?>"),
- Evaluated (Abs ["f", "t"] (Sym "f")) (Lam "f" (Lam "t" (Var "f"))) (TyVar "<?>"),
- Evaluated (Abs ["f", "t"] (Sym "f")) (Lam "f" (Lam "t" (Var "f"))) (TyVar "<?>")
+ `shouldBe` [ Evaluated (Abs ["f", "t"] (Sym "t")) (Lam "f" (Lam "t" (Var "t"))) Nothing
+ , Evaluated (Abs ["f", "t"] (Sym "f")) (Lam "f" (Lam "t" (Var "f"))) Nothing
+ , Evaluated (Abs ["f", "t"] (Sym "f")) (Lam "f" (Lam "t" (Var "f"))) Nothing
]
it "can load 'bool.lisp'" $ do
boolProg <- readFile "bool.lisp"
- let PurerEnv {outputs} = runProgram (loadProgramInEnv boolProg)
+ let PurerEnv{outputs} = runProgram (loadProgramInEnv boolProg)
outputs
`shouldBe` [ Evaluated
(Abs ["f", "t"] (Sym "f"))
(Lam "f" (Lam "t" (Var "f")))
- (TyVar "<?>")
+ Nothing
]
it "can load 'fac.lisp'" $ do
boolProg <- readFile "fac.lisp"
- let PurerEnv {outputs} = runProgram (loadProgramInEnv boolProg)
+ let PurerEnv{outputs} = runProgram (loadProgramInEnv boolProg)
outputs
`shouldBe` [ Evaluated
(Abs ["f", "t"] (Sym "t"))
(Lam "f" (Lam "t" (Var "t")))
- (TyVar "<?>")
+ Nothing
]
around withTempFile $
@@ -136,11 +134,11 @@ spec = parallel $
out <- readFile outputFileName
out
- `shouldBe` "\955\928> (lam (z s) (s (lam (z s) z))) : <?>\n\955\928> Bye!\n"
+ `shouldBe` "\955\928> (lam (z s) (s (lam (z s) z)))\n\955\928> Bye!\n"
withTempFile :: (String -> IO ()) -> IO ()
withTempFile =
bracket mkTempFile rmTempFile
- where
- mkTempFile = getTemporaryDirectory >>= \dir -> mkstemp (dir </> "test-repl") >>= \(fp, h) -> hClose h >> pure fp
- rmTempFile fn = removeFile fn >> removeFile (fn <.> "out")
+ where
+ mkTempFile = getTemporaryDirectory >>= \dir -> mkstemp (dir </> "test-repl") >>= \(fp, h) -> hClose h >> pure fp
+ rmTempFile fn = removeFile fn >> removeFile (fn <.> "out")