1{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
2-- Utility functions for the test suite.
4module Tests.Helpers ( test
12import Text.Pandoc.Definition
13import Text.Pandoc.Builder (Inlines, Blocks, doc, plain)
15import Test.Framework.Providers.HUnit
16import Test.Framework.Providers.QuickCheck2
17import Test.HUnit (assertBool)
18import Text.Pandoc.Shared (normalize, trimr)
19import Text.Pandoc.Options
20import Text.Pandoc.Writers.Native (writeNative)
21import qualified Test.QuickCheck.Property as QP
22import Data.Algorithm.Diff
23import qualified Data.Map as M
25test :: (ToString a, ToString b, ToString c)
26 => (a -> b) -- ^ function to test
27 -> String -- ^ name of test case
28 -> (a, c) -- ^ (input, expected value)
30test fn name (input, expected) =
31 testCase name $ assertBool msg (actual' == expected')
32 where msg = nl ++ dashes "input" ++ nl ++ input' ++ nl ++
33 dashes "result" ++ nl ++
34 unlines (map vividize diff) ++
37 input' = toString input
38 actual' = lines $ toString $ fn input
39 expected' = lines $ toString expected
40 diff = getDiff expected' actual'
41 dashes "" = replicate 72 '-'
42 dashes x = replicate (72 - length x - 5) '-' ++ " " ++ x ++ " ---"
44vividize :: Diff String -> String
45vividize (Both s _) = " " ++ s
46vividize (First s) = "- " ++ s
47vividize (Second s) = "+ " ++ s
49property :: QP.Testable a => TestName -> a -> Test
50property = testProperty
53(=?>) :: a -> b -> (a,b)
57 toString :: a -> String
59instance ToString Pandoc where
60 toString d = writeNative def{ writerStandalone = s } $ toPandoc d
66instance ToString Blocks where
67 toString = writeNative def . toPandoc
69instance ToString Inlines where
70 toString = trimr . writeNative def . toPandoc
72instance ToString String where
76 toPandoc :: a -> Pandoc
78instance ToPandoc Pandoc where
81instance ToPandoc Blocks where
82 toPandoc = normalize . doc
84instance ToPandoc Inlines where
85 toPandoc = normalize . doc . plain
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list