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.If.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 (maybe, not, (&&))
19 import Language.Symantic.Repr
20 import Language.Symantic.Expr
21 import Language.Symantic.Type
26 e1 = if_ (bool True) (bool False) (bool True)
27 e2 = if_ (bool True && bool True) (bool False) (bool True)
30 type Ex lam = Expr_Root (Expr_Lambda lam .|. Expr_If .|. Expr_Bool)
31 ex_from = root_expr_from (Proxy::Proxy (Ex lam)) (Proxy::Proxy lam)
36 Left err -> Left err @?= snd `left` expected
37 Right (Exists_Type_and_Repr ty (Forall_Repr r)) ->
39 Left (_, err) -> Right ("…"::String) @?= Left err
40 Right (ty_expected::Type_Root_of_Expr (Ex IO) h, _::h, _::Text) ->
41 (>>= (@?= (\(_::Proxy h, err) -> err) `left` expected)) $
42 case ty `eq_type` ty_expected of
43 Nothing -> return $ Left $
44 error_expr (Proxy::Proxy (Ex IO)) $
45 Error_Expr_Type_mismatch ast
47 (Exists_Type ty_expected)
55 -- , (text_from_expr :: Repr_String IO h -> String) r
59 tests = testGroup "If"
61 [ AST "bool" [AST "True" []]
62 , AST "bool" [AST "False" []]
63 , AST "bool" [AST "True" []]
67 , "if True then False else True" )