1 {-# LANGUAGE FlexibleContexts #-}
3 {-# LANGUAGE NoMonomorphismRestriction #-}
4 {-# LANGUAGE ScopedTypeVariables #-}
5 {-# LANGUAGE TypeOperators #-}
6 {-# OPTIONS_GHC -fno-warn-missing-signatures #-}
8 module Expr.Eq.Test where
11 import Test.Tasty.HUnit
13 import Control.Arrow (left)
14 import Data.Proxy (Proxy(..))
15 import Data.Text (Text)
16 import Data.Type.Equality ((:~:)(Refl))
17 import Prelude hiding ((&&), not, (||), (==))
19 import Language.Symantic.Type
20 import Language.Symantic.Expr
21 import Language.Symantic.Repr
28 e1 = if_ ((t && t) == (t || f)) t f
29 e2 = if_ (((t && t) || f) == (t && (t || f))) t f
30 e3 = if_ (not (t == f) == (t == t)) t f
33 type Ex lam = Expr_Root (Expr_Lambda lam .|. Expr_Bool .|. Expr_Eq)
34 ex_from = root_expr_from (Proxy::Proxy (Ex lam)) (Proxy::Proxy lam)
39 Left err -> Left err @?= snd `left` expected
40 Right (Exists_Type_and_Repr ty (Forall_Repr r)) ->
42 Left (_, err) -> Right ("…"::String) @?= Left err
43 Right (ty_expected::Type_Root_of_Expr (Ex IO) h, _::h, _::Text) ->
44 (>>= (@?= (\(_::Proxy h, err) -> err) `left` expected)) $
45 case ty `type_eq` ty_expected of
46 Nothing -> return $ Left $
47 error_expr (Proxy::Proxy (Ex IO)) $
48 Error_Expr_Type_mismatch ast
50 (Exists_Type ty_expected)
58 -- , (text_from_expr :: Repr_String IO h -> Text) r
62 tests = testGroup "Eq"
63 [ AST "==" [ AST "bool" [AST "True" []]
64 , AST "bool" [AST "True" []]
73 , AST "==" [ AST "var" [AST "x" []]
74 , AST "not" [AST "var" [AST "x" []]] ]
76 , AST "bool" [AST "True" []]
80 , "(\\x0 -> x0 == !x0) True" )