@@ -0,0 +1,273 @@
1+{-# LANGUAGE OverloadedStrings #-}
2+module Tests.Readers.Creole (tests) where
3+
4+import Data.Text (Text)
5+import qualified Data.Text as T
6+import Test.Tasty
7+import Tests.Helpers
8+import Text.Pandoc
9+import Text.Pandoc.Arbitrary ()
10+import Text.Pandoc.Builder
11+
12+creole :: Text -> Pandoc
13+creole = purely $ readCreole def{ readerStandalone = True }
14+
15+infix 4 =:
16+(=:) :: ToString c
17+ => String -> (Text, c) -> TestTree
18+(=:) = test creole
19+
20+tests :: [TestTree]
21+tests = [
22+ testGroup "Basic Text Formatting" [
23+ "bold, single line, fully delimited" =:
24+ "only **bold** is bold"
25+ =?> para ("only " <> strong "bold" <> " is bold")
26+ , "italics, single line, fully delimited" =:
27+ "only //this// is in italics"
28+ =?> para ("only " <> emph "this" <> " is in italics")
29+ , "bold in italics, fully delimited" =:
30+ "//**this**// is in bold italics"
31+ =?> para (emph (strong "this") <> " is in bold italics")
32+ , "italics in bold, fully delimited" =:
33+ "**//this//** is in bold italics"
34+ =?> para (strong (emph "this") <> " is in bold italics")
35+
36+ , "escape bold marker" =:
37+ "~**not bold" =?> para "**not bold"
38+ , "escape italics marker" =:
39+ "~//not in italics" =?> para "//not in italics"
40+
41+ , "inline nowiki, simple" =:
42+ "this is {{{**not** ~interpreted}}} at all"
43+ =?> para ("this is " <> code "**not** ~interpreted" <> " at all")
44+ , "inline nowiki, curly braces inside" =:
45+ "this is {{{{{{//including// some `}' chars}}}}}}"
46+ =?> para ("this is " <> code "{{{//including// some `}' chars}}}")
47+
48+ , "placeholder" =:
49+ "foo <<<place holder>>> bar"
50+ =?> para "foo bar"
51+ , "placeholder escaped" =:
52+ "foo ~<<<no place holder>>> bar"
53+ =?> para "foo <<<no place holder>>> bar"
54+ ]
55+ , testGroup "Headers" [
56+ "header level 1, no space, no trailing =" =:
57+ "= Top-Level Header"
58+ =?> header 1 (str "Top-Level Header")
59+ , "header level 1, leading space, trailing =" =:
60+ " = Top-Level Header = "
61+ =?> header 1 (str "Top-Level Header")
62+ , "header level 2, no space, no trailing =" =:
63+ "== Second Level"
64+ =?> header 2 (str "Second Level")
65+ , "header level 2, leading space, no trailing =" =:
66+ " == Second Level"
67+ =?> header 2 (str "Second Level")
68+ , "header level 3, no space, no trailing =" =:
69+ "=== Third"
70+ =?> header 3 (str "Third")
71+ , "header level 3, no space, > 3 trailing =" =:
72+ "=== Third ======="
73+ =?> header 3 (str "Third")
74+ , "header level 4, no space, no trailing =" =:
75+ "==== Fourth Level Heading"
76+ =?> header 4 (str "Fourth Level Heading")
77+ , "header level 4, no space, < 4 trailing =" =:
78+ "==== Fourth Level Heading =="
79+ =?> header 4 (str "Fourth Level Heading")
80+ , "header level 5, no space, no trailing =" =:
81+ "===== Fifth"
82+ =?> header 5 (str "Fifth")
83+ , "header level 6, no space, no trailing =" =:
84+ "====== Sixth"
85+ =?> header 6 (str "Sixth")
86+ ]
87+ , testGroup "Paragraphs" [
88+ "paragraphs: multiple, one line" =:
89+ "first line\n\nanother line\n"
90+ =?> para "first line" <> para "another line"
91+ ]
92+ , testGroup "Lists" [
93+ "unordered list, two entries, one separating space" =:
94+ "* foo\n* bar"
95+ =?> bulletList [ plain "foo", plain "bar" ]
96+ , "unordered list, three entries, one separating space" =:
97+ "* foo\n* bar\n* baz"
98+ =?> bulletList [ plain "foo", plain "bar", plain "baz" ]
99+ , "para followed by, unordered list, two entries, one separating space" =:
100+ "blubber\n* foo\n* bar"
101+ =?> para "blubber" <> bulletList [ plain "foo", plain "bar" ]
102+ , "nested unordered list, one separating space" =:
103+ "* foo\n** bar\n** baz\n* blubb"
104+ =?> bulletList [ plain "foo"
105+ <> bulletList [ plain "bar", plain "baz" ]
106+ , plain "blubb" ]
107+ , "nested many unordered lists, one separating space" =:
108+ ("* foo\n** bar\n*** third\n*** third two\n** baz\n*** third again\n"
109+ <> "**** fourth\n***** fith\n* blubb")
110+ =?> bulletList [ plain "foo"
111+ <> bulletList [ plain "bar"
112+ <> bulletList [ plain "third"
113+ , plain "third two"]
114+ , plain "baz"
115+ <> bulletList [ plain "third again"
116+ <> bulletList [
117+ plain "fourth"
118+ <> bulletList [
119+ plain "fith"
120+ ]
121+ ]
122+ ]
123+ ]
124+ , plain "blubb" ]
125+ , "nested unordered list, mixed separating space" =:
126+ "*foo\n ** bar\n **baz\n * blubb"
127+ =?> bulletList [ plain "foo"
128+ <> bulletList [ plain "bar", plain "baz" ]
129+ , plain "blubb" ]
130+ , "ordered list, two entries, one separating space" =:
131+ "# foo\n# bar"
132+ =?> orderedList [ plain "foo", plain "bar" ]
133+ , "ordered list, three entries, one separating space" =:
134+ "# foo\n# bar\n# baz"
135+ =?> orderedList [ plain "foo", plain "bar", plain "baz" ]
136+ , "para followed by, ordered list, two entries, one separating space" =:
137+ "blubber\n# foo\n# bar"
138+ =?> para "blubber" <> orderedList [ plain "foo", plain "bar" ]
139+ , "nested ordered list, one separating space" =:
140+ "# foo\n## bar\n## baz\n# blubb"
141+ =?> orderedList [ plain "foo"
142+ <> orderedList [ plain "bar", plain "baz" ]
143+ , plain "blubb" ]
144+ , "nested many ordered lists, one separating space" =:
145+ ("# foo\n## bar\n### third\n### third two\n## baz\n### third again\n"
146+ <> "#### fourth\n##### fith\n# blubb")
147+ =?> orderedList [ plain "foo"
148+ <> orderedList [ plain "bar"
149+ <> orderedList [ plain "third"
150+ , plain "third two"]
151+ , plain "baz"
152+ <> orderedList [ plain "third again"
153+ <> orderedList [
154+ plain "fourth"
155+ <> orderedList [
156+ plain "fith"
157+ ]
158+ ]
159+ ]
160+ ]
161+ , plain "blubb" ]
162+ , "nested ordered list, mixed separating space" =:
163+ "#foo\n ## bar\n ##baz\n # blubb"
164+ =?> orderedList [ plain "foo"
165+ <> orderedList [ plain "bar", plain "baz" ]
166+ , plain "blubb" ]
167+ , "mixed nested ordered and unordered lists, one separating space" =:
168+ ("# foo\n** bar\n### third\n### third two\n** baz\n### third again\n"
169+ <> "#### fourth\n***** fith\n# blubb")
170+ =?> orderedList [ plain "foo"
171+ <> bulletList [ plain "bar"
172+ <> orderedList [ plain "third"
173+ , plain "third two"]
174+ , plain "baz"
175+ <> orderedList [ plain "third again"
176+ <> orderedList [
177+ plain "fourth"
178+ <> bulletList [
179+ plain "fith"
180+ ]
181+ ]
182+ ]
183+ ]
184+ , plain "blubb" ]
185+ ]
186+ , testGroup "NoWiki" [
187+ "quoted block, simple" =:
188+ "{{{\nfoo bar\n //baz//\n}}}"
189+ =?> codeBlock "foo bar\n //baz//"
190+ , "quoted block, curly bracket exception" =:
191+ "{{{\nfoo bar\n }}}\nbaz\n }}}\n}}}"
192+ =?> codeBlock "foo bar\n }}}\nbaz\n}}}"
193+ , "forced line breaks" =:
194+ "{{{no break!\\\\here}}} but a break\\\\here!"
195+ =?> para (code "no break!\\\\here" <> " but a break"
196+ <> linebreak <> "here!")
197+ ]
198+ , testGroup "Images and Links" [
199+ "image simple" =:
200+ "{{foo.png}}" =?> para (image "foo.png" "" (str ""))
201+ , "image with alt text" =:
202+ "Image of a bar: {{/path/to/bar.png|A Bar}} look at it!"
203+ =?> para ("Image of a bar: "
204+ <> image "/path/to/bar.png" "" (str "A Bar") <> " look at it!")
205+
206+ , "auto link" =:
207+ "foo http://foo.example.com/bar/baz.html bar"
208+ =?> para ("foo "
209+ <> link "http://foo.example.com/bar/baz.html" ""
210+ (str "http://foo.example.com/bar/baz.html")
211+ <> " bar")
212+ , "escaped auto link" =:
213+ "foo ~http://foo.example.com/bar/baz.html bar"
214+ =?> para ("foo http://foo.example.com/bar/baz.html bar")
215+ , "wiki link simple" =:
216+ "foo [[http://foo.example.com/foo.png]] bar"
217+ =?> para ("foo "
218+ <> link "http://foo.example.com/foo.png" ""
219+ (str "http://foo.example.com/foo.png")
220+ <> " bar")
221+ , "wiki link with name" =:
222+ "foo [[http://foo.example.com/foo.png|my link]] bar"
223+ =?> para ("foo "
224+ <> link "http://foo.example.com/foo.png" ""
225+ (str "my link")
226+ <> " bar")
227+ , "image link" =:
228+ "[[http://foo.example.com/|{{foo.png}}]]"
229+ =?> para (link "http://foo.example.com/" "" (image "foo.png" "" (str "")))
230+ ]
231+ , testGroup "Table" [
232+ "Table with Header" =:
233+ T.unlines [ "|= Foo |= Bar |= Baz |"
234+ , "| One | Two | Three |"
235+ , "| 1 | 2 | 3 |"
236+ , "| A | B | C |"
237+ ]
238+ =?> simpleTable
239+ [plain "Foo", plain "Bar" , plain "Baz"]
240+ [[plain "One", plain "Two" , plain "Three"]
241+ ,[plain "1", plain "2" , plain "3"]
242+ ,[plain "A", plain "B" , plain "C"]]
243+ , "Table without Header" =:
244+ T.unlines [ "| One | Two | Three |"
245+ , "| 1 | 2 | 3 |"
246+ , "| A | B | C |"
247+ ]
248+ =?> simpleTable [mempty]
249+ [[plain "One", plain "Two" , plain "Three"]
250+ ,[plain "1", plain "2" , plain "3"]
251+ ,[plain "A", plain "B" , plain "C"]]
252+ , "Table without Header, no markers at line ends" =:
253+ T.unlines [ "| One | Two | Three"
254+ , "| 1 | 2 | 3"
255+ , "| A | B | C "
256+ ]
257+ =?> simpleTable [mempty]
258+ [[plain "One", plain "Two" , plain "Three"]
259+ ,[plain "1", plain "2" , plain "3"]
260+ ,[plain "A", plain "B" , plain "C"]]
261+ , "Table with Header, with formatting" =:
262+ T.unlines [ "|= **Foo** |= **Bar** |= **Baz** |"
263+ , "|//one// element |//second// elt|Three |"
264+ , "| {{{1}}} | {{{{}}}} | [[link]] |"
265+ ]
266+ =?> simpleTable
267+ [plain $ strong "Foo", plain $ strong "Bar" , plain $ strong "Baz"]
268+ [[plain (emph "one" <> " element"), plain (emph "second" <> " elt")
269+ ,plain "Three"]
270+ ,[plain $ code "1", plain $ code "{}"
271+ ,plain $ link "link" "" (str "link")]]
272+ ]
273+ ]