2018-03-18 10:46:28 -07:00
|
|
|
{-# LANGUAGE NoImplicitPrelude #-}
|
2013-01-23 08:47:43 -08:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2011-01-21 10:23:41 -08:00
|
|
|
module Tests.Writers.ConTeXt (tests) where
|
|
|
|
|
2018-03-18 10:46:28 -07:00
|
|
|
import Prelude
|
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 10:23:41 -08: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 10:23:41 -08:00
|
|
|
|
2016-07-14 08:54:06 -07:00
|
|
|
context :: (ToPandoc a) => a -> String
|
2017-06-10 23:39:49 +02:00
|
|
|
context = unpack . purely (writeConTeXt def) . toPandoc
|
2011-01-21 10:23:41 -08:00
|
|
|
|
2016-07-14 08:54:06 -07: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 12:18:59 -08:00
|
|
|
|
2018-01-16 14:38:33 +13:00
|
|
|
contextNtb :: (ToPandoc a) => a -> String
|
|
|
|
contextNtb = unpack . purely (writeConTeXt def{ writerExtensions = enableExtension Ext_ntb pandocExtensions }) . toPandoc
|
|
|
|
|
2018-01-26 08:56:28 +13:00
|
|
|
contextDiv :: (ToPandoc a) => a -> String
|
|
|
|
contextDiv = unpack . purely (writeConTeXt def{ writerSectionDivs = True }) . toPandoc
|
|
|
|
|
2011-01-21 20:50:18 -08: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 13:23:06 -08:00
|
|
|
infix 4 =:
|
2011-01-21 20:50:18 -08:00
|
|
|
(=:) :: (ToString a, ToPandoc a)
|
2017-03-14 17:05:36 +01:00
|
|
|
=> String -> (a, String) -> TestTree
|
2011-01-21 20:50:18 -08:00
|
|
|
(=:) = test context
|
2011-01-21 10:23:41 -08:00
|
|
|
|
2017-03-14 17:05:36 +01:00
|
|
|
tests :: [TestTree]
|
2011-01-21 10:23:41 -08:00
|
|
|
tests = [ testGroup "inline code"
|
2012-06-27 15:05:13 -07:00
|
|
|
[ "with '}'" =: code "}" =?> "\\mono{\\}}"
|
2011-01-21 20:50:18 -08:00
|
|
|
, "without '}'" =: code "]" =?> "\\type{]}"
|
2017-03-14 17:05:36 +01:00
|
|
|
, testProperty "code property" $ \s -> null s ||
|
2011-01-22 12:18:59 -08:00
|
|
|
if '{' `elem` s || '}' `elem` s
|
2018-01-19 21:25:24 -08:00
|
|
|
then context' (code s) == "\\mono{" ++
|
|
|
|
context' (str s) ++ "}"
|
|
|
|
else context' (code s) == "\\type{" ++ s ++ "}"
|
2011-01-21 10:23:41 -08:00
|
|
|
]
|
|
|
|
, testGroup "headers"
|
|
|
|
[ "level 1" =:
|
2018-01-26 08:56:28 +13: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-21 20:50:18 -08:00
|
|
|
]
|
|
|
|
, testGroup "bullet lists"
|
|
|
|
[ "nested" =:
|
2013-01-07 20:58:12 -08:00
|
|
|
bulletList [
|
|
|
|
plain (text "top")
|
2013-01-23 08:47:43 -08: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 10:23:41 -08:00
|
|
|
]
|
2018-01-16 14:38:33 +13: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-23 09:15:59 +13:00
|
|
|
=?> unlines [ "\\startplacetable[title={Table 1}]"
|
2018-01-16 14:38:33 +13: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 10:23:41 -08:00
|
|
|
]
|