]> Git — Sourcephile - haskell/symantic.git/blob - Language/Symantic/Repr/Host/Test.hs
IO, Monoid, Foldable, Text
[haskell/symantic.git] / Language / Symantic / Repr / Host / Test.hs
1 {-# LANGUAGE ConstraintKinds #-}
2 {-# LANGUAGE FlexibleContexts #-}
3 {-# LANGUAGE OverloadedStrings #-}
4 {-# LANGUAGE Rank2Types #-}
5 {-# LANGUAGE ScopedTypeVariables #-}
6 {-# LANGUAGE TypeOperators #-}
7
8 module Repr.Host.Test where
9
10 -- import Data.Function (($))
11 -- import Data.Functor.Identity (Identity)
12 import Test.Tasty
13 import Test.Tasty.HUnit
14
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(..))
19
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
30
31 tests :: TestTree
32 tests = testGroup "Host" $
33 [ testGroup "Bool" $
34 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda_App Identity
35 .|. Expr_Lambda_Val Identity
36 .|. Expr_Bool
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
46 ]
47 , testGroup "Lambda" $
48 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda_App Identity
49 .|. Expr_Lambda_Val Identity
50 .|. Expr_Bool
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
59
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
64
65 , Lambda.Test.e3 ==> True
66 , Lambda.Test.e4 ==> True
67
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
72
73 , Lambda.Test.e6 ==> False
74 , (Lambda.Test.e7 `app` val id) ==> True
75 , (Lambda.Test.e7 `app` val not) ==> False
76 ]
77 , testGroup "Maybe" $
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
86 ]
87 , testGroup "If" $
88 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda_App Identity
89 .|. Expr_Lambda_Val Identity
90 .|. Expr_If
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
96 ]
97 , testGroup "List" $
98 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda_App Identity
99 .|. Expr_Lambda_Val Identity
100 .|. Expr_List Identity
101 .|. Expr_Bool
102 .|. Expr_Int
103 .|. Expr_If
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]
109 ]
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
115 .|. Expr_Bool
116 .|. Expr_Int
117 .|. Expr_If
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]
123 ]
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
131 .|. Expr_Bool
132 .|. Expr_Int
133 .|. Expr_If
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)
139 ]
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
146 .|. Expr_Bool
147 .|. Expr_Int
148 .|. Expr_If
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]
154 ]
155 ]