@@ -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