From ea41a7529715987941257a0330c1eb1ae08cc12c Mon Sep 17 00:00:00 2001 From: Paweł Dybiec Date: Wed, 8 Jan 2020 20:22:14 +0100 Subject: Initial commit Initial version of project. What is done: * Syntax of expressions,commands,programs and types * Crude typechecking * Some typechecking tests --- test/Spec.hs | 6 ++++++ test/TypecheckTest.hs | 14 ++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 test/Spec.hs create mode 100644 test/TypecheckTest.hs (limited to 'test') diff --git a/test/Spec.hs b/test/Spec.hs new file mode 100644 index 0000000..4e3f0c1 --- /dev/null +++ b/test/Spec.hs @@ -0,0 +1,6 @@ +import Test.Hspec +import TypecheckTest +main :: IO () +main = hspec $ do + typecheckTest + diff --git a/test/TypecheckTest.hs b/test/TypecheckTest.hs new file mode 100644 index 0000000..b08574a --- /dev/null +++ b/test/TypecheckTest.hs @@ -0,0 +1,14 @@ +module TypecheckTest + where +import Typecheck +import Syntax +import Test.Hspec +typecheckTest :: Spec +typecheckTest = describe "inferExpr" $ do + it "can infer variables" $ do + inferExpr (Var "a") [("a", TInt)] `shouldBe` Just TInt + inferExpr (Var "a") [("a", TRecord [("b",TInt)])] `shouldBe` (Just $ TRecord [("b",TInt)]) + inferExpr (Var "a") [("a", TVariant [("b",TInt)])] `shouldBe` (Just $ TVariant[("b",TInt)]) + inferExpr (Var "a") [("a", TPtr TInt)] `shouldBe` ( Just $ TPtr TInt ) + it "shouldn't infer undefined variables" $ do + inferExpr (Var "a") [] `shouldBe` Nothing -- cgit 1.4.1