2 {-# LANGUAGE ExistentialQuantification #-}
4 {-# LANGUAGE RankNTypes #-}
8 import Data.List qualified as List
10 import Symantic.Classes (ProductFunctor (..), SumFunctor (..))
11 import System.IO.Unsafe (unsafePerformIO)
13 import Test.Tasty.Golden
14 import Text.Printf (printf)
16 import Examples.Ex01 qualified as Ex01
25 [ testGroup "Generator" $
26 (\f -> zipWith f goldens [1 :: Int ..]) $ \(Golden site) siteNum ->
27 let siteDir = printf "Site%03d" siteNum
28 in let expectedFile = getGoldenDir $ printf "Generator/%s/expected.txt" siteDir
34 return $ fromString $ List.unlines $ show <$> generate site
35 , testGroup "Encoder" $
36 (\f -> zipWith f goldens [1 :: Int ..]) $ \(Golden site) siteNum ->
37 let siteDir = printf "Site%03d" siteNum
38 in testGroup siteDir $
39 (\f -> zipWith f (generate site) [1 :: Int ..]) $ \Gen{..} genNum ->
40 let expectedFile = getGoldenDir $ printf "Encoder/%s/output%02d.expected.txt" siteDir genNum
42 (printf "output%02d" genNum)
46 return $ fromString $ show $ encode site genValue
49 getGoldenDir :: FilePath -> FilePath
50 getGoldenDir p = unsafePerformIO $ getDataFileName $ "tests/Goldens/" <> p
52 goldenDiff :: FilePath -> FilePath -> [String]
53 goldenDiff ref new = ["diff", "-u", "-w", "-B", ref, new]
55 data Golden = forall a. Show a => Golden (forall repr. Testable repr => repr a)
59 , Golden ("foo" </> index)
60 , Golden ("root" </> ("foo" </> index <+> "bar" </> index))
63 </> ("a" </> literalSlug "b" <+> "c" </> literalSlug "d")
64 <.> ("A" </> literalSlug "B" <+> "C" </> literalSlug "D")