git.iko.soy/typeable/pandoc
on master help sign in
Added 'property' in Tests.Helpers & some quickcheck tests.
commit209b300d6adeb2427c0058b808945ac39f851b24 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 22 Jan 2011, 12:18 (16 years ago) parentd86d926
4 files changed+29−2
pandoc.cabal+2 tests/Tests/Helpers.hs+14−2 tests/Tests/Readers/LaTeX.hs+1 tests/Tests/Writers/ConTeXt.hs+12
pandoc.cabal+2
@@ -341,6 +341,8 @@ Executable test-pandoc
341341 Extensions: CPP
342342 Build-Depends: base >= 4 && < 5, Diff, test-framework >= 0.3 && < 0.4,
343343 test-framework-hunit >= 0.2 && < 0.3,
344+ test-framework-quickcheck2 >= 0.2 && < 0.3,
345+ QuickCheck >= 2.3,
344346 HUnit >= 1.2 && < 1.3,
345347 template-haskell == 2.4.*
346348 Other-Modules: Tests.Old
tests/Tests/Helpers.hs+14−2
@@ -1,17 +1,26 @@
11{-# LANGUAGE TypeSynonymInstances, FlexibleInstances, TemplateHaskell #-}
22-- Utility functions for the test suite.
33
4−module Tests.Helpers where
4+module Tests.Helpers ( lit
5+ , test
6+ , (=?>)
7+ , property
8+ , ToString(..)
9+ , ToPandoc(..)
10+ )
11+ where
512
613import Text.Pandoc.Definition
714import Text.Pandoc.Builder (Inlines, Blocks, doc, plain)
815import Test.Framework
916import Test.Framework.Providers.HUnit
10−import Test.HUnit hiding (Test)
17+import Test.Framework.Providers.QuickCheck2
18+import Test.HUnit (assertBool)
1119import Text.Pandoc.Shared (normalize, defaultWriterOptions,
1220 WriterOptions(..), removeTrailingSpace)
1321import Text.Pandoc.Writers.Native (writeNative)
1422import Language.Haskell.TH.Quote
23+import qualified Test.QuickCheck.Property as QP
1524
1625lit :: QuasiQuoter
1726lit = QuasiQuoter ((\a -> let b = rnl a in [|b|]) . filter (/= '\r')) $
@@ -37,6 +46,9 @@ test fn name (input, expected) =
3746 dashes x = '\n' : replicate (72 - length x - 5) '-' ++ " " ++
3847 x ++ " ---\n"
3948
49+property :: QP.Testable a => TestName -> a -> Test
50+property = testProperty
51+
4052infix 6 =?>
4153(=?>) :: a -> b -> (a,b)
4254x =?> y = (x, y)
tests/Tests/Readers/LaTeX.hs+1
@@ -4,6 +4,7 @@ module Tests.Readers.LaTeX (tests) where
44import Text.Pandoc.Definition
55import Test.Framework
66import Tests.Helpers
7+import Tests.Arbitrary
78import Text.Pandoc.Builder
89import Text.Pandoc
910
tests/Tests/Writers/ConTeXt.hs+12
@@ -5,10 +5,15 @@ import Test.Framework
55import Text.Pandoc.Builder
66import Text.Pandoc
77import Tests.Helpers
8+import Tests.Arbitrary()
89
910context :: (ToString a, ToPandoc a) => a -> String
1011context = writeConTeXt defaultWriterOptions . toPandoc
1112
13+context' :: (ToString a, ToPandoc a) => a -> String
14+context' = writeConTeXt defaultWriterOptions{ writerWrapText = False }
15+ . toPandoc
16+
1217{-
1318 "my test" =: X =?> Y
1419
@@ -30,10 +35,17 @@ tests :: [Test]
3035tests = [ testGroup "inline code"
3136 [ "with '}'" =: code "}" =?> "\\mono{\\letterclosebrace{}}"
3237 , "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 ++ "}"
3343 ]
3444 , testGroup "headers"
3545 [ "level 1" =:
3646 header 1 "My header" =?> "\\subject{My header}"
47+ , property "header 1 property" $ \ils ->
48+ context' (header 1 ils) == "\\subject{" ++ context' ils ++ "}"
3749 ]
3850 , testGroup "bullet lists"
3951 [ "nested" =: