about summary refs log tree commit diff
path: root/test/TypecheckTest.hs
diff options
context:
space:
mode:
Diffstat (limited to 'test/TypecheckTest.hs')
-rw-r--r--test/TypecheckTest.hs14
1 files changed, 14 insertions, 0 deletions
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