]> Git — Sourcephile - haskell/symantic.git/blob - Language/Symantic/Compiling/Map/Test.hs
Add tests for Compiling.
[haskell/symantic.git] / Language / Symantic / Compiling / Map / Test.hs
1 {-# LANGUAGE DataKinds #-}
2 {-# LANGUAGE NoMonomorphismRestriction #-}
3 {-# OPTIONS_GHC -fno-warn-missing-signatures #-}
4 {-# OPTIONS_GHC -O0 #-} -- speedup compile-time…
5 module Compiling.Map.Test where
6
7 import Test.Tasty
8
9 import Data.Map.Strict (Map)
10 import qualified Data.Map.Strict as Map
11 import Data.Proxy (Proxy(..))
12 import Data.Text (Text)
13 import qualified Data.Text as Text
14 import Prelude hiding (zipWith)
15
16 import Language.Symantic.Typing
17 import Language.Symantic.Compiling.Bool
18 import Language.Symantic.Compiling.Map
19 import Language.Symantic.Compiling.List
20 import Language.Symantic.Compiling.Term
21 import Language.Symantic.Compiling.Tuple2
22 import Language.Symantic.Compiling.Int
23 import Language.Symantic.Compiling.Text
24 import Compiling.Term.Test
25
26 -- * Terms
27 t = bool True
28 f = bool False
29 e1 = map_fromList $ zipWith (lam (lam . tuple2))
30 (list $ int Prelude.<$> [1..5])
31 (list $ (text . Text.singleton) Prelude.<$> ['a'..'e'])
32
33 -- * Tests
34 type Ifaces =
35 [ Proxy (->)
36 , Proxy []
37 , Proxy Int
38 , Proxy Map
39 , Proxy Text
40 , Proxy (,)
41 , Proxy Num
42 , Proxy Monoid
43 ]
44 (==>) = test_term_from (Proxy::Proxy Ifaces)
45
46 tests :: TestTree
47 tests = testGroup "Map"
48 [ Syntax "Map.fromList"
49 [ Syntax "zipWith"
50 [ syLam (Syntax "x" []) syInt $
51 syLam (Syntax "y" []) syText $
52 Syntax "(,)"
53 [ Syntax "x" []
54 , Syntax "y" []
55 ]
56 , Syntax "list"
57 [ syInt
58 , Syntax "int" [Syntax "1" []]
59 , Syntax "int" [Syntax "2" []]
60 , Syntax "int" [Syntax "3" []]
61 ]
62 , Syntax "list"
63 [ syText
64 , Syntax "text" [Syntax "\"a\"" []]
65 , Syntax "text" [Syntax "\"b\"" []]
66 , Syntax "text" [Syntax "\"c\"" []]
67 ]
68 ]
69 ] ==> Right
70 ( (tyMap :$ tyInt) :$ tyText
71 , Map.fromList [(1, "a"), (2, "b"), (3, "c")]
72 , "Map.fromList (((\\x0 -> (\\x1 -> zipWith (\\x2 -> (\\x3 -> (x2, x3))) x0 x1)) [1, 2, 3]) [\"a\", \"b\", \"c\"])" )
73 , Syntax "Map.foldrWithKey"
74 [ syLam (Syntax "k" []) syInt $
75 syLam (Syntax "v" []) syText $
76 syLam (Syntax "a" []) (syTuple2 [syInt, syText]) $
77 syTuple2
78 [ Syntax "+"
79 [ Syntax "k" []
80 , Syntax "fst" [ Syntax "a" [] ]
81 ]
82 , Syntax "mappend"
83 [ Syntax "v" []
84 , Syntax "snd" [ Syntax "a" [] ]
85 ]
86 ]
87 , syTuple2
88 [ Syntax "int" [Syntax "0" []]
89 , Syntax "text" [Syntax "\"\"" []]
90 ]
91 , Syntax "Map.fromList"
92 [ Syntax "zipWith"
93 [ syLam (Syntax "x" []) syInt $
94 syLam (Syntax "y" []) syText $
95 syTuple2
96 [ Syntax "x" []
97 , Syntax "y" []
98 ]
99 , Syntax "list"
100 [ syInt
101 , Syntax "int" [Syntax "1" []]
102 , Syntax "int" [Syntax "2" []]
103 , Syntax "int" [Syntax "3" []]
104 ]
105 , Syntax "list"
106 [ syText
107 , Syntax "text" [Syntax "\"a\"" []]
108 , Syntax "text" [Syntax "\"b\"" []]
109 , Syntax "text" [Syntax "\"c\"" []]
110 ]
111 ]
112 ]
113 ] ==> Right
114 ( (tyTuple2 :$ tyInt) :$ tyText
115 , (6, "abc")
116 , "((\\x0 -> (\\x1 -> Map.foldrWithKey (\\x2 -> (\\x3 -> (\\x4 -> ((\\x5 -> x2 + x5) (fst x4), (\\x5 -> mappend x3 x5) (snd x4))))) x0 x1)) (0, \"\")) (Map.fromList (((\\x0 -> (\\x1 -> zipWith (\\x2 -> (\\x3 -> (x2, x3))) x0 x1)) [1, 2, 3]) [\"a\", \"b\", \"c\"]))" )
117 ]