~jaro/balkon

ref: a084e3323207472c41ea5f174d13626080d6531d balkon/test/Data/Text/ParagraphLayout/PrettyShow/Golden.hs -rw-r--r-- 1.0 KiB
a084e332Jaro Test shifted baseline. 1 year, 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module Data.Text.ParagraphLayout.PrettyShow.Golden
    ( goldenTest
    , goldenPath
    , actualPath
    , fontInfoPath
    )
where

import Test.Hspec.Golden
import System.FilePath ((<.>), (</>))
import Data.Text.ParagraphLayout.PrettyShow

goldenPath :: FilePath -> String -> FilePath
goldenPath dir name = dir </> name <.> "golden"

actualPath :: FilePath -> String -> FilePath
actualPath dir name = dir </> name <.> "actual"

fontInfoPath :: FilePath -> String -> FilePath
fontInfoPath dir name = dir </> name <.> "fontInfo"

goldenTest :: (PrettyShow a, Show inner, Read inner) =>
    FilePath -> (a -> inner) -> (inner -> a) -> inner -> FilePath -> Golden a
goldenTest goldenDir unwrap wrap innerOutput name = Golden
    { output = wrap innerOutput
    , encodePretty = show . unwrap
    , writeToFile = \ path -> writeFile path . prettyShow
    , readFromFile = \ path -> wrap . read <$> readFile path
    , goldenFile = goldenPath goldenDir name
    , actualFile = Just (actualPath goldenDir name)
    , failFirstTime = True
    }