1 {-# LANGUAGE DataKinds #-}
2 {-# LANGUAGE FlexibleContexts #-}
4 {-# LANGUAGE NoMonomorphismRestriction #-}
5 {-# LANGUAGE Rank2Types #-}
6 {-# LANGUAGE ScopedTypeVariables #-}
7 {-# LANGUAGE TypeOperators #-}
8 {-# OPTIONS_GHC -fno-warn-missing-signatures #-}
9 module Compiling.Applicative.Test where
12 import Test.Tasty.HUnit
14 import qualified Control.Arrow as Arrow
15 import qualified Control.Monad as Monad
16 -- import Control.Monad.IO.Class (MonadIO(..))
17 import Data.Proxy (Proxy(..))
18 import Data.Text (Text)
19 import Data.Type.Equality ((:~:)(Refl))
20 import Prelude hiding ((&&), not, (||))
22 import Language.Symantic.Typing
23 import Language.Symantic.Compiling
24 import Language.Symantic.Interpreting
33 type Consts = Consts_of_Ifaces Ifaces
35 (==>) (ast::Syntax Text) expected =
37 case root_term_from ast of
38 Left err -> Left err @?= Prelude.snd `Arrow.left` expected
39 Right (ETerm ty (Term te)::ETerm Ifaces) ->
41 Left (_, err) -> Right ("…"::Text) @?= Left err
42 Right (ty_expected::Type Consts h, _::h, _::Text) ->
43 (Monad.>>= (@?= (\(_::Type Consts h, err) -> err) `Arrow.left` expected)) $
44 case ty `eq_type` ty_expected of
45 Nothing -> Monad.return $ Left $
46 Error_Term_Type_mismatch
47 (At Nothing $ EType ty)
48 (At Nothing $ EType ty_expected)
50 let h = host_from_term te
56 -- , (text_from_expr :: Repr_Text h -> Text) r
60 tests = testGroup "Applicative"
62 [ syJust [Syntax "xor" [syTrue]]
64 ] ==> Right (tyMaybe :$ tyBool, Just False, "Just (\\x0 -> True `xor` x0) <*> Just True")
68 ] ==> Right (tyMaybe :$ tyBool, Just True, "Just False *> Just True")
72 ] ==> Right (tyMaybe :$ tyBool, Just False, "Just False <* Just True")