1{-# LANGUAGE TypeSynonymInstances, FlexibleInstances, TemplateHaskell #-}
2-- Utility functions for the test suite.
4module Tests.Helpers ( lit
14import Text.Pandoc.Definition
15import Text.Pandoc.Builder (Inlines, Blocks, doc, plain)
17import Test.Framework.Providers.HUnit
18import Test.Framework.Providers.QuickCheck2
19import Test.HUnit (assertBool)
20import Text.Pandoc.Shared (normalize, defaultWriterOptions,
21 WriterOptions(..), removeTrailingSpace)
22import Text.Pandoc.Writers.Native (writeNative)
23import Language.Haskell.TH.Quote (QuasiQuoter(..))
24import Language.Haskell.TH.Syntax (Q, runIO)
25import qualified Test.QuickCheck.Property as QP
26import System.Console.ANSI
27import Data.Algorithm.Diff
31 quoteExp = (\a -> let b = rnl a in [|b|]) . filter (/= '\r')
32 , quotePat = error "Cannot use lit as a pattern"
34 where rnl ('\n':xs) = xs
40-- adapted from TH 2.5 code
41quoteFile :: QuasiQuoter -> QuasiQuoter
42quoteFile (QuasiQuoter { quoteExp = qe, quotePat = qp }) =
43 QuasiQuoter { quoteExp = get qe, quotePat = get qp }
45 get :: (String -> Q a) -> String -> Q a
46 get old_quoter file_name = do { file_cts <- runIO (readFile file_name)
47 ; old_quoter file_cts }
49test :: (ToString a, ToString b, ToString c)
50 => (a -> b) -- ^ function to test
51 -> String -- ^ name of test case
52 -> (a, c) -- ^ (input, expected value)
54test fn name (input, expected) =
55 testCase name $ assertBool msg (actual' == expected')
56 where msg = nl ++ dashes "input" ++ nl ++ input' ++ nl ++
57 dashes "expected" ++ nl ++ expected'' ++
58 dashes "got" ++ nl ++ actual'' ++
61 input' = toString input
62 actual' = toString $ fn input
63 expected' = toString expected
64 diff = getDiff (lines expected') (lines actual')
65 expected'' = unlines $ map vividize $ filter (\(d,_) -> d /= S) diff
66 actual'' = unlines $ map vividize $ filter (\(d,_) -> d /= F) diff
67 dashes "" = replicate 72 '-'
68 dashes x = replicate (72 - length x - 5) '-' ++ " " ++ x ++ " ---"
70vividize :: (DI,String) -> String
72vividize (_,s) = vivid s
74property :: QP.Testable a => TestName -> a -> Test
75property = testProperty
77vivid :: String -> String
78vivid s = setSGRCode [SetColor Background Dull Red
79 , SetColor Foreground Vivid White] ++ s
83(=?>) :: a -> b -> (a,b)
87 toString :: a -> String
89instance ToString Pandoc where
90 toString d = writeNative defaultWriterOptions{ writerStandalone = s }
93 (Pandoc (Meta [] [] []) _) -> False
96instance ToString Blocks where
97 toString = writeNative defaultWriterOptions . toPandoc
99instance ToString Inlines where
100 toString = removeTrailingSpace . writeNative defaultWriterOptions .
103instance ToString String where
106class ToPandoc a where
107 toPandoc :: a -> Pandoc
109instance ToPandoc Pandoc where
112instance ToPandoc Blocks where
113 toPandoc = normalize . doc
115instance ToPandoc Inlines where
116 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