1 {-# LANGUAGE FlexibleContexts #-}
3 {-# LANGUAGE NoMonomorphismRestriction #-}
4 {-# LANGUAGE Rank2Types #-}
5 {-# LANGUAGE ScopedTypeVariables #-}
6 {-# OPTIONS_GHC -fno-warn-missing-signatures #-}
7 module Expr.Int.Test where
10 import Test.Tasty.HUnit
12 import Control.Arrow (left)
13 -- import Data.Functor.Identity (Identity)
14 -- import Control.Monad.IO.Class (MonadIO(..))
15 import Data.Proxy (Proxy(..))
16 import Data.Text (Text)
17 import Data.Type.Equality ((:~:)(Refl))
18 import Prelude hiding (and, not, or)
20 import Language.LOL.Symantic.Repr
21 import Language.LOL.Symantic.AST
22 import Language.LOL.Symantic.Expr
23 import Language.LOL.Symantic.Type
24 -- import Language.LOL.Symantic.Trans
26 -- * Class 'Sym_Int_Vars'
28 -- | A few boolean variables.
29 class Sym_Int_Vars repr where
33 instance Sym_Int_Vars (Repr_Text fun) where
34 x = Repr_Text $ \_p _v -> "x"
35 y = Repr_Text $ \_p _v -> "y"
36 z = Repr_Text $ \_p _v -> "z"
39 e1 = int 1 `add` int 0
40 e2 = (int 1 `add` int 0) `add` neg (int 1 `add` int 1)
41 e3 = (int 1 `add` neg (int 0)) `add` (int 1 `add` neg (int 1))
42 e4 = int 0 `add` neg (int 1)
43 e5 = int 1 `add` neg x
45 e7 = (x `add` y) `add` z
46 e8 = x `add` (y `add` int 1)
51 case expr_lambda_int_from (Proxy::Proxy IO) ast of
52 Left err -> Left err @?= snd `left` expected
53 Right (Exists_Type_and_Repr ty (Forall_Repr r)) ->
55 Left (_, err) -> Right ("…"::String) @?= Left err
56 Right (ty_expected::Type_Root_of_Expr (Expr_Lambda_Int IO) h, _::h, _::Text) ->
57 (>>= (@?= (\(_::Proxy h, err) -> err) `left` expected)) $
58 case ty `type_eq` ty_expected of
59 Nothing -> return $ Left $
60 error_expr (Proxy::Proxy (Expr_Lambda_Int IO)) $
61 Error_Expr_Type_mismatch ast
63 (Exists_Type ty_expected)
71 -- , (text_from_expr :: Repr_Text IO h -> String) r
75 tests = testGroup "Int" $
76 [ AST "int" [AST "1" []] ==> Right
80 , AST "bool" [AST "True" []] ==> Left (Proxy::Proxy Bool,
82 Error_Expr_Unsupported $ AST "bool" [AST "True" []])
84 [ AST "int" [AST "1" []]
85 , AST "int" [AST "1" []]
91 [ AST "int" [AST "1" []]
92 , AST "int" [AST "1" []]
93 ] in ast ==> Left (Proxy::Proxy Int,
95 Error_Expr_Type_mismatch ast
96 (Exists_Type (type_var SZero `type_fun` type_var (SSucc SZero)
97 ::Type_Fun_Int IO (IO Zero -> IO (Succ Zero))))
98 (Exists_Type type_int))
103 , AST "var" [AST "x" []]
105 , AST "int" [AST "1" []]
115 [ AST "var" [AST "x" []]
116 , AST "int" [AST "1" []]
119 , AST "int" [AST "1" []]
123 , "(\\x0 -> x0 + 1) 1" )
126 , AST "int" [AST "1" []]
128 [ AST "var" [AST "x" []]
129 , AST "int" [AST "1" []]
134 , "let x0 = 1 in x0 + 1" )