~jaro/balkon

ref: 62b95c9e616030c3a1bdfe158634b2d6ee9fc4a9 balkon/test/Data/Text/ParagraphLayout/PrettyShow/Golden.hs -rw-r--r-- 1.0 KiB
62b95c9eJaro Test ultra narrow Arabic text. 1 year, 5 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
    }