{-# LANGUAGE NoMonomorphismRestriction #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE GADTs #-} {-# OPTIONS_GHC -fno-warn-missing-signatures #-} module Expr.Eq.Test where import Test.Tasty import Test.Tasty.HUnit import Control.Arrow (left) import Data.Proxy (Proxy(..)) import Data.Text (Text) import Data.Type.Equality ((:~:)(Refl)) import Prelude hiding (and, not, or) import Language.LOL.Symantic.Type import Language.LOL.Symantic.Expr import Language.LOL.Symantic.Repr import AST.Test -- * Expressions t = bool True f = bool False e1 = if_ ((t `and` t) `eq` (t `or` f)) t f e2 = if_ (((t `and` t) `or` f) `eq` (t `and` (t `or` f))) t f e3 = if_ (not (t `eq` f) `eq` (t `eq` t)) t f -- * Tests (==>) ast expected = testCase (show ast) $ case expr_lambda_bool_eq_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_Bool_Eq IO) h, _::h, _::Text) -> (>>= (@?= (\(_::Proxy h, err) -> err) `left` expected)) $ case ty `type_eq` ty_expected of Nothing -> return $ Left $ error_expr (Proxy::Proxy (Expr_Lambda_Bool_Eq 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 , text_from_expr r -- , (text_from_expr :: Repr_String IO h -> Text) r ) tests :: TestTree tests = testGroup "Eq" [ AST "eq" [ AST "bool" [AST "True" []] , AST "bool" [AST "True" []] ] ==> Right ( type_bool , True , "True == True" ) , AST "app" [ AST "val" [ AST "x" [] , AST "Bool" [] , AST "eq" [ AST "var" [AST "x" []] , AST "not" [AST "var" [AST "x" []]] ] ] , AST "bool" [AST "True" []] ] ==> Right ( type_bool , False , "(\\x0 -> x0 == !x0) True" ) ]