~alcinnz/CatTrap

ref: 484ba2c1fc86388a5e8e17aebc5d5409998768bb CatTrap/test/Test.hs -rw-r--r-- 37.4 KiB
484ba2c1 — Adrian Cochrane Test flexbox positioning! 1 year, 3 days ago
                                                                                
3dce4d79 Adrian Cochrane
d5266882 Adrian Cochrane
3a25ee5a Adrian Cochrane
52bc8445 Adrian Cochrane
b47a0b46 Adrian Cochrane
c06fd552 Adrian Cochrane
972a1386 Adrian Cochrane
c06fd552 Adrian Cochrane
b47a0b46 Adrian Cochrane
3dce4d79 Adrian Cochrane
3a25ee5a Adrian Cochrane
972a1386 Adrian Cochrane
3a25ee5a Adrian Cochrane
52bc8445 Adrian Cochrane
3dce4d79 Adrian Cochrane
c06fd552 Adrian Cochrane
b47a0b46 Adrian Cochrane
c06fd552 Adrian Cochrane
a5de823b Adrian Cochrane
c06fd552 Adrian Cochrane
a5de823b Adrian Cochrane
c06fd552 Adrian Cochrane
a5de823b Adrian Cochrane
c06fd552 Adrian Cochrane
a5de823b Adrian Cochrane
c06fd552 Adrian Cochrane
a5de823b Adrian Cochrane
c06fd552 Adrian Cochrane
a5de823b Adrian Cochrane
b47a0b46 Adrian Cochrane
a5de823b Adrian Cochrane
c06fd552 Adrian Cochrane
62b95550 Adrian Cochrane
c06fd552 Adrian Cochrane
62b95550 Adrian Cochrane
c06fd552 Adrian Cochrane
a5de823b Adrian Cochrane
c06fd552 Adrian Cochrane
a5de823b Adrian Cochrane
c06fd552 Adrian Cochrane
a5de823b Adrian Cochrane
c06fd552 Adrian Cochrane
a5de823b Adrian Cochrane
d5266882 Adrian Cochrane
eae2c200 Adrian Cochrane
d5266882 Adrian Cochrane
b47a0b46 Adrian Cochrane
a5de823b Adrian Cochrane
b47a0b46 Adrian Cochrane
a5de823b Adrian Cochrane
b47a0b46 Adrian Cochrane
a5de823b Adrian Cochrane
b47a0b46 Adrian Cochrane
a5de823b Adrian Cochrane
b47a0b46 Adrian Cochrane
a5de823b Adrian Cochrane
b47a0b46 Adrian Cochrane
a5de823b Adrian Cochrane
b47a0b46 Adrian Cochrane
a5de823b Adrian Cochrane
b47a0b46 Adrian Cochrane
a5de823b Adrian Cochrane
b47a0b46 Adrian Cochrane
a5de823b Adrian Cochrane
b47a0b46 Adrian Cochrane
a5de823b Adrian Cochrane
b47a0b46 Adrian Cochrane
a5de823b Adrian Cochrane
b47a0b46 Adrian Cochrane
62b95550 Adrian Cochrane
b47a0b46 Adrian Cochrane
62b95550 Adrian Cochrane
b47a0b46 Adrian Cochrane
a5de823b Adrian Cochrane
b47a0b46 Adrian Cochrane
a5de823b Adrian Cochrane
b47a0b46 Adrian Cochrane
a5de823b Adrian Cochrane
b47a0b46 Adrian Cochrane
a5de823b Adrian Cochrane
b47a0b46 Adrian Cochrane
d5266882 Adrian Cochrane
b47a0b46 Adrian Cochrane
d5266882 Adrian Cochrane
52bc8445 Adrian Cochrane
3a25ee5a Adrian Cochrane
972a1386 Adrian Cochrane
3a25ee5a Adrian Cochrane
972a1386 Adrian Cochrane
484ba2c1 Adrian Cochrane
3a25ee5a Adrian Cochrane
3dce4d79 Adrian Cochrane
d5266882 Adrian Cochrane
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
{-# LANGUAGE OverloadedStrings #-}
module Main where

import Test.Hspec

import Graphics.Layout.Arithmetic
import Data.CSS.Syntax.Tokens (tokenize, Token(..))
import Stylist (PropertyParser(..))
import Stylist.Tree (StyleTree(..))
import Data.Maybe (fromJust)

import Graphics.Layout.Box as B
import Graphics.Layout.Grid as Grid
import Graphics.Layout.Flow
import Graphics.Layout

import Graphics.Layout.CSS
import Graphics.Layout.Grid.Table
import Graphics.Layout.Inline.CSS
import Graphics.Layout.CSS.Font (placeholderFont)
import Graphics.Layout.Flex as Flex

import Data.Text.ParagraphLayout.Rich (constructParagraph,
        defaultParagraphOptions, defaultTextOptions,
        InnerNode(..), Box(..), RootNode(..))
import Data.Text.ParagraphLayout (PageOptions(..))
import Data.Text.Glyphize (Direction(..))

import Graphics.Layout.Grid.CSS (parseASCIIGrid)
import qualified Data.HashMap.Lazy as HM

main :: IO ()
main = hspec spec

spec :: Spec
spec = do
    describe "canary" $ do
        it "test framework works" $ do
            True `shouldBe` True
    describe "calc()" $ do
        it "Can perform basic arithmatic" $ do
            runMath "42" `shouldBe` 42
            runMath "6 * 9" `shouldBe` 54
            runMath "6 * 9 - 42" `shouldBe` 12
            runMath "6 * (9 - 42)" `shouldBe` -198
            runMath "6 * calc(9 - 42)" `shouldBe` -198
            runMath "6 * abs(9 - 42)" `shouldBe` 198
    describe "Flow sizing" $ do
        -- Based on http://hixie.ch/tests/adhoc/css/box/block/
        it "Can overflow parent" $ do
            width (fst $ layoutFlow zeroBox {
                    size = Size 3 1
                } lengthBox {
                    border = Border (Pixels 0) (Pixels 0) (Pixels 2) (Pixels 2)
                } []) `shouldBe` 4
            width (fst $ layoutFlow zeroBox {
                    size = Size 3 1
                } lengthBox {
                    padding = Border (Pixels 0) (Pixels 0) (Pixels 2) (Pixels 2)
                } []) `shouldBe` 4
            width (fst $ layoutFlow zeroBox {
                    size = Size 3 1
                } lengthBox {
                    margin = Border (Pixels 0) (Pixels 0) (Pixels 2) (Pixels 2)
                } []) `shouldBe` 4
        it "Fits to parent" $ do
            width (fst $ layoutFlow zeroBox {
                    size = Size 5 1
                } lengthBox {
                    border = Border (Pixels 0) (Pixels 0) (Pixels 2) (Pixels 2),
                    size = Size Auto $ Pixels 1
                } []) `shouldBe` 5
            width (fst $ layoutFlow zeroBox {
                    size = Size 5 1
                } lengthBox {
                    padding = Border (Pixels 0) (Pixels 0) (Pixels 2) (Pixels 2),
                    size = Size Auto $ Pixels 1
                } []) `shouldBe` 5
            width (fst $ layoutFlow zeroBox {
                    size = Size 5 1
                } lengthBox {
                    margin = Border (Pixels 0) (Pixels 0) (Pixels 2) (Pixels 2),
                    size = Size Auto $ Pixels 1
                } []) `shouldBe` 5
        it "Fits children" $ do
            let child = mapX' (lowerLength 100) $ lengthBox {
                size = Size (Pixels 10) (Pixels 10)
              }
            height (fst $ layoutFlow zeroBox {
                size = Size 100 100
              } lengthBox [child, child]) `shouldBe` 20
        it "Collapses margins" $ do
            let a :: PaddedBox Length Double
                a = PaddedBox {
                    B.min = Size 0 Auto,
                    size = Size 0 Auto,
                    B.nat = Size 0 0,
                    B.max = Size 0 Auto,
                    padding = Border (Pixels 0) (Pixels 0) 0 0,
                    border = Border (Pixels 0) (Pixels 0) 0 0,
                    margin = Border (Pixels 5) (Pixels 10) 0 0
                  }
                b :: PaddedBox Length Double
                b = PaddedBox {
                    B.min = Size 0 Auto,
                    size = Size 0 Auto,
                    B.nat = Size 0 0,
                    B.max = Size 0 Auto,
                    padding = Border (Pixels 0) (Pixels 0) 0 0,
                    border = Border (Pixels 0) (Pixels 0) 0 0,
                    margin = Border (Pixels 10) (Pixels 5) 0 0
                  }
            height (fst $ layoutFlow zeroBox {
                    size = Size 100 100
                } lengthBox [a, a]) `shouldBe` 25
            height (fst $ layoutFlow zeroBox {
                    size = Size 100 100
                } lengthBox [b, b]) `shouldBe` 25
            height (fst $ layoutFlow zeroBox {
                    size = Size 100 100
                } lengthBox [a, b]) `shouldBe` 20
            height (fst $ layoutFlow zeroBox {
                    size = Size 100 100
                } lengthBox [b, a]) `shouldBe` 25
    {-describe "Grid" $ do
        it "computes single-columns widths/heights" $ do
            let (pxGrid, pxCells) = gridLayout zeroBox {
                    size = Size 100 100
                  } (buildGrid [Left $ Pixels 10] [Left $ Pixels 10])
                    [GridItem 0 1 0 1 (Size Start Start) zeroBox] True
            containerSize pxGrid `shouldBe` Size 10 10
            fst (head pxCells) `shouldBe` Size 0 0
            let (pcGrid, pcCells) = gridLayout zeroBox {
                    size = Size 100 100
                  } (buildGrid [Left $ Percent 0.5] [Left $ Percent 0.5])
                    [GridItem 0 1 0 1 (Size Start Start) zeroBox] True
            containerSize pcGrid `shouldBe` Size 50 50
            fst (head pcCells) `shouldBe` Size 0 0
            let (autoGrid, autoCells) = gridLayout zeroBox {
                    size = Size 100 100
                  } (buildGrid [Left Auto] [Left Auto])
                    [GridItem 0 1 0 1 (Size Start Start) zeroBox {
                        B.min = Size 10 10,
                        size = Size 20 20
                    }] True
            containerSize autoGrid `shouldBe` Size 20 20
            fst (head autoCells) `shouldBe` Size 0 0
            let (prefGrid, prefCells) = gridLayout zeroBox {
                    size = Size 100 100
                  } (buildGrid [Left Preferred] [Left Preferred])
                    [GridItem 0 1 0 1 (Size Start Start) zeroBox {
                        B.min = Size 10 10,
                        size = Size 15 15
                    }] True
            containerSize prefGrid `shouldBe` Size 15 15
            fst (head prefCells) `shouldBe` Size 0 0
            let (minGrid, minCells) = gridLayout zeroBox {
                    size = Size 100 100
                  } (buildGrid [Left Min] [Left Min])
                    [GridItem 0 1 0 1 (Size Start Start) zeroBox {
                        B.min = Size 10 10,
                        size = Size 15 15
                    }] True
            containerSize minGrid `shouldBe` Size 10 10
            fst (head minCells) `shouldBe` Size 0 0-}
    describe "Abstract layout" $ do
        it "Can overflow parent" $ do
            width (layoutGetBox $ head $ boxLayout zeroBox {
                    size = Size 3 1
                } (LayoutFlow () lengthBox {
                    border = Border (Pixels 0) (Pixels 0) (Pixels 2) (Pixels 2)
                } []) False) `shouldBe` 4
            height (layoutGetBox $ head $ boxLayout zeroBox {
                    size = Size 3 1
                } (LayoutFlow () lengthBox {
                    border = Border (Pixels 2) (Pixels 2) (Pixels 2) (Pixels 2)
                } []) False) `shouldBe` 4
            width (layoutGetBox $ head $ boxLayout zeroBox {
                    size = Size 3 1
                } (LayoutFlow () lengthBox {
                    padding = Border (Pixels 0) (Pixels 0) (Pixels 2) (Pixels 2)
                } []) False) `shouldBe` 4
            height (layoutGetBox $ head $ boxLayout zeroBox {
                    size = Size 3 1
                } (LayoutFlow () lengthBox {
                    padding = Border (Pixels 2) (Pixels 2) (Pixels 2) (Pixels 2)
                } []) False) `shouldBe` 4
            width (layoutGetBox $ head $ boxLayout zeroBox {
                    size = Size 3 1
                } (LayoutFlow () lengthBox {
                    margin = Border (Pixels 0) (Pixels 0) (Pixels 2) (Pixels 2)
                } []) False) `shouldBe` 4
            height (layoutGetBox $ head $ boxLayout zeroBox {
                    size = Size 3 1
                } (LayoutFlow () lengthBox {
                    margin = Border (Pixels 2) (Pixels 2) (Pixels 2) (Pixels 2)
                } []) False) `shouldBe` 4
        it "Fits to parent" $ do
            width (layoutGetBox $ head $ boxLayout zeroBox {
                    size = Size 5 1
                } (LayoutFlow () lengthBox {
                    border = Border (Pixels 0) (Pixels 0) (Pixels 2) (Pixels 2),
                    size = Size Auto $ Pixels 1
                } []) False) `shouldBe` 5
            width (layoutGetBox $ head $ boxLayout zeroBox {
                    size = Size 5 1
                } (LayoutFlow () lengthBox {
                    padding = Border (Pixels 0) (Pixels 0) (Pixels 2) (Pixels 2),
                    size = Size Auto $ Pixels 1
                } []) False) `shouldBe` 5
            width (layoutGetBox $ head $ boxLayout zeroBox {
                    size = Size 5 1
                } (LayoutFlow () lengthBox {
                    margin = Border (Pixels 0) (Pixels 0) (Pixels 2) (Pixels 2),
                    size = Size Auto $ Pixels 1
                } []) False) `shouldBe` 5
        it "Fits children" $ do
            let child = LayoutFlow () lengthBox {
                size = Size (Pixels 10) (Pixels 10),
                B.max = Size (Pixels 10) (Pixels 10)
              } []
            height (layoutGetBox $ head $ boxLayout zeroBox {
                size = Size 100 100
              } child False) `shouldBe` 10
            height (layoutGetBox $ head $ boxLayout zeroBox {
                size = Size 100 100
              } (LayoutFlow () lengthBox [child, child]) False) `shouldBe` 20
        it "Collapses margins" $ do
            let a :: LayoutItem Length Length ()
                a = LayoutFlow () PaddedBox {
                    B.min = Size Auto Auto,
                    size = Size Auto Auto,
                    B.nat = Size 0 0,
                    B.max = Size Auto Auto,
                    padding = Border (Pixels 0) (Pixels 0) (Pixels 0) (Pixels 0),
                    border = Border (Pixels 0) (Pixels 0) (Pixels 0) (Pixels 0),
                    margin = Border (Pixels 5) (Pixels 10) (Pixels 0) (Pixels 0)
                  } []
                b :: LayoutItem Length Length ()
                b = LayoutFlow () PaddedBox {
                    B.min = Size Auto Auto,
                    size = Size Auto Auto,
                    B.nat = Size 0 0,
                    B.max = Size Auto Auto,
                    padding = Border (Pixels 0) (Pixels 0) (Pixels 0) (Pixels 0),
                    border = Border (Pixels 0) (Pixels 0) (Pixels 0) (Pixels 0),
                    margin = Border (Pixels 10) (Pixels 5) (Pixels 0) (Pixels 0)
                  } []
            height (layoutGetBox $ head $ boxLayout zeroBox {
                    size = Size 100 100
                } (LayoutFlow () lengthBox [a, a]) False) `shouldBe` 25
            height (layoutGetBox $ head $ boxLayout zeroBox {
                    size = Size 100 100
                } (LayoutFlow () lengthBox [b, b]) False) `shouldBe` 25
            height (layoutGetBox $ head $ boxLayout zeroBox {
                    size = Size 100 100
                } (LayoutFlow () lengthBox [a, b]) False) `shouldBe` 20
            height (layoutGetBox $ head $ boxLayout zeroBox {
                    size = Size 100 100
                } (LayoutFlow () lengthBox [b, a]) False) `shouldBe` 25

        {-it "computes single-columns widths/heights" $ do
            let zeroCell = LayoutFlow () lengthBox []
            let nonzeroCell = LayoutFlow () lengthBox {
                B.min = Size (Pixels 10) (Pixels 10),
                size = Size (Pixels 20) (Pixels 20)
              } []

            let LayoutGrid (_, _) pxGrid pxCells = boxLayout zeroBox {
                    size = Size 100 100
                  } (LayoutGrid () (buildGrid [Left $ Pixels 10] [Left $ Pixels 10])
                    [(GridItem 0 1 0 1 (Size Start Start) lengthBox, zeroCell)]) True
            let LayoutFlow (pos, _) _ _ = snd $ head pxCells
            containerSize pxGrid `shouldBe` Size 10 10
            pos `shouldBe` (0, 0)
            let LayoutGrid (_, _) pxGrid pxCells = boxLayout zeroBox {
                    size = Size 100 100
                  } (LayoutGrid () (buildGrid [Left $ Percent 0.5] [Left $ Percent 0.5])
                    [(GridItem 0 1 0 1 (Size Start Start) lengthBox, zeroCell)]) True
            let LayoutFlow (pos, _) _ _ = snd $ head pxCells
            containerSize pxGrid `shouldBe` Size 50 50
            pos `shouldBe` (0, 0)
            let LayoutGrid (_, _) pxGrid pxCells = boxLayout zeroBox {
                    size = Size 100 100
                  } (LayoutGrid () (buildGrid [Left Auto] [Left Auto])
                    [(GridItem 0 1 0 1 (Size Start Start) lengthBox, nonzeroCell)]) True
            let LayoutFlow (pos, _) _ _ = snd $ head pxCells
            containerSize pxGrid `shouldBe` Size 20 10 -- FIXME Is the 10 correct?
            pos `shouldBe` (0, 0)
            let LayoutGrid (_, _) pxGrid pxCells = boxLayout zeroBox {
                    size = Size 100 100
                  } (LayoutGrid () (buildGrid [Left Preferred] [Left Preferred])
                    [(GridItem 0 1 0 1 (Size Start Start) lengthBox, nonzeroCell)]) True
            let LayoutFlow (pos, _) _ _ = snd $ head pxCells
            containerSize pxGrid `shouldBe` Size 20 0 -- FIXME Is the 0 correct?
            pos `shouldBe` (0, 0)
            let LayoutGrid (_, _) pxGrid pxCells = boxLayout zeroBox {
                    size = Size 100 100
                  } (LayoutGrid () (buildGrid [Left Min] [Left Min])
                    [(GridItem 0 1 0 1 (Size Start Start) lengthBox, nonzeroCell)]) True
            let LayoutFlow (pos, _) _ _ = snd $ head pxCells
            containerSize pxGrid `shouldBe` Size 10 10
            pos `shouldBe` (0, 0) -}
    describe "Grid templates" $ do
        it "parses successfully" $ do
            let grid = fromJust $ parseASCIIGrid [["head", "head"],
                                                  ["nav", "main"],
                                                  ["foot", "."]] 0 HM.empty
            HM.lookup "head" grid `shouldBe` Just ((0,2), (0, Just 1))
            HM.lookup "nav" grid `shouldBe` Just ((0,1), (1, Just 2))
            HM.lookup "main" grid `shouldBe` Just ((1,2), (1, Just 2))
            HM.lookup "foot" grid `shouldBe` Just ((0,1), (2, Nothing))
            HM.lookup "aside" grid `shouldBe` Nothing
        it "discards invalid non-squares" $ do
            let test grid = parseASCIIGrid grid 0 HM.empty `shouldBe` Nothing
            test [["head", "nav", "head"]]
            test [["head"], ["nav"], ["head"]]
            test [["head", "head"], ["head", "nav"]]
    describe "<table>" $ do
        it "parses to grids" $ do
            -- <table>
            --  <caption>Test table</caption>
            --  <thead><tr><th>A</th><th rowspan="2">B</th><th>C</th></tr></thead>
            --  <tbody><tr><td colspan="2">D</td><td colspan="2">E</td></tr></tbody>
            --  <tfoot><tr><td>F</td><td>G</td><td>H</td></tr></tfoot>
            -- </table>
            let text' txt = StyleTree temp { inlineStyles = plaintext txt } []
            let table :: StyleTree (CSSBox ())
                table = StyleTree temp { display = Table } [
                  StyleTree temp { display = TableHeaderGroup } [
                      StyleTree temp { display = TableRow } [
                          StyleTree temp { display = TableCell } [text' "A"],
                          StyleTree temp {
                              display = TableCell,
                              tableOptions = temp { rowspan = 2 }
                          } [text' "B"],
                          StyleTree temp { display = TableCell } [text' "C"]
                      ]
                  ],
                  StyleTree temp { display = TableRowGroup } [
                      StyleTree temp { display = TableRow } [
                          StyleTree temp {
                              display = TableCell,
                              tableOptions = temp { colspan = 2 }
                          } [text' "D"],
                          StyleTree temp {
                              display = TableCell,
                              tableOptions = temp { colspan = 2 }
                          } [text' "E"]
                      ]
                  ],
                  StyleTree temp { display = TableFooterGroup } [
                      StyleTree temp { display = TableRow } [
                          StyleTree temp { display = TableCell } [text' "F"],
                          StyleTree temp { display = TableCell } [text' "G"],
                          StyleTree temp { display = TableCell } [text' "H"]
                      ]
                  ],
                  StyleTree temp { display = TableCaption } [text' "Test table"]
                 ]
            let defaultPageOptions = PageOptions 0 0 2 2
            let gridItem x y = GridItem {
                cellStart = x, cellEnd = y,
                Grid.alignment = Start,
                minSize = 0, natSize = 0
              }
            let track cells' = Track {
                cells = cells',
                trackMins = [], trackNats = [], gap = Pixels 0
            }
            let inline txt = LayoutInline () (constructParagraph "" (
                        RootBox $ Box [
                            TextSequence ((placeholderFont, 12), zero, ()) txt
                        ] $ defaultTextOptions DirLTR
                    ) "" defaultParagraphOptions) defaultPageOptions
            finalizeCSS placeholderFont placeholderFont table `shouldBe`
                    LayoutFlow () lengthBox [
                        LayoutFlow () lengthBox [inline "Test table"],
                        LayoutGrid () Size {
                           inline = track [Left Auto, Left Auto, Left Auto, Left Auto, Left Auto, Left Auto],
                           block = track [Left Auto, Left Auto, Left Auto]
                        } [
                            gridItem 0 6 `Size` gridItem 0 1,
                            gridItem 0 6 `Size` gridItem 1 2,
                            gridItem 0 6 `Size` gridItem 2 3,
                            gridItem 0 6 `Size` gridItem 3 4,
                            gridItem 0 6 `Size` gridItem 4 5,
                            gridItem 0 6 `Size` gridItem 5 6,
                            gridItem 1 2 `Size` gridItem 0 1,
                            gridItem 3 4 `Size` gridItem 0 2,
                            gridItem 5 6 `Size` gridItem 0 1,
                            gridItem 1 3 `Size` gridItem 1 2,
                            gridItem 4 6 `Size` gridItem 1 2,
                            gridItem 1 2 `Size` gridItem 2 3,
                            gridItem 3 4 `Size` gridItem 2 3,
                            gridItem 5 6 `Size` gridItem 2 3
                        ] [
                            LayoutFlow () lengthBox [],
                            LayoutFlow () lengthBox [],
                            LayoutFlow () lengthBox [],
                            LayoutFlow () lengthBox [],
                            LayoutFlow () lengthBox [],
                            LayoutFlow () lengthBox [],
                            LayoutFlow () lengthBox [inline "A"],
                            LayoutFlow () lengthBox [inline "B"],
                            LayoutFlow () lengthBox [inline "C"],
                            LayoutFlow () lengthBox [inline "D"],
                            LayoutFlow () lengthBox [inline "E"],
                            LayoutFlow () lengthBox [inline "F"],
                            LayoutFlow () lengthBox [inline "G"],
                            LayoutFlow () lengthBox [inline "H"]
                        ]
                    ]
    describe "Flexbox" $ do
        it "wraps properly" $ do
            let child l = FlexChild {
                grow = 0,
                shrink = 0,
                basis = l,
                Flex.alignment = AlStart,
                flexInner = ()
              }
            let baseFlex = FlexParent {
                direction = Row,
                reverseRows = False,
                wrap = NoWrap,
                justify = JStart,
                alignLines = Just JStart,
                baseGap = 2,
                crossGap = 2,
                Flex.children = [[(child 10) { grow = 1 }, (child 20) { shrink = 1 },
                        (child 30) { grow = 2 }, (child 40) { shrink = 2 }]],
                pageWidth = 0
              } :: FlexParent () Double
            -- These test results don't look right...
            flexWrap baseFlex 50 `shouldBe` baseFlex {
                Flex.children = [[(child 10) { grow = 1 },
                        (child 1.3333333333333321) { shrink = 1 }, (child 30) { grow = 2 },
                        (child 2.6666666666666643) { shrink = 2}]]
              }
            flexWrap baseFlex 40 `shouldBe` baseFlex {
                Flex.children = [[(child 10) { grow = 1 },
                        (child $ -2) { shrink = 1 }, (child 30) { grow = 2 },
                        (child $ -4) { shrink = 2}]]
              }
            flexWrap baseFlex 30 `shouldBe` baseFlex {
                Flex.children = [[(child 10) { grow = 1 },
                        (child $ -5.333333333333332) { shrink = 1 }, (child 30) { grow = 2 },
                        (child $ -10.666666666666664) { shrink = 2}]]
              }
            flexWrap baseFlex 20 `shouldBe` baseFlex {
                Flex.children = [[(child 10) { grow = 1 },
                        (child $ -8.666666666666668) { shrink = 1 }, (child 30) { grow = 2 },
                        (child $ -17.333333333333336) { shrink = 2}]]
              }
            flexWrap baseFlex 10 `shouldBe` baseFlex {
                Flex.children = [[(child 10) { grow = 1 },
                        (child $ -12) { shrink = 1 }, (child 30) { grow = 2 },
                        (child $ -24) { shrink = 2}]]
              }
            flexWrap baseFlex { direction = Flex.Column } 50 `shouldBe` baseFlex {
                direction = Flex.Column,
                Flex.children = [[(child 10) { grow = 1 },
                        (child 1.3333333333333321) { shrink = 1 }, (child 30) { grow = 2 },
                        (child 2.6666666666666643) { shrink = 2}]]
              }
            flexWrap baseFlex { direction = Flex.Column } 40 `shouldBe` baseFlex {
                direction = Flex.Column,
                Flex.children = [[(child 10) { grow = 1 },
                        (child $ -2) { shrink = 1 }, (child 30) { grow = 2 },
                        (child $ -4) { shrink = 2}]]
              }
            flexWrap baseFlex { direction = Flex.Column } 30 `shouldBe` baseFlex {
                direction = Flex.Column,
                Flex.children = [[(child 10) { grow = 1 },
                        (child $ -5.333333333333332) { shrink = 1 }, (child 30) { grow = 2 },
                        (child $ -10.666666666666664) { shrink = 2}]]
              }
            flexWrap baseFlex { direction = Flex.Column } 20 `shouldBe` baseFlex {
                direction = Flex.Column,
                Flex.children = [[(child 10) { grow = 1 },
                        (child $ -8.666666666666668) { shrink = 1 }, (child 30) { grow = 2 },
                        (child $ -17.333333333333336) { shrink = 2}]]
              }
            flexWrap baseFlex { direction = Flex.Column } 10 `shouldBe` baseFlex {
                direction = Flex.Column,
                Flex.children = [[(child 10) { grow = 1 },
                        (child $ -12) { shrink = 1 }, (child 30) { grow = 2 },
                        (child $ -24) { shrink = 2}]]
              }
            flexWrap baseFlex { reverseRows = True } 50 `shouldBe` baseFlex {
                reverseRows = True,
                Flex.children = [[
                    FlexChild {
                        grow = 0.0,
                        shrink = 2.0,
                        basis = 2.6666666666666643,
                        Flex.alignment = AlStart,
                        flexInner = ()
                    },
                    FlexChild {
                        grow = 2.0,
                        shrink = 0.0,
                        basis = 30.0,
                        Flex.alignment = AlStart,
                        flexInner = ()
                    },
                    FlexChild {
                        grow = 0.0,
                        shrink = 1.0,
                        basis = 1.3333333333333321,
                        Flex.alignment = AlStart,
                        flexInner = ()
                    },
                    FlexChild {
                       grow = 1.0,
                       shrink = 0.0,
                       basis = 10.0,
                       Flex.alignment = AlStart,
                       flexInner = ()
                    }
                ]]
              }
            flexWrap baseFlex { reverseRows = True } 40 `shouldBe` baseFlex {
                reverseRows = True,
                Flex.children = [[
                    FlexChild {
                        grow = 0.0,
                        shrink = 2.0,
                        basis = -4,
                        Flex.alignment = AlStart,
                        flexInner = ()
                    },
                    FlexChild {
                        grow = 2.0,
                        shrink = 0.0,
                        basis = 30.0,
                        Flex.alignment = AlStart,
                        flexInner = ()
                    },
                    FlexChild {
                        grow = 0.0,
                        shrink = 1.0,
                        basis = -2,
                        Flex.alignment = AlStart,
                        flexInner = ()
                    },
                    FlexChild {
                       grow = 1.0,
                       shrink = 0.0,
                       basis = 10.0,
                       Flex.alignment = AlStart,
                       flexInner = ()
                    }
                ]]
            }
            flexWrap baseFlex { reverseRows = True } 30 `shouldBe` baseFlex {
                reverseRows = True,
                Flex.children = [[
                    FlexChild {
                        grow = 0.0,
                        shrink = 2.0,
                        basis = -10.666666666666664,
                        Flex.alignment = AlStart,
                        flexInner = ()
                    },
                    FlexChild {
                        grow = 2.0,
                        shrink = 0.0,
                        basis = 30.0,
                        Flex.alignment = AlStart,
                        flexInner = ()
                    },
                    FlexChild {
                        grow = 0.0,
                        shrink = 1.0,
                        basis = -5.333333333333332,
                        Flex.alignment = AlStart,
                        flexInner = ()
                    },
                    FlexChild {
                       grow = 1.0,
                       shrink = 0.0,
                       basis = 10.0,
                       Flex.alignment = AlStart,
                       flexInner = ()
                    }
                ]]
            }
            flexWrap baseFlex { reverseRows = True } 20 `shouldBe` baseFlex {
                reverseRows = True,
                Flex.children = [[
                    FlexChild {
                        grow = 0.0,
                        shrink = 2.0,
                        basis = -17.333333333333336,
                        Flex.alignment = AlStart,
                        flexInner = ()
                    },
                    FlexChild {
                        grow = 2.0,
                        shrink = 0.0,
                        basis = 30.0,
                        Flex.alignment = AlStart,
                        flexInner = ()
                    },
                    FlexChild {
                        grow = 0.0,
                        shrink = 1.0,
                        basis = -8.666666666666668,
                        Flex.alignment = AlStart,
                        flexInner = ()
                    },
                    FlexChild {
                       grow = 1.0,
                       shrink = 0.0,
                       basis = 10.0,
                       Flex.alignment = AlStart,
                       flexInner = ()
                    }
                ]]
              }
            flexWrap baseFlex { reverseRows = True } 10 `shouldBe` baseFlex {
                reverseRows = True,
                Flex.children = [[
                    FlexChild {
                        grow = 0.0,
                        shrink = 2.0,
                        basis = -24,
                        Flex.alignment = AlStart,
                        flexInner = ()
                    },
                    FlexChild {
                        grow = 2.0,
                        shrink = 0.0,
                        basis = 30.0,
                        Flex.alignment = AlStart,
                        flexInner = ()
                    },
                    FlexChild {
                        grow = 0.0,
                        shrink = 1.0,
                        basis = -12,
                        Flex.alignment = AlStart,
                        flexInner = ()
                    },
                    FlexChild {
                       grow = 1.0,
                       shrink = 0.0,
                       basis = 10.0,
                       Flex.alignment = AlStart,
                       flexInner = ()
                    }
                ]]
              }
            flexWrap baseFlex { wrap = Wrap } 50 `shouldBe` baseFlex {
                wrap = Wrap,
                Flex.children = [[(child 10) { grow = 1 },
                        (child 6) { shrink = 1 }, (child 30) { grow = 2 }], [
                        (child 40) { shrink = 2}]]
              }
            flexWrap baseFlex { wrap = Wrap } 40 `shouldBe` baseFlex {
                wrap = Wrap,
                Flex.children = [[(child 18) { grow = 1 },
                        (child 20) { shrink = 1 }], [(child 40) { grow = 2 }],
                        [(child 40) { shrink = 2}]]
              }
            flexWrap baseFlex { wrap = Wrap } 30 `shouldBe` baseFlex {
                wrap = Wrap,
                Flex.children = [[(child 10) { grow = 1 },
                        (child 18) { shrink = 1 }], [(child 30) { grow = 2 }],
                        [(child 30) { shrink = 2}]]
              }
            flexWrap baseFlex { wrap = Wrap } 20 `shouldBe` baseFlex {
                wrap = Wrap,
                Flex.children = [[(child 20) { grow = 1 }],
                        [(child 20) { shrink = 1 }], [(child 30) { grow = 2 }],
                        [(child 20) { shrink = 2}]]
              }
            flexWrap baseFlex { wrap = Wrap } 10 `shouldBe` baseFlex {
                wrap = Wrap,
                Flex.children = [[(child 10) { grow = 1 }], [(child 10) { shrink = 1 }],
                        [(child 30) { grow = 2 }], [(child 10) { shrink = 2}]]
              }
            flexWrap baseFlex { wrap = WrapReverse } 50 `shouldBe` baseFlex {
                wrap = WrapReverse,
                Flex.children = [[(child 40) { shrink = 2}], [(child 10) { grow = 1 },
                        (child 6) { shrink = 1 }, (child 30) { grow = 2 }]]
              }
            flexWrap baseFlex { wrap = WrapReverse } 40 `shouldBe` baseFlex {
                wrap = WrapReverse,
                Flex.children = [[(child 40) { shrink = 2}], [(child 40) { grow = 2 }],
                        [(child 18) { grow = 1 }, (child 20) { shrink = 1 }]]
              }
            flexWrap baseFlex { wrap = WrapReverse } 30 `shouldBe` baseFlex {
                wrap = WrapReverse,
                Flex.children = [[(child 30) { shrink = 2}], [(child 30) { grow = 2 }],
                        [(child 10) { grow = 1 }, (child 18) { shrink = 1 }]]
              }
            flexWrap baseFlex { wrap = WrapReverse } 20 `shouldBe` baseFlex {
                wrap = WrapReverse,
                Flex.children = [[(child 20) { shrink = 2}], [(child 30) { grow = 2 }],
                        [(child 20) { shrink = 1 }], [(child 20) { grow = 1 }]]
              }
            flexWrap baseFlex { wrap = WrapReverse } 10 `shouldBe` baseFlex {
                wrap = WrapReverse,
                Flex.children = [[(child 10) { shrink = 2}], [(child 30) { grow = 2 }],
                        [(child 10) { shrink = 1 }], [(child 10) { grow = 1 }]]
              }
        it "Paginates properly" $ do
            let child l align = FlexChild {
                grow = 0,
                shrink = 0,
                basis = l,
                Flex.alignment = align,
                flexInner = l
              }
            let baseFlex = FlexParent {
                direction = Row,
                reverseRows = False,
                wrap = Wrap,
                justify = JStart,
                alignLines = Just JStart,
                baseGap = 2,
                crossGap = 2,
                Flex.children = [[(child 10 AlStart) { grow = 1 },
                        (child 20 AlCenter) { shrink = 1 },
                        (child 30 AlEnd) { grow = 2 },
                        (child 40 AlStretch) { shrink = 2 }]],
                pageWidth = 80
              } :: FlexParent Double Double
            let self = flexWrap baseFlex 50
            self `shouldBe` baseFlex {
                Flex.children = [[(child 10 AlStart) { grow = 1 },
                        (child 6 AlCenter) { shrink = 1, flexInner = 20 },
                        (child 30 AlEnd) { grow = 2 }], [
                        (child 40 AlStretch) { shrink = 2}]]
              }
            flexSplit (\x -> Size x x) 30 50 self `shouldBe` (baseFlex {
                Flex.children = [[(child 10 AlStart) { grow = 1 },
                        (child 6 AlCenter) { shrink = 1, flexInner = 20 },
                        (child 30 AlEnd) { grow = 2 }]]
              }, baseFlex {
                Flex.children = [[(child 40 AlStretch) { shrink = 2}]]
              })
            print self { direction = Flex.Column }
            flexSplit (\x -> Size x x) 40 50 self { direction = Flex.Column } `shouldBe` (baseFlex {
                direction = Flex.Column,
                Flex.children = [[(child 10 AlStart) { grow = 1 },
                        (child (-4) AlCenter) { shrink = 1, flexInner = 20 },
                        (child 30 AlEnd) { grow = 2 }], [(child 40 AlStretch) { shrink = 2}]]
              }, baseFlex {
                direction = Flex.Column,
                Flex.children = []
              })
            flexSplit (\x -> Size x x) 10 50 self { direction = Flex.Column } `shouldBe` (baseFlex {
                direction = Flex.Column,
                Flex.children = []
              }, baseFlex {
                direction = Flex.Column,
                Flex.children = [[(child 10 AlStart) { grow = 1 },
                        (child 6 AlCenter) { shrink = 1, flexInner = 20 },
                        (child 30 AlEnd) { grow = 2 }], [(child 40 AlStretch) { shrink = 2}]]
              })
            flexSplit (\x -> Size x x) 10 50 self { direction = Flex.Column, pageWidth = 40 } `shouldBe` (baseFlex {
                Flex.children = [[(child 10 AlStart) { grow = 1 },
                        (child 6 AlCenter) { shrink = 1, flexInner = 20 },
                        (child 30 AlEnd) { grow = 2 }]],
                pageWidth = 40
              }, baseFlex {
                Flex.children = [[(child 40 AlStretch) { shrink = 2}]],
                pageWidth = 40
              })
        it "positions correctly" $ do
            let child l align = FlexChild {
                grow = 0,
                shrink = 0,
                basis = l,
                Flex.alignment = align,
                flexInner = l
              }
            let child' l align pos = FlexChild {
                grow = 0, shrink = 0, basis = l,
                Flex.alignment = align, flexInner = (pos, l)
              }
            let flex childs = FlexParent {
                direction = Row,
                reverseRows = False,
                wrap = Wrap,
                justify = JStart,
                alignLines = Just JStart,
                baseGap = 2,
                crossGap = 2,
                Flex.children = childs,
                pageWidth = 80
              }
            let baseFlex = flex [[(child 10 AlStart) { grow = 1 },
                    (child 20 AlCenter) { shrink = 1 },
                    (child 30 AlEnd) { grow = 2 },
                    (child 40 AlStretch) { shrink = 2 }]] :: FlexParent Double Double
            flexPosition (,) (\a -> Size a a) (10, 10) (Size 50 50) baseFlex `shouldBe` flex [[
                (child' 10 AlStart (10, 10)) { grow = 1 },
                (child' 20 AlCenter (22, 20)) { shrink = 1 },
                (child' 30 AlEnd (44, 20)) { grow = 2 },
                (child' 40 AlStretch (76, 10)) { shrink = 2 }
              ]]


runMath = flip evalCalc [] . mapCalc fst . flip parseCalc [] . filter (/= Whitespace) . tokenize

instance PropertyParser () where
    temp = ()
    inherit _ = ()
    longhand _ _ _ _ = Nothing