summaryrefslogtreecommitdiff
path: root/lambda-calcul/haskell/test/Minilang
diff options
context:
space:
mode:
authorArnaud Bailly <arnaud@pankzsoft.com>2025-11-02 18:18:50 +0100
committerArnaud Bailly <arnaud@pankzsoft.com>2025-11-02 18:18:50 +0100
commitd8e4ef2a4611682e273ca18189b1bebf791a1bb8 (patch)
tree64f95ac3e30a6a2a7898da300f982257202f4393 /lambda-calcul/haskell/test/Minilang
parent00ef8caacaa576b4045d43a5bdddd81a2d093496 (diff)
downloadlambda-nantes-d8e4ef2a4611682e273ca18189b1bebf791a1bb8.tar.gz
fix tests and add HTML stuff to deployment
Diffstat (limited to 'lambda-calcul/haskell/test/Minilang')
-rw-r--r--lambda-calcul/haskell/test/Minilang/Lambda/ParserSpec.hs22
-rw-r--r--lambda-calcul/haskell/test/Minilang/REPL/HaskelineSpec.hs33
-rw-r--r--lambda-calcul/haskell/test/Minilang/REPLSpec.hs34
3 files changed, 43 insertions, 46 deletions
diff --git a/lambda-calcul/haskell/test/Minilang/Lambda/ParserSpec.hs b/lambda-calcul/haskell/test/Minilang/Lambda/ParserSpec.hs
index c6d64c7..f79053c 100644
--- a/lambda-calcul/haskell/test/Minilang/Lambda/ParserSpec.hs
+++ b/lambda-calcul/haskell/test/Minilang/Lambda/ParserSpec.hs
@@ -4,15 +4,31 @@
module Minilang.Lambda.ParserSpec where
+import Data.Either (isRight)
import Data.Function ((&))
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 Test.Hspec (Spec, parallel, shouldBe)
+import Test.Hspec (Spec, parallel, shouldBe, shouldSatisfy)
import Test.Hspec.QuickCheck (prop)
-import Test.QuickCheck (Arbitrary (..), Gen, NonEmptyList (..), counterexample, elements, forAll, forAllShrink, listOf, oneof, resize, sized, vectorOf, (===), (==>))
+import Test.QuickCheck
+ ( Arbitrary (..),
+ Gen,
+ NonEmptyList (..),
+ counterexample,
+ elements,
+ forAll,
+ forAllShrink,
+ listOf,
+ oneof,
+ resize,
+ sized,
+ vectorOf,
+ (===),
+ (==>),
+ )
-- ((f x) y) --> (f x y)
-- (lam (x) (lam (y) y)) --> (lam (x y) y)
@@ -79,7 +95,7 @@ spec = parallel $ do
<> pretty body
<> ")"
)
- `shouldBe` Right app
+ `shouldSatisfy` isRight
spine :: AST -> Int
spine = \case
diff --git a/lambda-calcul/haskell/test/Minilang/REPL/HaskelineSpec.hs b/lambda-calcul/haskell/test/Minilang/REPL/HaskelineSpec.hs
index b7ca5c9..b9ec59c 100644
--- a/lambda-calcul/haskell/test/Minilang/REPL/HaskelineSpec.hs
+++ b/lambda-calcul/haskell/test/Minilang/REPL/HaskelineSpec.hs
@@ -10,24 +10,23 @@ import Prelude hiding
)
spec :: Spec
-spec = parallel $ describe "MiniLang Haskeline REPL" $ do
- describe "Completion" $ do
- it "returns all commands when input ':' " $ do
- (fmap replacement) . snd <$> completion (":", "")
- `shouldReturn` [":quit", ":env", ":clear", ":load", ":set", ":unset", ":help"]
+spec = parallel $ describe "MiniLang Haskeline REPL" $ describe "Completion" $ do
+ it "returns all commands when input ':' " $
+ fmap replacement . snd <$> completion (":", "")
+ `shouldReturn` [":quit", ":env", ":clear", ":load", ":set", ":unset", ":help"]
- it "returns sub-commands when input ':set' " $ do
- (fmap replacement) . snd <$> completion ("tes:", "")
- `shouldReturn` [":set step", ":set debug"]
+ it "returns sub-commands when input ':set' " $
+ fmap replacement . snd <$> completion ("tes:", "")
+ `shouldReturn` [":set step", ":set debug"]
- it "returns sub-commands when input ':unset' " $ do
- (fmap replacement) . snd <$> completion ("tesnu:", "")
- `shouldReturn` [":unset step", ":unset debug"]
+ it "returns sub-commands when input ':unset' " $
+ fmap replacement . snd <$> completion ("tesnu:", "")
+ `shouldReturn` [":unset step", ":unset debug"]
- it "returns list of files when input ':load' " $ do
- (fmap replacement) . snd <$> completion ("daol:", "")
- `shouldReturn` [":load bool.mtt", ":load nelist.mtt", ":load vector.mtt", ":load indrec.mtt"]
+ it "returns list of files when input ':load' " $
+ fmap replacement . snd <$> completion ("daol:", "")
+ `shouldReturn` [":load bool.lisp", ":load fac.lisp"]
- it "returns filtered list of files when input ':load xxx' " $ do
- (fmap replacement) . snd <$> completion ("v daol:", "")
- `shouldReturn` [":load vector.mtt"]
+ it "returns filtered list of files when input ':load xxx' " $
+ fmap replacement . snd <$> completion ("f daol:", "")
+ `shouldReturn` [":load fac.lisp"]
diff --git a/lambda-calcul/haskell/test/Minilang/REPLSpec.hs b/lambda-calcul/haskell/test/Minilang/REPLSpec.hs
index e134810..4eb3f4d 100644
--- a/lambda-calcul/haskell/test/Minilang/REPLSpec.hs
+++ b/lambda-calcul/haskell/test/Minilang/REPLSpec.hs
@@ -2,10 +2,7 @@ module Minilang.REPLSpec where
import Control.Exception (bracket)
import Data.Text.IO
-import Minilang.Lambda.Eval (Term (Var))
import Minilang.REPL
-import Minilang.REPL.Purer
-import Minilang.REPL.Types
import System.Directory (getTemporaryDirectory, removeFile)
import System.FilePath ((<.>), (</>))
import System.IO (IOMode (..), hClose, withFile)
@@ -19,16 +16,11 @@ spec = parallel $
it "evaluates MiniLang terms read from pure Monad" $ do
let out =
withInput
- [ "rec Nat : U = Sum (zero | succ Nat);",
- "id : Π A : U . Π _ : A . A = λ A . λ x . x;",
- "id Nat (succ (succ (succ zero)))"
- ]
+ ["((lam (x) x) y)"]
out
`shouldBe` [ "Bye!",
- "$succ $succ $succ $zero : Sum(zero| succ Nat)",
- "defined id : Π A : U . A → A",
- "defined Nat : U"
+ "y : b"
]
it "shows error when trying to load a non-existent file" $ do
@@ -41,7 +33,11 @@ spec = parallel $
it "evaluates single MiniLang term read from IO" $ \fileName -> do
let outputFileName = fileName <> ".out"
- writeFile fileName "rec Nat : U = Sum (zero | succ Nat);\nid : Π A : U . Π _ : A . A = λ A . λ x . x;\nid Nat (succ (succ (succ zero)))"
+ writeFile
+ fileName
+ "(let ((Succ (lam (n z s) (s n))) \
+ \ (Zero (lam (z s) z))) \
+ \ Zero)"
_ <- withFile fileName ReadMode $ \hin ->
withFile outputFileName AppendMode $ \hout ->
@@ -50,21 +46,7 @@ spec = parallel $
out <- readFile outputFileName
out
- `shouldBe` "\955\928> defined Nat : U\n\955\928> defined id : \928 A : U . A \8594 A\n\955\928> succ succ succ zero : Sum(zero| succ Nat)\n\955\928> Bye!\n"
-
- describe "Purer REPL" $ do
- it "keeps handling Inputs even when they fail" $ do
- let inputs =
- [ In "Unit : U",
- In "Unit : U = Sum(tt)",
- Com DumpEnv
- ]
-
- env (purerREPL (withInputs initialREPL inputs))
- `shouldBe` [("Unit", Var "x")]
-
- outputs (withInputs initialREPL inputs)
- `shouldContain` [Msg "cannot find \"Unit\" in empty context"]
+ `shouldBe` "\955\928> (lam (z s) z) : c -> d -> c\n\955\928> Bye!\n"
withTempFile :: (String -> IO ()) -> IO ()
withTempFile =