1 {-# LANGUAGE FlexibleContexts #-}
3 {-# LANGUAGE NoMonomorphismRestriction #-}
4 {-# LANGUAGE Rank2Types #-}
5 {-# LANGUAGE ScopedTypeVariables #-}
6 {-# OPTIONS_GHC -fno-warn-missing-signatures #-}
7 module Expr.If.Test where
10 import Test.Tasty.HUnit
12 import Control.Arrow (left)
13 import Data.Proxy (Proxy(..))
14 import Data.Type.Equality ((:~:)(Refl))
15 import Prelude hiding (maybe, not)
17 import Language.LOL.Symantic.Repr
18 import Language.LOL.Symantic.AST
19 import Language.LOL.Symantic.Expr
20 import Language.LOL.Symantic.Type
30 ( Eq h, Eq ast, Show h, Show ast
31 , root ~ Expr_Lambda_If_Bool IO
32 , Expr_from ast (Expr_Lambda IO root)
33 , Expr_from ast (Expr_Bool root)
34 , Expr_from ast (Expr_If root)
36 -> Either (Proxy h, Error_of_Expr ast root)
37 (Type_Root_of_Expr (Expr_Lambda_If_Bool IO) h, h, String)
41 case expr_lambda_if_bool_from (Proxy::Proxy IO) ast of
42 Left err -> Left err @?= snd `left` expected
43 Right (Exists_Type_and_Repr ty (Forall_Repr r)) ->
45 Left (_, err) -> Right ("…"::String) @?= Left err
46 Right (ty_expected::Type_Root_of_Expr (Expr_Lambda_If_Bool IO) h, _::h, _::String) ->
47 (>>= (@?= (\(_::Proxy h, err) -> err) `left` expected)) $
48 case ty `type_eq` ty_expected of
49 Nothing -> return $ Left $
50 error_expr (Proxy::Proxy (Expr_Lambda_If_Bool IO)) $
51 Error_Expr_Type_mismatch ast
53 (Exists_Type ty_expected)
61 -- , (string_from_expr :: Repr_String IO h -> String) r
65 tests = testGroup "If"
67 [ AST "bool" [AST "True" []]
68 , AST "bool" [AST "False" []]
69 , AST "bool" [AST "True" []]
73 , "if True then False else True" )