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 Control.Arrow (left)
14 import Data.Proxy (Proxy(..))
15 import Data.Text (Text)
16 import Data.Type.Equality ((:~:)(Refl))
17 import Prelude hiding (maybe, not)
19 import Language.Symantic.Repr
20 import Language.Symantic.Expr
21 import Language.Symantic.Type
26 e1 = maybe (bool True) (val not) (just $ bool True)
29 type Ex lam = Expr_Root
31 .|. Expr_Lambda_Val lam
35 ex_from = root_expr_from (Proxy::Proxy (Ex lam)) (Proxy::Proxy lam)
40 Left err -> Left err @?= snd `left` expected
41 Right (Exists_Type_and_Repr ty (Forall_Repr r)) ->
43 Left (_, err) -> Right ("…"::String) @?= Left err
44 Right (ty_expected::Type_Root_of_Expr (Ex IO) h, _::h, _::Text) ->
45 (>>= (@?= (\(_::Proxy h, err) -> err) `left` expected)) $
46 case ty `eq_type` ty_expected of
47 Nothing -> return $ Left $
48 error_expr (Proxy::Proxy (Ex IO)) $
49 Error_Expr_Type_mismatch ast
51 (Exists_Type ty_expected)
59 -- , (text_from_expr :: Repr_String IO 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)" )