git.iko.soy/typeable/pandoc
on master help sign in
Changed RunTests.hs to use the Diff library.
d86c017fiddlosopher
pandoc.cabal−1
@@ -126,7 +126,6 @@ Extra-Source-Files:
126 tests/lhs-test.html,
126 tests/lhs-test.html,
127 tests/lhs-test.html+lhs,
127 tests/lhs-test.html+lhs,
128 tests/lhs-test.fragment.html+lhs,
128 tests/lhs-test.fragment.html+lhs,
129− tests/Diff.hs,
130 tests/RunTests.hs
129 tests/RunTests.hs
131Extra-Tmp-Files: man/man1/pandoc.1, man/man1/hsmarkdown.1,
130Extra-Tmp-Files: man/man1/pandoc.1, man/man1/hsmarkdown.1,
132 man/man1/html2markdown.1, man/man1/markdown2pdf.1
131 man/man1/html2markdown.1, man/man1/markdown2pdf.1
tests/Diff.hsdeleted−76
@@ -1,76 +0,0 @@
1−-----------------------------------------------------------------------------
2−-- |
3−-- Module : Data.Algorithm.Diff
4−-- Copyright : (c) Sterling Clover 2008
5−-- License : BSD 3 Clause
6−-- Maintainer : s.clover@gmail.com
7−-- Stability : experimental
8−-- Portability : portable
9−--
10−-- This is an implementation of the O(ND) diff algorithm as described in
11−-- \"An O(ND) Difference Algorithm and Its Variations (1986)\"
12−-- <http://citeseer.ist.psu.edu/myers86ond.html>. It is O(mn) in space.
13−-- The algorithm is the same one used by standared Unix diff.
14−-- The assumption is that users of this library will want to diff over
15−-- interesting things or peform interesting tasks with the results
16−-- (given that, otherwise, they would simply use the standard Unix diff
17−-- utility). Thus no attempt is made to present a fancier API to aid
18−-- in doing standard and uninteresting things with the results.
19−-----------------------------------------------------------------------------
20−
21−module Diff (DI(..), getDiff, getGroupedDiff) where
22−import Data.Array
23−import Data.List
24−
25−-- | Difference Indicator. A value is either from the First list, the Second
26−-- or from Both.
27−data DI = F | S | B deriving (Show, Eq)
28−
29−data DL = DL {poi::Int, poj::Int, path::[DI]} deriving (Show, Eq)
30−
31−instance Ord DL where x <= y = poi x <= poi y
32−
33−canDiag :: (Eq a) => [a] -> [a] -> Int -> Int -> (Int, Int) -> Bool
34−canDiag as bs lena lenb = \(i,j) ->
35− if i < lena && j < lenb then arAs ! i == arBs ! j else False
36− where arAs = listArray (0,lena - 1) as
37− arBs = listArray (0,lenb - 1) bs
38−
39−chunk :: Int -> [a] -> [[a]]
40−chunk x = unfoldr (\a -> case splitAt x a of ([],[]) -> Nothing; a' -> Just a')
41−
42−dstep :: ((Int,Int)->Bool) -> [DL] -> [DL]
43−dstep cd dls = map maximum $ [hd]:(chunk 2 rst)
44− where (hd:rst) = concatMap extend dls
45− extend dl = let pdl = path dl
46− in [addsnake cd $ dl {poi=poi dl + 1, path=(F : pdl)},
47− addsnake cd $ dl {poj=poj dl + 1, path=(S : pdl)}]
48−
49−addsnake :: ((Int,Int)->Bool) -> DL -> DL
50−addsnake cd dl
51− | cd (pi, pj) = addsnake cd $
52− dl {poi = pi + 1, poj = pj + 1, path=(B : path dl)}
53− | otherwise = dl
54− where pi = poi dl; pj = poj dl
55−
56−lcs :: (Eq a) => [a] -> [a] -> [DI]
57−lcs as bs = path . head . dropWhile (\dl -> poi dl /= lena || poj dl /= lenb) .
58− concat . iterate (dstep cd) . (:[]) . addsnake cd $
59− DL {poi=0,poj=0,path=[]}
60− where cd = canDiag as bs lena lenb
61− lena = length as; lenb = length bs
62−
63−-- | Takes two lists and returns a list indicating the differences
64−-- between them.
65−getDiff :: (Eq t) => [t] -> [t] -> [(DI, t)]
66−getDiff a b = markup a b . reverse $ lcs a b
67− where markup (x:xs) ys (F:ds) = (F, x) : markup xs ys ds
68− markup xs (y:ys) (S:ds) = (S, y) : markup xs ys ds
69− markup (x:xs) (_:ys) (B:ds) = (B, x) : markup xs ys ds
70− markup _ _ _ = []
71−
72−-- | Takes two lists and returns a list indicating the differences
73−-- between them, grouped into chunks.
74−getGroupedDiff :: (Eq t) => [t] -> [t] -> [(DI, [t])]
75−getGroupedDiff a b = map go . groupBy (\x y -> fst x == fst y) $ getDiff a b
76− where go ((d,x) : xs) = (d, x : map snd xs)
tests/RunTests.hs+10−4
@@ -8,11 +8,14 @@
8-- If the lhs argument is provided, tests for lhs support will be
8-- If the lhs argument is provided, tests for lhs support will be
9-- run. These presuppose that pandoc has been compiled with the
9-- run. These presuppose that pandoc has been compiled with the
10-- -fhighlighting flag, so these tests are not run by default.
10-- -fhighlighting flag, so these tests are not run by default.
11+--
12+-- This program assumes that the Diff package has been installed:
13+-- cabal install Diff
11
14
12module Main where
15module Main where
13import System.Exit
16import System.Exit
14import System.IO.UTF8
17import System.IO.UTF8
15−import System.IO ( openTempFile, stderr )
18+import System.IO ( openTempFile, stderr, stdout, hFlush )
16import Prelude hiding ( putStrLn, putStr, readFile )
19import Prelude hiding ( putStrLn, putStr, readFile )
17import System.Process ( runProcess, waitForProcess )
20import System.Process ( runProcess, waitForProcess )
18import System.FilePath ( (</>), (<.>) )
21import System.FilePath ( (</>), (<.>) )
@@ -20,7 +23,7 @@ import System.Directory
20import System.Environment
23import System.Environment
21import System.Exit
24import System.Exit
22import Text.Printf
25import Text.Printf
23−import Diff
26+import Data.Algorithm.Diff
24
27
25pandocPath :: FilePath
28pandocPath :: FilePath
26pandocPath = ".." </> "dist" </> "build" </> "pandoc" </> "pandoc"
29pandocPath = ".." </> "dist" </> "build" </> "pandoc" </> "pandoc"
@@ -143,11 +146,14 @@ runTest :: String -- ^ Title of test
143 -> FilePath -- ^ Norm (for test results) filepath
146 -> FilePath -- ^ Norm (for test results) filepath
144 -> IO Bool
147 -> IO Bool
145runTest testname opts inp norm = do
148runTest testname opts inp norm = do
149+ putStr $ printf "%-28s ---> " testname
146 (outputPath, hOut) <- openTempFile "" "pandoc-test"
150 (outputPath, hOut) <- openTempFile "" "pandoc-test"
147 let inpPath = inp
151 let inpPath = inp
148 let normPath = norm
152 let normPath = norm
153+ hFlush stdout
154+ env <- getEnvironment -- we need at least HOME so pandoc can find data files
149 -- Note: COLUMNS must be set for markdown table reader
155 -- Note: COLUMNS must be set for markdown table reader
150− ph <- runProcess pandocPath (opts ++ [inpPath]) Nothing (Just [("COLUMNS", "80")]) Nothing (Just hOut) (Just stderr)
156+ ph <- runProcess pandocPath (opts ++ [inpPath]) Nothing (Just (("COLUMNS", "80"):env)) Nothing (Just hOut) (Just stderr)
151 ec <- waitForProcess ph
157 ec <- waitForProcess ph
152 result <- if ec == ExitSuccess
158 result <- if ec == ExitSuccess
153 then do
159 then do
@@ -159,5 +165,5 @@ runTest testname opts inp norm = do
159 else return $ TestFailed $ getDiff (lines outputContents) (lines normContents)
165 else return $ TestFailed $ getDiff (lines outputContents) (lines normContents)
160 else return $ TestError ec
166 else return $ TestError ec
161 removeFile outputPath
167 removeFile outputPath
162− putStrLn $ printf "%-28s ---> %s" testname (show result)
168+ putStrLn (show result)
163 return (result == TestPassed)
169 return (result == TestPassed)