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 (($))
11 -- import Data.Functor.Identity (Identity)
13 import Test.Tasty.HUnit
15 import Data.Functor.Identity
16 import Data.Text (Text)
17 import qualified Data.Text as Text
18 import Prelude hiding (and, not, or, Monad(..))
20 import Language.Symantic.Repr
21 import Language.Symantic.Expr
22 import qualified Expr.Lambda.Test as Lambda.Test
23 import qualified Expr.Bool.Test as Bool.Test
24 import qualified Expr.Maybe.Test as Maybe.Test
25 import qualified Expr.If.Test as If.Test
26 import qualified Expr.List.Test as List.Test
27 import qualified Expr.Functor.Test as Functor.Test
28 import qualified Expr.Applicative.Test as Applicative.Test
29 import qualified Expr.Foldable.Test as Foldable.Test
32 tests = testGroup "Host" $
34 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda_App Identity
35 .|. Expr_Lambda_Val Identity
37 )) repr => repr h) expected =
38 testCase (Text.unpack $ (text_from_expr :: Repr_Text Identity _h -> Text) $ expr) $
39 -- (>>= (@?= expected)) $
40 (\(Identity a) -> (a @?= expected)) $
41 host_from_expr expr in
42 [ Bool.Test.e1 ==> False
43 , Bool.Test.e2 ==> True
44 , Bool.Test.e3 ==> True
45 , Bool.Test.e4 ==> True
47 , testGroup "Lambda" $
48 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda_App Identity
49 .|. Expr_Lambda_Val Identity
51 )) repr => repr h) expected =
52 testCase (Text.unpack $ (text_from_expr :: Repr_Text Identity _h -> Text) $ expr) $
53 (\(Identity a) -> (a @?= expected)) $
54 host_from_expr expr in
55 [ (Lambda.Test.e1 `app` bool True `app` bool True) ==> False
56 , (Lambda.Test.e1 `app` bool True `app` bool False) ==> True
57 , (Lambda.Test.e1 `app` bool False `app` bool True) ==> True
58 , (Lambda.Test.e1 `app` bool False `app` bool False) ==> False
60 , (Lambda.Test.e2 `app` bool True `app` bool True) ==> False
61 , (Lambda.Test.e2 `app` bool True `app` bool False) ==> True
62 , (Lambda.Test.e2 `app` bool False `app` bool True) ==> True
63 , (Lambda.Test.e2 `app` bool False `app` bool False) ==> False
65 , Lambda.Test.e3 ==> True
66 , Lambda.Test.e4 ==> True
68 , (Lambda.Test.e5 `app` bool True `app` bool True) ==> True
69 , (Lambda.Test.e5 `app` bool True `app` bool False) ==> False
70 , (Lambda.Test.e5 `app` bool False `app` bool True) ==> False
71 , (Lambda.Test.e5 `app` bool False `app` bool False) ==> False
73 , Lambda.Test.e6 ==> False
74 , (Lambda.Test.e7 `app` val id) ==> True
75 , (Lambda.Test.e7 `app` val not) ==> False
78 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda_App Identity
79 .|. Expr_Lambda_Val Identity
80 .|. Expr_Maybe Identity
81 .|. Expr_Bool )) repr => repr h) expected =
82 testCase (Text.unpack $ (text_from_expr :: Repr_Text Identity _h -> Text) $ expr) $
83 (\(Identity a) -> (a @?= expected)) $
84 host_from_expr expr in
85 [ Maybe.Test.e1 ==> False
88 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda_App Identity
89 .|. Expr_Lambda_Val Identity
91 .|. Expr_Bool )) repr => repr h) expected =
92 testCase (Text.unpack $ (text_from_expr :: Repr_Text Identity _h -> Text) $ expr) $
93 (\(Identity a) -> (a @?= expected)) $
94 host_from_expr expr in
95 [ If.Test.e1 ==> False
98 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda_App Identity
99 .|. Expr_Lambda_Val Identity
100 .|. Expr_List Identity
104 .|. Expr_Eq )) repr => repr h) expected =
105 testCase (Text.unpack $ (text_from_expr :: Repr_Text Identity _h -> Text) $ expr) $
106 (\(Identity a) -> (a @?= expected)) $
107 host_from_expr expr in
108 [ List.Test.e1 ==> [2::Int,4]
110 , testGroup "Functor" $
111 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda_App Identity
112 .|. Expr_Lambda_Val Identity
113 .|. Expr_List Identity
114 .|. Expr_Functor Identity
118 .|. Expr_Eq )) repr => repr h) expected =
119 testCase (Text.unpack $ (text_from_expr :: Repr_Text Identity _h -> Text) $ expr) $
120 (\(Identity a) -> (a @?= expected)) $
121 host_from_expr expr in
122 [ Functor.Test.e1 ==> [2::Int,3,4]
124 , testGroup "Applicative" $
125 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda_App Identity
126 .|. Expr_Lambda_Val Identity
127 .|. Expr_List Identity
128 .|. Expr_Functor Identity
129 .|. Expr_Applicative Identity
130 .|. Expr_Maybe Identity
134 .|. Expr_Eq )) repr => repr h) expected =
135 testCase (Text.unpack $ (text_from_expr :: Repr_Text Identity _h -> Text) $ expr) $
136 (\(Identity a) -> (a @?= expected)) $
137 host_from_expr expr in
138 [ Applicative.Test.e1 ==> Just (3::Int)
140 , testGroup "Foldable" $
141 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda_App Identity
142 .|. Expr_Lambda_Val Identity
143 .|. Expr_List Identity
144 .|. Expr_Foldable Identity
145 .|. Expr_Maybe Identity
149 .|. Expr_Eq )) repr => repr h) expected =
150 testCase (Text.unpack $ (text_from_expr :: Repr_Text Identity _h -> Text) $ expr) $
151 (\(Identity a) -> (a @?= expected)) $
152 host_from_expr expr in
153 [ Foldable.Test.e1 ==> [1::Int,1,2,2,3,3]