~jaro/balkon

ref: 81d758baf4c7f7ab803edccb4dd1bb7e82a4753d balkon/test/Data/Text/ParagraphLayout/PrettyShow/Golden.hs -rw-r--r-- 1.0 KiB
81d758baJaro Test handling of empty lines. 1 year, 3 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
    }