]> Git — Sourcephile - haskell/symantic.git/blob - Language/Symantic/Expr/If/Test.hs
init
[haskell/symantic.git] / Language / Symantic / Expr / If / Test.hs
1 {-# LANGUAGE FlexibleContexts #-}
2 {-# LANGUAGE GADTs #-}
3 {-# LANGUAGE NoMonomorphismRestriction #-}
4 {-# LANGUAGE Rank2Types #-}
5 {-# LANGUAGE ScopedTypeVariables #-}
6 {-# OPTIONS_GHC -fno-warn-missing-signatures #-}
7 module Expr.If.Test where
8
9 import Test.Tasty
10 import Test.Tasty.HUnit
11
12 import Control.Arrow (left)
13 import Data.Proxy (Proxy(..))
14 import Data.Text (Text)
15 import Data.Type.Equality ((:~:)(Refl))
16 import Prelude hiding (maybe, not)
17
18 import Language.Symantic.Repr
19 import Language.Symantic.Expr
20 import Language.Symantic.Type
21
22 import AST.Test
23
24 -- * Expressions
25 e1 = if_ (bool True)
26 (bool False)
27 (bool True)
28
29 -- * Tests
30 (==>) ast expected =
31 testCase (show ast) $
32 case expr_lambda_if_bool_from (Proxy::Proxy IO) ast of
33 Left err -> Left err @?= snd `left` expected
34 Right (Exists_Type_and_Repr ty (Forall_Repr r)) ->
35 case expected of
36 Left (_, err) -> Right ("…"::String) @?= Left err
37 Right (ty_expected::Type_Root_of_Expr (Expr_Lambda_If_Bool IO) h, _::h, _::Text) ->
38 (>>= (@?= (\(_::Proxy h, err) -> err) `left` expected)) $
39 case ty `type_eq` ty_expected of
40 Nothing -> return $ Left $
41 error_expr (Proxy::Proxy (Expr_Lambda_If_Bool IO)) $
42 Error_Expr_Type_mismatch ast
43 (Exists_Type ty)
44 (Exists_Type ty_expected)
45 Just Refl -> do
46 h <- host_from_expr r
47 return $
48 Right
49 ( ty
50 , h
51 , text_from_expr r
52 -- , (text_from_expr :: Repr_String IO h -> String) r
53 )
54
55 tests :: TestTree
56 tests = testGroup "If"
57 [ AST "if"
58 [ AST "bool" [AST "True" []]
59 , AST "bool" [AST "False" []]
60 , AST "bool" [AST "True" []]
61 ] ==> Right
62 ( type_bool
63 , False
64 , "if True then False else True" )
65 ]