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
32 .|. Expr_Lambda_Val lam
36 ex_from = root_expr_from (Proxy::Proxy (Ex lam)) (Proxy::Proxy lam)
41 Left err -> Left err @?= snd `left` expected
42 Right (Exists_Type_and_Repr ty (Forall_Repr r)) ->
44 Left (_, err) -> Right ("…"::String) @?= Left err
45 Right (ty_expected::Type_Root_of_Expr (Ex IO) h, _::h, _::Text) ->
46 (>>= (@?= (\(_::Proxy h, err) -> err) `left` expected)) $
47 case ty `eq_type` ty_expected of
48 Nothing -> return $ Left $
49 error_expr (Proxy::Proxy (Ex IO)) $
50 Error_Expr_Type_mismatch ast
52 (Exists_Type ty_expected)
60 -- , (text_from_expr :: Repr_String IO h -> String) r
64 tests = testGroup "If"
66 [ AST "bool" [AST "True" []]
67 , AST "bool" [AST "False" []]
68 , AST "bool" [AST "True" []]
72 , "if True then False else True" )