git.iko.soy/typeable/pandoc
on master help sign in
Update all tests to use new readers and error structure.
5ede571Jesse Rosenthal
tests/Tests/Old.hs+1−2
@@ -19,7 +19,6 @@ import Prelude hiding ( readFile )
19import qualified Data.ByteString.Lazy as B
19import qualified Data.ByteString.Lazy as B
20import Text.Pandoc.UTF8 (toStringLazy)
20import Text.Pandoc.UTF8 (toStringLazy)
21import Text.Printf
21import Text.Printf
22−import Text.Pandoc.Error
23import Tests.Helpers (purely)
22import Tests.Helpers (purely)
24
23
25readFileUTF8 :: FilePath -> IO String
24readFileUTF8 :: FilePath -> IO String
@@ -197,7 +196,7 @@ lhsReaderTest format =
197 testWithNormalize normalizer "lhs" ["-r", format, "-w", "native"]
196 testWithNormalize normalizer "lhs" ["-r", format, "-w", "native"]
198 ("lhs-test" <.> format) norm
197 ("lhs-test" <.> format) norm
199 where normalizer = purely $ \nat -> do
198 where normalizer = purely $ \nat -> do
200− d <- handleError <$> readNative nat
199+ d <- readNative nat
201 writeNative def $ normalize d
200 writeNative def $ normalize d
202 norm = if format == "markdown+lhs"
201 norm = if format == "markdown+lhs"
203 then "lhs-test-markdown.native"
202 then "lhs-test-markdown.native"
tests/Tests/Readers/Docx.hs+5−5
@@ -13,8 +13,8 @@ import Text.Pandoc.Writers.Native (writeNative)
13import qualified Data.Map as M
13import qualified Data.Map as M
14import Text.Pandoc.MediaBag (MediaBag, lookupMedia, mediaDirectory)
14import Text.Pandoc.MediaBag (MediaBag, lookupMedia, mediaDirectory)
15import Codec.Archive.Zip
15import Codec.Archive.Zip
16−import Text.Pandoc.Error
17import Text.Pandoc.Class (runIOorExplode)
16import Text.Pandoc.Class (runIOorExplode)
17+import qualified Text.Pandoc.Class as P
18
18
19-- We define a wrapper around pandoc that doesn't normalize in the
19-- We define a wrapper around pandoc that doesn't normalize in the
20-- tests. Since we do our own normalization, we want to make sure
20-- tests. Since we do our own normalization, we want to make sure
@@ -43,9 +43,9 @@ compareOutput :: ReaderOptions
43compareOutput opts docxFile nativeFile = do
43compareOutput opts docxFile nativeFile = do
44 df <- B.readFile docxFile
44 df <- B.readFile docxFile
45 nf <- Prelude.readFile nativeFile
45 nf <- Prelude.readFile nativeFile
46− let (p, _) = handleError $ readDocx opts df
46+ p <- runIOorExplode $ readDocx opts df
47 df' <- runIOorExplode $ readNative nf
47 df' <- runIOorExplode $ readNative nf
48− return $ (noNorm p, noNorm $ handleError df')
48+ return $ (noNorm p, noNorm df')
49
49
50testCompareWithOptsIO :: ReaderOptions -> String -> FilePath -> FilePath -> IO Test
50testCompareWithOptsIO :: ReaderOptions -> String -> FilePath -> FilePath -> IO Test
51testCompareWithOptsIO opts name docxFile nativeFile = do
51testCompareWithOptsIO opts name docxFile nativeFile = do
@@ -62,7 +62,7 @@ testCompare = testCompareWithOpts def
62testForWarningsWithOptsIO :: ReaderOptions -> String -> FilePath -> [String] -> IO Test
62testForWarningsWithOptsIO :: ReaderOptions -> String -> FilePath -> [String] -> IO Test
63testForWarningsWithOptsIO opts name docxFile expected = do
63testForWarningsWithOptsIO opts name docxFile expected = do
64 df <- B.readFile docxFile
64 df <- B.readFile docxFile
65− let (_, _, warns) = handleError $ readDocxWithWarnings opts df
65+ warns <- runIOorExplode (readDocx opts df >> P.getWarnings)
66 return $ test id name (unlines warns, unlines expected)
66 return $ test id name (unlines warns, unlines expected)
67
67
68testForWarningsWithOpts :: ReaderOptions -> String -> FilePath -> [String] -> Test
68testForWarningsWithOpts :: ReaderOptions -> String -> FilePath -> [String] -> Test
@@ -95,7 +95,7 @@ compareMediaPathIO mediaPath mediaBag docxPath = do
95compareMediaBagIO :: FilePath -> IO Bool
95compareMediaBagIO :: FilePath -> IO Bool
96compareMediaBagIO docxFile = do
96compareMediaBagIO docxFile = do
97 df <- B.readFile docxFile
97 df <- B.readFile docxFile
98− let (_, mb) = handleError $ readDocx def df
98+ mb <- runIOorExplode (readDocx def df >> P.getMediaBag)
99 bools <- mapM
99 bools <- mapM
100 (\(fp, _, _) -> compareMediaPathIO fp mb docxFile)
100 (\(fp, _, _) -> compareMediaPathIO fp mb docxFile)
101 (mediaDirectory mb)
101 (mediaDirectory mb)
tests/Tests/Readers/EPUB.hs+4−2
@@ -7,10 +7,12 @@ import Test.Framework.Providers.HUnit
7import qualified Data.ByteString.Lazy as BL
7import qualified Data.ByteString.Lazy as BL
8import Text.Pandoc.Readers.EPUB
8import Text.Pandoc.Readers.EPUB
9import Text.Pandoc.MediaBag (MediaBag, mediaDirectory)
9import Text.Pandoc.MediaBag (MediaBag, mediaDirectory)
10−import Text.Pandoc.Error
10+import qualified Text.Pandoc.Class as P
11
11
12getMediaBag :: FilePath -> IO MediaBag
12getMediaBag :: FilePath -> IO MediaBag
13−getMediaBag fp = snd . handleError . readEPUB def <$> BL.readFile fp
13+getMediaBag fp = do
14+ bs <- BL.readFile fp
15+ snd <$> (P.runIOorExplode $ P.withMediaBag $ readEPUB def bs)
14
16
15testMediaBag :: FilePath -> [(String, String, Int)] -> IO ()
17testMediaBag :: FilePath -> [(String, String, Int)] -> IO ()
16testMediaBag fp bag = do
18testMediaBag fp bag = do
tests/Tests/Readers/HTML.hs+1−1
@@ -9,7 +9,7 @@ import Text.Pandoc.Builder
9import Text.Pandoc
9import Text.Pandoc
10
10
11html :: String -> Pandoc
11html :: String -> Pandoc
12−html = handleError . readHtml def
12+html = purely $ readHtml def
13
13
14tests :: [Test]
14tests :: [Test]
15tests = [ testGroup "base tag"
15tests = [ testGroup "base tag"
tests/Tests/Readers/LaTeX.hs+1−1
@@ -9,7 +9,7 @@ import Text.Pandoc.Builder
9import Text.Pandoc
9import Text.Pandoc
10
10
11latex :: String -> Pandoc
11latex :: String -> Pandoc
12−latex = handleError . readLaTeX def
12+latex = purely $ readLaTeX def
13
13
14infix 4 =:
14infix 4 =:
15(=:) :: ToString c
15(=:) :: ToString c
tests/Tests/Readers/Markdown.hs+6−6
@@ -10,17 +10,17 @@ import qualified Data.Set as Set
10import Text.Pandoc
10import Text.Pandoc
11
11
12markdown :: String -> Pandoc
12markdown :: String -> Pandoc
13−markdown = handleError . readMarkdown def
13+markdown = purely $ readMarkdown def
14
14
15markdownSmart :: String -> Pandoc
15markdownSmart :: String -> Pandoc
16−markdownSmart = handleError . readMarkdown def { readerSmart = True }
16+markdownSmart = purely $ readMarkdown def { readerSmart = True }
17
17
18markdownCDL :: String -> Pandoc
18markdownCDL :: String -> Pandoc
19−markdownCDL = handleError . readMarkdown def { readerExtensions = Set.insert
19+markdownCDL = purely $ readMarkdown def { readerExtensions = Set.insert
20 Ext_compact_definition_lists $ readerExtensions def }
20 Ext_compact_definition_lists $ readerExtensions def }
21
21
22markdownGH :: String -> Pandoc
22markdownGH :: String -> Pandoc
23−markdownGH = handleError . readMarkdown def { readerExtensions = githubMarkdownExtensions }
23+markdownGH = purely $ readMarkdown def { readerExtensions = githubMarkdownExtensions }
24
24
25infix 4 =:
25infix 4 =:
26(=:) :: ToString c
26(=:) :: ToString c
@@ -29,7 +29,7 @@ infix 4 =:
29
29
30testBareLink :: (String, Inlines) -> Test
30testBareLink :: (String, Inlines) -> Test
31testBareLink (inp, ils) =
31testBareLink (inp, ils) =
32− test (handleError . readMarkdown def{ readerExtensions =
32+ test (purely $ readMarkdown def{ readerExtensions =
33 Set.fromList [Ext_autolink_bare_uris, Ext_raw_html] })
33 Set.fromList [Ext_autolink_bare_uris, Ext_raw_html] })
34 inp (inp, doc $ para ils)
34 inp (inp, doc $ para ils)
35
35
@@ -303,7 +303,7 @@ tests = [ testGroup "inline code"
303 =?> para (note (para "See [^1]"))
303 =?> para (note (para "See [^1]"))
304 ]
304 ]
305 , testGroup "lhs"
305 , testGroup "lhs"
306− [ test (handleError . readMarkdown def{ readerExtensions = Set.insert
306+ [ test (purely $ readMarkdown def{ readerExtensions = Set.insert
307 Ext_literate_haskell $ readerExtensions def })
307 Ext_literate_haskell $ readerExtensions def })
308 "inverse bird tracks and html" $
308 "inverse bird tracks and html" $
309 "> a\n\n< b\n\n<div>\n"
309 "> a\n\n< b\n\n<div>\n"
tests/Tests/Readers/Odt.hs+5−6
@@ -5,7 +5,7 @@ import Text.Pandoc.Options
5import Text.Pandoc.Readers.Native
5import Text.Pandoc.Readers.Native
6import Text.Pandoc.Readers.Markdown
6import Text.Pandoc.Readers.Markdown
7import Text.Pandoc.Definition
7import Text.Pandoc.Definition
8−import Text.Pandoc.Class (runIOorExplode)
8+import Text.Pandoc.Class (runIOorExplode, runIO, withMediaBag)
9import Tests.Helpers
9import Tests.Helpers
10import Test.Framework
10import Test.Framework
11import qualified Data.ByteString.Lazy as B
11import qualified Data.ByteString.Lazy as B
@@ -63,17 +63,16 @@ compareOdtToNative :: TestCreator
63compareOdtToNative opts odtPath nativePath = do
63compareOdtToNative opts odtPath nativePath = do
64 nativeFile <- Prelude.readFile nativePath
64 nativeFile <- Prelude.readFile nativePath
65 odtFile <- B.readFile odtPath
65 odtFile <- B.readFile odtPath
66− native <- getNoNormVia id "native" <$>
66+ native <- getNoNormVia id "native" <$> runIO (readNative nativeFile)
67− runIOorExplode (readNative nativeFile)
68− let odt = getNoNormVia fst "odt" $ readOdt opts odtFile
67+ odt <- getNoNormVia id "odt" <$> runIO (readOdt opts odtFile)
69 return (odt,native)
68 return (odt,native)
70
69
71compareOdtToMarkdown :: TestCreator
70compareOdtToMarkdown :: TestCreator
72compareOdtToMarkdown opts odtPath markdownPath = do
71compareOdtToMarkdown opts odtPath markdownPath = do
73 markdownFile <- Prelude.readFile markdownPath
72 markdownFile <- Prelude.readFile markdownPath
74 odtFile <- B.readFile odtPath
73 odtFile <- B.readFile odtPath
75− let markdown = getNoNormVia id "markdown" $ readMarkdown opts markdownFile
74+ markdown <- getNoNormVia id "markdown" <$> runIO (readMarkdown opts markdownFile)
76− let odt = getNoNormVia fst "odt" $ readOdt opts odtFile
75+ odt <- getNoNormVia id "odt" <$> runIO (readOdt opts odtFile)
77 return (odt,markdown)
76 return (odt,markdown)
78
77
79
78
tests/Tests/Readers/Org.hs+2−2
@@ -9,10 +9,10 @@ import Text.Pandoc
9import Data.List (intersperse)
9import Data.List (intersperse)
10
10
11org :: String -> Pandoc
11org :: String -> Pandoc
12−org = handleError . readOrg def
12+org = purely $ readOrg def
13
13
14orgSmart :: String -> Pandoc
14orgSmart :: String -> Pandoc
15−orgSmart = handleError . readOrg def { readerSmart = True }
15+orgSmart = purely $ readOrg def { readerSmart = True }
16
16
17infix 4 =:
17infix 4 =:
18(=:) :: ToString c
18(=:) :: ToString c
tests/Tests/Readers/RST.hs+1−1
@@ -9,7 +9,7 @@ import Text.Pandoc.Builder
9import Text.Pandoc
9import Text.Pandoc
10
10
11rst :: String -> Pandoc
11rst :: String -> Pandoc
12−rst = handleError . readRST def{ readerStandalone = True }
12+rst = purely $ readRST def{ readerStandalone = True }
13
13
14infix 4 =:
14infix 4 =:
15(=:) :: ToString c
15(=:) :: ToString c
tests/Tests/Readers/Txt2Tags.hs+3−1
@@ -10,8 +10,10 @@ import Text.Pandoc
10import Data.List (intersperse)
10import Data.List (intersperse)
11import Text.Pandoc.Readers.Txt2Tags
11import Text.Pandoc.Readers.Txt2Tags
12
12
13+
13t2t :: String -> Pandoc
14t2t :: String -> Pandoc
14−t2t = handleError . readTxt2Tags (T2TMeta "date" "mtime" "in" "out") def
15+-- t2t = handleError . readTxt2Tags (T2TMeta "date" "mtime" "in" "out") def
16+t2t = purely $ readTxt2Tags def
15
17
16infix 4 =:
18infix 4 =:
17(=:) :: ToString c
19(=:) :: ToString c
tests/Tests/Writers/Docx.hs+3−4
@@ -7,7 +7,6 @@ import Tests.Helpers
7import Test.Framework
7import Test.Framework
8import Text.Pandoc.Readers.Docx
8import Text.Pandoc.Readers.Docx
9import Text.Pandoc.Writers.Docx
9import Text.Pandoc.Writers.Docx
10−import Text.Pandoc.Error
11import System.FilePath ((</>))
10import System.FilePath ((</>))
12import Text.Pandoc.Class (runIOorExplode)
11import Text.Pandoc.Class (runIOorExplode)
13
12
@@ -22,10 +21,10 @@ compareOutput opts nativeFileIn nativeFileOut = do
22 nf' <- Prelude.readFile nativeFileOut
21 nf' <- Prelude.readFile nativeFileOut
23 let wopts = fst opts
22 let wopts = fst opts
24 df <- runIOorExplode $ do
23 df <- runIOorExplode $ do
25− d <- handleError <$> readNative nf
24+ d <- readNative nf
26 writeDocx wopts{writerUserDataDir = Just (".." </> "data")} d
25 writeDocx wopts{writerUserDataDir = Just (".." </> "data")} d
27− df' <- handleError <$> runIOorExplode (readNative nf')
26+ df' <- runIOorExplode (readNative nf')
28− let (p, _) = handleError $ readDocx (snd opts) df
27+ p <- runIOorExplode $ readDocx (snd opts) df
29 return (p, df')
28 return (p, df')
30
29
31testCompareWithOptsIO :: Options -> String -> FilePath -> FilePath -> IO Test
30testCompareWithOptsIO :: Options -> String -> FilePath -> FilePath -> IO Test