git.iko.soy/typeable/pandoc
on master help sign in
Added normalize funcion to latex citation tests.

This is necessary because converting from markdown to latex correctly changes hyphens to en-dashes and some spaces to non-breaking spaces. Converting back to markdown does not undo this changes, and so the tests have to undo them.

commit53cb199babe37d26e799e71345db507b1c780f4b authorNathan Gass <gass@search.ch> dateTue 14 Dec 2010, 09:55 (16 years ago) parent3ac6f72
1 file changed+21−9
tests/RunTests.hs+21−9
tests/RunTests.hs+21−9
@@ -21,6 +21,7 @@ import System.Environment
2121import System.Exit
2222import Text.Printf
2323import Data.Algorithm.Diff
24+import Data.String.Utils ( replace )
2425import Prelude hiding ( readFile )
2526import qualified Data.ByteString.Lazy as B
2627import Data.ByteString.Lazy.UTF8 (toString, fromString)
@@ -166,7 +167,8 @@ runLatexCitationTests o n
166167 where
167168 o' = o ++ ["--" ++ n]
168169 f = n ++ "-citations.latex"
169− rt = runTest
170+ normalize = replace "\160" " " . replace "\8211" "-"
171+ rt = runTestWithNormalize normalize
170172
171173runWriterTest :: String -> IO Bool
172174runWriterTest format = do
@@ -178,13 +180,23 @@ runS5WriterTest :: String -> [String] -> String -> IO Bool
178180runS5WriterTest modifier opts format = runTest (format ++ " writer (" ++ modifier ++ ")")
179181 (["-r", "native", "-w", format] ++ opts) "s5.native" ("s5." ++ modifier <.> "html")
180182
181−-- | Run a test, return True if test passed.
182−runTest :: String -- ^ Title of test
183− -> [String] -- ^ Options to pass to pandoc
184− -> String -- ^ Input filepath
185− -> FilePath -- ^ Norm (for test results) filepath
186− -> IO Bool
187−runTest testname opts inp norm = do
183+
184+-- | Run a test without normalize function, return True if test passed.
185+runTest :: String -- ^ Title of test
186+ -> [String] -- ^ Options to pass to pandoc
187+ -> String -- ^ Input filepath
188+ -> FilePath -- ^ Norm (for test results) filepath
189+ -> IO Bool
190+runTest = runTestWithNormalize id
191+
192+-- | Run a test with normalize function, return True if test passed.
193+runTestWithNormalize :: (String -> String) -- ^ Normalize function for output
194+ -> String -- ^ Title of test
195+ -> [String] -- ^ Options to pass to pandoc
196+ -> String -- ^ Input filepath
197+ -> FilePath -- ^ Norm (for test results) filepath
198+ -> IO Bool
199+runTestWithNormalize normalize testname opts inp norm = do
188200 putStr $ printf "%-28s ---> " testname
189201 (outputPath, hOut) <- openTempFile "" "pandoc-test"
190202 let inpPath = inp
@@ -197,7 +209,7 @@ runTest testname opts inp norm = do
197209 result <- if ec == ExitSuccess
198210 then do
199211 -- filter \r so the tests will work on Windows machines
200− outputContents <- readFile' outputPath >>= return . filter (/='\r')
212+ outputContents <- readFile' outputPath >>= return . filter (/='\r') . normalize
201213 normContents <- readFile' normPath >>= return . filter (/='\r')
202214 if outputContents == normContents
203215 then return TestPassed