1 {-# LANGUAGE FlexibleContexts #-}
3 {-# LANGUAGE NoMonomorphismRestriction #-}
4 {-# LANGUAGE Rank2Types #-}
5 {-# LANGUAGE ScopedTypeVariables #-}
6 {-# LANGUAGE TypeOperators #-}
7 {-# OPTIONS_GHC -fno-warn-missing-signatures #-}
8 module Expr.Maybe.Test where
11 import Test.Tasty.HUnit
13 import qualified Control.Arrow as Arrow
14 import qualified Control.Monad as Monad
15 import Data.Proxy (Proxy(..))
16 import Data.Text (Text)
17 import Data.Type.Equality ((:~:)(Refl))
18 import Prelude hiding (maybe, not)
20 import Language.Symantic.Repr
21 import Language.Symantic.Expr
22 import Language.Symantic.Type
27 e1 = maybe (bool True) (lam not) (just $ bool True)
35 ex_from = root_expr_from (Proxy::Proxy Ex)
40 Left err -> Left err @?= Prelude.snd `Arrow.left` expected
41 Right (Exists_Type0_and_Repr ty (Forall_Repr r)) ->
43 Left (_, err) -> Right ("…"::String) @?= Left err
44 Right (ty_expected::Type_Root_of_Expr Ex h, _::h, _::Text) ->
45 (Monad.>>= (@?= (\(_::Proxy h, err) -> err) `Arrow.left` expected)) $
46 case ty `type0_eq` ty_expected of
47 Nothing -> Monad.return $ Left $
48 error_expr (Proxy::Proxy Ex) $
49 Error_Expr_Type_mismatch ast
51 (Exists_Type0 ty_expected)
53 let h = host_from_expr r
59 -- , (text_from_expr :: Repr_Text h -> Text) r
63 tests = testGroup "Maybe"
64 [ AST "just" [AST "bool" [AST "True" []]] ==> Right
65 ( type_maybe type_bool
71 , AST "bool" [AST "True" []]
72 , AST "var" [AST "x" []]
75 ( type_maybe type_bool
77 , "just (let x0 = True in x0)" )
79 [ AST "bool" [AST "True" []]
83 , AST "not" [AST "var" [AST "x" []]]
91 , "maybe True (\\x0 -> !x0) nothing" )
93 [ AST "bool" [AST "False" []]
97 , AST "not" [AST "var" [AST "x" []]]
100 [ AST "bool" [AST "True" []]
105 , "maybe False (\\x0 -> !x0) (just True)" )