aboutsummaryrefslogtreecommitdiff
path: root/test/Tests/Readers/Muse.hs
diff options
context:
space:
mode:
Diffstat (limited to 'test/Tests/Readers/Muse.hs')
-rw-r--r--test/Tests/Readers/Muse.hs120
1 files changed, 46 insertions, 74 deletions
diff --git a/test/Tests/Readers/Muse.hs b/test/Tests/Readers/Muse.hs
index 074b2dc27..77108eb83 100644
--- a/test/Tests/Readers/Muse.hs
+++ b/test/Tests/Readers/Muse.hs
@@ -43,6 +43,17 @@ infix 4 =:
spcSep :: [Inlines] -> Inlines
spcSep = mconcat . intersperse space
+simpleTable' :: Int -> Caption -> [Blocks] -> [[Blocks]] -> Blocks
+simpleTable' n capt headers rows
+ = table capt
+ (replicate n (AlignDefault, ColWidthDefault))
+ (TableHead nullAttr $ toHeaderRow headers)
+ [TableBody nullAttr 0 [] $ map toRow rows]
+ (TableFoot nullAttr [])
+ where
+ toRow = Row nullAttr . map simpleCell
+ toHeaderRow l = if null l then [] else [toRow l]
+
-- Tables don't round-trip yet
--
makeRoundTrip :: Block -> Block
@@ -982,14 +993,10 @@ tests =
, testGroup "Tables"
[ "Two cell table" =:
"One | Two" =?>
- table mempty [(AlignDefault, ColWidthDefault), (AlignDefault, ColWidthDefault)]
- []
- [[plain "One", plain "Two"]]
+ simpleTable [] [[plain "One", plain "Two"]]
, "Table with multiple words" =:
"One two | three four" =?>
- table mempty [(AlignDefault, ColWidthDefault), (AlignDefault, ColWidthDefault)]
- []
- [[plain "One two", plain "three four"]]
+ simpleTable [] [[plain "One two", plain "three four"]]
, "Not a table" =:
"One| Two" =?>
para (text "One| Two")
@@ -1001,38 +1008,30 @@ tests =
[ "One | Two"
, "Three | Four"
] =?>
- table mempty [(AlignDefault, ColWidthDefault), (AlignDefault, ColWidthDefault)]
- []
- [[plain "One", plain "Two"],
- [plain "Three", plain "Four"]]
+ simpleTable [] [[plain "One", plain "Two"],
+ [plain "Three", plain "Four"]]
, "Table with one header" =:
T.unlines
[ "First || Second"
, "Third | Fourth"
] =?>
- table mempty [(AlignDefault, ColWidthDefault), (AlignDefault, ColWidthDefault)]
- [plain "First", plain "Second"]
- [[plain "Third", plain "Fourth"]]
+ simpleTable [plain "First", plain "Second"] [[plain "Third", plain "Fourth"]]
, "Table with two headers" =:
T.unlines
[ "First || header"
, "Second || header"
, "Foo | bar"
] =?>
- table mempty [(AlignDefault, ColWidthDefault), (AlignDefault, ColWidthDefault)]
- [plain "First", plain "header"]
- [[plain "Second", plain "header"],
- [plain "Foo", plain "bar"]]
+ simpleTable [plain "First", plain "header"] [[plain "Second", plain "header"],
+ [plain "Foo", plain "bar"]]
, "Header and footer reordering" =:
T.unlines
[ "Foo ||| bar"
, "Baz || foo"
, "Bar | baz"
] =?>
- table mempty [(AlignDefault, ColWidthDefault), (AlignDefault, ColWidthDefault)]
- [plain "Baz", plain "foo"]
- [[plain "Bar", plain "baz"],
- [plain "Foo", plain "bar"]]
+ simpleTable [plain "Baz", plain "foo"] [[plain "Bar", plain "baz"],
+ [plain "Foo", plain "bar"]]
, "Table with caption" =:
T.unlines
[ "Foo || bar || baz"
@@ -1040,32 +1039,30 @@ tests =
, "Second | row | there"
, "|+ Table caption +|"
] =?>
- table (text "Table caption") (replicate 3 (AlignDefault, ColWidthDefault))
- [plain "Foo", plain "bar", plain "baz"]
- [[plain "First", plain "row", plain "here"],
- [plain "Second", plain "row", plain "there"]]
+ simpleTable' 3 (simpleCaption $ plain $ text "Table caption")
+ [plain "Foo", plain "bar", plain "baz"]
+ [[plain "First", plain "row", plain "here"],
+ [plain "Second", plain "row", plain "there"]]
, "Table caption with +" =:
T.unlines
[ "Foo | bar"
, "|+ Table + caption +|"
] =?>
- table (text "Table + caption") (replicate 2 (AlignDefault, ColWidthDefault))
- []
- [[plain "Foo", plain "bar"]]
+ simpleTable' 2 (simpleCaption $ plain $ text "Table + caption")
+ []
+ [[plain "Foo", plain "bar"]]
, "Caption without table" =:
"|+ Foo bar baz +|" =?>
- table (text "Foo bar baz") [] [] []
+ simpleTable' 0 (simpleCaption $ plain $ text "Foo bar baz") [] []
, "Table indented with space" =:
T.unlines
[ " Foo | bar"
, " Baz | foo"
, " Bar | baz"
] =?>
- table mempty [(AlignDefault, ColWidthDefault), (AlignDefault, ColWidthDefault)]
- []
- [[plain "Foo", plain "bar"],
- [plain "Baz", plain "foo"],
- [plain "Bar", plain "baz"]]
+ simpleTable [] [[plain "Foo", plain "bar"],
+ [plain "Baz", plain "foo"],
+ [plain "Bar", plain "baz"]]
, "Empty cells" =:
T.unlines
[ " | Foo"
@@ -1073,42 +1070,33 @@ tests =
, " bar |"
, " || baz"
] =?>
- table mempty [(AlignDefault, ColWidthDefault), (AlignDefault, ColWidthDefault)]
- [plain "", plain "baz"]
- [[plain "", plain "Foo"],
- [plain "", plain ""],
- [plain "bar", plain ""]]
+ simpleTable [plain "", plain "baz"] [[plain "", plain "Foo"],
+ [plain "", plain ""],
+ [plain "bar", plain ""]]
, "Empty cell in the middle" =:
T.unlines
[ " 1 | 2 | 3"
, " 4 | | 6"
, " 7 | 8 | 9"
] =?>
- table mempty [ (AlignDefault, ColWidthDefault)
- , (AlignDefault, ColWidthDefault), (AlignDefault, ColWidthDefault)]
- []
- [[plain "1", plain "2", plain "3"],
- [plain "4", mempty, plain "6"],
- [plain "7", plain "8", plain "9"]]
+ simpleTable []
+ [[plain "1", plain "2", plain "3"],
+ [plain "4", mempty, plain "6"],
+ [plain "7", plain "8", plain "9"]]
, "Grid table" =:
T.unlines
[ "+-----+-----+"
, "| foo | bar |"
, "+-----+-----+"
] =?>
- table mempty [(AlignDefault, ColWidthDefault), (AlignDefault, ColWidthDefault)]
- []
- [[para "foo", para "bar"]]
+ simpleTable [] [[para "foo", para "bar"]]
, "Grid table inside list" =:
T.unlines
[ " - +-----+-----+"
, " | foo | bar |"
, " +-----+-----+"
] =?>
- bulletList [table mempty [ (AlignDefault, ColWidthDefault)
- , (AlignDefault, ColWidthDefault)]
- []
- [[para "foo", para "bar"]]]
+ bulletList [simpleTable [] [[para "foo", para "bar"]]]
, "Grid table with two rows" =:
T.unlines
[ "+-----+-----+"
@@ -1117,10 +1105,8 @@ tests =
, "| bat | baz |"
, "+-----+-----+"
] =?>
- table mempty [(AlignDefault, ColWidthDefault), (AlignDefault, ColWidthDefault)]
- []
- [[para "foo", para "bar"]
- ,[para "bat", para "baz"]]
+ simpleTable [] [[para "foo", para "bar"]
+ ,[para "bat", para "baz"]]
, "Grid table inside grid table" =:
T.unlines
[ "+-----+"
@@ -1129,11 +1115,7 @@ tests =
, "|+---+|"
, "+-----+"
] =?>
- table mempty [(AlignDefault, ColWidthDefault)]
- []
- [[table mempty [(AlignDefault, ColWidthDefault)]
- []
- [[para "foo"]]]]
+ simpleTable [] [[simpleTable [] [[para "foo"]]]]
, "Grid table with example" =:
T.unlines
[ "+------------+"
@@ -1142,9 +1124,7 @@ tests =
, "| </example> |"
, "+------------+"
] =?>
- table mempty [(AlignDefault, ColWidthDefault)]
- []
- [[codeBlock "foo"]]
+ simpleTable [] [[codeBlock "foo"]]
]
, testGroup "Lists"
[ "Bullet list" =:
@@ -1513,19 +1493,11 @@ tests =
]
, "Definition list with table" =:
" foo :: bar | baz" =?>
- definitionList [ ("foo", [ table mempty [ (AlignDefault, ColWidthDefault)
- , (AlignDefault, ColWidthDefault)]
- []
- [[plain "bar", plain "baz"]]
+ definitionList [ ("foo", [ simpleTable [] [[plain "bar", plain "baz"]]
])]
, "Definition list with table inside bullet list" =:
" - foo :: bar | baz" =?>
- bulletList [definitionList [ ("foo", [ table
- mempty
- [ (AlignDefault, ColWidthDefault)
- , (AlignDefault, ColWidthDefault) ]
- []
- [[plain "bar", plain "baz"]]
+ bulletList [definitionList [ ("foo", [ simpleTable [] [[plain "bar", plain "baz"]]
])]]
, test emacsMuse "Multi-line definition lists from Emacs Muse manual"
(T.unlines