]> 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.Text (Text)
16 import qualified Data.Text as Text
17 import Prelude hiding (and, not, or)
18
19 import Language.Symantic.Repr
20 import Language.Symantic.Expr
21 import qualified Expr.Lambda.Test as Lambda.Test
22 import qualified Expr.Bool.Test as Bool.Test
23 import qualified Expr.Maybe.Test as Maybe.Test
24 import qualified Expr.If.Test as If.Test
25 import qualified Expr.List.Test as List.Test
26
27 tests :: TestTree
28 tests = testGroup "Host" $
29 [ testGroup "Bool" $
30 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root (Expr_Lambda IO .|. Expr_Bool)) repr => repr h) expected =
31 testCase (Text.unpack $ (text_from_expr :: Repr_Text IO _h -> Text) $ expr) $
32 (>>= (@?= expected)) $
33 host_from_expr expr in
34 [ Bool.Test.e1 ==> False
35 , Bool.Test.e2 ==> True
36 , Bool.Test.e3 ==> True
37 , Bool.Test.e4 ==> True
38 ]
39 , testGroup "Lambda" $
40 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root (Expr_Lambda IO .|. Expr_Bool)) repr => repr h) expected =
41 testCase (Text.unpack $ (text_from_expr :: Repr_Text IO _h -> Text) $ expr) $
42 (>>= (@?= expected)) $
43 host_from_expr expr in
44 [ (Lambda.Test.e1 `app` bool True `app` bool True) ==> False
45 , (Lambda.Test.e1 `app` bool True `app` bool False) ==> True
46 , (Lambda.Test.e1 `app` bool False `app` bool True) ==> True
47 , (Lambda.Test.e1 `app` bool False `app` bool False) ==> False
48
49 , (Lambda.Test.e2 `app` bool True `app` bool True) ==> False
50 , (Lambda.Test.e2 `app` bool True `app` bool False) ==> True
51 , (Lambda.Test.e2 `app` bool False `app` bool True) ==> True
52 , (Lambda.Test.e2 `app` bool False `app` bool False) ==> False
53
54 , Lambda.Test.e3 ==> True
55 , Lambda.Test.e4 ==> True
56
57 , (Lambda.Test.e5 `app` bool True `app` bool True) ==> True
58 , (Lambda.Test.e5 `app` bool True `app` bool False) ==> False
59 , (Lambda.Test.e5 `app` bool False `app` bool True) ==> False
60 , (Lambda.Test.e5 `app` bool False `app` bool False) ==> False
61
62 , Lambda.Test.e6 ==> False
63 , (Lambda.Test.e7 `app` val id) ==> True
64 , (Lambda.Test.e7 `app` val not) ==> False
65 ]
66 , testGroup "Maybe" $
67 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root (Expr_Lambda IO .|. Expr_Maybe IO .|. Expr_Bool)) repr => repr h) expected =
68 testCase (Text.unpack $ (text_from_expr :: Repr_Text IO _h -> Text) $ expr) $
69 (>>= (@?= expected)) $
70 host_from_expr expr in
71 [ Maybe.Test.e1 ==> False
72 ]
73 , testGroup "If" $
74 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root (Expr_Lambda IO .|. Expr_If .|. Expr_Bool)) repr => repr h) expected =
75 testCase (Text.unpack $ (text_from_expr :: Repr_Text IO _h -> Text) $ expr) $
76 (>>= (@?= expected)) $
77 host_from_expr expr in
78 [ If.Test.e1 ==> False
79 ]
80 , testGroup "List" $
81 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda IO
82 .|. Expr_List IO
83 .|. Expr_Bool
84 .|. Expr_Int
85 .|. Expr_If
86 .|. Expr_Eq )) repr => repr h) expected =
87 testCase (Text.unpack $ (text_from_expr :: Repr_Text IO _h -> Text) $ expr) $
88 (>>= (@?= expected)) $
89 host_from_expr expr in
90 [ List.Test.e1 ==> [2::Int,4]
91 ]
92 ]