1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{- |
Module : Tests.Readers.Org.Block.Header
Copyright : © 2014-2020 Albert Krewinkel
License : GNU GPL, version 2 or above
Maintainer : Albert Krewinkel <albert@zeitkraut.de>
Stability : alpha
Portability : portable
Test parsing of org header blocks.
-}
module Tests.Readers.Org.Block.Header (tests) where
import Prelude
import Test.Tasty (TestTree, testGroup)
import Tests.Helpers ((=?>))
import Tests.Readers.Org.Shared ((=:), spcSep, tagSpan)
import Text.Pandoc.Builder
import qualified Data.Text as T
tests :: [TestTree]
tests =
[ "First Level Header" =:
"* Headline\n" =?>
headerWith ("headline", [], []) 1 "Headline"
, "Third Level Header" =:
"*** Third Level Headline\n" =?>
headerWith ("third-level-headline", [], [])
3
("Third" <> space <> "Level" <> space <> "Headline")
, "Compact Headers with Paragraph" =:
T.unlines [ "* First Level"
, "** Second Level"
, " Text"
] =?>
mconcat [ headerWith ("first-level", [], [])
1
("First" <> space <> "Level")
, headerWith ("second-level", [], [])
2
("Second" <> space <> "Level")
, para "Text"
]
, "Separated Headers with Paragraph" =:
T.unlines [ "* First Level"
, ""
, "** Second Level"
, ""
, " Text"
] =?>
mconcat [ headerWith ("first-level", [], [])
1
("First" <> space <> "Level")
, headerWith ("second-level", [], [])
2
("Second" <> space <> "Level")
, para "Text"
]
, "Headers not preceded by a blank line" =:
T.unlines [ "** eat dinner"
, "Spaghetti and meatballs tonight."
, "** walk dog"
] =?>
mconcat [ headerWith ("eat-dinner", [], [])
2
("eat" <> space <> "dinner")
, para $ spcSep [ "Spaghetti", "and", "meatballs", "tonight." ]
, headerWith ("walk-dog", [], [])
2
("walk" <> space <> "dog")
]
, testGroup "Todo keywords"
[ "Header with known todo keyword" =:
"* TODO header" =?>
let todoSpan = spanWith ("", ["todo", "TODO"], []) "TODO"
in headerWith ("header", [], []) 1 (todoSpan <> space <> "header")
, "Header marked as done" =:
"* DONE header" =?>
let todoSpan = spanWith ("", ["done", "DONE"], []) "DONE"
in headerWith ("header", [], []) 1 (todoSpan <> space <> "header")
, "emphasis in first word" =:
"** TODO /fix/ this" =?>
let todoSpan = spanWith ("", ["todo", "TODO"], []) "TODO"
in headerWith ("fix-this", [], [])
2
(todoSpan <> space <> emph "fix" <> space <> "this")
, "Header with unknown todo keyword" =:
"* WAITING header" =?>
headerWith ("waiting-header", [], []) 1 "WAITING header"
, "Custom todo keywords" =:
T.unlines [ "#+TODO: WAITING CANCELLED"
, "* WAITING compile"
, "* CANCELLED lunch"
] =?>
let todoSpan = spanWith ("", ["todo", "WAITING"], []) "WAITING"
doneSpan = spanWith ("", ["done", "CANCELLED"], []) "CANCELLED"
in headerWith ("compile", [], []) 1 (todoSpan <> space <> "compile")
<> headerWith ("lunch", [], []) 1 (doneSpan <> space <> "lunch")
, "Custom todo keywords with multiple done-states" =:
T.unlines [ "#+TODO: WAITING | DONE CANCELLED "
, "* WAITING compile"
, "* CANCELLED lunch"
, "* DONE todo-feature"
] =?>
let waiting = spanWith ("", ["todo", "WAITING"], []) "WAITING"
cancelled = spanWith ("", ["done", "CANCELLED"], []) "CANCELLED"
done = spanWith ("", ["done", "DONE"], []) "DONE"
in headerWith ("compile", [], []) 1 (waiting <> space <> "compile")
<> headerWith ("lunch", [], []) 1 (cancelled <> space <> "lunch")
<> headerWith ("todo-feature", [], []) 1 (done <> space <> "todo-feature")
]
, "Tagged headers" =:
T.unlines [ "* Personal :PERSONAL:"
, "** Call Mom :@PHONE:"
, "** Call John :@PHONE:JOHN: "
] =?>
mconcat [ headerWith ("personal", [], [])
1
("Personal " <> tagSpan "PERSONAL")
, headerWith ("call-mom", [], [])
2
("Call Mom " <> tagSpan "@PHONE")
, headerWith ("call-john", [], [])
2
("Call John " <> tagSpan "@PHONE" <> "\160" <> tagSpan "JOHN")
]
, "Untagged header containing colons" =:
"* This: is not: tagged" =?>
headerWith ("this-is-not-tagged", [], []) 1 "This: is not: tagged"
, "Untagged header time followed by colon" =:
"** Meeting at 5:23: free food" =?>
let attr = ("meeting-at-523-free-food", [], [])
in headerWith attr 2 "Meeting at 5:23: free food"
, "tag followed by text" =:
"*** Looks like a :tag: but isn't" =?>
let attr = ("looks-like-a-tag-but-isnt", [], [])
in headerWith attr 3 "Looks like a :tag: but isn't"
, "Header starting with strokeout text" =:
T.unlines [ "foo"
, ""
, "* +thing+ other thing"
] =?>
mconcat [ para "foo"
, headerWith ("thing-other-thing", [], [])
1
(strikeout "thing" <> " other thing")
]
, "Comment Trees" =:
T.unlines [ "* COMMENT A comment tree"
, " Not much going on here"
, "** This will be dropped"
, "* Comment tree above"
] =?>
headerWith ("comment-tree-above", [], []) 1 "Comment tree above"
, "Nothing but a COMMENT header" =:
"* COMMENT Test" =?>
(mempty::Blocks)
, "Tree with :noexport:" =:
T.unlines [ "* Should be ignored :archive:noexport:old:"
, "** Old stuff"
, " This is not going to be exported"
] =?>
(mempty::Blocks)
, "Subtree with :noexport:" =:
T.unlines [ "* Exported"
, "** This isn't exported :noexport:"
, "*** This neither"
, "** But this is"
] =?>
mconcat [ headerWith ("exported", [], []) 1 "Exported"
, headerWith ("but-this-is", [], []) 2 "But this is"
]
, "Preferences are treated as header attributes" =:
T.unlines [ "* foo"
, " :PROPERTIES:"
, " :custom_id: fubar"
, " :bar: baz"
, " :END:"
] =?>
headerWith ("fubar", [], [("bar", "baz")]) 1 "foo"
, "Headers marked with a unnumbered property get a class of the same name" =:
T.unlines [ "* Not numbered"
, " :PROPERTIES:"
, " :UNNUMBERED: t"
, " :END:"
] =?>
headerWith ("not-numbered", ["unnumbered"], []) 1 "Not numbered"
, testGroup "planning information"
[ "Planning info is not included in output" =:
T.unlines [ "* important"
, T.unwords
[ "CLOSED: [2018-09-05 Wed 13:58]"
, "DEADLINE: <2018-09-17 Mon>"
, "SCHEDULED: <2018-09-10 Mon>"
]
] =?>
headerWith ("important", [], []) 1 "important"
, "Properties after planning info are recognized" =:
T.unlines [ "* important "
, " " <> T.unwords
[ "CLOSED: [2018-09-05 Wed 13:58]"
, "DEADLINE: <2018-09-17 Mon>"
, "SCHEDULED: <2018-09-10 Mon>"
]
, " :PROPERTIES:"
, " :custom_id: look"
, " :END:"
] =?>
headerWith ("look", [], []) 1 "important"
, "Planning info followed by test" =:
T.unlines [ "* important "
, " " <> T.unwords
[ "CLOSED: [2018-09-05 Wed 13:58]"
, "DEADLINE: <2018-09-17 Mon>"
, "SCHEDULED: <2018-09-10 Mon>"
]
, " :PROPERTIES:"
, " :custom_id: look"
, " :END:"
] =?>
headerWith ("look", [], []) 1 "important"
, "third and forth level headers" =:
T.unlines [ "#+OPTIONS: p:t h:3"
, "*** Third"
, " CLOSED: [2018-09-05 Wed 13:58]"
, " Text 3"
, "**** Fourth"
, "SCHEDULED: <2019-05-13 Mon 22:42>"
, "Text 4"
] =?>
mconcat
[ headerWith ("third", [], mempty) 3 "Third"
, plain $
strong "CLOSED:" <> space <> emph (str "[2018-09-05 Wed 13:58]")
, para "Text 3"
, orderedList [
mconcat
[ para "Fourth"
, plain $ strong "SCHEDULED:"
<> space
<> emph (str "<2019-05-13 Mon 22:42>")
, para "Text 4"
]]
]
]
]
|