1 {-# OPTIONS_GHC -fno-warn-missing-signatures #-}
2 module Lib.Bool.Test where
6 import Data.Proxy (Proxy(..))
7 import Prelude hiding ((&&), not, (||))
9 import Language.Symantic.Parsing
10 import Language.Symantic.Typing
11 import Language.Symantic.Compiling
12 import Language.Symantic.Interpreting
13 import Language.Symantic.Lib.Bool
14 import Language.Symantic.Lib.Lambda ((~>))
15 import Compiling.Term.Test
22 (==>) = test_compile @Ifaces
25 tests = testGroup "Bool" $
26 [ "True" ==> Right (ty @Bool, True, "True")
27 , "xor True True" ==> Right (ty @Bool, False, "((\\x0 -> (\\x1 -> x0 `xor` x1)) True) True")
28 , "xor False True" ==> Right (ty @Bool, True, "((\\x0 -> (\\x1 -> x0 `xor` x1)) False) True")
29 , "True `xor` True" ==> Right (ty @Bool, False, "((\\x0 -> (\\x1 -> x0 `xor` x1)) True) True")
30 , "(\\(xy:Bool) -> xy) True" ==> Right (ty @Bool, True, "(\\x0 -> x0) True")
31 , "(\\(False:Bool) -> False) True" ==> Right (ty @Bool, True, "(\\x0 -> x0) True")
32 , "(\\(False:Bool) -> False) (False `xor` True)" ==> Right
33 (ty @Bool, True, "(\\x0 -> x0) (((\\x0 -> (\\x1 -> x0 `xor` x1)) False) True)")
34 , "(\\(lett:Bool) -> lett) True" ==> Right (ty @Bool, True, "(\\x0 -> x0) True")
35 , "(\\(x:Bool) -> xor x x) True" ==> Right
36 (ty @Bool, False, "(\\x0 -> ((\\x1 -> (\\x2 -> x1 `xor` x2)) x0) x0) True")
37 , "let x = True in xor x True" ==> Right
38 (ty @Bool, False, "let x0 = True in ((\\x1 -> (\\x2 -> x1 `xor` x2)) x0) True")
39 , testGroup "Error_Term"
40 [ "True True" ==> Left (ty @Bool,
41 Right $ Error_Term_Con_Type $
43 At (maybeRight $ test_tokenizer "True") $
45 , "(\\(x:Bool) -> x `xor` True) Bool" ==> Left (ty @Bool,
46 Right $ Error_Term_unbound $ TeName "Bool")
47 , "(\\(x:Bool) -> x) True True" ==> Left (ty @Bool,
48 Right $ Error_Term_Con_Type $
50 At (maybeRight $ test_tokenizer "(\\(x:Bool) -> x) True") $
52 , "(\\(x:Bool -> Bool) -> x True) True" ==> Left (ty @Bool,
53 Right $ Error_Term_Con_Type $ Right $
55 (Right $ At (maybeRight $ test_tokenizer "(\\(x:Bool -> Bool) -> x True)") $
56 EType $ (ty @Bool ~> ty @Bool))
57 (At (maybeRight $ test_tokenizer "True") $
63 -- * Class 'Sym_Bool_Vars'
64 -- | A few boolean variables.
65 class Sym_Bool_Vars repr where
69 instance Sym_Bool_Vars TextI where
70 x = TextI $ \_p _v -> "x"
71 y = TextI $ \_p _v -> "y"
72 z = TextI $ \_p _v -> "z"
74 instance -- Trans_Boo_Const
77 ) => Sym_Bool_Vars (Trans_Bool_Const repr) where
84 te1 = bool True && bool False
85 te2 = (bool True && bool False) || (bool True && bool True)
86 te3 = (bool True || bool False) && (bool True || bool True)
87 te4 = bool True && not (bool False)
88 te5 = bool True && not x
90 te7 = (x `xor` y) `xor` z
91 te8 = x `xor` (y `xor` bool True)