diff options
| author | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-11-05 12:02:23 +0100 |
|---|---|---|
| committer | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-11-05 12:02:23 +0100 |
| commit | 99e2ce71faa82e7b99574895e0fe24183ba9f6c3 (patch) | |
| tree | 10538bb91d187a3c1d281a87a3974a6036f2ad2f /lambda-calcul/haskell/test | |
| parent | 438e3f8c5dcdfeead15a6a9a1760f7c254fc54b2 (diff) | |
| download | lambda-nantes-99e2ce71faa82e7b99574895e0fe24183ba9f6c3.tar.gz | |
can parse whole programs and load them
Diffstat (limited to 'lambda-calcul/haskell/test')
| -rw-r--r-- | lambda-calcul/haskell/test/Minilang/Lambda/ParserSpec.hs | 20 | ||||
| -rw-r--r-- | lambda-calcul/haskell/test/Minilang/REPL/HaskelineSpec.hs | 2 | ||||
| -rw-r--r-- | lambda-calcul/haskell/test/Minilang/REPLSpec.hs | 17 |
3 files changed, 37 insertions, 2 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 diff --git a/lambda-calcul/haskell/test/Minilang/REPL/HaskelineSpec.hs b/lambda-calcul/haskell/test/Minilang/REPL/HaskelineSpec.hs index 1b0f600..1cc1d09 100644 --- a/lambda-calcul/haskell/test/Minilang/REPL/HaskelineSpec.hs +++ b/lambda-calcul/haskell/test/Minilang/REPL/HaskelineSpec.hs @@ -26,7 +26,7 @@ spec = parallel $ describe "MiniLang Haskeline REPL" $ describe "Completion" $ d it "returns list of files when input ':load' " $ sort . fmap replacement . snd <$> completion ("daol:", "") - `shouldReturn` [":load bool.lisp", ":load fac.lisp"] + `shouldReturn` [":load bool-prog.lisp", ":load bool.lisp", ":load fac.lisp"] it "returns filtered list of files when input ':load xxx' " $ fmap replacement . snd <$> completion ("f daol:", "") diff --git a/lambda-calcul/haskell/test/Minilang/REPLSpec.hs b/lambda-calcul/haskell/test/Minilang/REPLSpec.hs index 861c24c..aa73b69 100644 --- a/lambda-calcul/haskell/test/Minilang/REPLSpec.hs +++ b/lambda-calcul/haskell/test/Minilang/REPLSpec.hs @@ -1,8 +1,15 @@ 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) +import Minilang.REPL.Types (Out (Evaluated)) import System.Directory (getTemporaryDirectory, removeFile) import System.FilePath ((<.>), (</>)) import System.IO (IOMode (..), hClose, withFile) @@ -83,6 +90,16 @@ spec = parallel $ "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) + -- outputs `shouldBe` [] + + it "can load 'bool.lisp'" $ do + boolProg <- readFile "bool.lisp" + let PurerEnv {outputs} = runProgram (loadProgramInEnv boolProg) + outputs `shouldBe` [Evaluated (Abs ["f", "t"] (Sym "f")) (Lam "f" (Lam "t" (Var "f"))) (TyVar "<?>")] + around withTempFile $ it "evaluates single MiniLang term read from IO" $ \fileName -> do let outputFileName = fileName <> ".out" |
