~jaro/balkon

61cc2375a6025f54efec90e59a653c61737fac83 — Jaro 1 year, 7 months ago 7a0c775
Colocate definitions of golden test paths.
1 files changed, 17 insertions(+), 10 deletions(-)

M test/Data/Text/ParagraphLayoutSpec.hs
M test/Data/Text/ParagraphLayoutSpec.hs => test/Data/Text/ParagraphLayoutSpec.hs +17 -10
@@ 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