@@ -20,6 +20,7 @@ import Test.Tasty.HUnit (assertBool, testCase, (@?=))
2020import Text.Pandoc.Arbitrary ()
2121import Text.Pandoc.Builder
2222import Text.Pandoc.Shared
23+import Text.Pandoc.Writers.Shared (toLegacyTable)
2324
2425tests :: [TestTree]
2526tests = [ testGroup "compactifyDL"
@@ -29,6 +30,7 @@ tests = [ testGroup "compactifyDL"
2930 in compactifyDL x == x)
3031 ]
3132 , testGroup "collapseFilePath" testCollapse
33+ , testGroup "toLegacyTable" testLegacyTable
3234 ]
3335
3436testCollapse :: [TestTree]
@@ -51,3 +53,62 @@ testCollapse = map (testCase "collapse")
5153 , collapseFilePath (joinPath [ "parent","foo",".."]) @?= (joinPath [ "parent"])
5254 , collapseFilePath (joinPath [ "","parent","foo","..","..","bar"]) @?= (joinPath [ "","bar"])
5355 , collapseFilePath (joinPath [ "",".","parent","foo"]) @?= (joinPath [ "","parent","foo"])]
56+
57+testLegacyTable :: [TestTree]
58+testLegacyTable =
59+ [ testCase "decomposes a table with head" $ gen1 @?= expect1
60+ , testCase "decomposes a table without head" $ gen2 @?= expect2
61+ ]
62+ where
63+ pln = toList . plain . str
64+ cl a h w = Cell ("", [], []) AlignDefault h w $ pln a
65+ rws = map $ Row nullAttr
66+ th = TableHead nullAttr . rws
67+ tb n x y = TableBody nullAttr n (rws x) (rws y)
68+ tf = TableFoot nullAttr . rws
69+
70+ headRows1 =
71+ [[cl "a" 1 1, cl "b" 2 2]
72+ ,[cl "c" 1 1]
73+ ]
74+ body1 = tb 1
75+ [[cl "e" 3 1,cl "f" 3 2]
76+ ,[]
77+ ,[]
78+ ]
79+ [[emptyCell,emptyCell,emptyCell]
80+ ,[cl "g" 1 1,emptyCell,emptyCell]
81+ ]
82+ footRows1 =
83+ [[cl "h" 1 2,cl "i" 2 1]
84+ ,[cl "j" 1 2]]
85+ caption1 = simpleCaption $ plain "caption"
86+ spec1 = replicate 2 (AlignDefault, ColWidth 0.5) ++ [(AlignRight, ColWidthDefault)]
87+ expect1 = ( [Str "caption"]
88+ , replicate 2 AlignDefault ++ [AlignRight]
89+ , replicate 2 0.5 ++ [0]
90+ , [pln "a", pln "b", mempty]
91+ , [[pln "c", mempty, mempty]
92+ ,[pln "e", pln "f", mempty]
93+ ,[mempty, mempty, mempty]
94+ ,[mempty, mempty, mempty]
95+ ,[mempty, mempty, mempty]
96+ ,[pln "g", mempty, mempty]
97+ ,[pln "h", mempty, pln "i"]
98+ ,[pln "j", mempty, mempty]]
99+ )
100+ gen1 = toLegacyTable caption1 spec1 (th headRows1) [body1] (tf footRows1)
101+
102+ expect2 = ( []
103+ , replicate 2 AlignDefault ++ [AlignRight]
104+ , replicate 2 0.5 ++ [0]
105+ , []
106+ , [[pln "e", pln "f", mempty]
107+ ,[mempty, mempty, mempty]
108+ ,[mempty, mempty, mempty]
109+ ,[mempty, mempty, mempty]
110+ ,[pln "g", mempty, mempty]
111+ ,[pln "h", mempty, pln "i"]
112+ ,[pln "j", mempty, mempty]]
113+ )
114+ gen2 = toLegacyTable emptyCaption spec1 (th []) [body1] (tf footRows1)