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.Text (Text)
16 import qualified Data.Text as Text
17 import Prelude hiding (and, not, or)
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
28 tests = testGroup "Host" $
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
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
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
54 , Lambda.Test.e3 ==> True
55 , Lambda.Test.e4 ==> True
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
62 , Lambda.Test.e6 ==> False
63 , (Lambda.Test.e7 `app` val id) ==> True
64 , (Lambda.Test.e7 `app` val not) ==> False
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
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
81 let (==>) (expr::forall repr. Sym_of_Expr (Expr_Root ( Expr_Lambda IO
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]