1 {-# LANGUAGE AllowAmbiguousTypes #-}
3 {-# LANGUAGE ExistentialQuantification #-}
4 {-# LANGUAGE ImportQualifiedPost #-}
5 {-# LANGUAGE PartialTypeSignatures #-}
7 {-# LANGUAGE RankNTypes #-}
8 {-# OPTIONS_GHC -Wno-orphans #-}
12 import Control.Monad.Trans.Reader as MT
14 import System.FilePath qualified as Sys
15 import System.IO.Unsafe (unsafePerformIO)
17 import Test.Tasty.Golden
18 import Text.Printf (printf)
20 import Examples.Ex01 qualified as Ex01
21 import Examples.Ex02 qualified as Ex02
22 import Examples.Ex03 qualified as Ex03
23 import Examples.Ex04 qualified as Ex04
24 import Examples.Ex05 qualified as Ex05
26 import Paths_literate_web
36 (printf "Site%03d" siteNum)
38 (goldenCompiler CompilerEnv{..})
42 (printf "Model%02d" modelNum)
44 (printf "/%s" destPath)
46 (getGoldenDir (printf "Compiler/Site%03d/Model%02d/Expected/%s" siteNum modelNum destPath))
47 (compilerEnvDest Sys.</> destPath)
49 | destPath <- goldenManifest
51 | (modelNum, Golden{..}) <- ol goldenModels
52 , let compilerEnvDest = getGoldenDir (printf "Compiler/Site%03d/Model%02d/Got/" siteNum modelNum)
53 , let compilerEnvIndex :: FilePath = "index.html"
54 -- , let compilerEnvSource = getGoldenDir (printf "Compiler/Site%03d/Model%02d/Source/" siteNum modelNum)
56 | (siteNum, goldenModels) <- ol goldens
60 getGoldenDir :: FilePath -> FilePath
61 getGoldenDir p = unsafePerformIO $ getDataFileName $ "tests/Goldens/" <> p
63 goldenDiff :: FilePath -> FilePath -> [String]
64 goldenDiff ref new = ["diff", "-u", "-w", "-B", ref, new]
67 { goldenCompiler :: CompilerEnv -> IO ()
68 , goldenManifest :: [Sys.FilePath]
72 {- [ Golden @() index [()]
76 , Golden @(Either () ())
77 ("root" </> ("foo" </> index <+> "bar" </> index))
79 , Golden @(Either () (), Either () ())
81 </> ("a" </> literalSlug "b" <+> "c" </> literalSlug "d")
82 <.> ("A" </> literalSlug "B" <+> "C" </> literalSlug "D")
89 { goldenCompiler = \env -> compile env Ex01.router Ex01.content
90 , goldenManifest = runIdentity $ siteManifest Ex01.router
95 { goldenCompiler = \env -> compile env Ex02.router Ex02.content
96 , goldenManifest = runIdentity $ siteManifest Ex02.router
100 { goldenCompiler = \env -> MT.runReaderT (compile env Ex03.router Ex03.content) model
101 , goldenManifest = runReader (siteManifest Ex03.router) model
103 | model <- [Ex03.model1, Ex03.model2]
106 { goldenCompiler = \env -> MT.runReaderT (compile env Ex04.router Ex04.content) model
107 , goldenManifest = runReader (siteManifest Ex04.router) model
109 | model <- [Ex04.model1]
112 { goldenCompiler = \env -> MT.runReaderT (MT.runReaderT (compile env Ex05.router Ex05.content) model03) model04
113 , goldenManifest = MT.runReader (MT.runReaderT (siteManifest Ex05.router) model03) model04
115 | model03 <- [Ex03.model1, Ex03.model2]
116 , model04 <- [Ex04.model1]