pandoc/test/Tests/Shared.hs
despresc 90e436d496 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-12 16:03:45 -08:00

53 lines
2.4 KiB
Haskell

{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{- |
Module : Tests.Shared
Copyright : © 2006-2019 John MacFarlane
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.
-}
module Tests.Shared (tests) where
import Prelude
import System.FilePath.Posix (joinPath)
import Test.Tasty
import Test.Tasty.HUnit (assertBool, testCase, (@?=))
import Text.Pandoc.Arbitrary ()
import Text.Pandoc.Builder
import Text.Pandoc.Shared
tests :: [TestTree]
tests = [ testGroup "compactifyDL"
[ testCase "compactifyDL with empty def" $
assertBool "compactifyDL"
(let x = [(str "word", [para (str "def"), mempty])]
in compactifyDL x == x)
]
, testGroup "collapseFilePath" testCollapse
]
testCollapse :: [TestTree]
testCollapse = map (testCase "collapse")
[ 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"])]