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.Text (Text)
15 import Data.Type.Equality ((:~:)(Refl))
16 import Prelude hiding (maybe, not)
18 import Language.LOL.Symantic.Repr
19 import Language.LOL.Symantic.AST
20 import Language.LOL.Symantic.Expr
21 import Language.LOL.Symantic.Type
24 e1 = maybe (bool True)
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)) ->
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
43 (Exists_Type ty_expected)
51 -- , (text_from_expr :: Repr_String IO h -> Text) r
55 tests = testGroup "Maybe"
56 [ AST "just" [AST "bool" [AST "True" []]] ==> Right
57 ( type_maybe type_bool
63 , AST "bool" [AST "True" []]
64 , AST "var" [AST "x" []]
67 ( type_maybe type_bool
69 , "just (let x0 = True in x0)" )
71 [ AST "bool" [AST "True" []]
75 , AST "not" [AST "var" [AST "x" []]]
83 , "maybe True (\\x0 -> !x0) nothing" )
85 [ AST "bool" [AST "False" []]
89 , AST "not" [AST "var" [AST "x" []]]
92 [ AST "bool" [AST "True" []]
97 , "maybe False (\\x0 -> !x0) (just True)" )