git.iko.soy/typeable/pandoc
on master help sign in
Adjusted source to 80-column limit.
75e8ab2John MacFarlane
tests/Tests/Helpers.hs+2
@@ -1,3 +1,5 @@
1+-- Utility functions for the test suite.
2+
1module Tests.Helpers where
3module Tests.Helpers where
2
4
3import Text.Pandoc
5import Text.Pandoc
tests/Tests/Old.hs+83−59
@@ -1,4 +1,3 @@
1−
2module Tests.Old (tests) where
1module Tests.Old (tests) where
3
2
4import Test.Framework (testGroup, Test )
3import Test.Framework (testGroup, Test )
@@ -46,51 +45,62 @@ showDiff (l,r) ((B, _ ) : ds) =
46 showDiff (l+1,r+1) ds
45 showDiff (l+1,r+1) ds
47
46
48tests :: [Test]
47tests :: [Test]
48+tests = [ testGroup "markdown"
49+ [ testGroup "writer"
49−tests = [ testGroup "markdown" [ testGroup "writer" (writerTests "markdown" ++ lhsWriterTests "markdown")
50+ $ writerTests "markdown" ++ lhsWriterTests "markdown"
51+ , testGroup "reader"
50− , testGroup "reader" [ test "basic" ["-r", "markdown", "-w", "native", "-s", "-S"]
52+ [ test "basic" ["-r", "markdown", "-w", "native", "-s", "-S"]
51− "testsuite.txt" "testsuite.native"
53+ "testsuite.txt" "testsuite.native"
52− , test "tables" ["-r", "markdown", "-w", "native", "--columns=80"]
54+ , test "tables" ["-r", "markdown", "-w", "native", "--columns=80"]
53− "tables.txt" "tables.native"
55+ "tables.txt" "tables.native"
54− , test "more" ["-r", "markdown", "-w", "native", "-S"]
56+ , test "more" ["-r", "markdown", "-w", "native", "-S"]
55− "markdown-reader-more.txt" "markdown-reader-more.native"
57+ "markdown-reader-more.txt" "markdown-reader-more.native"
56− , lhsReaderTest "markdown+lhs"
58+ , lhsReaderTest "markdown+lhs"
57− ]
59+ ]
58− , testGroup "citations" markdownCitationTests
60+ , testGroup "citations" markdownCitationTests
59− ]
61+ ]
62+ , testGroup "rst"
60− , testGroup "rst" [ testGroup "writer" (writerTests "rst" ++ lhsWriterTests "rst")
63+ [ testGroup "writer" (writerTests "rst" ++ lhsWriterTests "rst")
64+ , testGroup "reader"
61− , testGroup "reader" [ test "basic" ["-r", "rst", "-w", "native", "-s", "-S", "--columns=80"]
65+ [ test "basic" ["-r", "rst", "-w", "native",
62− "rst-reader.rst" "rst-reader.native"
66+ "-s", "-S", "--columns=80"] "rst-reader.rst" "rst-reader.native"
63− , test "tables" ["-r", "rst", "-w", "native", "--columns=80"]
67+ , test "tables" ["-r", "rst", "-w", "native", "--columns=80"]
64− "tables.rst" "tables-rstsubset.native"
68+ "tables.rst" "tables-rstsubset.native"
65− , lhsReaderTest "rst+lhs"
69+ , lhsReaderTest "rst+lhs"
66− ]
70+ ]
67− ]
71+ ]
72+ , testGroup "latex"
68− , testGroup "latex" [ testGroup "writer" (writerTests "latex" ++ lhsWriterTests "latex")
73+ [ testGroup "writer" (writerTests "latex" ++ lhsWriterTests "latex")
74+ , testGroup "reader"
69− , testGroup "reader" [ test "basic" ["-r", "latex", "-w", "native", "-s", "-R"]
75+ [ test "basic" ["-r", "latex", "-w", "native", "-s", "-R"]
70− "latex-reader.latex" "latex-reader.native"
76+ "latex-reader.latex" "latex-reader.native"
71− , lhsReaderTest "latex+lhs"
77+ , lhsReaderTest "latex+lhs"
72− ]
78+ ]
73− , latexCitationTests "biblatex"
79+ , latexCitationTests "biblatex"
74− , latexCitationTests "natbib"
80+ , latexCitationTests "natbib"
75− ]
81+ ]
82+ , testGroup "html"
76− , testGroup "html" [ testGroup "writer" (writerTests "html" ++ lhsWriterTests "html")
83+ [ testGroup "writer" (writerTests "html" ++ lhsWriterTests "html")
77− , test "reader" ["-r", "html", "-w", "native", "-s"]
84+ , test "reader" ["-r", "html", "-w", "native", "-s"]
78− "html-reader.html" "html-reader.native"
85+ "html-reader.html" "html-reader.native"
79− ]
86+ ]
87+ , testGroup "s5"
80− , testGroup "s5" [ s5WriterTest "basic" ["-s"] "s5"
88+ [ s5WriterTest "basic" ["-s"] "s5"
81− , s5WriterTest "fancy" ["-s","-m","-i"] "s5"
89+ , s5WriterTest "fancy" ["-s","-m","-i"] "s5"
82− , s5WriterTest "fragment" [] "html"
90+ , s5WriterTest "fragment" [] "html"
83− , s5WriterTest "inserts" ["-s", "-H", "insert",
91+ , s5WriterTest "inserts" ["-s", "-H", "insert",
84− "-B", "insert", "-A", "insert", "-c", "main.css"] "html"
92+ "-B", "insert", "-A", "insert", "-c", "main.css"] "html"
85− ]
93+ ]
94+ , testGroup "textile"
86− , testGroup "textile" [ testGroup "writer" $ writerTests "textile"
95+ [ testGroup "writer" $ writerTests "textile"
87− , test "reader" ["-r", "textile", "-w", "native", "-s"]
96+ , test "reader" ["-r", "textile", "-w", "native", "-s"]
88− "textile-reader.textile" "textile-reader.native"
97+ "textile-reader.textile" "textile-reader.native"
89− ]
98+ ]
99+ , testGroup "native"
90− , testGroup "native" [ testGroup "writer" $ writerTests "native"
100+ [ testGroup "writer" $ writerTests "native"
91− , test "reader" ["-r", "native", "-w", "native", "-s"]
101+ , test "reader" ["-r", "native", "-w", "native", "-s"]
92− "testsuite.native" "testsuite.native"
102+ "testsuite.native" "testsuite.native"
93− ]
103+ ]
94 , testGroup "other writers" $ map (\f -> testGroup f $ writerTests f)
104 , testGroup "other writers" $ map (\f -> testGroup f $ writerTests f)
95 [ "docbook", "opendocument" , "context" , "texinfo"
105 [ "docbook", "opendocument" , "context" , "texinfo"
96 , "man" , "plain" , "mediawiki", "rtf", "org"
106 , "man" , "plain" , "mediawiki", "rtf", "org"
@@ -108,26 +118,31 @@ lhsWriterTests format
108 , t "lhs to lhs" (format ++ "+lhs")
118 , t "lhs to lhs" (format ++ "+lhs")
109 ]
119 ]
110 where
120 where
111− t n f = test n ["--columns=78", "-r", "native", "-s", "-w", f] "lhs-test.native" ("lhs-test" <.> ext f)
121+ t n f = test n ["--columns=78", "-r", "native", "-s", "-w", f]
122+ "lhs-test.native" ("lhs-test" <.> ext f)
112 ext f = if null languages && format == "html"
123 ext f = if null languages && format == "html"
113 then "nohl" <.> f
124 then "nohl" <.> f
114 else f
125 else f
115
126
116lhsReaderTest :: String -> Test
127lhsReaderTest :: String -> Test
117lhsReaderTest format =
128lhsReaderTest format =
118− testWithNormalize normalizer "lhs" ["-r", format, "-w", "native"] ("lhs-test" <.> format) "lhs-test.native"
129+ testWithNormalize normalizer "lhs" ["-r", format, "-w", "native"]
130+ ("lhs-test" <.> format) "lhs-test.native"
119 where normalizer = writeNative defaultWriterOptions . normalize . read
131 where normalizer = writeNative defaultWriterOptions . normalize . read
120
132
121latexCitationTests :: String -> Test
133latexCitationTests :: String -> Test
122latexCitationTests n
134latexCitationTests n
123 = testGroup (n ++ " citations")
135 = testGroup (n ++ " citations")
136+ [ t ("latex reader (" ++ n ++ " citations)")
124− [ t ("latex reader (" ++ n ++ " citations)") (["-r", "latex", "-w", "markdown", "-s", "--no-wrap"] ++ o)
137+ (["-r", "latex", "-w", "markdown", "-s", "--no-wrap"] ++ o)
125 f "markdown-citations.txt"
138 f "markdown-citations.txt"
139+ , t ("latex writer (" ++ n ++ " citations)")
126− , t ("latex writer (" ++ n ++ " citations)") (["-r", "markdown", "-w", "latex", "-s", "--no-wrap"] ++ o)
140+ (["-r", "markdown", "-w", "latex", "-s", "--no-wrap"] ++ o)
127 "markdown-citations.txt" f
141 "markdown-citations.txt" f
128 ]
142 ]
129 where
143 where
130− o = ["--bibliography", "biblio.bib", "--csl", "chicago-author-date.csl", "--no-citeproc", "--" ++ n]
144+ o = ["--bibliography", "biblio.bib", "--csl", "chicago-author-date.csl",
145+ "--no-citeproc", "--" ++ n]
131 f = n ++ "-citations.latex"
146 f = n ++ "-citations.latex"
132 normalizer = substitute "\160" " " . substitute "\8211" "-"
147 normalizer = substitute "\160" " " . substitute "\8211" "-"
133 t = testWithNormalize normalizer
148 t = testWithNormalize normalizer
@@ -142,18 +157,22 @@ writerTests format
142
157
143s5WriterTest :: String -> [String] -> String -> Test
158s5WriterTest :: String -> [String] -> String -> Test
144s5WriterTest modifier opts format
159s5WriterTest modifier opts format
145− = test (format ++ " writer (" ++ modifier ++ ")") (["-r", "native", "-w", format] ++ opts)
160+ = test (format ++ " writer (" ++ modifier ++ ")")
161+ (["-r", "native", "-w", format] ++ opts)
146 "s5.native" ("s5." ++ modifier <.> "html")
162 "s5.native" ("s5." ++ modifier <.> "html")
147
163
148markdownCitationTests :: [Test]
164markdownCitationTests :: [Test]
149markdownCitationTests
165markdownCitationTests
150 = map styleToTest ["chicago-author-date","ieee","mhra"]
166 = map styleToTest ["chicago-author-date","ieee","mhra"]
151− ++ [test "no-citeproc" wopts "markdown-citations.txt" "markdown-citations.txt"]
167+ ++ [test "no-citeproc" wopts "markdown-citations.txt"
168+ "markdown-citations.txt"]
152 where
169 where
153− ropts = ["-r", "markdown", "-w", "markdown", "--bibliography", "biblio.bib", "--no-wrap"]
170+ ropts = ["-r", "markdown", "-w", "markdown", "--bibliography",
171+ "biblio.bib", "--no-wrap"]
154 wopts = ropts ++ ["--no-citeproc"]
172 wopts = ropts ++ ["--no-citeproc"]
155 styleToTest style = test style (ropts ++ ["--csl", style ++ ".csl"])
173 styleToTest style = test style (ropts ++ ["--csl", style ++ ".csl"])
174+ "markdown-citations.txt"
156− "markdown-citations.txt" ("markdown-citations." ++ style ++ ".txt")
175+ ("markdown-citations." ++ style ++ ".txt")
157
176
158-- | Run a test without normalize function, return True if test passed.
177-- | Run a test without normalize function, return True if test passed.
159test :: String -- ^ Title of test
178test :: String -- ^ Title of test
@@ -177,16 +196,21 @@ testWithNormalize normalizer testname opts inp norm = testCase testname $ do
177 let options = ["--data-dir", ".."] ++ [inpPath] ++ opts
196 let options = ["--data-dir", ".."] ++ [inpPath] ++ opts
178 let cmd = pandocPath ++ " " ++ unwords options
197 let cmd = pandocPath ++ " " ++ unwords options
179 ph <- runProcess pandocPath options Nothing
198 ph <- runProcess pandocPath options Nothing
180− (Just [("LANG","en_US.UTF-8"),("HOME", "./")]) Nothing (Just hOut) (Just stderr)
199+ (Just [("LANG","en_US.UTF-8"),("HOME", "./")]) Nothing (Just hOut)
200+ (Just stderr)
181 ec <- waitForProcess ph
201 ec <- waitForProcess ph
182 result <- if ec == ExitSuccess
202 result <- if ec == ExitSuccess
183 then do
203 then do
184 -- filter \r so the tests will work on Windows machines
204 -- filter \r so the tests will work on Windows machines
185− outputContents <- readFile' outputPath >>= return . filter (/='\r') . normalizer
205+ outputContents <- readFile' outputPath >>=
206+ return . filter (/='\r') . normalizer
186− normContents <- readFile' normPath >>= return . filter (/='\r') . normalizer
207+ normContents <- readFile' normPath >>=
208+ return . filter (/='\r') . normalizer
187 if outputContents == normContents
209 if outputContents == normContents
188 then return TestPassed
210 then return TestPassed
211+ else return
212+ $ TestFailed cmd normPath
189− else return $ TestFailed cmd normPath $ getDiff (lines outputContents) (lines normContents)
213+ $ getDiff (lines outputContents) (lines normContents)
190 else return $ TestError ec
214 else return $ TestError ec
191 removeFile outputPath
215 removeFile outputPath
192 assertBool (show result) (result == TestPassed)
216 assertBool (show result) (result == TestPassed)
tests/Tests/Readers/LaTeX.hs+26−25
@@ -6,30 +6,31 @@ import Test.Framework
6import Tests.Helpers
6import Tests.Helpers
7
7
8tests :: [Test]
8tests :: [Test]
9−tests = [ testGroup "basic" [ latexTest "simplest" "word"
9+tests = [ testGroup "basic"
10− (Inline $ Str "word")
10+ [ latexTest "simplest" "word" (Inline $ Str "word")
11−
12− , latexTest "space" "some text"
11+ , latexTest "space" "some text"
13− (Inlines $ [Str "some", Space, Str "text"])
12+ (Inlines $ [Str "some", Space, Str "text"])
14−
13+
15− , latexTest "emphasis" "\\emph{emphasized}"
14+ , latexTest "emphasis" "\\emph{emphasized}"
16− (Inline $ Emph [Str "emphasized"])
15+ (Inline $ Emph [Str "emphasized"])
17− ]
16+ ]
18−
17+
18+ , testGroup "headers"
19− , testGroup "headers" [ latexTest "1. level" "\\section{header}"
19+ [ latexTest "1. level" "\\section{header}"
20− $ Block $ Header 1 [Str "header"]
20+ $ Block $ Header 1 [Str "header"]
21−
21+
22− , latexTest "2. level" "\\subsection{header}"
22+ , latexTest "2. level" "\\subsection{header}"
23− $ Block $ Header 2 [Str "header"]
23+ $ Block $ Header 2 [Str "header"]
24−
24+
25− , latexTest "3. level" "\\subsubsection{header}"
25+ , latexTest "3. level" "\\subsubsection{header}"
26− $ Block $ Header 3 [Str "header"]
26+ $ Block $ Header 3 [Str "header"]
27−
27+
28− , latexTest "with emphasis" "\\section{text \\emph{emph}}"
28+ , latexTest "with emphasis" "\\section{text \\emph{emph}}"
29− $ Block $ Header 1 [Str "text", Space, Emph [Str "emph"]]
29+ $ Block $ Header 1 [Str "text", Space, Emph [Str "emph"]]
30−
30+
31− , latexTest "with link" "\\section{text \\href{/url}{link}}"
31+ , latexTest "with link" "\\section{text \\href{/url}{link}}"
32+ $ Block
32− $ Block $ Header 1 [Str "text", Space, Link [Str "link"] ("/url", "")]
33+ $ Header 1 [Str "text", Space, Link [Str "link"] ("/url", "")]
33− ]
34+ ]
34 ]
35 ]
35
36