summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Gass <gass@search.ch>2010-12-14 09:55:07 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2010-12-14 19:41:22 -0800
commit53cb199babe37d26e799e71345db507b1c780f4b (patch)
tree587be2a38149d8c77fe618270c5d809d9a06d58a
parent3ac6f72f988da20af7d460868fc1971b3ea63758 (diff)
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.
-rw-r--r--tests/RunTests.hs30
1 files changed, 21 insertions, 9 deletions
diff --git a/tests/RunTests.hs b/tests/RunTests.hs
index 0dc11ef0c..2c7bc0749 100644
--- a/tests/RunTests.hs
+++ b/tests/RunTests.hs
@@ -21,6 +21,7 @@ import System.Environment
import System.Exit
import Text.Printf
import Data.Algorithm.Diff
+import Data.String.Utils ( replace )
import Prelude hiding ( readFile )
import qualified Data.ByteString.Lazy as B
import Data.ByteString.Lazy.UTF8 (toString, fromString)
@@ -166,7 +167,8 @@ runLatexCitationTests o n
where
o' = o ++ ["--" ++ n]
f = n ++ "-citations.latex"
- rt = runTest
+ normalize = replace "\160" " " . replace "\8211" "-"
+ rt = runTestWithNormalize normalize
runWriterTest :: String -> IO Bool
runWriterTest format = do
@@ -178,13 +180,23 @@ runS5WriterTest :: String -> [String] -> String -> IO Bool
runS5WriterTest modifier opts format = runTest (format ++ " writer (" ++ modifier ++ ")")
(["-r", "native", "-w", format] ++ opts) "s5.native" ("s5." ++ modifier <.> "html")
--- | Run a test, return True if test passed.
-runTest :: String -- ^ Title of test
- -> [String] -- ^ Options to pass to pandoc
- -> String -- ^ Input filepath
- -> FilePath -- ^ Norm (for test results) filepath
- -> IO Bool
-runTest testname opts inp norm = do
+
+-- | Run a test without normalize function, return True if test passed.
+runTest :: String -- ^ Title of test
+ -> [String] -- ^ Options to pass to pandoc
+ -> String -- ^ Input filepath
+ -> FilePath -- ^ Norm (for test results) filepath
+ -> IO Bool
+runTest = runTestWithNormalize id
+
+-- | Run a test with normalize function, return True if test passed.
+runTestWithNormalize :: (String -> String) -- ^ Normalize function for output
+ -> String -- ^ Title of test
+ -> [String] -- ^ Options to pass to pandoc
+ -> String -- ^ Input filepath
+ -> FilePath -- ^ Norm (for test results) filepath
+ -> IO Bool
+runTestWithNormalize normalize testname opts inp norm = do
putStr $ printf "%-28s ---> " testname
(outputPath, hOut) <- openTempFile "" "pandoc-test"
let inpPath = inp
@@ -197,7 +209,7 @@ runTest testname opts inp norm = do
result <- if ec == ExitSuccess
then do
-- filter \r so the tests will work on Windows machines
- outputContents <- readFile' outputPath >>= return . filter (/='\r')
+ outputContents <- readFile' outputPath >>= return . filter (/='\r') . normalize
normContents <- readFile' normPath >>= return . filter (/='\r')
if outputContents == normContents
then return TestPassed