@@ -23,6 +23,8 @@ import Text.Pandoc.Writers.Native (writeNative)
23import Language.Haskell.TH.Quote
23import Language.Haskell.TH.Quote
24import Language.Haskell.TH.Syntax (Q, runIO)
24import Language.Haskell.TH.Syntax (Q, runIO)
25import qualified Test.QuickCheck.Property as QP
25import qualified Test.QuickCheck.Property as QP
26+import System.Console.ANSI
27+import Data.Algorithm.Diff
27lit :: QuasiQuoter
29lit :: QuasiQuoter
28lit = QuasiQuoter ((\a -> let b = rnl a in [|b|]) . filter (/= '\r')) $
30lit = QuasiQuoter ((\a -> let b = rnl a in [|b|]) . filter (/= '\r')) $
@@ -49,20 +51,32 @@ test :: (ToString a, ToString b, ToString c)
50test fn name (input, expected) =
52test fn name (input, expected) =
51 testCase name $ assertBool msg (actual' == expected')
53 testCase name $ assertBool msg (actual' == expected')
52− where msg = dashes "input" ++ input' ++
54+ where msg = nl ++ dashes "input" ++ nl ++ input' ++ nl ++
53− dashes "expected" ++ expected' ++
55+ dashes "expected" ++ nl ++ expected'' ++
54− dashes "got" ++ actual' ++
56+ dashes "got" ++ nl ++ actual'' ++
56 input' = toString input
59 input' = toString input
57 actual' = toString $ fn input
60 actual' = toString $ fn input
58 expected' = toString expected
61 expected' = toString expected
62+ diff = getDiff (lines expected') (lines actual')
63+ expected'' = unlines $ map vividize $ filter (\(d,_) -> d /= S) diff
64+ actual'' = unlines $ map vividize $ filter (\(d,_) -> d /= F) diff
59− dashes "" = '\n' : replicate 72 '-'
65+ dashes "" = replicate 72 '-'
60− dashes x = '\n' : replicate (72 - length x - 5) '-' ++ " " ++
66+ dashes x = replicate (72 - length x - 5) '-' ++ " " ++ x ++ " ---"
68+vividize :: (DI,String) -> String
70+vividize (_,s) = vivid s
63property :: QP.Testable a => TestName -> a -> Test
72property :: QP.Testable a => TestName -> a -> Test
64property = testProperty
73property = testProperty
75+vivid :: String -> String
76+vivid s = setSGRCode [SetColor Background Dull Red
77+ , SetColor Foreground Vivid White] ++ s
78+ ++ setSGRCode [Reset]
66infix 6 =?>
80infix 6 =?>
67(=?>) :: a -> b -> (a,b)
81(=?>) :: a -> b -> (a,b)
68x =?> y = (x, y)
82x =?> y = (x, y)