git.iko.soy/typeable/pandoc
on 4eff607 help sign in
46 lines 1.3 kB history raw
1{-# LANGUAGE ScopedTypeVariables, FlexibleContexts #-}
2module Tests.Walk (tests) where
4import Text.Pandoc.Definition
5import Text.Pandoc.Walk
6import Test.Framework
7import Tests.Helpers
8import Data.Char (toUpper)
9import Tests.Arbitrary()
10import Data.Generics
12tests :: [Test]
13tests = [ testGroup "Walk"
14 [ property "p_walk inlineTrans" (p_walk inlineTrans)
15 , property "p_walk blockTrans" (p_walk blockTrans)
16 , property "p_query inlineQuery" (p_query inlineQuery)
17 , property "p_query blockQuery" (p_query blockQuery)
18 ]
19 ]
21p_walk :: (Typeable a, Walkable a Pandoc)
22 => (a -> a) -> Pandoc -> Bool
23p_walk f d = everywhere (mkT f) d == walk f d
25p_query :: (Eq a, Typeable a1, Monoid a, Walkable a1 Pandoc)
26 => (a1 -> a) -> Pandoc -> Bool
27p_query f d = everything mappend (mempty `mkQ` f) d == query f d
29inlineTrans :: Inline -> Inline
30inlineTrans (Str xs) = Str $ map toUpper xs
31inlineTrans (Emph xs) = Strong xs
32inlineTrans x = x
34blockTrans :: Block -> Block
35blockTrans (Plain xs) = Para xs
36blockTrans (BlockQuote xs) = Div ("",["special"],[]) xs
37blockTrans x = x
39inlineQuery :: Inline -> String
40inlineQuery (Str xs) = xs
41inlineQuery _ = ""
43blockQuery :: Block -> [Int]
44blockQuery (Header lev _ _) = [lev]
45blockQuery _ = []