blob: b042495f924ec5b69c22dc76846496f6a8b003c1 (
plain) (
blame)
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
|
;;; ox-jira-test.el --- tests for ox-jira.el
;; Copyright (C) 2016 Stig Brautaset
;; Author: Stig Brautaset <stig@brautaset.org>
;; This file is NOT part of GNU Emacs.
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Code:
(require 'ert)
(require 'org-element)
(require 'ox)
(require 'ox-jira)
(eval-when-compile
(require 'cl-lib))
(defun to-jira (string)
(org-export-string-as string 'jira nil '(:src-collapse-threshold 3)))
;; This is my first foray into testing in Emacs. Please be kind.
;; Let's write the simplest possible test that actually invokes anything org
;; export related.
;;
(ert-deftest ox-jira-test/hello-world ()
(should (equal "hello world\n" (to-jira "hello world"))))
;; Let's do some standalone tests of very simple markup for inline text
;; effects.
;;
(ert-deftest ox-jira-test/text-effects ()
(should (equal "this is *strong* text\n" (to-jira "this is *strong* text")))
(should (equal "this is _emphasised_ text\n" (to-jira "this is /emphasised/ text")))
(should (equal "this is +underlined+ text\n" (to-jira "this is _underlined_ text")))
(should (equal "this is -deleted- text\n" (to-jira "this is +deleted+ text")))
(should (equal "this is {{inline code}}\n" (to-jira "this is ~inline code~")))
(should (equal "this is {{verbatim}} text\n" (to-jira "this is =verbatim= text"))))
;; Test that super^script and sub_script have empty anchor immediately
;; preceeding, so they can be tacked at the end of words without whitespace
;; immediately before it.
;;
(ert-deftest ox-jira-test/embeddable-text-effects ()
(should (equal "this is super{anchor}^scripted^ text\n" (to-jira "this is super^scripted text")))
(should (equal "this is sub{anchor}~scripted~ text\n" (to-jira "this is sub_scripted text"))))
;; Quotations are a bit more elaborate, so let's test those separately. They
;; can have other text effects inside them too.
;;
(ert-deftest ox-jira-test/quotations ()
(should (equal "{quote}
This is a quote.
It can have multiple paragraphs.
{quote}
" (to-jira "
#+BEGIN_QUOTE
This is a quote.
It can have multiple paragraphs.
#+END_QUOTE")))
(should (equal "{quote}
This is a quote with _emphasis_.
{quote}
" (to-jira "
#+begin_quote
This is a quote with /emphasis/.
#+end_quote"))))
;; Headline numbering in org is *relative*, so we cannot test that they work
;; one-by-one.
;;
(ert-deftest ox-jira-test/headlines ()
(should (equal "h1. top level
h2. second level
h3. third level
" (to-jira "* top level
** second level
*** third level"))))
;; Override headline offset
;;
(ert-deftest ox-jira-test/headlines-with-customized-levels ()
(let ((ox-jira-override-headline-offset 2))
(should (equal "h3. top level
h4. second level
h5. third level
" (to-jira "* top level
** second level
*** third level")))))
(ert-deftest ox-jira-test/todo-headlines ()
(should
(equal "h1. {color:lightgreen}{{DONE}}{color} This is a headline
h1. {color:red}{{TODO}}{color} This is another headline
" (to-jira "* DONE This is a headline
* TODO This is another headline"))))
(ert-deftest ox-jira-test/tag-headlines ()
(should (equal "h1. This is a headline {color:blue}{{:TAG:XXX:}}{color}
h1. This is another headline {color:blue}{{:FOO:BAR:}}{color}
" (to-jira "* This is a headline :TAG:XXX:
* This is another headline :FOO:BAR:"))))
(ert-deftest ox-jira-test/full-headlines ()
(should (equal "h1. {color:lightgreen}{{DONE}}{color} This is a headline {color:blue}{{:TAG:XXX:}}{color}
h1. {color:red}{{TODO}}{color} This is another headline {color:blue}{{:FOO:BAR:}}{color}
" (to-jira "* DONE This is a headline :TAG:XXX:
* TODO This is another headline :FOO:BAR:"))))
;; As far as I understand these are not useful in JIRA output, so let's just
;; filter them out.
;;
(ert-deftest ox-jira-test/keywords()
(should (equal "" (to-jira "#+TITLE: MyTitle
#+DATE: 2016-02-26
#+OPTIONS: f:t"))))
(ert-deftest ox-jira-test/links ()
(should (equal "fi [http://jira.atlassian.com] fo\n"
(to-jira "fi [[http://jira.atlassian.com]] fo")))
(should (equal "fi [Jira|http://jira.atlassian.com] fo\n"
(to-jira "fi [[http://jira.atlassian.com][Jira]] fo")))
(should (equal "see [#Heading Name] for details\n"
(to-jira "see [[*Heading Name]] for details")))
(should (equal "see [This Thing|#Heading Name] for details\n"
(to-jira "see [[*Heading Name][This Thing]] for details")))
(should (equal "see [#Heading Name] for details\n"
(to-jira "see [[#Heading Name]] for details")))
(should (equal "see [This Thing|#This Thing] for details\n"
(to-jira "see [[#Heading Name][This Thing]] for details")))
(should (equal "contact [User Name|~accountid:accountid] for details\n"
(to-jira "contact [[~accountid:accountid][User Name]] for details\n")))
(cl-letf (((symbol-function #'org-export-custom-protocol-maybe)
(lambda (link &rest _)
(let ((path (org-element-property :path link)))
(if (string-prefix-p "example-protocol:" path)
"http://example.com"
nil)))))
(should (equal "fi [http://example.com] fo\n"
(to-jira "fi [[example-protocol:example.net]] fo")))
(should (equal "fi [Example|http://example.com] fo\n"
(to-jira "fi [[example-protocol:example.net][Example]] fo")))
(should (not (equal "fi [Example|[http://example.com] fo\n"
(to-jira "fi [[unsupported-protocol:example.net][Example]] fo"))))))
;; Check that text in paragraphs does not have hard newlines.
;;
(ert-deftest ox-jira-test/paragraphs ()
(should (equal "fi fo fa fum\n" (to-jira "fi
fo
fa
fum"))))
(ert-deftest ox-jira-test/unordered-lists()
(should (equal "* fi
* fo
* fa
* fum
" (to-jira "- fi
- fo
- fa
- fum"))))
(ert-deftest ox-jira-test/ordered-lists()
(should (equal "# fi
# fo
# fa
# fum
" (to-jira "1. fi
2. fo
3. fa
3. fum"))))
(ert-deftest ox-jira-test/nested-lists()
(should (equal "* fi
** fo
*** fa
**** fum
" (to-jira "- fi
- fo
- fa
- fum")))
(should (equal "* fi
*# fo
*#* fa
*#*# fum
" (to-jira "- fi
1. fo
- fa
1. fum"))))
(ert-deftest ox-jira-test/unordered-list-with-checkboxes()
(should (equal "* (x) fi
* (/) fo
" (to-jira "- [ ] fi
- [X] fo"))))
(ert-deftest ox-jira-test/checkboxes-and-statistics()
(should (equal "* (i) Progress \\[50%]
** (x) fi
** (/) fo
" (to-jira "- [-] Progress [50%]
- [ ] fi
- [X] fo"))))
(ert-deftest ox-jira-test/definition-lists()
(should (equal "* *fi*: fo
* *fa*: fum
" (to-jira "- fi :: fo
- fa :: fum"))))
;; This is not really supported by JIRA, so we have to fake it.
;;
(ert-deftest ox-jira-test/multi-para-list-items()
(should (equal "# fi
fo
# fa
" (to-jira "1. fi
fo
2. fa")))
(should (equal "# fi
#* fifi
#* fofo
# fa
# fum
" (to-jira "1. fi
* fifi
* fofo
2. fa
3. fum")))
(should (equal "# fi
#* {code:title=|language=sql|collapse=false}SELECT 1;
{code}
{code:title=|language=sql|collapse=false}SELECT 2;
{code}
#* fofo
# fa
" (to-jira "1. fi
*
#+begin_src sql
SELECT 1;
#+end_src
#+begin_src sql
SELECT 2;
#+end_src
* fofo
2. fa
")))
)
(ert-deftest ox-jira-test/plain-text ()
(should (equal "fi fo \\[fa] fum
" (to-jira "fi fo [fa] fum"))))
(ert-deftest ox-jira-test/src-blocks ()
(should (equal "{code:title=|language=none|collapse=false}echo hello
# echo world
{code}
" (to-jira "#+begin_src sh
echo hello
# echo world
#+end_src
")))
(should (equal "{code:title=|language=sql|collapse=false}BEGIN;
SELECT NOW();
END;
{code}
" (to-jira "#+begin_src sql
BEGIN;
SELECT NOW();
END;
#+end_src
")))
(should (equal "{code:title=Hello|language=sql|collapse=false}BEGIN;
SELECT NOW();
END;
{code}
" (to-jira "#+CAPTION: Hello
#+begin_src sql
BEGIN;
SELECT NOW();
END;
#+end_src
")))
(should (equal "{code:title=Hello World|language=sql|collapse=true}BEGIN;
SELECT NOW();
SELECT NOW();
END;
{code}
" (to-jira "#+CAPTION: Hello World
#+begin_src sql
BEGIN;
SELECT NOW();
SELECT NOW();
END;
#+end_src
")))
)
;; The Holy Grail. Do me proud, Org mode!
;;
(ert-deftest ox-jira-test/tables ()
(should (equal "| a | b |
| c | d |
" (to-jira "
| a | b |
| c | d |
")))
(should (equal "| | b |
| c | |
" (to-jira "
| | b |
| c | |
")))
;; This should really be
;; : || a || b ||
;; : | c | d |
;;
;; but I haven't figured out how to identify the header row yet. This test
;; checks that we at least ignore the horizontal lines.
(should (equal "|| a || b ||
| c | d |
" (to-jira "
| a | b |
|---+---|
| c | d |
"))))
(ert-deftest ox-jira-test/example-blocks ()
(should (equal "{noformat}
stuff that should
not be
formatted
{noformat}
" (to-jira "#+begin_example
stuff that should
not be
formatted
#+end_example
"))))
(ert-deftest ox-jira-test/fixed-width-blocks ()
(should (equal "{noformat}
stuff that should
not be
formatted
{noformat}
" (to-jira ": stuff that should
: not be
: formatted
"))))
(ert-deftest ox-jira-test/horizontal-rule ()
(should
(equal "----\n" (to-jira "-----\n")))
(should
(equal "----\n" (to-jira "-------\n"))))
(ert-deftest ox-jira-test/footnotes ()
(should (equal "fi fo{anchor:fnr1}[^1^|#fn1]. Another one{anchor:fnr2}[^2^|#fn2].
h1. Footnotes
{anchor:fn1}[^1^|#fnr1] fa fum.
{anchor:fn2}[^2^|#fnr2] fut fut.
" (to-jira "fi fo[fn:1]. Another one[fn:2].
* Footnotes
[fn:1] fa fum.
[fn:2] fut fut.
"))))
(ert-deftest ox-jira-test/timestamps ()
(should (equal "An inactive datestamp: _\\[2017-01-11 Wed]_\n"
(to-jira "An inactive datestamp: [2017-01-11 Wed]")))
(should (equal "An inactive timestamp: _\\[2017-01-11 Wed 12:34]_\n"
(to-jira "An inactive timestamp: [2017-01-11 Wed 12:34]")))
(should (equal "An active datestamp: _<2017-01-11 Wed>_\n"
(to-jira "An active datestamp: <2017-01-11 Wed>")))
(should (equal "An active timestamp: _<2017-01-11 Wed 02:12>_\n"
(to-jira "An active timestamp: <2017-01-11 Wed 02:12>"))))
(provide 'ox-jira-test)
;;; ox-jira.el-test.el ends here
|