git.iko.soy/typeable/pandoc
on master help sign in
Added some basic testing infrastructure and some latex reader tests.
commitec4deb25327cd525d188093918330149d0ead4e7 authorNathan Gass <gass@search.ch> dateWed 12 Jan 2011, 14:16 (16 years ago) parent4f6099f
4 files changed+79−1
pandoc.cabal+4−1 tests/Helpers.hs+37 tests/Latex/Reader.hs+35 tests/test-pandoc.hs+3
pandoc.cabal+4−1
@@ -298,7 +298,10 @@ Executable test-pandoc
298298 if !flag(tests)
299299 Buildable: False
300300 else
301− Ghc-Options: -Wall
301+ if impl(ghc >= 6.12)
302+ Ghc-Options: -O2 -Wall -fno-warn-unused-do-bind
303+ else
304+ Ghc-Options: -O2 -Wall
302305 Extensions: CPP
303306 Build-Depends: base >= 4 && < 5, Diff, test-framework, test-framework-hunit, HUnit
304307 Other-Modules: Text.Pandoc.Shared, Text.Pandoc.Highlighting, Text.Pandoc.Writers.Native
tests/Helpers.hsnew file+37
@@ -0,0 +1,37 @@
1+module Helpers where
2+
3+import Text.Pandoc
4+
5+import Test.Framework
6+import Test.Framework.Providers.HUnit
7+import Test.HUnit hiding (Test)
8+
9+data Expect = Inline Inline
10+ | Inlines [Inline]
11+ | Block Block
12+ | Blocks [Block]
13+
14+assertPandoc :: Expect -> Pandoc -> Assertion
15+assertPandoc (Inline e) (Pandoc _ [Para [g]]) = e @=? g
16+assertPandoc (Inlines e) (Pandoc _ [Para g] ) = e @=? g
17+assertPandoc (Block e) (Pandoc _ [g] ) = e @=? g
18+assertPandoc (Blocks e) (Pandoc _ g ) = e @=? g
19+assertPandoc _ _ = assertFailure "Wrong structur of Pandoc document."
20+
21+latexTest :: String-> String -> Expect -> Test
22+latexTest = latexTestWithState defaultParserState
23+
24+latexTestWithState :: ParserState -> String -> String -> Expect -> Test
25+latexTestWithState state name string exp = testCase name $ exp `assertPandoc` readLaTeX state string
26+
27+blocks :: [Block] -> Pandoc
28+blocks bs = Pandoc (Meta { docTitle = [], docAuthors = [], docDate = [] }) bs
29+
30+block :: Block -> Pandoc
31+block b = blocks [b]
32+
33+inlines :: [Inline] -> Pandoc
34+inlines is = block $ Para is
35+
36+inline :: Inline -> Pandoc
37+inline i = inlines [i]
tests/Latex/Reader.hsnew file+35
@@ -0,0 +1,35 @@
1+module Latex.Reader (tests) where
2+
3+import Text.Pandoc.Definition
4+
5+import Test.Framework
6+import Helpers
7+
8+tests :: [Test]
9+tests = [ testGroup "basic" [ latexTest "simplest" "word"
10+ (Inline $ Str "word")
11+
12+ , latexTest "space" "some text"
13+ (Inlines $ [Str "some", Space, Str "text"])
14+
15+ , latexTest "emphasis" "\\emph{emphasized}"
16+ (Inline $ Emph [Str "emphasized"])
17+ ]
18+
19+ , testGroup "headers" [ latexTest "1. level" "\\section{header}"
20+ $ Block $ Header 1 [Str "header"]
21+
22+ , latexTest "2. level" "\\subsection{header}"
23+ $ Block $ Header 2 [Str "header"]
24+
25+ , latexTest "3. level" "\\subsubsection{header}"
26+ $ Block $ Header 3 [Str "header"]
27+
28+ , latexTest "with emphasis" "\\section{text \\emph{emph}}"
29+ $ Block $ Header 1 [Str "text", Space, Emph [Str "emph"]]
30+
31+ , latexTest "with link" "\\section{text \\href{/url}{link}}"
32+ $ Block $ Header 1 [Str "text", Space, Link [Str "link"] ("/url", "")]
33+ ]
34+ ]
35+
tests/test-pandoc.hs+3
@@ -5,9 +5,12 @@ module Main where
55import Test.Framework
66
77import qualified Old
8+import qualified Latex.Reader
89
910tests :: [Test]
1011tests = [ testGroup "Old" Old.tests
12+ , testGroup "Latex" [ testGroup "Reader" Latex.Reader.tests
13+ ]
1114 ]
1215
1316main :: IO ()