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)
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
31 tests = testGroup "Host" $
33 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda_App IO
34 .|. Expr_Lambda_Val IO
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
45 , testGroup "Lambda" $
46 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda_App IO
47 .|. Expr_Lambda_Val IO
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
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
63 , Lambda.Test.e3 ==> True
64 , Lambda.Test.e4 ==> True
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
71 , Lambda.Test.e6 ==> False
72 , (Lambda.Test.e7 `app` val id) ==> True
73 , (Lambda.Test.e7 `app` val not) ==> False
76 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda_App IO
77 .|. Expr_Lambda_Val 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
86 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda_App IO
87 .|. Expr_Lambda_Val IO
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
96 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda_App IO
97 .|. Expr_Lambda_Val IO
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]
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
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]
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
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)