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
|
2021-01-08 18:38:20 +01:00
|
|
|
Copyright : © 2006-2021 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-10-28 05:28:29 +02:00
|
|
|
import Test.Tasty.HUnit (assertBool, testCase, (@?=))
|
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
|
2020-04-10 16:04:24 +02:00
|
|
|
import Text.Pandoc.Writers.Shared (toLegacyTable)
|
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
|
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
|
|
|
|
]
|
|
|
|
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)
|