~jaro/balkon

ref: 95ceab6991b5b491ebe39374989d3bcf7d12314c balkon/test/Data/Text/ParagraphLayout/RectSpec.hs -rw-r--r-- 4.3 KiB
95ceab69Jaro Implement calculation of safe paragraph width. 1 year, 4 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
module Data.Text.ParagraphLayout.RectSpec (spec) where

import Data.Int (Int32)
import Data.List.NonEmpty (NonEmpty ((:|)))

import Test.Hspec
import Data.Text.ParagraphLayout.Internal.Rect

positiveRect :: Rect Int32
positiveRect = Rect 50 (-70) 10 10

negativeRect :: Rect Int32
negativeRect = Rect 80 (-75) (-15) (-15)

spec :: Spec
spec = do

    describe "union of two rects" $ do

        describe "low X, low Y" $
            llSpec $ union LL positiveRect negativeRect

        describe "low X, high Y" $
            lhSpec $ union LH positiveRect negativeRect

        describe "high X, low Y" $
            hlSpec $ union HL positiveRect negativeRect

        describe "high X, high Y" $
            hhSpec $ union HH positiveRect negativeRect

    describe "union of list" $ do

        describe "when empty" $
            it "should be Nothing" $ do
                unionMany LL []
                    `shouldBe` (Nothing :: Maybe (Rect Int32))

        describe "with single item" $ do

            describe "matching LL origin" $
                it "should be identity" $
                    unionMany LL [positiveRect]
                        `shouldBe` Just positiveRect

            describe "matching HH origin" $
                it "should be identity" $
                    unionMany HH [negativeRect]
                        `shouldBe` Just negativeRect

        describe "with single item repeated" $ do

            describe "matching LL origin" $
                it "should be equal to item" $
                    unionMany LL (replicate 2 positiveRect)
                        `shouldBe` Just positiveRect

            describe "matching HH origin" $
                it "should be equal to item" $
                    unionMany HH (replicate 7 negativeRect)
                        `shouldBe` Just negativeRect

        describe "with two items" $
            it "should behave the same as binary function" $
                unionMany LL [positiveRect, negativeRect]
                    `shouldBe` Just (union LL positiveRect negativeRect)

    describe "union of non-empty list" $ do

        describe "with single item" $ do

            describe "matching LL origin" $
                it "should be identity" $
                    unionMany1 LL (positiveRect :| [])
                        `shouldBe` positiveRect

            describe "matching HH origin" $
                it "should be identity" $
                    unionMany1 HH (negativeRect :| [])
                        `shouldBe` negativeRect

        describe "with two items" $
            it "should behave the same as binary function" $
                unionMany1 LL (positiveRect :| [negativeRect])
                    `shouldBe` union LL positiveRect negativeRect

llSpec :: Rect Int32 -> SpecWith ()
llSpec r = do
    commonSpec r
    it "has origin at 50,-90" $
        (x_origin r, y_origin r) `shouldBe` (50, -90)
    it "has terminus at 80,-60" $
        (x_terminus r, y_terminus r) `shouldBe` (80, -60)
    it "has size 30,30" $
        (x_size r, y_size r) `shouldBe` (30, 30)

lhSpec :: Rect Int32 -> SpecWith ()
lhSpec r = do
    commonSpec r
    it "has origin at 50,-60" $
        (x_origin r, y_origin r) `shouldBe` (50, -60)
    it "has terminus at 80,-90" $
        (x_terminus r, y_terminus r) `shouldBe` (80, -90)
    it "has size 30,-30" $
        (x_size r, y_size r) `shouldBe` (30, -30)

hlSpec :: Rect Int32 -> SpecWith ()
hlSpec r = do
    commonSpec r
    it "has origin at 80,-90" $
        (x_origin r, y_origin r) `shouldBe` (80, -90)
    it "has terminus at 50,-60" $
        (x_terminus r, y_terminus r) `shouldBe` (50, -60)
    it "has size -30,30" $
        (x_size r, y_size r) `shouldBe` (-30, 30)

hhSpec :: Rect Int32 -> SpecWith ()
hhSpec r = do
    commonSpec r
    it "has origin at 80,-60" $
        (x_origin r, y_origin r) `shouldBe` (80, -60)
    it "has terminus at 50,-90" $
        (x_terminus r, y_terminus r) `shouldBe` (50, -90)
    it "has size -30,-30" $
        (x_size r, y_size r) `shouldBe` (-30, -30)

commonSpec :: Rect Int32 -> SpecWith ()
commonSpec r = do
    it "has minimum coordinates at at 50,-90" $
        (x_min r, y_min r) `shouldBe` (50, -90)
    it "has maximum coordinates at 80,-60" $
        (x_max r, y_max r) `shouldBe` (80, -60)
    it "has absolute size 30,30" $
        (width r, height r) `shouldBe` (30, 30)