{-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE Rank2Types #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeOperators #-} module Repr.Host.Test where -- import Data.Function (($)) -- import Data.Functor.Identity (Identity) import Test.Tasty import Test.Tasty.HUnit import Data.Text (Text) import qualified Data.Text as Text import Prelude hiding (and, not, or) import Language.Symantic.Repr import Language.Symantic.Expr import qualified Expr.Lambda.Test as Lambda.Test import qualified Expr.Bool.Test as Bool.Test import qualified Expr.Maybe.Test as Maybe.Test import qualified Expr.If.Test as If.Test import qualified Expr.List.Test as List.Test tests :: TestTree tests = testGroup "Host" $ [ testGroup "Bool" $ let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root (Expr_Lambda IO .|. Expr_Bool)) repr => repr h) expected = testCase (Text.unpack $ (text_from_expr :: Repr_Text IO _h -> Text) $ expr) $ (>>= (@?= expected)) $ host_from_expr expr in [ Bool.Test.e1 ==> False , Bool.Test.e2 ==> True , Bool.Test.e3 ==> True , Bool.Test.e4 ==> True ] , testGroup "Lambda" $ let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root (Expr_Lambda IO .|. Expr_Bool)) repr => repr h) expected = testCase (Text.unpack $ (text_from_expr :: Repr_Text IO _h -> Text) $ expr) $ (>>= (@?= expected)) $ host_from_expr expr in [ (Lambda.Test.e1 `app` bool True `app` bool True) ==> False , (Lambda.Test.e1 `app` bool True `app` bool False) ==> True , (Lambda.Test.e1 `app` bool False `app` bool True) ==> True , (Lambda.Test.e1 `app` bool False `app` bool False) ==> False , (Lambda.Test.e2 `app` bool True `app` bool True) ==> False , (Lambda.Test.e2 `app` bool True `app` bool False) ==> True , (Lambda.Test.e2 `app` bool False `app` bool True) ==> True , (Lambda.Test.e2 `app` bool False `app` bool False) ==> False , Lambda.Test.e3 ==> True , Lambda.Test.e4 ==> True , (Lambda.Test.e5 `app` bool True `app` bool True) ==> True , (Lambda.Test.e5 `app` bool True `app` bool False) ==> False , (Lambda.Test.e5 `app` bool False `app` bool True) ==> False , (Lambda.Test.e5 `app` bool False `app` bool False) ==> False , Lambda.Test.e6 ==> False , (Lambda.Test.e7 `app` val id) ==> True , (Lambda.Test.e7 `app` val not) ==> False ] , testGroup "Maybe" $ let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root (Expr_Lambda IO .|. Expr_Maybe IO .|. Expr_Bool)) repr => repr h) expected = testCase (Text.unpack $ (text_from_expr :: Repr_Text IO _h -> Text) $ expr) $ (>>= (@?= expected)) $ host_from_expr expr in [ Maybe.Test.e1 ==> False ] , testGroup "If" $ let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root (Expr_Lambda IO .|. Expr_If .|. Expr_Bool)) repr => repr h) expected = testCase (Text.unpack $ (text_from_expr :: Repr_Text IO _h -> Text) $ expr) $ (>>= (@?= expected)) $ host_from_expr expr in [ If.Test.e1 ==> False ] , testGroup "List" $ let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda IO .|. Expr_List IO .|. Expr_Bool .|. Expr_Int .|. Expr_If .|. Expr_Eq )) repr => repr h) expected = testCase (Text.unpack $ (text_from_expr :: Repr_Text IO _h -> Text) $ expr) $ (>>= (@?= expected)) $ host_from_expr expr in [ List.Test.e1 ==> [2::Int,4] ] ]