~jaro/balkon

96147a5add8883ebba8f2abc060636a623ba5fa5 — Jaro 1 year, 8 months ago 30e51ed
Allow polymorphism in writing golden tests.
1 files changed, 13 insertions(+), 10 deletions(-)

M test/Data/Text/ParagraphLayoutSpec.hs
M test/Data/Text/ParagraphLayoutSpec.hs => test/Data/Text/ParagraphLayoutSpec.hs +13 -10
@@ 89,16 89,19 @@ commaSpace = ", "
commaNewline :: String
commaNewline = "," ++ newline

shouldBeGolden :: ParagraphLayout -> FilePath -> Golden ParagraphLayout
shouldBeGolden output_ name = Golden
    { output = output_
    , encodePretty = show
    , writeToFile = \path -> writeFile path . prettyShow
    , readFromFile = \path -> readFile path >>= return . read
    , goldenFile = ".golden" </> name </> "golden"
    , actualFile = Just (".golden" </> name </> "actual")
    , failFirstTime = False
    }
class ShouldBeGolden a where
    shouldBeGolden :: a -> FilePath -> Golden a

instance ShouldBeGolden ParagraphLayout where
    shouldBeGolden output_ name = Golden
        { output = output_
        , encodePretty = show
        , writeToFile = \path -> writeFile path . prettyShow
        , readFromFile = \path -> readFile path >>= return . read
        , goldenFile = ".golden" </> name </> "golden"
        , actualFile = Just (".golden" </> name </> "actual")
        , failFirstTime = False
        }

emptyLayout :: ParagraphLayout
emptyLayout = ParagraphLayout (Rect 0 0 0 0) []