git.iko.soy/typeable/pandoc
on master help sign in
Added 'property' in Tests.Helpers & some quickcheck tests.
209b300John MacFarlane
pandoc.cabal+2
@@ -341,6 +341,8 @@ Executable test-pandoc
341 Extensions: CPP
341 Extensions: CPP
342 Build-Depends: base >= 4 && < 5, Diff, test-framework >= 0.3 && < 0.4,
342 Build-Depends: base >= 4 && < 5, Diff, test-framework >= 0.3 && < 0.4,
343 test-framework-hunit >= 0.2 && < 0.3,
343 test-framework-hunit >= 0.2 && < 0.3,
344+ test-framework-quickcheck2 >= 0.2 && < 0.3,
345+ QuickCheck >= 2.3,
344 HUnit >= 1.2 && < 1.3,
346 HUnit >= 1.2 && < 1.3,
345 template-haskell == 2.4.*
347 template-haskell == 2.4.*
346 Other-Modules: Tests.Old
348 Other-Modules: Tests.Old
tests/Tests/Helpers.hs+14−2
@@ -1,17 +1,26 @@
1{-# LANGUAGE TypeSynonymInstances, FlexibleInstances, TemplateHaskell #-}
1{-# LANGUAGE TypeSynonymInstances, FlexibleInstances, TemplateHaskell #-}
2-- Utility functions for the test suite.
2-- Utility functions for the test suite.
3
3
4−module Tests.Helpers where
4+module Tests.Helpers ( lit
5+ , test
6+ , (=?>)
7+ , property
8+ , ToString(..)
9+ , ToPandoc(..)
10+ )
11+ where
5
12
6import Text.Pandoc.Definition
13import Text.Pandoc.Definition
7import Text.Pandoc.Builder (Inlines, Blocks, doc, plain)
14import Text.Pandoc.Builder (Inlines, Blocks, doc, plain)
8import Test.Framework
15import Test.Framework
9import Test.Framework.Providers.HUnit
16import Test.Framework.Providers.HUnit
10−import Test.HUnit hiding (Test)
17+import Test.Framework.Providers.QuickCheck2
18+import Test.HUnit (assertBool)
11import Text.Pandoc.Shared (normalize, defaultWriterOptions,
19import Text.Pandoc.Shared (normalize, defaultWriterOptions,
12 WriterOptions(..), removeTrailingSpace)
20 WriterOptions(..), removeTrailingSpace)
13import Text.Pandoc.Writers.Native (writeNative)
21import Text.Pandoc.Writers.Native (writeNative)
14import Language.Haskell.TH.Quote
22import Language.Haskell.TH.Quote
23+import qualified Test.QuickCheck.Property as QP
15
24
16lit :: QuasiQuoter
25lit :: QuasiQuoter
17lit = QuasiQuoter ((\a -> let b = rnl a in [|b|]) . filter (/= '\r')) $
26lit = QuasiQuoter ((\a -> let b = rnl a in [|b|]) . filter (/= '\r')) $
@@ -37,6 +46,9 @@ test fn name (input, expected) =
37 dashes x = '\n' : replicate (72 - length x - 5) '-' ++ " " ++
46 dashes x = '\n' : replicate (72 - length x - 5) '-' ++ " " ++
38 x ++ " ---\n"
47 x ++ " ---\n"
39
48
49+property :: QP.Testable a => TestName -> a -> Test
50+property = testProperty
51+
40infix 6 =?>
52infix 6 =?>
41(=?>) :: a -> b -> (a,b)
53(=?>) :: a -> b -> (a,b)
42x =?> y = (x, y)
54x =?> y = (x, y)
tests/Tests/Readers/LaTeX.hs+1
@@ -4,6 +4,7 @@ module Tests.Readers.LaTeX (tests) where
4import Text.Pandoc.Definition
4import Text.Pandoc.Definition
5import Test.Framework
5import Test.Framework
6import Tests.Helpers
6import Tests.Helpers
7+import Tests.Arbitrary
7import Text.Pandoc.Builder
8import Text.Pandoc.Builder
8import Text.Pandoc
9import Text.Pandoc
9
10
tests/Tests/Writers/ConTeXt.hs+12
@@ -5,10 +5,15 @@ import Test.Framework
5import Text.Pandoc.Builder
5import Text.Pandoc.Builder
6import Text.Pandoc
6import Text.Pandoc
7import Tests.Helpers
7import Tests.Helpers
8+import Tests.Arbitrary()
8
9
9context :: (ToString a, ToPandoc a) => a -> String
10context :: (ToString a, ToPandoc a) => a -> String
10context = writeConTeXt defaultWriterOptions . toPandoc
11context = writeConTeXt defaultWriterOptions . toPandoc
11
12
13+context' :: (ToString a, ToPandoc a) => a -> String
14+context' = writeConTeXt defaultWriterOptions{ writerWrapText = False }
15+ . toPandoc
16+
12{-
17{-
13 "my test" =: X =?> Y
18 "my test" =: X =?> Y
14
19
@@ -30,10 +35,17 @@ tests :: [Test]
30tests = [ testGroup "inline code"
35tests = [ testGroup "inline code"
31 [ "with '}'" =: code "}" =?> "\\mono{\\letterclosebrace{}}"
36 [ "with '}'" =: code "}" =?> "\\mono{\\letterclosebrace{}}"
32 , "without '}'" =: code "]" =?> "\\type{]}"
37 , "without '}'" =: code "]" =?> "\\type{]}"
38+ , property "code property" $ \s -> null s ||
39+ if '{' `elem` s || '}' `elem` s
40+ then (context' $ code s) == "\\mono{" ++
41+ (context' $ str s) ++ "}"
42+ else (context' $ code s) == "\\type{" ++ s ++ "}"
33 ]
43 ]
34 , testGroup "headers"
44 , testGroup "headers"
35 [ "level 1" =:
45 [ "level 1" =:
36 header 1 "My header" =?> "\\subject{My header}"
46 header 1 "My header" =?> "\\subject{My header}"
47+ , property "header 1 property" $ \ils ->
48+ context' (header 1 ils) == "\\subject{" ++ context' ils ++ "}"
37 ]
49 ]
38 , testGroup "bullet lists"
50 , testGroup "bullet lists"
39 [ "nested" =:
51 [ "nested" =: