1 {-# LANGUAGE FlexibleContexts #-}
3 {-# LANGUAGE NoMonomorphismRestriction #-}
4 {-# LANGUAGE Rank2Types #-}
5 {-# LANGUAGE ScopedTypeVariables #-}
6 {-# OPTIONS_GHC -fno-warn-missing-signatures #-}
7 module Expr.Maybe.Test where
10 import Test.Tasty.HUnit
12 import Data.Proxy (Proxy(..))
13 import Data.Type.Equality ((:~:)(Refl))
14 import Prelude hiding (maybe, not)
16 import Language.LOL.Symantic.Repr
17 import Language.LOL.Symantic.AST
18 import Language.LOL.Symantic.Expr
19 import Language.LOL.Symantic.Type
22 e1 = maybe (bool True)
27 (==>) :: forall h ast root.
28 ( Eq h, Eq ast, Show h, Show ast
29 , root ~ Expr_Lambda_Bool_Maybe IO
30 , Expr_from ast (Expr_Lambda IO root)
31 , Expr_from ast (Expr_Maybe IO root)
32 , Expr_from ast (Expr_Bool root)
34 => ast -> (Type_Fun_Bool_Maybe IO h, h, String) -> TestTree
35 (==>) ast expected@(ty_expected::Type_Fun_Bool_Maybe IO h, _::h, _::String) =
37 (>>= (@?= Right expected)) $
38 case expr_lambda_bool_maybe_from (Proxy::Proxy IO) ast of
39 Left err -> return $ Left err
40 Right (Exists_Type_and_Repr ty (Forall_Repr r)) ->
41 case ty `type_eq` ty_expected of
42 Nothing -> return $ Left $
43 error_expr (Proxy::Proxy root) $ Error_Expr_Type
44 (error_type_lift $ Error_Type_Unsupported ast) ast
51 -- , string_from_expr r
52 , (string_from_expr :: Repr_String IO h -> String) r
56 tests = testGroup "Maybe"
57 [ AST "just" [AST "bool" [AST "True" []]] ==>
58 ( type_maybe type_bool
64 , AST "bool" [AST "True" []]
65 , AST "var" [AST "x" []]
68 ( type_maybe type_bool
70 , "just (let x0 = True in x0)" )
72 [ AST "bool" [AST "True" []]
76 , AST "not" [AST "var" [AST "x" []]]
84 , "maybe True (\\x0 -> !x0) nothing" )
86 [ AST "bool" [AST "False" []]
90 , AST "not" [AST "var" [AST "x" []]]
93 [ AST "bool" [AST "True" []]
98 , "maybe False (\\x0 -> !x0) (just True)" )