diff options
author | Paweł Dybiec <pawel.to.malpa@gmail.com> | 2020-01-09 18:16:17 +0100 |
---|---|---|
committer | Paweł Dybiec <pawel.to.malpa@gmail.com> | 2020-01-09 18:16:17 +0100 |
commit | a682acca0adfd805bde4b5159df551e4cd353135 (patch) | |
tree | 190da75815090c03ede8c30f5bc9074d0c8438f5 /test | |
parent | Infer for record types (diff) |
More tests
Diffstat (limited to 'test')
-rw-r--r-- | test/TypecheckTest.hs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/TypecheckTest.hs b/test/TypecheckTest.hs index b08574a..299c8c0 100644 --- a/test/TypecheckTest.hs +++ b/test/TypecheckTest.hs @@ -12,3 +12,23 @@ typecheckTest = describe "inferExpr" $ do inferExpr (Var "a") [("a", TPtr TInt)] `shouldBe` ( Just $ TPtr TInt ) it "shouldn't infer undefined variables" $ do inferExpr (Var "a") [] `shouldBe` Nothing + it "should be able to infer types of arithmetic expressions" $ do + inferExpr (IntLit 5) [] `shouldBe` (Just TInt) + inferExpr (Add (IntLit 1) (IntLit 3)) [] `shouldBe` (Just TInt) + inferExpr (Mult (IntLit 1) (IntLit 3)) [] `shouldBe` (Just TInt) + inferExpr (Neg (IntLit 3)) [] `shouldBe` (Just TInt) + it "shouldn't be able to do arithmetic operations on pointer" $ do + inferExpr (Add (IntLit 1) (Var "a")) [("a",(TPtr TInt))] `shouldBe` Nothing + inferExpr (Add (Var "a") (IntLit 1)) [("a",(TPtr TInt))] `shouldBe` Nothing + inferExpr (Mult (IntLit 1) (Var "a")) [("a",(TPtr TInt))] `shouldBe` Nothing + inferExpr (Mult (Var "a") (IntLit 1)) [("a",(TPtr TInt))] `shouldBe` Nothing + inferExpr (Neg (Var "a")) [("a",(TPtr TInt))] `shouldBe` Nothing + it "should infer compound types" $ do + inferExpr (Variant (TVariant [("Cons",TInt),("Cons2",TPtr TInt)]) "Cons" (IntLit 5)) [] `shouldBe` (Just $ TVariant [("Cons",TInt),("Cons2",TPtr TInt)]) + inferExpr (Record [("aa",Var "a"),("bb",Var "b")]) [("a",TInt), ("b",TPtr TInt)] `shouldBe` (Just $ TRecord [("aa",TInt),("bb",TPtr TInt)]) + it "should unpack Ptr for every dereference" $ do + inferExpr (Deref (Var "a")) [("a",TPtr TInt)] `shouldBe` (Just TInt) + inferExpr (Deref (Var "a")) [("a",TPtr $ TPtr TInt)] `shouldBe` (Just $ TPtr TInt) + + + |