From 61cc2375a6025f54efec90e59a653c61737fac83 Mon Sep 17 00:00:00 2001 From: Jaro Date: Thu, 20 Apr 2023 14:36:17 +0200 Subject: [PATCH] Colocate definitions of golden test paths. --- test/Data/Text/ParagraphLayoutSpec.hs | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/test/Data/Text/ParagraphLayoutSpec.hs b/test/Data/Text/ParagraphLayoutSpec.hs index 6eb27d6..8fe4d0d 100644 --- a/test/Data/Text/ParagraphLayoutSpec.hs +++ b/test/Data/Text/ParagraphLayoutSpec.hs @@ -23,6 +23,15 @@ goldenPagesDir = ".golden" "paginatedParagraphLayout" goldenShapedRunsDir :: FilePath goldenShapedRunsDir = ".golden" "shapedRuns" +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" + class ShouldBeGolden a where shouldBeGolden :: a -> FilePath -> Golden a @@ -32,8 +41,8 @@ instance ShouldBeGolden ParagraphLayout where , encodePretty = show , writeToFile = \ path -> writeFile path . prettyShow , readFromFile = \ path -> readFile path >>= return . read - , goldenFile = goldenLayoutDir name <.> "golden" - , actualFile = Just (goldenLayoutDir name <.> "actual") + , goldenFile = goldenPath goldenLayoutDir name + , actualFile = Just (actualPath goldenLayoutDir name) , failFirstTime = True } @@ -43,8 +52,8 @@ instance ShouldBeGolden Pages where , encodePretty = show . getPages , writeToFile = \ path -> writeFile path . prettyShow , readFromFile = \ path -> readFile path >>= return . Pages . read - , goldenFile = goldenPagesDir name <.> "golden" - , actualFile = Just (goldenPagesDir name <.> "actual") + , goldenFile = goldenPath goldenPagesDir name + , actualFile = Just (actualPath goldenPagesDir name) , failFirstTime = True } @@ -54,14 +63,11 @@ instance ShouldBeGolden ShapedRuns where , encodePretty = show . getShapedRuns , writeToFile = \ path -> writeFile path . prettyShow , readFromFile = \ path -> readFile path >>= return . ShapedRuns . read - , goldenFile = goldenShapedRunsDir name <.> "golden" - , actualFile = Just (goldenShapedRunsDir name <.> "actual") + , goldenFile = goldenPath goldenShapedRunsDir name + , actualFile = Just (actualPath goldenShapedRunsDir name) , failFirstTime = True } -fontInfoPath :: String -> FilePath -fontInfoPath name = goldenShapedRunsDir name <.> "fontInfo" - shapedRuns' :: ParagraphLayout -> ShapedRuns shapedRuns' = ShapedRuns . shapedRuns @@ -76,7 +82,8 @@ emptySpanLayout = ParagraphLayout (Rect 0 0 0 0) [SpanLayout []] shapedRunsSpecWithFont :: FilePath -> Font -> String -> FilePath -> Paragraph -> SpecWith () shapedRunsSpecWithFont fontPath font subject name p = do - let writeInfo = writeFontInfo (fontInfoPath name) fontPath font + let infoPath = fontInfoPath goldenShapedRunsDir name + let writeInfo = writeFontInfo infoPath fontPath font after_ writeInfo $ it subject $ do let result = layoutPlain p shapedRuns' result `shouldBeGolden` name -- 2.30.2