1 {-# LANGUAGE FlexibleContexts #-}
3 {-# LANGUAGE NoMonomorphismRestriction #-}
4 {-# LANGUAGE Rank2Types #-}
5 {-# LANGUAGE ScopedTypeVariables #-}
6 {-# LANGUAGE TypeOperators #-}
7 {-# OPTIONS_GHC -fno-warn-missing-signatures #-}
8 module Expr.Map.Test where
11 import Test.Tasty.HUnit
13 import qualified Control.Arrow as Arrow
14 import qualified Control.Monad as Monad
15 -- import qualified Data.List as List
16 import qualified Data.Map.Strict as Map
17 import Data.Proxy (Proxy(..))
18 import Data.Text (Text)
19 import qualified Data.Text as Text
20 import Data.Type.Equality ((:~:)(Refl))
21 import Prelude hiding (maybe, not)
23 import Language.Symantic.Repr
24 import Language.Symantic.Expr
25 import Language.Symantic.Type
32 e1 = map_from_list $ list_zipWith (lam (lam . tuple2))
33 (list $ int Prelude.<$> [1..5])
34 (list $ (text . Text.singleton) Prelude.<$> ['a'..'e'])
52 ex_from = root_expr_from (Proxy::Proxy Ex)
57 Left err -> Left err @?= Prelude.snd `Arrow.left` expected
58 Right (Exists_Type0_and_Repr ty (Forall_Repr r)) ->
60 Left (_, err) -> Right ("…"::String) @?= Left err
61 Right (ty_expected::Type_Root_of_Expr Ex h, _::h, _::Text) ->
62 (Monad.>>= (@?= (\(_::Proxy h, err) -> err) `Arrow.left` expected)) $
63 case ty `type0_eq` ty_expected of
64 Nothing -> Monad.return $ Left $
65 error_expr (Proxy::Proxy Ex) $
66 Error_Expr_Type_mismatch ast
68 (Exists_Type0 ty_expected)
70 let h = host_from_expr r
76 -- , (text_from_expr :: Repr_Text h -> Text) r
80 tests = testGroup "Map"
90 [ AST "var" [AST "x" []]
91 , AST "var" [AST "y" []]
97 , AST "int" [AST "1" []]
98 , AST "int" [AST "2" []]
99 , AST "int" [AST "3" []]
103 , AST "text" [AST "a" []]
104 , AST "text" [AST "b" []]
105 , AST "text" [AST "c" []]
109 ( type_map type_int type_text
110 , Map.fromList [(1, "a"), (2, "b"), (3, "c")]
111 , "map_from_list (list_zipWith (\\x0 -> (\\x1 -> (x0, x1))) [1, 2, 3] [\"a\", \"b\", \"c\"])" )
112 , AST "map_foldrWithKey"
121 , AST "(,)" [AST "Int" [], AST "Text" []]
124 [ AST "var" [AST "k" []]
125 , AST "fst" [ AST "var" [AST "a" []] ]
128 [ AST "var" [AST "v" []]
129 , AST "snd" [ AST "var" [AST "a" []] ]
136 [ AST "int" [AST "0" []]
137 , AST "text" [AST "" []]
139 , AST "map_from_list"
148 [ AST "var" [AST "x" []]
149 , AST "var" [AST "y" []]
155 , AST "int" [AST "1" []]
156 , AST "int" [AST "2" []]
157 , AST "int" [AST "3" []]
161 , AST "text" [AST "a" []]
162 , AST "text" [AST "b" []]
163 , AST "text" [AST "c" []]
168 ( type_tuple2 type_int type_text
170 , "map_foldrWithKey (\\x0 -> (\\x1 -> (\\x2 -> (x0 + fst x2, mappend x1 (snd x2))))) (0, \"\") (map_from_list (list_zipWith (\\x0 -> (\\x1 -> (x0, x1))) [1, 2, 3] [\"a\", \"b\", \"c\"]))" )