git.iko.soy/typeable/pandoc
on master help sign in
Update tests to work with runPure.
commit1673bda95e83aa124241ffdf14d25282d4cad055 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 27 Nov 2016, 11:52 (10 years ago) parentb969863
14 files changed+28−22
tests/Tests/Helpers.hs+8−3 tests/Tests/Old.hs+2−1 tests/Tests/Readers/Docx.hs+1−1 tests/Tests/Readers/Odt.hs+1−1 tests/Tests/Writers/AsciiDoc.hs+1−1 tests/Tests/Writers/ConTeXt.hs+2−2 tests/Tests/Writers/Docbook.hs+1−1 tests/Tests/Writers/HTML.hs+1−1 tests/Tests/Writers/LaTeX.hs+1−1 tests/Tests/Writers/Markdown.hs+3−3 tests/Tests/Writers/Native.hs+2−2 tests/Tests/Writers/Plain.hs+1−1 tests/Tests/Writers/RST.hs+3−3 tests/Tests/Writers/TEI.hs+1−1
tests/Tests/Helpers.hs+8−3
@@ -3,6 +3,7 @@
33
44module Tests.Helpers ( test
55 , (=?>)
6+ , purely
67 , property
78 , ToString(..)
89 , ToPandoc(..)
@@ -11,6 +12,7 @@ module Tests.Helpers ( test
1112
1213import Text.Pandoc.Definition
1314import Text.Pandoc.Builder (Inlines, Blocks, doc, plain)
15+import Text.Pandoc.Class
1416import Test.Framework
1517import Test.Framework.Providers.HUnit
1618import Test.Framework.Providers.QuickCheck2
@@ -49,6 +51,9 @@ vividize (Second s) = "+ " ++ s
4951property :: QP.Testable a => TestName -> a -> Test
5052property = testProperty
5153
54+purely :: (b -> PandocPure a) -> b -> a
55+purely f = either (error . show) id . runPure . f
56+
5257infix 5 =?>
5358(=?>) :: a -> b -> (a,b)
5459x =?> y = (x, y)
@@ -57,17 +62,17 @@ class ToString a where
5762 toString :: a -> String
5863
5964instance ToString Pandoc where
60− toString d = writeNative def{ writerTemplate = s } $ toPandoc d
65+ toString d = purely (writeNative def{ writerTemplate = s }) $ toPandoc d
6166 where s = case d of
6267 (Pandoc (Meta m) _)
6368 | M.null m -> Nothing
6469 | otherwise -> Just "" -- need this to get meta output
6570
6671instance ToString Blocks where
67− toString = writeNative def . toPandoc
72+ toString = purely (writeNative def) . toPandoc
6873
6974instance ToString Inlines where
70− toString = trimr . writeNative def . toPandoc
75+ toString = trimr . purely (writeNative def) . toPandoc
7176
7277instance ToString String where
7378 toString = id
tests/Tests/Old.hs+2−1
@@ -20,6 +20,7 @@ import qualified Data.ByteString.Lazy as B
2020import Text.Pandoc.UTF8 (toStringLazy)
2121import Text.Printf
2222import Text.Pandoc.Error
23+import Tests.Helpers (purely)
2324
2425readFileUTF8 :: FilePath -> IO String
2526readFileUTF8 f = B.readFile f >>= return . toStringLazy
@@ -195,7 +196,7 @@ lhsReaderTest :: String -> Test
195196lhsReaderTest format =
196197 testWithNormalize normalizer "lhs" ["-r", format, "-w", "native"]
197198 ("lhs-test" <.> format) norm
198− where normalizer = writeNative def . normalize . handleError . readNative
199+ where normalizer = purely $ writeNative def . normalize . handleError . readNative
199200 norm = if format == "markdown+lhs"
200201 then "lhs-test-markdown.native"
201202 else "lhs-test.native"
tests/Tests/Readers/Docx.hs+1−1
@@ -26,7 +26,7 @@ noNorm :: Pandoc -> NoNormPandoc
2626noNorm = NoNormPandoc
2727
2828instance ToString NoNormPandoc where
29− toString d = writeNative def{ writerTemplate = s } $ toPandoc d
29+ toString d = purely (writeNative def{ writerTemplate = s }) $ toPandoc d
3030 where s = case d of
3131 NoNormPandoc (Pandoc (Meta m) _)
3232 | M.null m -> Nothing
tests/Tests/Readers/Odt.hs+1−1
@@ -41,7 +41,7 @@ newtype NoNormPandoc = NoNormPandoc {unNoNorm :: Pandoc}
4141 deriving ( Show )
4242
4343instance ToString NoNormPandoc where
44− toString d = writeNative def{ writerTemplate = s } $ toPandoc d
44+ toString d = purely (writeNative def{ writerTemplate = s }) $ toPandoc d
4545 where s = case d of
4646 NoNormPandoc (Pandoc (Meta m) _)
4747 | M.null m -> Nothing
tests/Tests/Writers/AsciiDoc.hs+1−1
@@ -7,7 +7,7 @@ import Tests.Helpers
77import Text.Pandoc.Arbitrary()
88
99asciidoc :: (ToPandoc a) => a -> String
10−asciidoc = writeAsciiDoc def{ writerWrapText = WrapNone } . toPandoc
10+asciidoc = purely (writeAsciiDoc def{ writerWrapText = WrapNone }) . toPandoc
1111
1212tests :: [Test]
1313tests = [ testGroup "emphasis"
tests/Tests/Writers/ConTeXt.hs+2−2
@@ -8,10 +8,10 @@ import Tests.Helpers
88import Text.Pandoc.Arbitrary()
99
1010context :: (ToPandoc a) => a -> String
11−context = writeConTeXt def . toPandoc
11+context = purely (writeConTeXt def) . toPandoc
1212
1313context' :: (ToPandoc a) => a -> String
14−context' = writeConTeXt def{ writerWrapText = WrapNone } . toPandoc
14+context' = purely (writeConTeXt def{ writerWrapText = WrapNone }) . toPandoc
1515
1616{-
1717 "my test" =: X =?> Y
tests/Tests/Writers/Docbook.hs+1−1
@@ -11,7 +11,7 @@ docbook :: (ToPandoc a) => a -> String
1111docbook = docbookWithOpts def{ writerWrapText = WrapNone }
1212
1313docbookWithOpts :: ToPandoc a => WriterOptions -> a -> String
14−docbookWithOpts opts = writeDocbook opts . toPandoc
14+docbookWithOpts opts = purely (writeDocbook opts) . toPandoc
1515
1616{-
1717 "my test" =: X =?> Y
tests/Tests/Writers/HTML.hs+1−1
@@ -8,7 +8,7 @@ import Tests.Helpers
88import Text.Pandoc.Arbitrary()
99
1010html :: (ToPandoc a) => a -> String
11−html = writeHtmlString def{ writerWrapText = WrapNone } . toPandoc
11+html = purely (writeHtmlString def{ writerWrapText = WrapNone }) . toPandoc
1212
1313{-
1414 "my test" =: X =?> Y
tests/Tests/Writers/LaTeX.hs+1−1
@@ -14,7 +14,7 @@ latexListing :: (ToPandoc a) => a -> String
1414latexListing = latexWithOpts def{ writerListings = True }
1515
1616latexWithOpts :: (ToPandoc a) => WriterOptions -> a -> String
17−latexWithOpts opts = writeLaTeX opts . toPandoc
17+latexWithOpts opts = purely (writeLaTeX opts) . toPandoc
1818
1919{-
2020 "my test" =: X =?> Y
tests/Tests/Writers/Markdown.hs+3−3
@@ -9,10 +9,10 @@ import Tests.Helpers
99import Text.Pandoc.Arbitrary()
1010
1111markdown :: (ToPandoc a) => a -> String
12−markdown = writeMarkdown def . toPandoc
12+markdown = purely (writeMarkdown def) . toPandoc
1313
1414markdownWithOpts :: (ToPandoc a) => WriterOptions -> a -> String
15−markdownWithOpts opts x = writeMarkdown opts $ toPandoc x
15+markdownWithOpts opts x = purely (writeMarkdown opts) $ toPandoc x
1616
1717{-
1818 "my test" =: X =?> Y
@@ -179,7 +179,7 @@ shortcutLinkRefsTests =
179179 (=:) :: (ToString a, ToPandoc a)
180180
181181 => String -> (a, String) -> Test
182− (=:) = test (writeMarkdown (def {writerReferenceLinks = True}) . toPandoc)
182+ (=:) = test (purely (writeMarkdown def{writerReferenceLinks = True}) . toPandoc)
183183 in testGroup "Shortcut reference links"
184184 [ "Simple link (shortcutable)"
185185 =: (para (link "/url" "title" "foo"))
tests/Tests/Writers/Native.hs+2−2
@@ -8,11 +8,11 @@ import Text.Pandoc.Arbitrary()
88
99p_write_rt :: Pandoc -> Bool
1010p_write_rt d =
11− read (writeNative def{ writerTemplate = Just "" } d) == d
11+ read (purely (writeNative def{ writerTemplate = Just "" }) d) == d
1212
1313p_write_blocks_rt :: [Block] -> Bool
1414p_write_blocks_rt bs = length bs > 20 ||
15− read (writeNative def (Pandoc nullMeta bs)) ==
15+ read (purely (writeNative def) (Pandoc nullMeta bs)) ==
1616 bs
1717
1818tests :: [Test]
tests/Tests/Writers/Plain.hs+1−1
@@ -11,7 +11,7 @@ import Text.Pandoc.Arbitrary()
1111infix 4 =:
1212(=:) :: (ToString a, ToPandoc a)
1313 => String -> (a, String) -> Test
14−(=:) = test (writePlain def . toPandoc)
14+(=:) = test (purely (writePlain def) . toPandoc)
1515
1616
1717tests :: [Test]
tests/Tests/Writers/RST.hs+3−3
@@ -10,7 +10,7 @@ import Text.Pandoc.Arbitrary()
1010infix 4 =:
1111(=:) :: (ToString a, ToPandoc a)
1212 => String -> (a, String) -> Test
13−(=:) = test (writeRST def{ writerHighlight = True } . toPandoc)
13+(=:) = test (purely (writeRST def{ writerHighlight = True }) . toPandoc)
1414
1515tests :: [Test]
1616tests = [ testGroup "rubrics"
@@ -47,7 +47,7 @@ tests = [ testGroup "rubrics"
4747 [ "foo"
4848 , "==="]
4949 -- note: heading normalization is only done in standalone mode
50− , test (writeRST def{ writerTemplate = Just "$body$\n" } . toPandoc)
50+ , test (purely (writeRST def{ writerTemplate = Just "$body$\n" }) . toPandoc)
5151 "heading levels" $
5252 header 1 (text "Header 1") <>
5353 header 3 (text "Header 2") <>
@@ -77,7 +77,7 @@ tests = [ testGroup "rubrics"
7777 , ""
7878 , "Header 2"
7979 , "--------"]
80− , test (writeRST def{ writerTemplate = Just "$body$\n" } . toPandoc)
80+ , test (purely (writeRST def{ writerTemplate = Just "$body$\n" }) . toPandoc)
8181 "minimal heading levels" $
8282 header 2 (text "Header 1") <>
8383 header 3 (text "Header 2") <>
tests/Tests/Writers/TEI.hs+1−1
@@ -22,7 +22,7 @@ which is in turn shorthand for
2222infix 4 =:
2323(=:) :: (ToString a, ToPandoc a)
2424 => String -> (a, String) -> Test
25−(=:) = test (writeTEI def . toPandoc)
25+(=:) = test (purely (writeTEI def) . toPandoc)
2626
2727tests :: [Test]
2828tests = [ testGroup "block elements"