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.Proxy (Proxy(..))
16 import Data.Text (Text)
17 import Data.Type.Equality ((:~:)(Refl))
18 import Prelude hiding ((&&), not, (||), (+), negate)
20 import Language.Symantic.Repr
21 import Language.Symantic.Expr
22 import Language.Symantic.Type
23 -- import Language.Symantic.Trans
27 -- * Class 'Sym_Int_Vars'
29 -- | A few boolean variables.
30 class Sym_Int_Vars repr where
34 instance Sym_Int_Vars Repr_Text where
35 x = Repr_Text $ \_p _v -> "x"
36 y = Repr_Text $ \_p _v -> "y"
37 z = Repr_Text $ \_p _v -> "z"
41 e2 = (int 1 + int 0) + negate (int 1 + int 1)
42 e3 = (int 1 + negate (int 0)) + (int 1 + negate (int 1))
43 e4 = int 0 + negate (int 1)
56 ex_from = root_expr_from (Proxy::Proxy Ex)
61 Left err -> Left err @?= Prelude.snd `Arrow.left` expected
62 Right (Exists_Type0_and_Repr ty (Forall_Repr r)) ->
64 Left (_, err) -> Right ("…"::String) @?= Left err
65 Right (ty_expected::Type_Root_of_Expr Ex h, _::h, _::Text) ->
66 (Monad.>>= (@?= (\(_::Proxy h, err) -> err) `Arrow.left` expected)) $
67 case ty `type0_eq` ty_expected of
68 Nothing -> Monad.return $ Left $
69 error_expr (Proxy::Proxy Ex) $
70 Error_Expr_Type_mismatch ast
72 (Exists_Type0 ty_expected)
74 let h = host_from_expr r
80 -- , (text_from_expr :: Repr_Text h -> Text) r
84 tests = testGroup "Int" $
85 [ AST "int" [AST "1" []] ==> Right
89 , AST "bool" [AST "True" []] ==> Left (Proxy::Proxy Bool,
91 Error_Expr_Unsupported $ AST "bool" [AST "True" []])
93 [ AST "int" [AST "1" []]
94 , AST "int" [AST "1" []]
100 [ AST "int" [AST "1" []]
101 , AST "int" [AST "1" []]
102 ] in ast ==> Left (Proxy::Proxy Int,
103 Error_Expr_Alt_Curr $
104 Error_Expr_Type_mismatch ast
105 (Exists_Type0 (type_var0 SZero `type_fun` type_var0 (SSucc SZero)
106 ::Type_Root_of_Expr Ex ((->) Var0 Var0)))
107 (Exists_Type0 type_int))
112 , AST "var" [AST "x" []]
114 , AST "int" [AST "1" []]
124 [ AST "var" [AST "x" []]
125 , AST "int" [AST "1" []]
128 , AST "int" [AST "1" []]
132 , "(\\x0 -> x0 + 1) 1" )
135 , AST "int" [AST "1" []]
137 [ AST "var" [AST "x" []]
138 , AST "int" [AST "1" []]
143 , "let x0 = 1 in x0 + 1" )