summaryrefslogtreecommitdiff
path: root/lambda-calcul/haskell/test/Minilang/REPL
diff options
context:
space:
mode:
Diffstat (limited to 'lambda-calcul/haskell/test/Minilang/REPL')
-rw-r--r--lambda-calcul/haskell/test/Minilang/REPL/NetSpec.hs45
1 files changed, 22 insertions, 23 deletions
diff --git a/lambda-calcul/haskell/test/Minilang/REPL/NetSpec.hs b/lambda-calcul/haskell/test/Minilang/REPL/NetSpec.hs
index 6a2b1ab..2f8880a 100644
--- a/lambda-calcul/haskell/test/Minilang/REPL/NetSpec.hs
+++ b/lambda-calcul/haskell/test/Minilang/REPL/NetSpec.hs
@@ -1,6 +1,5 @@
module Minilang.REPL.NetSpec where
--- import Control.Concurrent (threadDelay)
import Control.Concurrent.Async
import Control.Concurrent.STM.TVar
import Control.Exception (bracket)
@@ -46,48 +45,48 @@ withServer =
runTestClient :: Int -> String -> [In] -> IO [Either String Out]
runTestClient port envId inputs =
runClient "127.0.0.1" port ("/repl/" <> envId) client
- where
- client cnx = do
- outs <- forM inputs $ \inp -> do
- WS.sendBinaryData cnx (encode inp)
- eitherDecode <$> WS.receiveData cnx
- WS.sendBinaryData cnx (encode EOF)
- WS.sendClose cnx (encode ("" :: String))
- pure outs
+ where
+ client cnx = do
+ outs <- forM inputs $ \inp -> do
+ WS.sendBinaryData cnx (encode inp)
+ eitherDecode <$> WS.receiveData cnx
+ WS.sendBinaryData cnx (encode EOF)
+ WS.sendClose cnx (encode ("" :: String))
+ pure outs
temporaryFile :: (FilePath -> IO c) -> IO c
temporaryFile = bracket newTempFile removeFile
- where
- newTempFile = do
- dir <- getTemporaryDirectory
- (f, h) <- mkstemp (dir </> "repl.test")
- hClose h
- pure f
+ where
+ newTempFile = do
+ dir <- getTemporaryDirectory
+ (f, h) <- mkstemp (dir </> "repl.test")
+ hClose h
+ pure f
spec :: Spec
spec = around withServer $
describe "MiniLang Network REPL" $ do
- it "evaluates expression and returns evaluation result" $ \Server {serverPort} -> do
+ it "evaluates expression and returns evaluation result" $ \Server{serverPort} -> do
let inp = [Com (Set (SelectLanguage Typed)), In "((lam (x) x) y)"]
expectedOutput =
- [ Right (Msg "Language set to Typed"),
- Right $ Evaluated (AST.Sym "y") (Var "y") (TyVar "a")
+ [ Right (Msg "Language set to Typed")
+ , Right $ Evaluated (AST.Sym "y") (Var "y") (Just $ TyVar "a")
]
res <- runTestClient serverPort ".newenv1" inp
res `shouldBe` expectedOutput
- it "allows retrieving empty initial env" $ \Server {serverPort} -> do
+ it "allows retrieving empty initial env" $ \Server{serverPort} -> do
let inp = [Com (Set (SelectLanguage Typed)), Com DumpEnv]
expectedOutput =
- [ Right (Msg "Language set to Typed"),
- Right $ CurrentEnv newEnv newContext Typed
+ [ Right (Msg "Language set to Typed")
+ , Right $ CurrentEnv newEnv newContext Typed
]
res <- runTestClient serverPort ".newenv2" inp
res `shouldBe` expectedOutput
- it "can reconnect to existing environment" $ \Server {serverPort} -> do
+ it "can reconnect to existing environment" $ \Server{serverPort} -> do
let inp = [In "Unit : U = Sum(tt)"]
_ <- runTestClient serverPort ".newenv3" inp
res <- runTestClient serverPort ".newenv3" [In "Unit"]
@@ -95,5 +94,5 @@ spec = around withServer $
res `shouldSatisfy` isEvaluated
isEvaluated :: [Either a Out] -> Bool
-isEvaluated [Right (Evaluated _ _ _)] = True
+isEvaluated [Right Evaluated{}] = True
isEvaluated _ = False