82b3e0ab97
- The (non-exported) prelude is in prelude/Prelude.hs. - It exports Monoid and Applicative, like base 4.8 prelude, but works with older base versions. - It exports (<>) for mappend. - It hides 'catch' on older base versions. This allows us to remove many imports of Data.Monoid and Control.Applicative, and remove Text.Pandoc.Compat.Monoid. It should allow us to use -Wall again for ghc 7.10.
60 lines
2.8 KiB
Haskell
60 lines
2.8 KiB
Haskell
module Tests.Shared (tests) where
|
|
|
|
import Text.Pandoc.Definition
|
|
import Text.Pandoc.Shared
|
|
import Test.Framework
|
|
import Tests.Helpers
|
|
import Tests.Arbitrary()
|
|
import Test.Framework.Providers.HUnit
|
|
import Test.HUnit ( assertBool, (@?=) )
|
|
import Text.Pandoc.Builder
|
|
import System.FilePath.Posix (joinPath)
|
|
|
|
tests :: [Test]
|
|
tests = [ testGroup "normalize"
|
|
[ property "p_normalize_blocks_rt" p_normalize_blocks_rt
|
|
, property "p_normalize_inlines_rt" p_normalize_inlines_rt
|
|
, property "p_normalize_no_trailing_spaces"
|
|
p_normalize_no_trailing_spaces
|
|
]
|
|
, testGroup "compactify'DL"
|
|
[ testCase "compactify'DL with empty def" $
|
|
assertBool "compactify'DL"
|
|
(let x = [(str "word", [para (str "def"), mempty])]
|
|
in compactify'DL x == x)
|
|
]
|
|
, testGroup "collapseFilePath" testCollapse
|
|
]
|
|
|
|
p_normalize_blocks_rt :: [Block] -> Bool
|
|
p_normalize_blocks_rt bs =
|
|
normalizeBlocks bs == normalizeBlocks (normalizeBlocks bs)
|
|
|
|
p_normalize_inlines_rt :: [Inline] -> Bool
|
|
p_normalize_inlines_rt ils =
|
|
normalizeInlines ils == normalizeInlines (normalizeInlines ils)
|
|
|
|
p_normalize_no_trailing_spaces :: [Inline] -> Bool
|
|
p_normalize_no_trailing_spaces ils = null ils' || last ils' /= Space
|
|
where ils' = normalizeInlines $ ils ++ [Space]
|
|
|
|
testCollapse :: [Test]
|
|
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"]))]
|