From 96147a5add8883ebba8f2abc060636a623ba5fa5 Mon Sep 17 00:00:00 2001 From: Jaro Date: Fri, 17 Mar 2023 19:32:26 +0100 Subject: [PATCH] Allow polymorphism in writing golden tests. --- test/Data/Text/ParagraphLayoutSpec.hs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/test/Data/Text/ParagraphLayoutSpec.hs b/test/Data/Text/ParagraphLayoutSpec.hs index 03d409d..9b7e692 100644 --- a/test/Data/Text/ParagraphLayoutSpec.hs +++ b/test/Data/Text/ParagraphLayoutSpec.hs @@ -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) [] -- 2.30.2