1 {-# LANGUAGE OverloadedStrings #-}
2 {-# LANGUAGE RankNTypes #-}
7 import Symantic qualified as Sym
9 import Test.Tasty.HUnit
11 import Examples.Ex01 qualified as Ex01
12 import Examples.Ex02 qualified as Ex02
14 import Text.Printf (printf)
29 [ Gen ["index.html"] $ Ex01.Index
30 , Gen ["about.html"] $ Ex01.About
31 -- , Gen ["user", "contact.html"] $ Ex01.Contact "user"
32 -- , Gen ["post"] $ Ex01.Post []
33 -- , Gen ["post", "dir"] $ Ex01.Post ["dir"]
34 -- , Gen ["post", "dir", "dir"] $ Ex01.Post ["dir", "dir"]
43 , [Gen{genSlugs = ["static"], genValue = Ex02.SiteStatic}, Gen{genSlugs = ["feed"], genValue = Ex02.SiteFeeds}, Gen{genSlugs = ["filter", "all"], genValue = Ex02.SiteFilter (Ex02.Filter{filterLang = Nothing, filterTag = Nothing})}, Gen{genSlugs = ["filter", "all", "tag0"], genValue = Ex02.SiteFilter (Ex02.Filter{filterLang = Nothing, filterTag = Just (Ex02.Tag{unTag = "tag0"})})}, Gen{genSlugs = ["filter", "all", "tag1"], genValue = Ex02.SiteFilter (Ex02.Filter{filterLang = Nothing, filterTag = Just (Ex02.Tag{unTag = "tag1"})})}, Gen{genSlugs = ["filter", "fr"], genValue = Ex02.SiteFilter (Ex02.Filter{filterLang = Just Ex02.LangEn, filterTag = Nothing})}, Gen{genSlugs = ["filter", "fr", "tag0"], genValue = Ex02.SiteFilter (Ex02.Filter{filterLang = Just Ex02.LangEn, filterTag = Just (Ex02.Tag{unTag = "tag0"})})}, Gen{genSlugs = ["filter", "fr", "tag1"], genValue = Ex02.SiteFilter (Ex02.Filter{filterLang = Just Ex02.LangEn, filterTag = Just (Ex02.Tag{unTag = "tag1"})})}, Gen{genSlugs = ["filter", "en"], genValue = Ex02.SiteFilter (Ex02.Filter{filterLang = Just Ex02.LangFr, filterTag = Nothing})}, Gen{genSlugs = ["filter", "en", "tag0"], genValue = Ex02.SiteFilter (Ex02.Filter{filterLang = Just Ex02.LangFr, filterTag = Just (Ex02.Tag{unTag = "tag0"})})}, Gen{genSlugs = ["filter", "en", "tag1"], genValue = Ex02.SiteFilter (Ex02.Filter{filterLang = Just Ex02.LangFr, filterTag = Just (Ex02.Tag{unTag = "tag1"})})}]
49 [ testCoderIsomorphism "Ex01" Ex01.site ()
50 , testCoderIsomorphism "Ex02" Ex02.site Ex02.model0
60 [ Gen ["index.html"] $ Ex01.Index
61 , Gen ["about.html"] $ Ex01.About
62 -- , Gen ["user", "contact.html"] $ Ex01.Contact "user"
63 -- , Gen ["post", "a", "b"] $ Ex01.Post ["a", "b"]
76 [ Gen ["index.html"] $ Ex01.Index
77 , Gen ["about.html"] $ Ex01.About
78 -- , Gen ["user", "contact.html"] $ Ex01.Contact "user"
79 -- , Gen ["post", "a", "b"] $ Ex01.Post ["a", "b"]
89 [ {- Gen ["static"] $ Ex02.SiteStatic
91 ["filter", "all", "tag0"]
94 { Ex02.filterLang = Nothing
95 , Ex02.filterTag = Just (Ex02.Tag "tag0")
107 Sym.Reader model Generator a ->
108 [(model, [Gen a])] ->
110 testGenerator tn site models =
113 [ testCase (printf "Model%02d" modelNum) do
114 generate (Sym.unReader site model) @?= expectedGens
115 | (modelNum, (model, expectedGens)) <- ol models
118 testCoderIsomorphism ::
122 (forall repr. Testable model repr => Sym.Reader model repr a) ->
125 testCoderIsomorphism tn site model =
127 [ testGroup (printf "Request%d" urlNum) $
128 [ ( testCase "decode . encode" do
129 decode @() decoder Request{requestSlugs = encode encoder genValue, requestBody = ""}
130 >>= (@?= Right genValue)
132 , ( testCase "encode . decode" do
133 dec <- decode @() decoder Request{requestSlugs = genSlugs, requestBody = ""}
134 encode encoder <$> dec @?= Right genSlugs
137 | (urlNum, Gen{..}) <- ol $ generate (Sym.unReader site model)
140 decoder = Sym.unReader site model
141 encoder = Sym.unReader site model
147 Sym.Reader model (Decoder ()) a ->
148 [(model, [Gen a])] ->
150 testDecoder tn site models =
154 (printf "Model%d" modelNum)
155 [ testCase (printf "Gen%d" genNum) do
156 decode (Sym.unReader site model) Request{requestSlugs = genSlugs, requestBody = ""}
157 >>= (@?= Right genValue)
158 | (genNum, Gen{..}) <- ol expectedGens
160 | (modelNum, (model, expectedGens)) <- ol models
163 testEncoder :: String -> Sym.Reader model Encoder a -> [(model, [Gen a])] -> TestTree
164 testEncoder tn site models =
168 (printf "Model%d" modelNum)
169 [ testCase (printf "Gen%d" genNum) do
170 encode (Sym.unReader site model) genValue @?= genSlugs
171 | (genNum, Gen{..}) <- ol expectedGens
173 | (modelNum, (model, expectedGens)) <- ol models