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.Bool.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
25 import Language.Symantic.Transforming
27 -- * Class 'Sym_Bool_Vars'
29 -- | A few boolean variables.
30 class Sym_Bool_Vars repr where
34 instance Sym_Bool_Vars TextI where
35 x = TextI $ \_p _v -> "x"
36 y = TextI $ \_p _v -> "y"
37 z = TextI $ \_p _v -> "z"
39 instance -- Trans_Boo_Const
42 ) => Sym_Bool_Vars (Trans_Bool_Const repr) where
49 te1 = bool True && bool False
50 te2 = (bool True && bool False) || (bool True && bool True)
51 te3 = (bool True || bool False) && (bool True || bool True)
52 te4 = bool True && not (bool False)
53 te5 = bool True && not x
55 te7 = (x `xor` y) `xor` z
56 te8 = x `xor` (y `xor` bool True)
64 (==>) (ast::Syntax Text) expected =
66 case root_term_from ast of
67 Left err -> Left err @?= Prelude.snd `Arrow.left` expected
68 Right (ETerm ty (Term te)::ETerm Ifaces) ->
70 Left (_, err) -> Right ("…"::Text) @?= Left err
71 Right (ty_expected::Type (Consts_of_Ifaces Ifaces) 'KiTerm h, _::UnProxy h, _::Text) ->
72 (Monad.>>= (@?= (\(_::Type (Consts_of_Ifaces Ifaces) 'KiTerm h, err) -> err) `Arrow.left` expected)) $
73 case ty `eq_type` ty_expected of
74 Nothing -> Monad.return $ Left $
75 Error_Term_Type_mismatch
76 (At Nothing $ EType ty)
77 (At Nothing $ EType ty_expected)
79 let h = host_from_term te
85 -- , (text_from_expr :: Repr_Text h -> Text) r
89 syTrue = Syntax "True" []
92 tests = testGroup "Bool" $
93 [ syTrue ==> Right (tyBool, True, "True")
94 , Syntax "xor" [syTrue, syTrue] ==> Right
95 (tyBool, False, "True `xor` True")
104 (tyBool, True, "(\\x0 -> x0) True")
116 (tyBool, False, "(\\x0 -> x0 `xor` True) True" )
125 (tyBool, False, "let x0 = True in x0 `xor` True")
126 , testGroup "Error_Term" $
127 [ let sy = Syntax " "
130 ] in sy ==> Left (tyBool,
131 Error_Term_not_applicable $ At (Just sy) $
144 Error_Term_unknown $ At (Just syBool) $
146 , let sy = Syntax " "
152 ] in sy ==> Left (tyBool,
153 Error_Term_Syntax $ Error_Syntax_more_arguments_needed $
155 , let sy = Syntax " "
163 ] in sy ==> Left (tyBool,
164 Error_Term_Syntax $ Error_Syntax_too_many_arguments $
170 , Syntax " " [Syntax "x" [], syTrue]
176 Error_Term_Type_mismatch
177 (At (Just sy) $ EType $ (tyBool ~> tyBool))
178 (At (Just $ syTrue) $ EType tyBool)