~jaro/balkon

09dd2f080bc54db671c518ebb0d546e5ef89c379 — Jaro 1 year, 9 months ago bb6ef2f
Improve test readability with runIO.
1 files changed, 121 insertions(+), 120 deletions(-)

M test/Data/Text/ParagraphLayoutSpec.hs
M test/Data/Text/ParagraphLayoutSpec.hs => test/Data/Text/ParagraphLayoutSpec.hs +121 -120
@@ 1,7 1,5 @@
module Data.Text.ParagraphLayoutSpec (spec) where

import Data.Text.Glyphize (Font)

import Test.Hspec
import Test.Hspec.Golden
import System.FilePath ((</>))


@@ 109,151 107,154 @@ emptyLayout = ParagraphLayout (Rect 0 0 0 0) []
emptySpanLayout :: ParagraphLayout
emptySpanLayout = ParagraphLayout (Rect 0 0 0 0) [SpanLayout []]

opts :: Font -> ParagraphOptions
opts font = ParagraphOptions font Normal 8000

spec :: Spec
spec = do

    describe "layoutPlain" $ do
        describe "with Arabic font" $ before loadPlexSansArabicRegular $ do
            it "handles input with no spans" $ \font -> do
                let result = layoutPlain $ emptyParagraph $ opts font

        describe "with Arabic font" $ do
            font <- runIO $ loadPlexSansArabicRegular

            it "handles input with no spans" $ do
                let opts = ParagraphOptions font Normal 8000
                let result = layoutPlain $ emptyParagraph opts
                result `shouldBe` emptyLayout
            it "wraps filler text at 20em" $ \font -> do
                let
                    result = layoutPlain $ arabicFillerParagraph $
                        (opts font)
                        { paragraphMaxWidth = 20000 }

            it "wraps filler text at 20em" $ do
                let opts = ParagraphOptions font Normal 20000
                let result = layoutPlain $ arabicFillerParagraph opts
                result `shouldBeGolden` "arabicFiller20em"
            it "wraps filler text with spans at 20em" $ \font -> do
                let
                    result = layoutPlain $ spannedArabicFillerParagraph $
                        (opts font)
                        { paragraphMaxWidth = 20000 }

            it "wraps filler text with spans at 20em" $ do
                let opts = ParagraphOptions font Normal 20000
                let result = layoutPlain $ spannedArabicFillerParagraph opts
                result `shouldBeGolden` "spannedArabicFiller20em"
            it "spans do not reposition filler text at 20em" $ \font -> do
                let
                    withoutSpans = layoutPlain $ arabicFillerParagraph $
                        (opts font)
                        { paragraphMaxWidth = 20000 }
                    withSpans = layoutPlain $ spannedArabicFillerParagraph $
                        (opts font)
                        { paragraphMaxWidth = 20000 }

            it "spans do not reposition filler text at 20em" $ do
                let opts = ParagraphOptions font Normal 20000
                let withoutSpans = layoutPlain $ arabicFillerParagraph opts
                let withSpans = layoutPlain $ spannedArabicFillerParagraph opts
                paragraphRect withoutSpans `shouldBe` paragraphRect withSpans
        describe "with Devanagari font" $ before loadSaralaRegular $ do

        describe "with Devanagari font" $ do
            font <- runIO $ loadSaralaRegular

            describe "lone accent character" $ do
                let
                    result = \font -> layoutPlain $
                        devanagariAccentParagraph $
                        opts font
                it "inserts a dotted circle" $ \font -> do
                    x_size (paragraphRect (result font)) `shouldBe` 645
                it "is golden" $ \font -> do
                    result font `shouldBeGolden`
                        "devanagariAccentParagraph"
                    opts = ParagraphOptions font Normal 8000
                    result = layoutPlain $
                        devanagariAccentParagraph opts

                it "inserts a dotted circle" $ do
                    x_size (paragraphRect result) `shouldBe` 645

                it "is golden" $ do
                    result `shouldBeGolden` "devanagariAccentParagraph"

            describe "lone accent character after prefix" $ do
                let
                    result = \font -> layoutPlain $
                        devanagariPrefixedAccentParagraph $
                        opts font
                it "does not insert a dotted circle" $ \font -> do
                    x_size (paragraphRect (result font)) `shouldBe` 0
                it "is golden" $ \font -> do
                    result font `shouldBeGolden`
                        "devanagariPrefixedAccentParagraph"
            it "handles input without wrapping" $ \font -> do
                let
                    result = layoutPlain $ devanagariParagraph $
                        (opts font)
                        { paragraphMaxWidth = 9000 }
                    opts = ParagraphOptions font Normal 8000
                    result = layoutPlain $
                        devanagariPrefixedAccentParagraph opts

                it "does not insert a dotted circle" $ do
                    x_size (paragraphRect result) `shouldBe` 0

                it "is golden" $ do
                    result `shouldBeGolden` "devanagariPrefixedAccentParagraph"

            it "handles input without wrapping" $ do
                let opts = ParagraphOptions font Normal 9000
                let result = layoutPlain $ devanagariParagraph opts
                result `shouldBeGolden` "devanagariParagraph"
        -- Note: This font does not contain Japanese glyphs.
        describe "with Latin font" $ before loadUbuntuRegular $ do
            it "handles input with no spans" $ \font -> do
                let result = layoutPlain $ emptyParagraph $ opts font

        describe "with Latin font" $ do
            -- Note: This font does not contain Japanese glyphs.
            font <- runIO $ loadUbuntuRegular

            it "handles input with no spans" $ do
                let opts = ParagraphOptions font Normal 8000
                let result = layoutPlain $ emptyParagraph opts
                result `shouldBe` emptyLayout
            it "handles one span with no text" $ \font -> do
                let result = layoutPlain $ emptySpanParagraph $ opts font

            it "handles one span with no text" $ do
                let opts = ParagraphOptions font Normal 8000
                let result = layoutPlain $ emptySpanParagraph opts
                result `shouldBe` emptySpanLayout
            it "handles Czech hello" $ \font -> do
                let result = layoutPlain $ czechHelloParagraph $ opts font

            it "handles Czech hello" $ do
                let opts = ParagraphOptions font Normal 8000
                let result = layoutPlain $ czechHelloParagraph opts
                result `shouldBeGolden` "czechHelloParagraph"
            it "renders an \"ffi\" ligature" $ \ font -> do
                let result = layoutPlain $ ligatureParagraph $ opts font

            it "renders an \"ffi\" ligature" $ do
                let opts = ParagraphOptions font Normal 8000
                let result = layoutPlain $ ligatureParagraph opts
                result `shouldBeGolden` "ligatureParagraph"
            it "breaks an \"ffi\" ligature into \"ff\" + \"i\"" $ \ font -> do
                let result = layoutPlain $ ligatureParagraph $
                        (opts font)
                        { paragraphMaxWidth = 2418 }

            it "breaks an \"ffi\" ligature into \"ff\" + \"i\"" $ do
                let opts = ParagraphOptions font Normal 2418
                let result = layoutPlain $ ligatureParagraph opts
                result `shouldBeGolden` "ligatureParagraphBreak1"
            it "breaks an \"ffi\" ligature into \"f\" + \"fi\"" $ \ font -> do
                let result = layoutPlain $ ligatureParagraph $
                        (opts font)
                        { paragraphMaxWidth = 1800 }

            it "breaks an \"ffi\" ligature into \"f\" + \"fi\"" $ do
                let opts = ParagraphOptions font Normal 1800
                let result = layoutPlain $ ligatureParagraph opts
                result `shouldBeGolden` "ligatureParagraphBreak2"
            it "handles mixed languages in LTR layout" $ \font -> do
                let result = layoutPlain $ mixedLanguageLTRParagraph $ opts font

            it "handles mixed languages in LTR layout" $ do
                let opts = ParagraphOptions font Normal 8000
                let result = layoutPlain $ mixedLanguageLTRParagraph opts
                result `shouldBeGolden` "mixedLanguageLTRParagraph"
            it "handles normal line height" $ \font -> do
                let
                    result = layoutPlain $ trivialParagraph $
                        (opts font)
                        { paragraphLineHeight = Normal }

            it "handles normal line height" $ do
                let opts = ParagraphOptions font Normal 8000
                let result = layoutPlain $ trivialParagraph opts
                result `shouldBeGolden` "lineHeightNormal"
            it "handles larger line height" $ \font -> do
                let
                    result = layoutPlain $ trivialParagraph $
                        (opts font)
                        { paragraphLineHeight = Absolute 1600 }

            it "handles larger line height" $ do
                let opts = ParagraphOptions font (Absolute 1600) 8000
                let result = layoutPlain $ trivialParagraph opts
                result `shouldBeGolden` "lineHeightLarger"
            it "handles smaller line height" $ \font -> do
                let
                    result = layoutPlain $ trivialParagraph $
                        (opts font)
                        { paragraphLineHeight = Absolute 599 }

            it "handles smaller line height" $ do
                let opts = ParagraphOptions font (Absolute 599) 8000
                let result = layoutPlain $ trivialParagraph opts
                result `shouldBeGolden` "lineHeightSmaller"
            it "wraps mid-word when line is narrow" $ \font -> do
                let
                    result = layoutPlain $ czechHelloParagraph $
                        (opts font)
                        { paragraphMaxWidth = 1300 }

            it "wraps mid-word when line is narrow" $ do
                let opts = ParagraphOptions font Normal 1300
                let result = layoutPlain $ czechHelloParagraph opts
                result `shouldBeGolden` "czechHelloParagraphNarrow"
            it "wraps by characters when line is ultra narrow" $ \font -> do
                let
                    result = layoutPlain $ czechHelloParagraph $
                        (opts font)
                        { paragraphMaxWidth = 100 }

            it "wraps by characters when line is ultra narrow" $ do
                let opts = ParagraphOptions font Normal 100
                let result = layoutPlain $ czechHelloParagraph opts
                result `shouldBeGolden` "czechHelloParagraphUltraNarrow"
            it "wraps lorem ipsum at 20em" $ \font -> do
                let
                    result = layoutPlain $ loremIpsumParagraph $
                        (opts font)
                        { paragraphMaxWidth = 20000 }

            it "wraps lorem ipsum at 20em" $ do
                let opts = ParagraphOptions font Normal 20000
                let result = layoutPlain $ loremIpsumParagraph opts
                result `shouldBeGolden` "loremIpsum20em"
            it "wraps lorem ipsum at 100em" $ \font -> do
                let
                    result = layoutPlain $ loremIpsumParagraph $
                        (opts font)
                        { paragraphMaxWidth = 100000 }

            it "wraps lorem ipsum at 100em" $ do
                let opts = ParagraphOptions font Normal 100000
                let result = layoutPlain $ loremIpsumParagraph opts
                result `shouldBeGolden` "loremIpsum100em"
            it "wraps lorem ipsum with spans at 20em" $ \font -> do
                let
                    result = layoutPlain $ spannedLoremIpsumParagraph $
                        (opts font)
                        { paragraphMaxWidth = 20000 }

            it "wraps lorem ipsum with spans at 20em" $ do
                let opts = ParagraphOptions font Normal 20000
                let result = layoutPlain $ spannedLoremIpsumParagraph opts
                result `shouldBeGolden` "spannedLoremIpsum20em"
            it "spans do not reposition lorem ipsum at 20em" $ \font -> do
                let
                    withoutSpans = layoutPlain $ loremIpsumParagraph $
                        (opts font)
                        { paragraphMaxWidth = 20000 }
                    withSpans = layoutPlain $ spannedLoremIpsumParagraph $
                        (opts font)
                        { paragraphMaxWidth = 20000 }

            it "spans do not reposition lorem ipsum at 20em" $ do
                let opts = ParagraphOptions font Normal 20000
                let withoutSpans = layoutPlain $ loremIpsumParagraph opts
                let withSpans = layoutPlain $ spannedLoremIpsumParagraph opts
                paragraphRect withoutSpans `shouldBe` paragraphRect withSpans
            it "wraps mixed-script words correctly" $ \font -> do
                let
                    result = layoutPlain $ mixedScriptWordsParagraph $
                        (opts font)
                        { paragraphMaxWidth = 6000 }

            it "wraps mixed-script words correctly" $ do
                let opts = ParagraphOptions font Normal 6000
                let result = layoutPlain $ mixedScriptWordsParagraph opts
                result `shouldBeGolden` "mixedScriptWordsParagraph"