]> Git — Sourcephile - haskell/symantic.git/blob - Language/Symantic/Repr/Host/Test.hs
init
[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)
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
30 tests :: TestTree
31 tests = testGroup "Host" $
32 [ testGroup "Bool" $
33 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda_App IO
34 .|. Expr_Lambda_Val IO
35 .|. Expr_Bool
36 )) repr => repr h) expected =
37 testCase (Text.unpack $ (text_from_expr :: Repr_Text IO _h -> Text) $ expr) $
38 (>>= (@?= expected)) $
39 host_from_expr expr in
40 [ Bool.Test.e1 ==> False
41 , Bool.Test.e2 ==> True
42 , Bool.Test.e3 ==> True
43 , Bool.Test.e4 ==> True
44 ]
45 , testGroup "Lambda" $
46 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda_App IO
47 .|. Expr_Lambda_Val IO
48 .|. Expr_Bool
49 )) repr => repr h) expected =
50 testCase (Text.unpack $ (text_from_expr :: Repr_Text IO _h -> Text) $ expr) $
51 (>>= (@?= expected)) $
52 host_from_expr expr in
53 [ (Lambda.Test.e1 `app` bool True `app` bool True) ==> False
54 , (Lambda.Test.e1 `app` bool True `app` bool False) ==> True
55 , (Lambda.Test.e1 `app` bool False `app` bool True) ==> True
56 , (Lambda.Test.e1 `app` bool False `app` bool False) ==> False
57
58 , (Lambda.Test.e2 `app` bool True `app` bool True) ==> False
59 , (Lambda.Test.e2 `app` bool True `app` bool False) ==> True
60 , (Lambda.Test.e2 `app` bool False `app` bool True) ==> True
61 , (Lambda.Test.e2 `app` bool False `app` bool False) ==> False
62
63 , Lambda.Test.e3 ==> True
64 , Lambda.Test.e4 ==> True
65
66 , (Lambda.Test.e5 `app` bool True `app` bool True) ==> True
67 , (Lambda.Test.e5 `app` bool True `app` bool False) ==> False
68 , (Lambda.Test.e5 `app` bool False `app` bool True) ==> False
69 , (Lambda.Test.e5 `app` bool False `app` bool False) ==> False
70
71 , Lambda.Test.e6 ==> False
72 , (Lambda.Test.e7 `app` val id) ==> True
73 , (Lambda.Test.e7 `app` val not) ==> False
74 ]
75 , testGroup "Maybe" $
76 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda_App IO
77 .|. Expr_Lambda_Val IO
78 .|. Expr_Maybe IO
79 .|. Expr_Bool )) repr => repr h) expected =
80 testCase (Text.unpack $ (text_from_expr :: Repr_Text IO _h -> Text) $ expr) $
81 (>>= (@?= expected)) $
82 host_from_expr expr in
83 [ Maybe.Test.e1 ==> False
84 ]
85 , testGroup "If" $
86 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda_App IO
87 .|. Expr_Lambda_Val IO
88 .|. Expr_If
89 .|. Expr_Bool )) repr => repr h) expected =
90 testCase (Text.unpack $ (text_from_expr :: Repr_Text IO _h -> Text) $ expr) $
91 (>>= (@?= expected)) $
92 host_from_expr expr in
93 [ If.Test.e1 ==> False
94 ]
95 , testGroup "List" $
96 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda_App IO
97 .|. Expr_Lambda_Val IO
98 .|. Expr_List IO
99 .|. Expr_Bool
100 .|. Expr_Int
101 .|. Expr_If
102 .|. Expr_Eq )) repr => repr h) expected =
103 testCase (Text.unpack $ (text_from_expr :: Repr_Text IO _h -> Text) $ expr) $
104 (>>= (@?= expected)) $
105 host_from_expr expr in
106 [ List.Test.e1 ==> [2::Int,4]
107 ]
108 , testGroup "Functor" $
109 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda_App Identity
110 .|. Expr_Lambda_Val Identity
111 .|. Expr_List Identity
112 .|. Expr_Functor Identity
113 .|. Expr_Bool
114 .|. Expr_Int
115 .|. Expr_If
116 .|. Expr_Eq )) repr => repr h) expected =
117 testCase (Text.unpack $ (text_from_expr :: Repr_Text Identity _h -> Text) $ expr) $
118 (\(Identity a) -> (a @?= expected)) $
119 host_from_expr expr in
120 [ Functor.Test.e1 ==> [2::Int,3,4]
121 ]
122 , testGroup "Applicative" $
123 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda_App Identity
124 .|. Expr_Lambda_Val Identity
125 .|. Expr_List Identity
126 .|. Expr_Functor Identity
127 .|. Expr_Applicative Identity
128 .|. Expr_Maybe Identity
129 .|. Expr_Bool
130 .|. Expr_Int
131 .|. Expr_If
132 .|. Expr_Eq )) repr => repr h) expected =
133 testCase (Text.unpack $ (text_from_expr :: Repr_Text Identity _h -> Text) $ expr) $
134 (\(Identity a) -> (a @?= expected)) $
135 host_from_expr expr in
136 [ Applicative.Test.e1 ==> Just (3::Int)
137 ]
138 ]