2015-04-16 19:27:33 +03:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module Tests.Writers.RST (tests) where
|
|
|
|
|
2017-03-14 17:05:36 +01:00
|
|
|
import Test.Tasty
|
2015-04-16 19:27:33 +03:00
|
|
|
import Tests.Helpers
|
2017-03-04 13:03:41 +01:00
|
|
|
import Text.Pandoc
|
|
|
|
import Text.Pandoc.Arbitrary ()
|
|
|
|
import Text.Pandoc.Builder
|
2015-04-16 19:27:33 +03:00
|
|
|
|
|
|
|
infix 4 =:
|
|
|
|
(=:) :: (ToString a, ToPandoc a)
|
2017-03-14 17:05:36 +01:00
|
|
|
=> String -> (a, String) -> TestTree
|
2017-01-22 11:36:30 +01:00
|
|
|
(=:) = test (purely (writeRST def . toPandoc))
|
2015-04-16 19:27:33 +03:00
|
|
|
|
2017-03-14 17:05:36 +01:00
|
|
|
tests :: [TestTree]
|
2015-04-16 19:27:33 +03:00
|
|
|
tests = [ testGroup "rubrics"
|
|
|
|
[ "in list item" =:
|
|
|
|
bulletList [header 2 (text "foo")] =?>
|
|
|
|
"- .. rubric:: foo"
|
|
|
|
, "in definition list item" =:
|
|
|
|
definitionList [(text "foo", [header 2 (text "bar"),
|
|
|
|
para $ text "baz"])] =?>
|
|
|
|
unlines
|
|
|
|
[ "foo"
|
|
|
|
, " .. rubric:: bar"
|
|
|
|
, ""
|
|
|
|
, " baz"]
|
|
|
|
, "in block quote" =:
|
|
|
|
blockQuote (header 1 (text "bar")) =?>
|
|
|
|
" .. rubric:: bar"
|
|
|
|
, "with id" =:
|
|
|
|
blockQuote (headerWith ("foo",[],[]) 1 (text "bar")) =?>
|
|
|
|
unlines
|
|
|
|
[ " .. rubric:: bar"
|
|
|
|
, " :name: foo"]
|
|
|
|
, "with id class" =:
|
|
|
|
blockQuote (headerWith ("foo",["baz"],[]) 1 (text "bar")) =?>
|
|
|
|
unlines
|
|
|
|
[ " .. rubric:: bar"
|
|
|
|
, " :name: foo"
|
|
|
|
, " :class: baz"]
|
|
|
|
]
|
2018-01-15 12:24:20 +01:00
|
|
|
, testGroup "ligatures" -- handling specific sequences of blocks
|
|
|
|
[ "a list is closed by a comment before a quote" =: -- issue 4248
|
|
|
|
bulletList [plain "bulleted"] <> blockQuote (plain "quoted") =?>
|
|
|
|
unlines
|
|
|
|
[ "- bulleted"
|
|
|
|
, ""
|
|
|
|
, ".."
|
|
|
|
, ""
|
|
|
|
, " quoted"]
|
|
|
|
]
|
2015-04-16 19:27:33 +03:00
|
|
|
, testGroup "headings"
|
|
|
|
[ "normal heading" =:
|
|
|
|
header 1 (text "foo") =?>
|
|
|
|
unlines
|
|
|
|
[ "foo"
|
|
|
|
, "==="]
|
2015-10-12 23:00:27 -07:00
|
|
|
-- note: heading normalization is only done in standalone mode
|
2016-11-27 11:52:42 +01:00
|
|
|
, test (purely (writeRST def{ writerTemplate = Just "$body$\n" }) . toPandoc)
|
2015-10-12 23:00:27 -07:00
|
|
|
"heading levels" $
|
2015-04-16 19:27:33 +03:00
|
|
|
header 1 (text "Header 1") <>
|
|
|
|
header 3 (text "Header 2") <>
|
|
|
|
header 2 (text "Header 2") <>
|
|
|
|
header 1 (text "Header 1") <>
|
|
|
|
header 4 (text "Header 2") <>
|
|
|
|
header 5 (text "Header 3") <>
|
|
|
|
header 3 (text "Header 2") =?>
|
|
|
|
unlines
|
|
|
|
[ "Header 1"
|
|
|
|
, "========"
|
|
|
|
, ""
|
|
|
|
, "Header 2"
|
|
|
|
, "--------"
|
|
|
|
, ""
|
|
|
|
, "Header 2"
|
|
|
|
, "--------"
|
|
|
|
, ""
|
|
|
|
, "Header 1"
|
|
|
|
, "========"
|
|
|
|
, ""
|
|
|
|
, "Header 2"
|
|
|
|
, "--------"
|
|
|
|
, ""
|
|
|
|
, "Header 3"
|
|
|
|
, "~~~~~~~~"
|
|
|
|
, ""
|
|
|
|
, "Header 2"
|
|
|
|
, "--------"]
|
2016-11-27 11:52:42 +01:00
|
|
|
, test (purely (writeRST def{ writerTemplate = Just "$body$\n" }) . toPandoc)
|
2015-10-12 23:00:27 -07:00
|
|
|
"minimal heading levels" $
|
2015-09-19 17:45:54 +03:00
|
|
|
header 2 (text "Header 1") <>
|
|
|
|
header 3 (text "Header 2") <>
|
|
|
|
header 2 (text "Header 1") <>
|
|
|
|
header 4 (text "Header 2") <>
|
|
|
|
header 5 (text "Header 3") <>
|
|
|
|
header 3 (text "Header 2") =?>
|
|
|
|
unlines
|
|
|
|
[ "Header 1"
|
2015-10-12 23:00:27 -07:00
|
|
|
, "========"
|
2015-09-19 17:45:54 +03:00
|
|
|
, ""
|
|
|
|
, "Header 2"
|
2015-10-12 23:00:27 -07:00
|
|
|
, "--------"
|
2015-09-19 17:45:54 +03:00
|
|
|
, ""
|
|
|
|
, "Header 1"
|
2015-10-12 23:00:27 -07:00
|
|
|
, "========"
|
2015-09-19 17:45:54 +03:00
|
|
|
, ""
|
|
|
|
, "Header 2"
|
2015-10-12 23:00:27 -07:00
|
|
|
, "--------"
|
2015-09-19 17:45:54 +03:00
|
|
|
, ""
|
|
|
|
, "Header 3"
|
2015-10-12 23:00:27 -07:00
|
|
|
, "~~~~~~~~"
|
2015-09-19 17:45:54 +03:00
|
|
|
, ""
|
|
|
|
, "Header 2"
|
2015-10-12 23:00:27 -07:00
|
|
|
, "--------"]
|
2015-04-16 19:27:33 +03:00
|
|
|
]
|
|
|
|
]
|