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) (\x -> x >>= \x' -> return $ not x') (just $ bool True)
25 (==>) :: forall h ast root.
26 ( Eq h, Eq ast, Show h, Show ast
27 , root ~ Expr_Lambda_Bool_Maybe IO
28 , Expr_from ast (Expr_Lambda IO root)
29 , Expr_from ast (Expr_Maybe IO root)
30 , Expr_from ast (Expr_Bool root)
32 => ast -> (Type_Fun_Bool_Maybe IO h, h, String) -> TestTree
33 (==>) ast expected@(ty_expected::Type_Fun_Bool_Maybe IO h, _::h, _::String) =
35 (>>= (@?= Right expected)) $
36 case expr_lambda_bool_maybe_from (Proxy::Proxy IO) ast of
37 Left err -> return $ Left err
38 Right (Exists_Type_and_Repr ty (Forall_Repr r)) ->
39 case ty `type_eq` ty_expected of
40 Nothing -> return $ Left $
41 error_expr (Proxy::Proxy root) $ Error_Expr_Type
42 (error_type_lift $ Error_Type_Unsupported_here ast) ast
49 -- , string_from_expr r
50 , (string_from_expr :: Repr_String IO h -> String) r
53 (Implicit_HBool (Is_Last_Expr
54 (Expr_Lambda IO (Expr_Root (Expr_Alt Expr_Bool (Expr_Maybe IO))))
55 (Expr_Maybe IO (Expr_Root (Expr_Alt Expr_Bool (Expr_Maybe IO))))))
58 tests = testGroup "Maybe"
59 [ AST "just" [AST "bool" [AST "True" []]] ==>
60 ( type_maybe type_bool
66 , AST "bool" [AST "True" []]
67 , AST "var" [AST "x" []]
70 ( type_maybe type_bool
72 , "just (let x0 = True in x0)" )
74 [ AST "bool" [AST "True" []]
75 , AST "bool" [AST "True" []]
79 , "(True | True) & !(True & True)" )
84 , AST "var" [AST "x" []]
86 , AST "bool" [AST "True" []]
90 , "(\\x0 -> x0) True" )
96 [ AST "var" [AST "x" []]
97 , AST "bool" [AST "True" []]
100 , AST "bool" [AST "True" []]
104 , "(\\x0 -> (x0 | True) & !(x0 & True)) True" )
107 , AST "bool" [AST "True" []]
109 [ AST "var" [AST "x" []]
110 , AST "bool" [AST "True" []]
115 , "let x0 = True in (x0 | True) & !(x0 & True)" )