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 Control.Arrow (left)
13 import Data.Proxy (Proxy(..))
14 import Data.Type.Equality ((:~:)(Refl))
15 import Prelude hiding (maybe, not)
17 import Language.LOL.Symantic.Repr
18 import Language.LOL.Symantic.AST
19 import Language.LOL.Symantic.Expr
20 import Language.LOL.Symantic.Type
23 e1 = maybe (bool True)
30 case expr_lambda_maybe_bool_from (Proxy::Proxy IO) ast of
31 Left err -> Left err @?= snd `left` expected
32 Right (Exists_Type_and_Repr ty (Forall_Repr r)) ->
34 Left (_, err) -> Right ("…"::String) @?= Left err
35 Right (ty_expected::Type_Root_of_Expr (Expr_Lambda_Maybe_Bool IO) h, _::h, _::String) ->
36 (>>= (@?= (\(_::Proxy h, err) -> err) `left` expected)) $
37 case ty `type_eq` ty_expected of
38 Nothing -> return $ Left $
39 error_expr (Proxy::Proxy (Expr_Lambda_Maybe_Bool IO)) $
40 Error_Expr_Type_mismatch ast
42 (Exists_Type ty_expected)
50 -- , (string_from_expr :: Repr_String IO h -> String) r
54 tests = testGroup "Maybe"
55 [ AST "just" [AST "bool" [AST "True" []]] ==> Right
56 ( type_maybe type_bool
62 , AST "bool" [AST "True" []]
63 , AST "var" [AST "x" []]
66 ( type_maybe type_bool
68 , "just (let x0 = True in x0)" )
70 [ AST "bool" [AST "True" []]
74 , AST "not" [AST "var" [AST "x" []]]
82 , "maybe True (\\x0 -> !x0) nothing" )
84 [ AST "bool" [AST "False" []]
88 , AST "not" [AST "var" [AST "x" []]]
91 [ AST "bool" [AST "True" []]
96 , "maybe False (\\x0 -> !x0) (just True)" )