1 {-# LANGUAGE FlexibleContexts #-}
2 {-# LANGUAGE TypeOperators #-}
6 import Test.Tasty.HUnit
9 import Language.Symantic.Type
13 type Type_Fun_Bool lam = Type_Root (Type_Fun lam :|: Type_Bool)
14 type Type_Fun_Bool_Int lam = Type_Root (Type_Fun lam :|: Type_Bool :|: Type_Int)
15 type Type_Fun_Int lam = Type_Root (Type_Fun lam :|: Type_Int)
18 tests = testGroup "Type" $
19 let (==>) ast expected p =
21 (@?= Exists_Type <$> expected) $
22 type_from p ast (Right . Exists_Type) in
25 ==> Right (type_bool :: Type_Fun_Bool lam Bool) $
26 (Proxy :: Proxy (Type_Fun_Bool lam))
27 , AST "->" [AST "Bool" []]
28 ==> Left (lift_error_type $
29 Error_Type_Wrong_number_of_arguments (AST "->" [AST "Bool" []]) 2) $
30 (Proxy :: Proxy (Type_Fun_Bool lam))
31 , AST "->" [AST "Bool" [], AST "Bool" []]
32 ==> Right (type_bool `type_fun` type_bool
33 :: Type_Fun_Bool lam (Lambda lam Bool Bool)) $
34 (Proxy :: Proxy (Type_Fun_Bool lam))
35 , AST "->" [ AST "->" [AST "Bool" [], AST "Bool" []]
37 ==> Right ((type_bool `type_fun` type_bool) `type_fun` type_bool
38 :: Type_Fun_Bool lam (Lambda lam (Lambda lam Bool Bool) Bool)) $
39 (Proxy :: Proxy (Type_Fun_Bool lam))
40 , AST "->" [ AST "Bool" []
41 , AST "->" [AST "Bool" [], AST "Bool" []] ]
42 ==> Right (type_bool `type_fun` (type_bool `type_fun` type_bool)
43 :: Type_Fun_Bool lam (Lambda lam Bool (Lambda lam Bool Bool))) $
44 (Proxy :: Proxy (Type_Fun_Bool lam))
46 ==> Left (lift_error_type $ Error_Type_Unsupported $ AST "Int" []) $
47 (Proxy :: Proxy (Type_Fun_Bool lam))
48 , AST "->" [AST "Bool" [], AST "Int" []]
49 ==> Left (lift_error_type $ Error_Type_Unsupported $ AST "Int" []) $
50 (Proxy :: Proxy (Type_Fun_Bool lam))
51 , AST "->" [ AST "->" [AST "Int" [], AST "Bool" []]
53 ==> Left (lift_error_type $ Error_Type_Unsupported $ AST "Int" []) $
54 (Proxy :: Proxy (Type_Fun_Bool lam))
58 ==> Right (type_int :: Type_Fun_Int lam Int) $
59 (Proxy :: Proxy (Type_Fun_Int lam))
60 , AST "->" [AST "Int" []]
61 ==> Left (lift_error_type $
62 Error_Type_Wrong_number_of_arguments (AST "->" [AST "Int" []]) 2) $
63 (Proxy :: Proxy (Type_Fun_Int lam))
64 , AST "->" [AST "Int" [], AST "Int" []]
65 ==> Right (type_int `type_fun` type_int
66 :: Type_Fun_Int lam (Lambda lam Int Int)) $
67 (Proxy :: Proxy (Type_Fun_Int lam))
68 , AST "->" [ AST "->" [AST "Int" [], AST "Int" []]
70 ==> Right ((type_int `type_fun` type_int) `type_fun` type_int
71 :: Type_Fun_Int lam (Lambda lam (Lambda lam Int Int) Int)) $
72 (Proxy :: Proxy (Type_Fun_Int lam))
73 , AST "->" [ AST "Int" []
74 , AST "->" [AST "Int" [], AST "Int" []] ]
75 ==> Right (type_int `type_fun` (type_int `type_fun` type_int)
76 :: Type_Fun_Int lam (Lambda lam Int (Lambda lam Int Int))) $
77 (Proxy :: Proxy (Type_Fun_Int lam))
79 ==> Left (lift_error_type $ Error_Type_Unsupported $ AST "Bool" []) $
80 (Proxy :: Proxy (Type_Fun_Int lam))
81 , AST "->" [AST "Int" [], AST "Bool" []]
82 ==> Left (lift_error_type $ Error_Type_Unsupported $ AST "Bool" []) $
83 (Proxy :: Proxy (Type_Fun_Int lam))
84 , AST "->" [ AST "->" [AST "Bool" [], AST "Int" []]
86 ==> Left (lift_error_type $ Error_Type_Unsupported $ AST "Bool" []) $
87 (Proxy :: Proxy (Type_Fun_Int lam))
91 ==> Right (type_int :: Type_Fun_Bool_Int lam Int) $
92 (Proxy :: Proxy (Type_Fun_Bool_Int lam))
93 , AST "->" [AST "Bool" [], AST "Int" []]
94 ==> Right (type_bool `type_fun` type_int
95 :: Type_Fun_Bool_Int lam (Lambda lam Bool Int)) $
96 (Proxy :: Proxy (Type_Fun_Bool_Int lam))
97 , AST "->" [ AST "->" [AST "Int" [], AST "Bool" []]
99 ==> Right ((type_int `type_fun` type_bool) `type_fun` type_int
100 :: Type_Fun_Bool_Int lam (Lambda lam (Lambda lam Int Bool) Int)) $
101 (Proxy :: Proxy (Type_Fun_Bool_Int lam))