~jaro/balkon

ref: 63a571647035682e5d177186b58d59a58ce37a8c balkon/test/Data/Text/ParagraphLayout/PrettyShow/Golden.hs -rw-r--r-- 1.0 KiB
63a57164Jaro Define BoxOptions and TextOptions for formatting. 1 year, 6 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
    }