1 {-# LANGUAGE ConstraintKinds #-}
2 {-# LANGUAGE FlexibleContexts #-}
3 {-# LANGUAGE OverloadedStrings #-}
4 {-# LANGUAGE Rank2Types #-}
5 {-# LANGUAGE ScopedTypeVariables #-}
6 {-# LANGUAGE TypeOperators #-}
8 module Repr.Host.Test where
10 -- import Data.Function (($))
12 import Test.Tasty.HUnit
14 import Data.Text (Text)
15 import qualified Data.Text as Text
16 import Prelude hiding (and, not, or, Monad(..), id)
18 import Language.Symantic.Repr
19 import Language.Symantic.Expr
20 import qualified Expr.Lambda.Test as Lambda.Test
21 import qualified Expr.Bool.Test as Bool.Test
22 import qualified Expr.Maybe.Test as Maybe.Test
23 import qualified Expr.If.Test as If.Test
24 import qualified Expr.List.Test as List.Test
25 import qualified Expr.Functor.Test as Functor.Test
26 import qualified Expr.Applicative.Test as Applicative.Test
27 import qualified Expr.Foldable.Test as Foldable.Test
30 tests = testGroup "Host" $
32 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda
34 )) repr => repr h) expected =
35 testCase (Text.unpack $ text_from_expr $ expr) $
36 -- (>>= (@?= expected)) $
38 host_from_expr expr in
39 [ Bool.Test.e1 ==> False
40 , Bool.Test.e2 ==> True
41 , Bool.Test.e3 ==> True
42 , Bool.Test.e4 ==> True
44 , testGroup "Lambda" $
45 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda
47 )) repr => repr h) expected =
48 testCase (Text.unpack $ text_from_expr $ expr) $
50 host_from_expr expr in
51 [ (Lambda.Test.e1 $$ bool True $$ bool True) ==> False
52 , (Lambda.Test.e1 $$ bool True $$ bool False) ==> True
53 , (Lambda.Test.e1 $$ bool False $$ bool True) ==> True
54 , (Lambda.Test.e1 $$ bool False $$ bool False) ==> False
56 , (Lambda.Test.e2 $$ bool True $$ bool True) ==> False
57 , (Lambda.Test.e2 $$ bool True $$ bool False) ==> True
58 , (Lambda.Test.e2 $$ bool False $$ bool True) ==> True
59 , (Lambda.Test.e2 $$ bool False $$ bool False) ==> False
61 , Lambda.Test.e3 ==> True
62 , Lambda.Test.e4 ==> True
64 , (Lambda.Test.e5 $$ bool True $$ bool True) ==> True
65 , (Lambda.Test.e5 $$ bool True $$ bool False) ==> False
66 , (Lambda.Test.e5 $$ bool False $$ bool True) ==> False
67 , (Lambda.Test.e5 $$ bool False $$ bool False) ==> False
69 , Lambda.Test.e6 ==> False
70 , (Lambda.Test.e7 $$ lam id) ==> True
71 , (Lambda.Test.e7 $$ lam not) ==> False
74 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda
76 .|. Expr_Bool )) repr => repr h) expected =
77 testCase (Text.unpack $ text_from_expr $ expr) $
79 host_from_expr expr in
80 [ Maybe.Test.e1 ==> False
83 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda
85 .|. Expr_Bool )) repr => repr h) expected =
86 testCase (Text.unpack $ text_from_expr $ expr) $
88 host_from_expr expr in
89 [ If.Test.e1 ==> False
92 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda
99 .|. Expr_Eq )) repr => repr h) expected =
100 testCase (Text.unpack $ text_from_expr $ expr) $
102 host_from_expr expr in
103 [ List.Test.e1 ==> [2::Int,4]
105 , testGroup "Functor" $
106 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda
113 .|. Expr_Eq )) repr => repr h) expected =
114 testCase (Text.unpack $ (text_from_expr :: Repr_Text _h -> Text) $ expr) $
116 host_from_expr expr in
117 [ Functor.Test.e1 ==> [2::Int,3,4]
119 , testGroup "Applicative" $
120 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda
129 .|. Expr_Eq )) repr => repr h) expected =
130 testCase (Text.unpack $ text_from_expr $ expr) $
132 host_from_expr expr in
133 [ Applicative.Test.e1 ==> Just (3::Int)
135 , testGroup "Foldable" $
136 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda
144 .|. Expr_Eq )) repr => repr h) expected =
145 testCase (Text.unpack $ text_from_expr $ expr) $
147 host_from_expr expr in
148 [ Foldable.Test.e1 ==> [1::Int,1,2,2,3,3]