{-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE NoMonomorphismRestriction #-} {-# LANGUAGE Rank2Types #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeOperators #-} {-# OPTIONS_GHC -fno-warn-missing-signatures #-} module Compiling.Term.Test where import Test.Tasty import Test.Tasty.HUnit import qualified Control.Arrow as Arrow import qualified Control.Monad as Monad -- import Control.Monad.IO.Class (MonadIO(..)) import Data.Proxy (Proxy(..)) import Data.Text (Text) import Data.Type.Equality ((:~:)(Refl)) import Prelude as P import Language.Symantic.Typing import Language.Symantic.Compiling import Language.Symantic.Interpreting test_term_from :: forall is h. ( Sym_of_Ifaces is HostI , Sym_of_Ifaces is TextI , Term_from is (Syntax Text) , Eq h , Show h , Show_Const (Consts_of_Ifaces is) ) => Proxy is -> Syntax Text -> Either (Type (Consts_of_Ifaces is) h, Error_Term is (Syntax Text)) (Type (Consts_of_Ifaces is) h, h, Text) -> TestTree test_term_from _is ast expected = testCase (elide $ show ast) $ case root_term_from ast of Left err -> Left err @?= P.snd `Arrow.left` expected Right (ETerm ty (Term te)::ETerm is) -> case expected of Left (_, err) -> Right ("…"::Text) @?= Left err Right (ty_expected::Type (Consts_of_Ifaces is) h, _::h, _::Text) -> (Monad.>>= (@?= (\(_::Type (Consts_of_Ifaces is) h, err) -> err) `Arrow.left` expected)) $ case ty `eq_type` ty_expected of Nothing -> Monad.return $ Left $ Error_Term_Type_mismatch (At Nothing $ EType ty) (At Nothing $ EType ty_expected) Just Refl -> do let h = host_from_term te Monad.return $ Right ( ty , h , text_from_term te -- , (text_from_term :: Repr_Text h -> Text) r ) where elide s | P.length s P.> 42 = P.take 42 s P.++ ['…'] elide s = s