aboutsummaryrefslogtreecommitdiff
path: root/tests/Tests/Walk.hs
diff options
context:
space:
mode:
authorClare Macrae <github@cfmacrae.fastmail.co.uk>2014-06-29 19:22:31 +0100
committerClare Macrae <github@cfmacrae.fastmail.co.uk>2014-06-29 19:22:31 +0100
commit717e16660d1ee83f690b35d0aa9b60c8ac9d6b61 (patch)
treeaa850d4ee99fa0b14da9ba0396ba6aa67e2037e3 /tests/Tests/Walk.hs
parentfccfc8429cf4d002df37977f03508c9aae457416 (diff)
parentce69021e42d7bf50deccba2a52ed4717f6ddac10 (diff)
downloadpandoc-717e16660d1ee83f690b35d0aa9b60c8ac9d6b61.tar.gz
Merge remote-tracking branch 'jgm/master' into dokuwiki
Diffstat (limited to 'tests/Tests/Walk.hs')
-rw-r--r--tests/Tests/Walk.hs47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/Tests/Walk.hs b/tests/Tests/Walk.hs
new file mode 100644
index 000000000..34350e28a
--- /dev/null
+++ b/tests/Tests/Walk.hs
@@ -0,0 +1,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 = 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 = 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 _ = []
+