From 484ba2c1fc86388a5e8e17aebc5d5409998768bb Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Wed, 22 Nov 2023 16:43:55 +1300 Subject: [PATCH] Test flexbox positioning! --- test/Test.hs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/Test.hs b/test/Test.hs index 0ba9120..ac9e226 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -771,6 +771,39 @@ spec = do 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 -- 2.30.2