~jaro/balkon

ref: c5e25e2b7a77d3af82227c1151820c2f4ddc559f balkon/test/Data/Text/ParagraphLayout/PrettyShow/Golden.hs -rw-r--r-- 1.0 KiB
c5e25e2bJaro Clean up vertical alignment code structure. 1 year, 2 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
    }