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.Expr
20 import Language.LOL.Symantic.Type
25 e1 = maybe (bool True)
32 case expr_lambda_maybe_bool_from (Proxy::Proxy IO) ast of
33 Left err -> Left err @?= snd `left` expected
34 Right (Exists_Type_and_Repr ty (Forall_Repr r)) ->
36 Left (_, err) -> Right ("…"::String) @?= Left err
37 Right (ty_expected::Type_Root_of_Expr (Expr_Lambda_Maybe_Bool IO) h, _::h, _::Text) ->
38 (>>= (@?= (\(_::Proxy h, err) -> err) `left` expected)) $
39 case ty `type_eq` ty_expected of
40 Nothing -> return $ Left $
41 error_expr (Proxy::Proxy (Expr_Lambda_Maybe_Bool IO)) $
42 Error_Expr_Type_mismatch ast
44 (Exists_Type ty_expected)
52 -- , (text_from_expr :: Repr_String IO h -> Text) r
56 tests = testGroup "Maybe"
57 [ AST "just" [AST "bool" [AST "True" []]] ==> Right
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)" )