@@ -20,6 +20,7 @@ import Text.Layout.Table.Spec.AlignSpec
2020import Text.Layout.Table.Spec.CutMark
2121import Text.Layout.Table.Spec.OccSpec
2222import Text.Layout.Table.Spec.Position
23+ import Text.Layout.Table.Spec.RowGroup
2324import Text.Layout.Table.Primitives.Basic
2425import Text.Layout.Table.Primitives.AlignInfo
2526import Text.Layout.Table.Justify
@@ -331,6 +332,35 @@ spec = do
331332 prop " gives the same result as wide string" $ \ (Small n) x -> buildCell (dropLeft n . WideText $ T. pack x) `shouldBe` (buildCell . dropLeft n $ WideString x :: String )
332333 describe " dropRight" $ do
333334 prop " gives the same result as wide string" $ \ (Small n) x -> buildCell (dropRight n . WideText $ T. pack x) `shouldBe` (buildCell . dropRight n $ WideString x :: String )
335+
336+ describe " row groups" $ do
337+ describe " rowGroupShape" $ do
338+ it " multi" $ rowGroupShape (MultiRowGroup [[0 , 1 ], [2 , 3 ]]) `shouldBe` [() , () ]
339+ it " multi only first row 1" $ rowGroupShape (MultiRowGroup [[0 , 1 ], [2 , 3 , 4 ]]) `shouldBe` [() , () ]
340+ it " multi only first row 2" $ rowGroupShape (MultiRowGroup [[0 , 1 ], [] ]) `shouldBe` [() , () ]
341+ it " multi empty" $ rowGroupShape (MultiRowGroup [] ) `shouldBe` []
342+ it " singleton empty" $ rowGroupShape (SingletonRowGroup [] ) `shouldBe` []
343+ it " singleton" $ rowGroupShape (SingletonRowGroup [1 , 2 ]) `shouldBe` [() , () ]
344+ it " nullable empty" $ rowGroupShape (NullableRowGroup [] ) `shouldBe` []
345+ it " nullable one element" $ rowGroupShape (NullableRowGroup [[Just 4 ]]) `shouldBe` [() ]
346+ it " nullable but no null" $ rowGroupShape (NullableRowGroup [[Just 1 , Just 2 ]]) `shouldBe` [() , () ]
347+ it " nullable mixed" $ rowGroupShape (NullableRowGroup [[Just 1 , Nothing , Nothing ]]) `shouldBe` [() , () , () ]
348+
349+ let rgs = [rg1, rg2, rg3] :: [RowGroup Int ]
350+ rg1 = MultiRowGroup [[0 , 1 , 2 ], [3 , 4 , 5 ]]
351+ rg2 = SingletonRowGroup [6 , 7 , 8 ]
352+ rg3 = NullableRowGroup [[Nothing , Just 9 , Nothing ]]
353+ it " transposeRowGroups" $
354+ transposeRowGroups rgs `shouldBe` [ SegmentedColumn [ColumnSegment [0 , 3 ], SingleValueSegment 6 , NullableColumnSegment [Nothing ]]
355+ , SegmentedColumn [ColumnSegment [1 , 4 ], SingleValueSegment 7 , NullableColumnSegment [Just 9 ]]
356+ , SegmentedColumn [ColumnSegment [2 , 5 ], SingleValueSegment 8 , NullableColumnSegment [Nothing ]]
357+ ]
358+ describe " mapRowGroupColumns" $ do
359+ let mappers = [(negate 1 , (+ 1 )), (0 , (* 2 )), (negate 2 , (`div` 2 ))]
360+ it " multi" $ mapRowGroupColumns mappers rg1 `shouldBe` [[1 , 2 , 1 ], [4 , 8 , 2 ]]
361+ it " singleton" $ mapRowGroupColumns mappers rg2 `shouldBe` [[7 , 14 , 4 ]]
362+ it " nullable" $ mapRowGroupColumns mappers rg3 `shouldBe` [[negate 1 , 18 , negate 2 ]]
363+
334364 where
335365 customCM = doubleCutMark " <.." " ..>"
336366 unevenCM = doubleCutMark " <" " -->"
0 commit comments