2013-01-23 17:47:43 +01:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2011-01-21 19:23:41 +01:00
|
|
|
module Tests.Writers.ConTeXt (tests) where
|
|
|
|
|
2017-06-10 23:39:49 +02:00
|
|
|
import Data.Text (unpack)
|
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
|
|
|
|
|
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{]}"
|
2017-03-14 17:05:36 +01:00
|
|
|
, testProperty "code property" $ \s -> null s ||
|
2011-01-22 21:18:59 +01:00
|
|
|
if '{' `elem` s || '}' `elem` s
|
2018-01-20 06:25:24 +01:00
|
|
|
then context' (code s) == "\\mono{" ++
|
|
|
|
context' (str s) ++ "}"
|
|
|
|
else context' (code s) == "\\type{" ++ s ++ "}"
|
2011-01-21 19:23:41 +01:00
|
|
|
]
|
|
|
|
, testGroup "headers"
|
|
|
|
[ "level 1" =:
|
2012-10-30 06:45:52 +01:00
|
|
|
headerWith ("my-header",[],[]) 1 "My header" =?> "\\section[my-header]{My header}"
|
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" $
|
|
|
|
let caption = text "Table 1"
|
|
|
|
aligns = [(AlignRight, 0.0), (AlignLeft, 0.0), (AlignCenter, 0.0), (AlignDefault, 0.0)]
|
|
|
|
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"]]
|
|
|
|
in table caption aligns headers rows
|
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
|
|
|
]
|