{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE NoMonomorphismRestriction #-} {-# LANGUAGE Rank2Types #-} {-# LANGUAGE ScopedTypeVariables #-} {-# OPTIONS_GHC -fno-warn-missing-signatures #-} module Expr.If.Test where import Test.Tasty import Test.Tasty.HUnit import Control.Arrow (left) import Data.Proxy (Proxy(..)) import Data.Type.Equality ((:~:)(Refl)) import Prelude hiding (maybe, not) import Language.LOL.Symantic.Repr import Language.LOL.Symantic.AST import Language.LOL.Symantic.Expr import Language.LOL.Symantic.Type -- * Expressions e1 = if_ (bool True) (bool False) (bool True) -- * Tests (==>) :: forall h ast root. ( Eq h, Eq ast, Show h, Show ast , root ~ Expr_Lambda_If_Bool IO , Expr_from ast (Expr_Lambda IO root) , Expr_from ast (Expr_Bool root) , Expr_from ast (Expr_If root) ) => ast -> Either (Proxy h, Error_of_Expr ast root) (Type_Root_of_Expr (Expr_Lambda_If_Bool IO) h, h, String) -> TestTree (==>) ast expected = testCase (show ast) $ case expr_lambda_if_bool_from (Proxy::Proxy IO) ast of Left err -> Left err @?= snd `left` expected Right (Exists_Type_and_Repr ty (Forall_Repr r)) -> case expected of Left (_, err) -> Right ("…"::String) @?= Left err Right (ty_expected::Type_Root_of_Expr (Expr_Lambda_If_Bool IO) h, _::h, _::String) -> (>>= (@?= (\(_::Proxy h, err) -> err) `left` expected)) $ case ty `type_eq` ty_expected of Nothing -> return $ Left $ error_expr (Proxy::Proxy (Expr_Lambda_If_Bool IO)) $ Error_Expr_Type_mismatch ast (Exists_Type ty) (Exists_Type ty_expected) Just Refl -> do h <- host_from_expr r return $ Right ( ty , h , string_from_expr r -- , (string_from_expr :: Repr_String IO h -> String) r ) tests :: TestTree tests = testGroup "If" [ AST "if" [ AST "bool" [AST "True" []] , AST "bool" [AST "False" []] , AST "bool" [AST "True" []] ] ==> Right ( type_bool , False , "if True then False else True" ) ]