~jaro/balkon

ref: 4c1db0da368a4d8a2a33ab0d37deef45e99a54d2 balkon/test/Data/Text/ParagraphLayout/RichSpec.hs -rw-r--r-- 2.4 KiB
4c1db0daJaro Test layout with mixed font sizes. 1 year, 6 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
module Data.Text.ParagraphLayout.RichSpec (spec) where

import Test.Hspec
import System.FilePath ((</>))
import Data.Text.ParagraphLayout
import Data.Text.ParagraphLayout.FontLoader
import Data.Text.ParagraphLayout.Internal.Paginable (paginateAll)
import Data.Text.ParagraphLayout.PrettyShow
import Data.Text.ParagraphLayout.PrettyShow.Golden
import Data.Text.ParagraphLayout.Rich
import Data.Text.ParagraphLayout.Rich.ParagraphData

spec :: Spec
spec = do

    describe "layoutRich" $ do
        let
            goldenDir = ".golden" </> "richParagraphLayout"
            shouldBeGolden = goldenTest goldenDir id id

        describe "with Latin font" $ do
            font <- runIO $ loadFont latinFont 0 testingOptions
            fontSmall <- runIO $ loadFont latinFont 0 testingOptionsSmall

            it "wraps lorem ipsum at 20em" $ do
                let opts = defaultParagraphOptions { paragraphMaxWidth = 20000 }
                let input = loremIpsumParagraph font opts
                let result = layoutRich input
                result `shouldBeGolden` "loremIpsum20em"

            it "handles mixed sizes" $ do
                let opts = defaultParagraphOptions
                let input = mixedSizesParagraph (font, fontSmall) opts
                let result = layoutRich input
                result `shouldBeGolden` "mixedSizes"

            it "handles nested boxes" $ do
                let opts = defaultParagraphOptions
                let input = nestedBoxesParagraph font opts
                let result = layoutRich input
                result `shouldBeGolden` "nestedBoxes"

    describe "paginate" $ do
        let
            goldenDir = ".golden" </> "paginatedRichParagraphLayout"
            shouldBeGolden = goldenTest goldenDir getRichPages RichPages

        describe "with Latin font" $ do
            font <- runIO $ loadFont latinFont 0 testingOptions

            it "wraps lorem ipsum at 20em" $ do
                let opts = defaultParagraphOptions { paragraphMaxWidth = 20000 }
                let input = loremIpsumParagraph font opts
                let pl = layoutRich input
                let popts = PageOptions
                        { pageCurrentHeight = 2500
                        , pageNextHeight = 8500
                        , pageOrphans = 2
                        , pageWidows = 3
                        }
                let pages = paginateAll popts pl
                pages `shouldBeGolden` "loremIpsum20em"