1 {-# LANGUAGE FlexibleContexts #-}
3 {-# LANGUAGE NoMonomorphismRestriction #-}
4 {-# LANGUAGE Rank2Types #-}
5 {-# LANGUAGE ScopedTypeVariables #-}
6 {-# LANGUAGE TypeOperators #-}
7 {-# OPTIONS_GHC -fno-warn-missing-signatures #-}
8 module Expr.Int.Test where
11 import Test.Tasty.HUnit
13 import qualified Control.Arrow as Arrow
14 import qualified Control.Monad as Monad
15 import Data.Functor.Identity
16 -- import Control.Monad.IO.Class (MonadIO(..))
17 import Data.Proxy (Proxy(..))
18 import Data.Text (Text)
19 import Data.Type.Equality ((:~:)(Refl))
20 import Prelude hiding ((&&), not, (||), (+), negate)
22 import Language.Symantic.Repr
23 import Language.Symantic.Expr
24 import Language.Symantic.Type
25 -- import Language.Symantic.Trans
29 -- * Class 'Sym_Int_Vars'
31 -- | A few boolean variables.
32 class Sym_Int_Vars repr where
36 instance Sym_Int_Vars (Repr_Text fun) where
37 x = Repr_Text $ \_p _v -> "x"
38 y = Repr_Text $ \_p _v -> "y"
39 z = Repr_Text $ \_p _v -> "z"
43 e2 = (int 1 + int 0) + negate (int 1 + int 1)
44 e3 = (int 1 + negate (int 0)) + (int 1 + negate (int 1))
45 e4 = int 0 + negate (int 1)
52 type Ex lam = Expr_Root
54 .|. Expr_Lambda_Val lam
57 ex_from = root_expr_from (Proxy::Proxy (Ex lam)) (Proxy::Proxy lam)
62 Left err -> Left err @?= snd `Arrow.left` expected
63 Right (Exists_Type_and_Repr ty (Forall_Repr r)) ->
65 Left (_, err) -> Right ("…"::String) @?= Left err
66 Right (ty_expected::Type_Root_of_Expr (Ex Identity) h, _::h, _::Text) ->
67 (Monad.>>= (@?= (\(_::Proxy h, err) -> err) `Arrow.left` expected)) $
68 case ty `eq_type` ty_expected of
69 Nothing -> Monad.return $ Left $
70 error_expr (Proxy::Proxy (Ex Identity)) $
71 Error_Expr_Type_mismatch ast
73 (Exists_Type ty_expected)
75 let h = runIdentity $ host_from_expr r
81 -- , (text_from_expr :: Repr_Text Identity h -> Text) r
85 tests = testGroup "Int" $
86 [ AST "int" [AST "1" []] ==> Right
90 , AST "bool" [AST "True" []] ==> Left (Proxy::Proxy Bool,
92 Error_Expr_Unsupported $ AST "bool" [AST "True" []])
94 [ AST "int" [AST "1" []]
95 , AST "int" [AST "1" []]
100 , let ast = AST "app"
101 [ AST "int" [AST "1" []]
102 , AST "int" [AST "1" []]
103 ] in ast ==> Left (Proxy::Proxy Int,
104 Error_Expr_Alt_Curr $
105 Error_Expr_Type_mismatch ast
106 (Exists_Type (type_var0 SZero `type_fun` type_var0 (SSucc SZero)
107 ::Type_Root (Type_Var0 :|: Type_Var1 :|: Type_Fun Identity :|: Type_Int)
108 (Lambda Identity Var0 Var0)))
109 (Exists_Type type_int))
114 , AST "var" [AST "x" []]
116 , AST "int" [AST "1" []]
126 [ AST "var" [AST "x" []]
127 , AST "int" [AST "1" []]
130 , AST "int" [AST "1" []]
134 , "(\\x0 -> x0 + 1) 1" )
137 , AST "int" [AST "1" []]
139 [ AST "var" [AST "x" []]
140 , AST "int" [AST "1" []]
145 , "let x0 = 1 in x0 + 1" )