1 {-# LANGUAGE ConstraintKinds #-}
2 {-# LANGUAGE OverloadedStrings #-}
3 {-# LANGUAGE RankNTypes #-}
4 {-# LANGUAGE UndecidableInstances #-}
9 import Network.URI.Slug
12 import Test.Tasty.HUnit
14 import Examples.Ex01 qualified as Ex01
27 [ Node (GeneratorNode Ex01.Index ["index.html"]) []
28 , Node (GeneratorNode Ex01.About ["about.html"]) []
29 , Node (GeneratorNode (Ex01.Contact "user") ["user", "contact.html"]) []
30 , Node (GeneratorNode (Ex01.Post []) ["post"]) []
31 , Node (GeneratorNode (Ex01.Post ["dir"]) ["post", "dir"]) []
32 , Node (GeneratorNode (Ex01.Post ["dir", "dir"]) ["post", "dir", "dir"]) []
39 , Ex01.Post ["dir", "dir"]
44 [ testCoderIsomorphism "Ex01" Ex01.site
51 [ (Ex01.Index, ["index.html"])
52 , (Ex01.About, ["about.html"])
53 , (Ex01.Contact "user", ["user", "contact.html"])
54 , (Ex01.Post ["a", "b"], ["post", "a", "b"])
62 [ (Ex01.Index, ["index.html"])
63 , (Ex01.About, ["about.html"])
64 , (Ex01.Contact "user", ["user", "contact.html"])
65 , (Ex01.Post ["a", "b"], ["post", "a", "b"])
75 {-expected-} (Forest (GeneratorNode a)) ->
78 testGenerator tn site expectedCheck expectedValues =
79 let lay = generator site
82 [ testCase "generate" $ generate lay @?= expectedCheck
83 , testCase "generateValues" $ generateValues lay @?= expectedValues
86 testCoderIsomorphism ::
90 (forall repr. Testable repr => repr a) ->
92 testCoderIsomorphism tn site =
97 [ (testCase "decode . encode" $ decode site (encode site a) @?= Right a)
98 , (testCase "encode . decode" $ encode site <$> decode site slugs @?= Right slugs)
101 (show <$> [1 :: Int ..])
102 (zip (generateValues site) (generateSlugs site))
104 testDecoder :: (Eq a, Show a) => String -> Decoder a -> [(a, [Slug])] -> TestTree
105 testDecoder tn site as =
108 (\n (expected, slugs) -> testCase n $ decode site slugs @?= Right expected)
109 (show <$> [1 :: Int ..])
112 testEncoder :: String -> Encoder a -> [(a, [Slug])] -> TestTree
113 testEncoder tn site as =
116 (\n (a, expected) -> testCase n $ encode site a @?= expected)
117 (show <$> [1 :: Int ..])