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 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 (maybe, not, (&&), Monad(..))
20 import Language.Symantic.Repr
21 import Language.Symantic.Expr
22 import Language.Symantic.Type
27 e1 = if_ (bool True) (bool False) (bool True)
28 e2 = if_ (bool True && bool True) (bool False) (bool True)
36 ex_from = root_expr_from (Proxy::Proxy Ex)
41 Left err -> Left err @?= Prelude.snd `Arrow.left` expected
42 Right (Exists_Type0_and_Repr ty (Forall_Repr r)) ->
44 Left (_, err) -> Right ("…"::String) @?= Left err
45 Right (ty_expected::Type_Root_of_Expr Ex h, _::h, _::Text) ->
46 (Monad.>>= (@?= (\(_::Proxy h, err) -> err) `Arrow.left` expected)) $
47 case ty `type0_eq` ty_expected of
48 Nothing -> Monad.return $ Left $
49 error_expr (Proxy::Proxy Ex) $
50 Error_Expr_Type_mismatch ast
52 (Exists_Type0 ty_expected)
54 let h = host_from_expr r
60 -- , (text_from_expr :: Repr_Text h -> Text) 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" )