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
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2019-02-04 22:52:31 +01:00
|
|
|
{- |
|
|
|
|
Module : Tests.Shared
|
2022-01-01 20:02:31 +01:00
|
|
|
Copyright : © 2006-2022 John MacFarlane
|
2019-02-04 22:52:31 +01:00
|
|
|
License : GNU GPL, version 2 or above
|
|
|
|
|
|
|
|
Maintainer : John MacFarlane <jgm@berkeley@edu>
|
|
|
|
Stability : alpha
|
|
|
|
Portability : portable
|
|
|
|
|
|
|
|
Tests for functions used in many parts of the library.
|
|
|
|
-}
|
2011-01-29 19:03:00 +01:00
|
|
|
module Tests.Shared (tests) where
|
|
|
|
|
2017-03-04 13:03:41 +01:00
|
|
|
import System.FilePath.Posix (joinPath)
|
2017-03-14 17:05:36 +01:00
|
|
|
import Test.Tasty
|
2017-03-04 13:03:41 +01:00
|
|
|
import Text.Pandoc.Arbitrary ()
|
2014-07-25 19:53:04 +02:00
|
|
|
import Text.Pandoc.Builder
|
2017-03-04 13:03:41 +01:00
|
|
|
import Text.Pandoc.Shared
|
2022-02-12 06:37:00 +01:00
|
|
|
import Test.Tasty.HUnit
|
|
|
|
import Tests.Helpers
|
|
|
|
import Text.Pandoc
|
|
|
|
import Text.Pandoc.Writers.Shared
|
|
|
|
import qualified Data.Text as T
|
2011-01-29 19:03:00 +01:00
|
|
|
|
2017-03-14 17:05:36 +01:00
|
|
|
tests :: [TestTree]
|
2017-01-27 21:36:45 +01:00
|
|
|
tests = [ testGroup "compactifyDL"
|
|
|
|
[ testCase "compactifyDL with empty def" $
|
|
|
|
assertBool "compactifyDL"
|
2014-07-25 19:53:04 +02:00
|
|
|
(let x = [(str "word", [para (str "def"), mempty])]
|
2017-01-27 21:36:45 +01:00
|
|
|
in compactifyDL x == x)
|
2014-07-25 19:53:04 +02:00
|
|
|
]
|
2014-08-08 22:03:41 +02:00
|
|
|
, testGroup "collapseFilePath" testCollapse
|
2020-04-10 16:04:24 +02:00
|
|
|
, testGroup "toLegacyTable" testLegacyTable
|
2022-02-12 06:37:00 +01:00
|
|
|
, testGroup "table of contents" testTOC
|
|
|
|
]
|
|
|
|
|
|
|
|
givesTOC :: String -> (Blocks, Blocks) -> TestTree
|
|
|
|
givesTOC desc (blocks, toc) = test (toTableOfContents def) desc (toList blocks, head . toList $ toc)
|
|
|
|
|
|
|
|
linkId :: T.Text -> T.Text -> T.Text -> Inlines -> Inlines
|
|
|
|
linkId lId = linkWith (lId,[],[])
|
|
|
|
|
|
|
|
headerId :: T.Text -> Int -> Inlines -> Blocks
|
|
|
|
headerId hId = headerWith (hId,[],[])
|
|
|
|
|
|
|
|
testTOC :: [TestTree]
|
|
|
|
testTOC = [ givesTOC "empty case" $ mempty =?> bulletList []
|
|
|
|
, givesTOC "no headers" $ horizontalRule =?> bulletList []
|
|
|
|
, givesTOC "unlinked header" $
|
|
|
|
header 1 "H1" =?>
|
|
|
|
bulletList [plain "H1"]
|
|
|
|
, givesTOC "linked header" $
|
|
|
|
headerId "h1" 1 "H1" =?>
|
|
|
|
bulletList [plain $ linkId "toc-h1" "#h1" "" "H1"]
|
|
|
|
, givesTOC "nested headlines" $
|
|
|
|
header 1 "H1a" <> header 2 "H2" =?>
|
|
|
|
bulletList [plain "H1a" <> bulletList [plain "H2"]]
|
|
|
|
, givesTOC "only referenced headers" $
|
|
|
|
header 1 "H1a" <> headerId "h2" 2 "H2" =?>
|
|
|
|
bulletList [plain "H1a" <>
|
|
|
|
bulletList [plain $ linkId "toc-h2" "#h2" "" "H2"]]
|
|
|
|
, givesTOC "section id used as backup" $
|
|
|
|
divWith ("sec",["section"],[]) (header 1 "H1") =?>
|
|
|
|
bulletList [plain $ linkId "toc-sec" "#sec" "" "H1"]
|
|
|
|
]
|
2011-01-29 19:03:00 +01:00
|
|
|
|
2017-03-14 17:05:36 +01:00
|
|
|
testCollapse :: [TestTree]
|
2014-08-08 22:03:41 +02:00
|
|
|
testCollapse = map (testCase "collapse")
|
2020-09-13 16:48:14 +02:00
|
|
|
[ collapseFilePath (joinPath [ ""]) @?= joinPath [ ""]
|
|
|
|
, collapseFilePath (joinPath [ ".","foo"]) @?= joinPath [ "foo"]
|
|
|
|
, collapseFilePath (joinPath [ ".",".","..","foo"]) @?= joinPath [ joinPath ["..", "foo"]]
|
|
|
|
, collapseFilePath (joinPath [ "..","foo"]) @?= joinPath [ "..","foo"]
|
|
|
|
, collapseFilePath (joinPath [ "","bar","..","baz"]) @?= joinPath [ "","baz"]
|
|
|
|
, collapseFilePath (joinPath [ "","..","baz"]) @?= joinPath [ "","..","baz"]
|
|
|
|
, collapseFilePath (joinPath [ ".","foo","..",".","bar","..",".",".","baz"]) @?= joinPath [ "baz"]
|
|
|
|
, collapseFilePath (joinPath [ ".",""]) @?= joinPath [ ""]
|
|
|
|
, collapseFilePath (joinPath [ ".",".",""]) @?= joinPath [ ""]
|
|
|
|
, collapseFilePath (joinPath [ "..",""]) @?= joinPath [ ".."]
|
|
|
|
, collapseFilePath (joinPath [ "..",".",""]) @?= joinPath [ ".."]
|
|
|
|
, collapseFilePath (joinPath [ ".","..",""]) @?= joinPath [ ".."]
|
|
|
|
, collapseFilePath (joinPath [ "..","..",""]) @?= joinPath [ "..",".."]
|
|
|
|
, collapseFilePath (joinPath [ "parent","foo","baz","..","bar"]) @?= joinPath [ "parent","foo","bar"]
|
|
|
|
, collapseFilePath (joinPath [ "parent","foo","baz","..","..","bar"]) @?= joinPath [ "parent","bar"]
|
|
|
|
, collapseFilePath (joinPath [ "parent","foo",".."]) @?= joinPath [ "parent"]
|
|
|
|
, collapseFilePath (joinPath [ "","parent","foo","..","..","bar"]) @?= joinPath [ "","bar"]
|
|
|
|
, collapseFilePath (joinPath [ "",".","parent","foo"]) @?= joinPath [ "","parent","foo"]]
|
2020-04-10 16:04:24 +02:00
|
|
|
|
|
|
|
testLegacyTable :: [TestTree]
|
|
|
|
testLegacyTable =
|
|
|
|
[ testCase "decomposes a table with head" $ gen1 @?= expect1
|
|
|
|
, testCase "decomposes a table without head" $ gen2 @?= expect2
|
2021-11-12 05:55:37 +01:00
|
|
|
, testCase "decomposes the table from issue 7683" $ gen3 @?= expect3
|
2020-04-10 16:04:24 +02:00
|
|
|
]
|
|
|
|
where
|
|
|
|
pln = toList . plain . str
|
|
|
|
cl a h w = Cell ("", [], []) AlignDefault h w $ pln a
|
|
|
|
rws = map $ Row nullAttr
|
|
|
|
th = TableHead nullAttr . rws
|
|
|
|
tb n x y = TableBody nullAttr n (rws x) (rws y)
|
|
|
|
tf = TableFoot nullAttr . rws
|
|
|
|
|
|
|
|
headRows1 =
|
|
|
|
[[cl "a" 1 1, cl "b" 2 2]
|
|
|
|
,[cl "c" 1 1]
|
|
|
|
]
|
|
|
|
body1 = tb 1
|
|
|
|
[[cl "e" 3 1,cl "f" 3 2]
|
|
|
|
,[]
|
|
|
|
,[]
|
|
|
|
]
|
|
|
|
[[emptyCell,emptyCell,emptyCell]
|
|
|
|
,[cl "g" 1 1,emptyCell,emptyCell]
|
|
|
|
]
|
|
|
|
footRows1 =
|
|
|
|
[[cl "h" 1 2,cl "i" 2 1]
|
|
|
|
,[cl "j" 1 2]]
|
|
|
|
caption1 = simpleCaption $ plain "caption"
|
|
|
|
spec1 = replicate 2 (AlignDefault, ColWidth 0.5) ++ [(AlignRight, ColWidthDefault)]
|
|
|
|
expect1 = ( [Str "caption"]
|
|
|
|
, replicate 2 AlignDefault ++ [AlignRight]
|
|
|
|
, replicate 2 0.5 ++ [0]
|
|
|
|
, [pln "a", pln "b", mempty]
|
|
|
|
, [[pln "c", mempty, mempty]
|
|
|
|
,[pln "e", pln "f", mempty]
|
|
|
|
,[mempty, mempty, mempty]
|
|
|
|
,[mempty, mempty, mempty]
|
|
|
|
,[mempty, mempty, mempty]
|
|
|
|
,[pln "g", mempty, mempty]
|
|
|
|
,[pln "h", mempty, pln "i"]
|
|
|
|
,[pln "j", mempty, mempty]]
|
|
|
|
)
|
|
|
|
gen1 = toLegacyTable caption1 spec1 (th headRows1) [body1] (tf footRows1)
|
|
|
|
|
|
|
|
expect2 = ( []
|
|
|
|
, replicate 2 AlignDefault ++ [AlignRight]
|
|
|
|
, replicate 2 0.5 ++ [0]
|
|
|
|
, []
|
|
|
|
, [[pln "e", pln "f", mempty]
|
|
|
|
,[mempty, mempty, mempty]
|
|
|
|
,[mempty, mempty, mempty]
|
|
|
|
,[mempty, mempty, mempty]
|
|
|
|
,[pln "g", mempty, mempty]
|
|
|
|
,[pln "h", mempty, pln "i"]
|
|
|
|
,[pln "j", mempty, mempty]]
|
|
|
|
)
|
|
|
|
gen2 = toLegacyTable emptyCaption spec1 (th []) [body1] (tf footRows1)
|
2021-11-12 05:55:37 +01:00
|
|
|
|
|
|
|
spec3 = replicate 4 (AlignDefault, ColWidthDefault)
|
|
|
|
body3 = tb 0
|
|
|
|
[]
|
|
|
|
[[cl "a" 2 1, cl "b" 1 2, cl "c" 2 1]
|
|
|
|
,[cl "d" 1 1, cl "e" 1 1]
|
|
|
|
]
|
|
|
|
expect3 = ( []
|
|
|
|
, replicate 4 AlignDefault
|
|
|
|
, replicate 4 0
|
|
|
|
, []
|
|
|
|
, [[pln "a", pln "b", mempty, pln "c"]
|
|
|
|
,[mempty, pln "d", pln "e", mempty]]
|
|
|
|
)
|
|
|
|
gen3 = toLegacyTable emptyCaption spec3 (th []) [body3] (tf [])
|