]> Git — Sourcephile - haskell/symantic.git/blob - Language/LOL/Symantic/Expr/Maybe/Test.hs
init
[haskell/symantic.git] / Language / LOL / Symantic / Expr / Maybe / Test.hs
1 {-# LANGUAGE FlexibleContexts #-}
2 {-# LANGUAGE GADTs #-}
3 {-# LANGUAGE NoMonomorphismRestriction #-}
4 {-# LANGUAGE Rank2Types #-}
5 {-# LANGUAGE ScopedTypeVariables #-}
6 {-# OPTIONS_GHC -fno-warn-missing-signatures #-}
7 module Expr.Maybe.Test where
8
9 import Test.Tasty
10 import Test.Tasty.HUnit
11
12 import Control.Arrow (left)
13 import Data.Proxy (Proxy(..))
14 import Data.Text (Text)
15 import Data.Type.Equality ((:~:)(Refl))
16 import Prelude hiding (maybe, not)
17
18 import Language.LOL.Symantic.Repr
19 import Language.LOL.Symantic.AST
20 import Language.LOL.Symantic.Expr
21 import Language.LOL.Symantic.Type
22
23 -- * Expressions
24 e1 = maybe (bool True)
25 (val not)
26 (just $ bool True)
27
28 -- * Tests
29 (==>) ast expected =
30 testCase (show ast) $
31 case expr_lambda_maybe_bool_from (Proxy::Proxy IO) ast of
32 Left err -> Left err @?= snd `left` expected
33 Right (Exists_Type_and_Repr ty (Forall_Repr r)) ->
34 case expected of
35 Left (_, err) -> Right ("…"::String) @?= Left err
36 Right (ty_expected::Type_Root_of_Expr (Expr_Lambda_Maybe_Bool IO) h, _::h, _::Text) ->
37 (>>= (@?= (\(_::Proxy h, err) -> err) `left` expected)) $
38 case ty `type_eq` ty_expected of
39 Nothing -> return $ Left $
40 error_expr (Proxy::Proxy (Expr_Lambda_Maybe_Bool IO)) $
41 Error_Expr_Type_mismatch ast
42 (Exists_Type ty)
43 (Exists_Type ty_expected)
44 Just Refl -> do
45 h <- host_from_expr r
46 return $
47 Right
48 ( ty
49 , h
50 , text_from_expr r
51 -- , (text_from_expr :: Repr_String IO h -> Text) r
52 )
53
54 tests :: TestTree
55 tests = testGroup "Maybe"
56 [ AST "just" [AST "bool" [AST "True" []]] ==> Right
57 ( type_maybe type_bool
58 , Just True
59 , "just True" )
60 , AST "just"
61 [ AST "let_val"
62 [ AST "x" []
63 , AST "bool" [AST "True" []]
64 , AST "var" [AST "x" []]
65 ]
66 ] ==> Right
67 ( type_maybe type_bool
68 , Just True
69 , "just (let x0 = True in x0)" )
70 , AST "maybe"
71 [ AST "bool" [AST "True" []]
72 , AST "val"
73 [ AST "x" []
74 , AST "Bool" []
75 , AST "not" [AST "var" [AST "x" []]]
76 ]
77 , AST "nothing"
78 [ AST "Bool" []
79 ]
80 ] ==> Right
81 ( type_bool
82 , True
83 , "maybe True (\\x0 -> !x0) nothing" )
84 , AST "maybe"
85 [ AST "bool" [AST "False" []]
86 , AST "val"
87 [ AST "x" []
88 , AST "Bool" []
89 , AST "not" [AST "var" [AST "x" []]]
90 ]
91 , AST "just"
92 [ AST "bool" [AST "True" []]
93 ]
94 ] ==> Right
95 ( type_bool
96 , False
97 , "maybe False (\\x0 -> !x0) (just True)" )
98 ]