1 {-# LANGUAGE AllowAmbiguousTypes #-}
3 {-# LANGUAGE ExistentialQuantification #-}
4 {-# LANGUAGE ImportQualifiedPost #-}
5 {-# LANGUAGE PartialTypeSignatures #-}
7 {-# LANGUAGE RankNTypes #-}
8 {-# OPTIONS_GHC -Wno-orphans #-}
12 import Control.Monad.Classes qualified as MC
13 import Control.Monad.Trans.Reader as MT
14 import Data.ByteString.Lazy qualified as BSL
15 import Data.Functor.Identity (Identity (..))
16 import Data.Text qualified as Text
18 import Symantic qualified as Sym
19 import System.FilePath qualified as Sys
20 import System.IO.Unsafe (unsafePerformIO)
22 import Test.Tasty.Golden
23 import Text.Printf (printf)
25 import Examples.Ex01 qualified as Ex01
26 import Examples.Ex02 qualified as Ex02
27 import Examples.Ex03 qualified as Ex03
28 import Examples.Ex04 qualified as Ex04
29 import Examples.Ex05 qualified as Ex05
31 import Paths_literate_web
41 (printf "Site%03d" siteNum)
43 (goldenCompiler CompilerEnv{..})
47 (printf "Model%02d" modelNum)
49 (printf "/%s" destPath)
51 (getGoldenDir (printf "Compiler/Site%03d/Model%02d/Expected/%s" siteNum modelNum destPath))
52 (compilerEnvDest Sys.</> destPath)
54 | destPath <- goldenManifest
56 | (modelNum, Golden{..}) <- ol goldenModels
57 , let compilerEnvDest = getGoldenDir (printf "Compiler/Site%03d/Model%02d/Got/" siteNum modelNum)
58 , let compilerEnvIndex :: FilePath = "index.html"
59 -- , let compilerEnvSource = getGoldenDir (printf "Compiler/Site%03d/Model%02d/Source/" siteNum modelNum)
61 | (siteNum, goldenModels) <- ol goldens
65 getGoldenDir :: FilePath -> FilePath
66 getGoldenDir p = unsafePerformIO $ getDataFileName $ "tests/Goldens/" <> p
68 goldenDiff :: FilePath -> FilePath -> [String]
69 goldenDiff ref new = ["diff", "-u", "-w", "-B", ref, new]
72 { goldenCompiler :: CompilerEnv -> IO ()
73 , goldenManifest :: [Sys.FilePath]
77 {- [ Golden @() index [()]
81 , Golden @(Either () ())
82 ("root" </> ("foo" </> index <+> "bar" </> index))
84 , Golden @(Either () (), Either () ())
86 </> ("a" </> literalSlug "b" <+> "c" </> literalSlug "d")
87 <.> ("A" </> literalSlug "B" <+> "C" </> literalSlug "D")
94 { goldenCompiler = \env -> compile env Ex01.router Ex01.content
95 , goldenManifest = runIdentity $ manifest Ex01.router Ex01.content
100 { goldenCompiler = \env -> compile env Ex02.router Ex02.content
101 , goldenManifest = runIdentity $ manifest Ex02.router Ex02.content
105 { goldenCompiler = \env -> MT.runReaderT (compile env Ex03.router Ex03.content) model
106 , goldenManifest = runReader (manifest Ex03.router Ex03.content) model
108 | model <- [Ex03.model1, Ex03.model2]
111 { goldenCompiler = \env -> MT.runReaderT (compile env Ex04.router Ex04.content) model
112 , goldenManifest = runReader (manifest Ex04.router Ex04.content) model
114 | model <- [Ex04.model1]
117 { goldenCompiler = \env -> MT.runReaderT (MT.runReaderT (compile env Ex05.router Ex05.content) model03) model04
118 , goldenManifest = MT.runReader (MT.runReaderT (manifest Ex05.router Ex05.content) model03) model04
120 | model03 <- [Ex03.model1, Ex03.model2]
121 , model04 <- [Ex04.model1]