aboutsummaryrefslogtreecommitdiff
path: root/tests/Tests/Walk.hs
blob: f6aa1beae793c335fbb15ad0cd0ea0883926f87f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{-# LANGUAGE ScopedTypeVariables, FlexibleContexts #-}
module Tests.Walk (tests) where

import Text.Pandoc.Definition
import Text.Pandoc.Walk
import Test.Framework
import Tests.Helpers
import Data.Char (toUpper)
import Tests.Arbitrary()
import Data.Generics
import Data.Monoid

tests :: [Test]
tests = [ testGroup "Walk"
          [ property "p_walk inlineTrans" (p_walk inlineTrans)
          , property "p_walk blockTrans" (p_walk blockTrans)
          , property "p_query inlineQuery" (p_query inlineQuery)
          , property "p_query blockQuery" (p_query blockQuery)
          ]
        ]

p_walk :: (Typeable a, Walkable a Pandoc)
       => (a -> a) -> Pandoc -> Bool
p_walk f = (\(d :: Pandoc) -> everywhere (mkT f) d == walk f d)

p_query :: (Eq a, Typeable a1, Monoid a, Walkable a1 Pandoc)
        => (a1 -> a) -> Pandoc -> Bool
p_query f = (\(d :: Pandoc) -> everything mappend (mempty `mkQ` f) d == query f d)

inlineTrans :: Inline -> Inline
inlineTrans (Str xs) = Str $ map toUpper xs
inlineTrans (Emph xs) = Strong xs
inlineTrans x = x

blockTrans :: Block -> Block
blockTrans (Plain xs) = Para xs
blockTrans (BlockQuote xs) = Div ("",["special"],[]) xs
blockTrans x = x

inlineQuery :: Inline -> String
inlineQuery (Str xs) = xs
inlineQuery _ = ""

blockQuery :: Block -> [Int]
blockQuery (Header lev _ _) = [lev]
blockQuery _ = []