2013-01-23 17:47:43 +01:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2011-01-21 19:23:41 +01:00
|
|
|
module Tests.Writers.ConTeXt (tests) where
|
|
|
|
|
Switch to new pandoc-types and use Text instead of String [API change].
PR #5884.
+ Use pandoc-types 1.20 and texmath 0.12.
+ Text is now used instead of String, with a few exceptions.
+ In the MediaBag module, some of the types using Strings
were switched to use FilePath instead (not Text).
+ In the Parsing module, new parsers `manyChar`, `many1Char`,
`manyTillChar`, `many1TillChar`, `many1Till`, `manyUntil`,
`mantyUntilChar` have been added: these are like their
unsuffixed counterparts but pack some or all of their output.
+ `glob` in Text.Pandoc.Class still takes String since it seems
to be intended as an interface to Glob, which uses strings.
It seems to be used only once in the package, in the EPUB writer,
so that is not hard to change.
2019-11-04 22:12:37 +01:00
|
|
|
import Data.Text (unpack, pack)
|
2017-03-14 17:05:36 +01:00
|
|
|
import Test.Tasty
|
|
|
|
import Test.Tasty.QuickCheck
|
2011-01-21 19:23:41 +01:00
|
|
|
import Tests.Helpers
|
2017-03-04 13:03:41 +01:00
|
|
|
import Text.Pandoc
|
|
|
|
import Text.Pandoc.Arbitrary ()
|
|
|
|
import Text.Pandoc.Builder
|
2011-01-21 19:23:41 +01:00
|
|
|
|
2016-07-14 17:54:06 +02:00
|
|
|
context :: (ToPandoc a) => a -> String
|
2017-06-10 23:39:49 +02:00
|
|
|
context = unpack . purely (writeConTeXt def) . toPandoc
|
2011-01-21 19:23:41 +01:00
|
|
|
|
2016-07-14 17:54:06 +02:00
|
|
|
context' :: (ToPandoc a) => a -> String
|
2017-06-10 23:39:49 +02:00
|
|
|
context' = unpack . purely (writeConTeXt def{ writerWrapText = WrapNone }) . toPandoc
|
2011-01-22 21:18:59 +01:00
|
|
|
|
2018-01-16 02:38:33 +01:00
|
|
|
contextNtb :: (ToPandoc a) => a -> String
|
|
|
|
contextNtb = unpack . purely (writeConTeXt def{ writerExtensions = enableExtension Ext_ntb pandocExtensions }) . toPandoc
|
|
|
|
|
2018-01-25 20:56:28 +01:00
|
|
|
contextDiv :: (ToPandoc a) => a -> String
|
|
|
|
contextDiv = unpack . purely (writeConTeXt def{ writerSectionDivs = True }) . toPandoc
|
|
|
|
|
2011-01-22 05:50:18 +01:00
|
|
|
{-
|
|
|
|
"my test" =: X =?> Y
|
|
|
|
|
|
|
|
is shorthand for
|
|
|
|
|
|
|
|
test context "my test" $ X =?> Y
|
|
|
|
|
|
|
|
which is in turn shorthand for
|
|
|
|
|
|
|
|
test context "my test" (X,Y)
|
|
|
|
-}
|
|
|
|
|
2012-02-05 22:23:06 +01:00
|
|
|
infix 4 =:
|
2011-01-22 05:50:18 +01:00
|
|
|
(=:) :: (ToString a, ToPandoc a)
|
2017-03-14 17:05:36 +01:00
|
|
|
=> String -> (a, String) -> TestTree
|
2011-01-22 05:50:18 +01:00
|
|
|
(=:) = test context
|
2011-01-21 19:23:41 +01:00
|
|
|
|
2017-03-14 17:05:36 +01:00
|
|
|
tests :: [TestTree]
|
2011-01-21 19:23:41 +01:00
|
|
|
tests = [ testGroup "inline code"
|
2012-06-28 00:05:13 +02:00
|
|
|
[ "with '}'" =: code "}" =?> "\\mono{\\}}"
|
2011-01-22 05:50:18 +01:00
|
|
|
, "without '}'" =: code "]" =?> "\\type{]}"
|
2019-09-24 00:03:26 +02:00
|
|
|
, testProperty "code property" $ \s -> null s || '\n' `elem` s ||
|
2011-01-22 21:18:59 +01:00
|
|
|
if '{' `elem` s || '}' `elem` s
|
Switch to new pandoc-types and use Text instead of String [API change].
PR #5884.
+ Use pandoc-types 1.20 and texmath 0.12.
+ Text is now used instead of String, with a few exceptions.
+ In the MediaBag module, some of the types using Strings
were switched to use FilePath instead (not Text).
+ In the Parsing module, new parsers `manyChar`, `many1Char`,
`manyTillChar`, `many1TillChar`, `many1Till`, `manyUntil`,
`mantyUntilChar` have been added: these are like their
unsuffixed counterparts but pack some or all of their output.
+ `glob` in Text.Pandoc.Class still takes String since it seems
to be intended as an interface to Glob, which uses strings.
It seems to be used only once in the package, in the EPUB writer,
so that is not hard to change.
2019-11-04 22:12:37 +01:00
|
|
|
then context' (code $ pack s) == "\\mono{" ++
|
|
|
|
context' (str $ pack s) ++ "}"
|
|
|
|
else context' (code $ pack s) == "\\type{" ++ s ++ "}"
|
2011-01-21 19:23:41 +01:00
|
|
|
]
|
|
|
|
, testGroup "headers"
|
|
|
|
[ "level 1" =:
|
2018-01-25 20:56:28 +01:00
|
|
|
headerWith ("my-header",[],[]) 1 "My header" =?> "\\section[title={My header},reference={my-header}]"
|
|
|
|
, test contextDiv "section-divs" $
|
|
|
|
( headerWith ("header1", [], []) 1 (text "Header1")
|
|
|
|
<> headerWith ("header2", [], []) 2 (text "Header2")
|
|
|
|
<> headerWith ("header3", [], []) 3 (text "Header3")
|
|
|
|
<> headerWith ("header4", [], []) 4 (text "Header4")
|
|
|
|
<> headerWith ("header5", [], []) 5 (text "Header5")
|
|
|
|
<> headerWith ("header6", [], []) 6 (text "Header6"))
|
|
|
|
=?>
|
|
|
|
unlines [ "\\startsection[title={Header1},reference={header1}]\n"
|
|
|
|
, "\\startsubsection[title={Header2},reference={header2}]\n"
|
|
|
|
, "\\startsubsubsection[title={Header3},reference={header3}]\n"
|
|
|
|
, "\\startsubsubsubsection[title={Header4},reference={header4}]\n"
|
|
|
|
, "\\startsubsubsubsubsection[title={Header5},reference={header5}]\n"
|
|
|
|
, "\\startsubsubsubsubsubsection[title={Header6},reference={header6}]\n"
|
|
|
|
, "\\stopsubsubsubsubsubsection\n"
|
|
|
|
, "\\stopsubsubsubsubsection\n"
|
|
|
|
, "\\stopsubsubsubsection\n"
|
|
|
|
, "\\stopsubsubsection\n"
|
|
|
|
, "\\stopsubsection\n"
|
|
|
|
, "\\stopsection" ]
|
2011-01-22 05:50:18 +01:00
|
|
|
]
|
|
|
|
, testGroup "bullet lists"
|
|
|
|
[ "nested" =:
|
2013-01-08 05:58:12 +01:00
|
|
|
bulletList [
|
|
|
|
plain (text "top")
|
2013-01-23 17:47:43 +01:00
|
|
|
<> bulletList [
|
|
|
|
plain (text "next")
|
|
|
|
<> bulletList [plain (text "bot")]
|
|
|
|
]
|
|
|
|
] =?> unlines
|
|
|
|
[ "\\startitemize[packed]"
|
|
|
|
, "\\item"
|
|
|
|
, " top"
|
|
|
|
, " \\startitemize[packed]"
|
|
|
|
, " \\item"
|
|
|
|
, " next"
|
|
|
|
, " \\startitemize[packed]"
|
|
|
|
, " \\item"
|
|
|
|
, " bot"
|
|
|
|
, " \\stopitemize"
|
|
|
|
, " \\stopitemize"
|
|
|
|
, "\\stopitemize" ]
|
2011-01-21 19:23:41 +01:00
|
|
|
]
|
2018-01-16 02:38:33 +01:00
|
|
|
, testGroup "natural tables"
|
|
|
|
[ test contextNtb "table with header and caption" $
|
2020-03-28 23:22:48 +01:00
|
|
|
let capt = text "Table 1"
|
2020-04-04 22:35:42 +02:00
|
|
|
aligns = [(AlignRight, ColWidthDefault), (AlignLeft, ColWidthDefault), (AlignCenter, ColWidthDefault), (AlignDefault, ColWidthDefault)]
|
2018-01-16 02:38:33 +01:00
|
|
|
headers = [plain $ text "Right",
|
|
|
|
plain $ text "Left",
|
|
|
|
plain $ text "Center",
|
|
|
|
plain $ text "Default"]
|
|
|
|
rows = [[plain $ text "1.1",
|
|
|
|
plain $ text "1.2",
|
|
|
|
plain $ text "1.3",
|
|
|
|
plain $ text "1.4"]
|
|
|
|
,[plain $ text "2.1",
|
|
|
|
plain $ text "2.2",
|
|
|
|
plain $ text "2.3",
|
|
|
|
plain $ text "2.4"]
|
|
|
|
,[plain $ text "3.1",
|
|
|
|
plain $ text "3.2",
|
|
|
|
plain $ text "3.3",
|
|
|
|
plain $ text "3.4"]]
|
2020-04-10 02:08:49 +02:00
|
|
|
toRow = Row nullAttr . map simpleCell
|
|
|
|
in table (simpleCaption $ plain capt)
|
|
|
|
aligns
|
|
|
|
(TableHead nullAttr [toRow headers])
|
|
|
|
[TableBody nullAttr 0 [] $ map toRow rows]
|
|
|
|
(TableFoot nullAttr [])
|
2018-01-22 21:15:59 +01:00
|
|
|
=?> unlines [ "\\startplacetable[title={Table 1}]"
|
2018-01-16 02:38:33 +01:00
|
|
|
, "\\startTABLE"
|
|
|
|
, "\\startTABLEhead"
|
|
|
|
, "\\NC[align=left] Right"
|
|
|
|
, "\\NC[align=right] Left"
|
|
|
|
, "\\NC[align=middle] Center"
|
|
|
|
, "\\NC Default"
|
|
|
|
, "\\NC\\NR"
|
|
|
|
, "\\stopTABLEhead"
|
|
|
|
, "\\startTABLEbody"
|
|
|
|
, "\\NC[align=left] 1.1"
|
|
|
|
, "\\NC[align=right] 1.2"
|
|
|
|
, "\\NC[align=middle] 1.3"
|
|
|
|
, "\\NC 1.4"
|
|
|
|
, "\\NC\\NR"
|
|
|
|
, "\\NC[align=left] 2.1"
|
|
|
|
, "\\NC[align=right] 2.2"
|
|
|
|
, "\\NC[align=middle] 2.3"
|
|
|
|
, "\\NC 2.4"
|
|
|
|
, "\\NC\\NR"
|
|
|
|
, "\\stopTABLEbody"
|
|
|
|
, "\\startTABLEfoot"
|
|
|
|
, "\\NC[align=left] 3.1"
|
|
|
|
, "\\NC[align=right] 3.2"
|
|
|
|
, "\\NC[align=middle] 3.3"
|
|
|
|
, "\\NC 3.4"
|
|
|
|
, "\\NC\\NR"
|
|
|
|
, "\\stopTABLEfoot"
|
|
|
|
, "\\stopTABLE"
|
|
|
|
, "\\stopplacetable" ]
|
|
|
|
]
|
2011-01-21 19:23:41 +01:00
|
|
|
]
|