1 {-# LANGUAGE ConstraintKinds #-}
2 {-# LANGUAGE OverloadedStrings #-}
3 {-# LANGUAGE RankNTypes #-}
4 {-# LANGUAGE UndecidableInstances #-}
8 import Network.URI.Slug ()
11 import Test.Tasty.HUnit
13 import Examples.Ex01 qualified as Ex01
26 [ Gen ["index.html"] $ Ex01.Index
27 , Gen ["about.html"] $ Ex01.About
28 , Gen ["user", "contact.html"] $ Ex01.Contact "user"
29 , Gen ["post"] $ Ex01.Post []
30 , Gen ["post", "dir"] $ Ex01.Post ["dir"]
31 , Gen ["post", "dir", "dir"] $ Ex01.Post ["dir", "dir"]
38 , Ex01.Post ["dir", "dir"]
43 [ testCoderIsomorphism "Ex01" Ex01.site
50 [ Gen ["index.html"] $ Ex01.Index
51 , Gen ["about.html"] $ Ex01.About
52 , Gen ["user", "contact.html"] $ Ex01.Contact "user"
53 , Gen ["post", "a", "b"] $ Ex01.Post ["a", "b"]
61 [ Gen ["index.html"] $ Ex01.Index
62 , Gen ["about.html"] $ Ex01.About
63 , Gen ["user", "contact.html"] $ Ex01.Contact "user"
64 , Gen ["post", "a", "b"] $ Ex01.Post ["a", "b"]
74 {-expected-} [Gen a] ->
77 testGenerator tn site expectedCheck expectedValues =
80 [ testCase "generate" $ gen @?= expectedCheck
81 , testCase "generateValues" $ genValue <$> gen @?= expectedValues
86 testCoderIsomorphism ::
90 (forall repr. Testable repr => repr a) ->
92 testCoderIsomorphism tn site =
97 [ (testCase "decode . encode" $ decode site (encode site genValue) @?= Right genValue)
98 , (testCase "encode . decode" $ encode site <$> decode site genSlugs @?= Right genSlugs)
101 (show <$> [1 :: Int ..])
104 testDecoder :: (Eq a, Show a) => String -> Decoder a -> [Gen a] -> TestTree
105 testDecoder tn site as =
108 (\n Gen{..} -> testCase n $ decode site genSlugs @?= Right genValue)
109 (show <$> [1 :: Int ..])
112 testEncoder :: String -> Encoder a -> [Gen a] -> TestTree
113 testEncoder tn site as =
116 (\n Gen{..} -> testCase n $ encode site genValue @?= genSlugs)
117 (show <$> [1 :: Int ..])