Parsing and exporting special blocks preserve case
[org-mode/org-kjn.git] / testing / lisp / test-org-element.el
blobe93ab7583d5ef060c52806881c33601500b5a09d
1 ;;; test-org-element.el --- Tests for org-element.el
3 ;; Copyright (C) 2012, 2013, 2014 Nicolas Goaziou
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
7 ;; This program is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
12 ;; This program is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ;;; Code:
22 (unless (featurep 'org-element)
23 (signal 'missing-test-dependency "org-element"))
25 (defun org-test-parse-and-interpret (text)
26 "Parse TEXT as Org syntax and interpret it.
27 Return interpreted string."
28 (with-temp-buffer
29 (org-mode)
30 (insert text)
31 (org-element-interpret-data (org-element-parse-buffer))))
35 ;;; Test `org-element-map'
37 (ert-deftest test-org-element/map ()
38 "Test `org-element-map'."
39 ;; Can map to `plain-text' objects.
40 (should
41 (= 2
42 (org-test-with-temp-text "Some text \alpha
43 #+BEGIN_CENTER
44 Some other text
45 #+END_CENTER"
46 (let ((count 0))
47 (org-element-map
48 (org-element-parse-buffer) 'plain-text
49 (lambda (s) (when (string-match "text" s) (incf count))))
50 count))))
51 ;; Applies to secondary strings
52 (should
53 (org-element-map '("some " (bold nil "bold") "text") 'bold 'identity))
54 ;; Enter secondary strings before entering contents.
55 (should
56 (equal
57 "alpha"
58 (org-element-property
59 :name
60 (org-test-with-temp-text "* Some \\alpha headline\n\\beta entity."
61 (org-element-map (org-element-parse-buffer) 'entity 'identity nil t)))))
62 ;; Apply NO-RECURSION argument.
63 (should-not
64 (org-test-with-temp-text "#+BEGIN_CENTER\n\\alpha\n#+END_CENTER"
65 (org-element-map
66 (org-element-parse-buffer) 'entity 'identity nil nil 'center-block)))
67 ;; Use WITH-AFFILIATED argument.
68 (should
69 (equal
70 '("a" "1" "b" "2")
71 (org-test-with-temp-text "#+CAPTION[a]: 1\n#+CAPTION[b]: 2\nParagraph"
72 (org-element-map
73 (org-element-at-point) 'plain-text 'identity nil nil nil t)))))
77 ;;; Test Setters
79 (ert-deftest test-org-element/put-property ()
80 "Test `org-element-put-property' specifications."
81 ;; Standard test.
82 (org-test-with-temp-text "* Headline\n *a*"
83 (let ((tree (org-element-parse-buffer)))
84 (org-element-put-property
85 (org-element-map tree 'bold 'identity nil t) :test 1)
86 (should (org-element-property
87 :test (org-element-map tree 'bold 'identity nil t)))))
88 ;; Put property on a string.
89 (should
90 (org-element-property :test (org-element-put-property "Paragraph" :test t))))
92 (ert-deftest test-org-element/set-contents ()
93 "Test `org-element-set-contents' specifications."
94 ;; Accept multiple entries.
95 (should
96 (equal '("b" (italic nil "a"))
97 (org-test-with-temp-text "* Headline\n *a*"
98 (let ((tree (org-element-parse-buffer)))
99 (org-element-set-contents
100 (org-element-map tree 'bold 'identity nil t) "b" '(italic nil "a"))
101 (org-element-contents
102 (org-element-map tree 'bold 'identity nil t))))))
103 ;; Accept atoms and elements.
104 (should
105 (equal '("b")
106 (org-test-with-temp-text "* Headline\n *a*"
107 (let ((tree (org-element-parse-buffer)))
108 (org-element-set-contents
109 (org-element-map tree 'bold 'identity nil t) "b")
110 (org-element-contents
111 (org-element-map tree 'bold 'identity nil t))))))
112 (should
113 (equal '((italic nil "b"))
114 (org-test-with-temp-text "* Headline\n *a*"
115 (let ((tree (org-element-parse-buffer)))
116 (org-element-set-contents
117 (org-element-map tree 'bold 'identity nil t) '(italic nil "b"))
118 (org-element-contents
119 (org-element-map tree 'bold 'identity nil t))))))
120 ;; Allow nil contents.
121 (should-not
122 (org-test-with-temp-text "* Headline\n *a*"
123 (let ((tree (org-element-parse-buffer)))
124 (org-element-set-contents (org-element-map tree 'bold 'identity nil t))
125 (org-element-contents (org-element-map tree 'bold 'identity nil t))))))
127 (ert-deftest test-org-element/secondary-p ()
128 "Test `org-element-secondary-p' specifications."
129 ;; In a secondary string, return property name.
130 (should
131 (eq :title
132 (org-test-with-temp-text "* Headline *object*"
133 (org-element-map (org-element-parse-buffer) 'bold
134 (lambda (object) (org-element-secondary-p object))
135 nil t))))
136 ;; Outside a secondary string, return nil.
137 (should-not
138 (org-test-with-temp-text "Paragraph *object*"
139 (org-element-map (org-element-parse-buffer) 'bold
140 (lambda (object) (org-element-type (org-element-secondary-p object)))
141 nil t))))
143 (ert-deftest test-org-element/adopt-elements ()
144 "Test `org-element-adopt-elements' specifications."
145 ;; Adopt an element.
146 (should
147 (equal '(plain-text italic)
148 (org-test-with-temp-text "* Headline\n *a*"
149 (let ((tree (org-element-parse-buffer)))
150 (org-element-adopt-elements
151 (org-element-map tree 'bold 'identity nil t) '(italic nil "a"))
152 (mapcar (lambda (blob) (org-element-type blob))
153 (org-element-contents
154 (org-element-map tree 'bold 'identity nil t)))))))
155 ;; Adopt a string.
156 (should
157 (equal '("a" "b")
158 (org-test-with-temp-text "* Headline\n *a*"
159 (let ((tree (org-element-parse-buffer)))
160 (org-element-adopt-elements
161 (org-element-map tree 'bold 'identity nil t) "b")
162 (org-element-contents
163 (org-element-map tree 'bold 'identity nil t)))))))
165 (ert-deftest test-org-element/extract-element ()
166 "Test `org-element-extract-element' specifications."
167 ;; Extract a greater element.
168 (should
169 (equal '(org-data nil)
170 (org-test-with-temp-text "* Headline"
171 (let* ((tree (org-element-parse-buffer))
172 (element (org-element-map tree 'headline 'identity nil t)))
173 (org-element-extract-element element)
174 tree))))
175 ;; Extract an element.
176 (should-not
177 (org-element-map
178 (org-test-with-temp-text "Paragraph"
179 (let* ((tree (org-element-parse-buffer))
180 (element (org-element-map tree 'paragraph 'identity nil t)))
181 (org-element-extract-element element)
182 tree))
183 'paragraph
184 'identity))
185 ;; Extract an object, even in a secondary string.
186 (should-not
187 (org-element-map
188 (org-test-with-temp-text "*bold*"
189 (let* ((tree (org-element-parse-buffer))
190 (element (org-element-map tree 'bold 'identity nil t)))
191 (org-element-extract-element element)
192 tree))
193 'bold
194 'identity))
195 (should-not
196 (org-element-map
197 (org-test-with-temp-text "* Headline *bold*"
198 (let* ((tree (org-element-parse-buffer))
199 (element (org-element-map tree 'bold 'identity nil t)))
200 (org-element-extract-element element)
201 tree))
202 'bold
203 'identity))
204 ;; Return value doesn't have any :parent set.
205 (should-not
206 (org-element-property
207 :parent
208 (org-test-with-temp-text "* Headline\n Paragraph with *bold* text."
209 (let* ((tree (org-element-parse-buffer))
210 (element (org-element-map tree 'bold 'identity nil t)))
211 (org-element-extract-element element))))))
213 (ert-deftest test-org-element/insert-before ()
214 "Test `org-element-insert-before' specifications."
215 ;; Standard test.
216 (should
217 (equal
218 '(italic entity bold)
219 (org-test-with-temp-text "/some/ *paragraph*"
220 (let* ((tree (org-element-parse-buffer))
221 (paragraph (org-element-map tree 'paragraph 'identity nil t))
222 (bold (org-element-map tree 'bold 'identity nil t)))
223 (org-element-insert-before '(entity (:name "\\alpha")) bold)
224 (org-element-map tree '(bold entity italic) #'org-element-type nil)))))
225 ;; Insert an object in a secondary string.
226 (should
227 (equal
228 '(entity italic)
229 (org-test-with-temp-text "* /A/\n Paragraph."
230 (let* ((tree (org-element-parse-buffer))
231 (headline (org-element-map tree 'headline 'identity nil t))
232 (italic (org-element-map tree 'italic 'identity nil t)))
233 (org-element-insert-before '(entity (:name "\\alpha")) italic)
234 (org-element-map (org-element-property :title headline) '(entity italic)
235 #'org-element-type))))))
237 (ert-deftest test-org-element/set-element ()
238 "Test `org-element-set-element' specifications."
239 ;; Check if new element is inserted.
240 (should
241 (org-test-with-temp-text "* Headline\n*a*"
242 (let* ((tree (org-element-parse-buffer))
243 (bold (org-element-map tree 'bold 'identity nil t)))
244 (org-element-set-element bold '(italic nil "b"))
245 (org-element-map tree 'italic 'identity))))
246 ;; Check if old element is removed.
247 (should-not
248 (org-test-with-temp-text "* Headline\n*a*"
249 (let* ((tree (org-element-parse-buffer))
250 (bold (org-element-map tree 'bold 'identity nil t)))
251 (org-element-set-element bold '(italic nil "b"))
252 (org-element-map tree 'bold 'identity))))
253 ;; Check if :parent property is correctly set.
254 (should
255 (eq 'paragraph
256 (org-test-with-temp-text "* Headline\n*a*"
257 (let* ((tree (org-element-parse-buffer))
258 (bold (org-element-map tree 'bold 'identity nil t)))
259 (org-element-set-element bold '(italic nil "b"))
260 (org-element-type
261 (org-element-property
262 :parent (org-element-map tree 'italic 'identity nil t)))))))
263 ;; Allow to replace strings with elements.
264 (should
265 (equal '("b")
266 (org-test-with-temp-text "* Headline"
267 (let* ((tree (org-element-parse-buffer))
268 (text (org-element-map tree 'plain-text 'identity nil t)))
269 (org-element-set-element text (list 'bold nil "b"))
270 (org-element-map tree 'plain-text 'identity)))))
271 ;; Allow to replace elements with strings.
272 (should
273 (equal "a"
274 (org-test-with-temp-text "* =verbatim="
275 (let* ((tree (org-element-parse-buffer))
276 (verb (org-element-map tree 'verbatim 'identity nil t)))
277 (org-element-set-element verb "a")
278 (org-element-map tree 'plain-text 'identity nil t)))))
279 ;; Allow to replace strings with strings.
280 (should
281 (equal "b"
282 (org-test-with-temp-text "a"
283 (let* ((tree (org-element-parse-buffer))
284 (text (org-element-map tree 'plain-text 'identity nil t)))
285 (org-element-set-element text "b")
286 (org-element-map tree 'plain-text 'identity nil t))))))
290 ;;; Test Parsers
292 ;;;; Affiliated Keywords
294 (ert-deftest test-org-element/affiliated-keywords-parser ()
295 "Test affiliated keywords parsing."
296 ;; Read simple keywords.
297 (should
298 (equal "para"
299 (org-element-property
300 :name
301 (org-test-with-temp-text "#+NAME: para\nParagraph"
302 (org-element-at-point)))))
303 (should
304 (= 1
305 (org-element-property
306 :begin
307 (org-test-with-temp-text "#+NAME: para\nParagraph"
308 (org-element-at-point)))))
309 ;; Parse multiple keywords.
310 (should
311 (equal
312 '("line2" "line1")
313 (org-element-property
314 :attr_ascii
315 (org-test-with-temp-text
316 "#+ATTR_ASCII: line1\n#+ATTR_ASCII: line2\nParagraph"
317 (org-element-at-point)))))
318 ;; Parse "parsed" keywords.
319 (should
320 (equal
321 '(("caption"))
322 (org-test-with-temp-text "#+CAPTION: caption\nParagraph"
323 (car (org-element-property :caption (org-element-at-point))))))
324 ;; Parse dual keywords.
325 (should
326 (equal
327 '((("long") "short"))
328 (org-test-with-temp-text "#+CAPTION[short]: long\nParagraph"
329 (org-element-property :caption (org-element-at-point)))))
330 ;; Allow multiple caption keywords.
331 (should
332 (equal
333 '((("l2") "s2") (("l1") "s1"))
334 (org-test-with-temp-text "#+CAPTION[s1]: l1\n#+CAPTION[s2]: l2\nParagraph"
335 (org-element-property :caption (org-element-at-point)))))
336 (should
337 (equal
338 '((("l1")) (nil "s1"))
339 (org-test-with-temp-text "#+CAPTION[s1]:\n#+CAPTION: l1\nParagraph"
340 (org-element-property :caption (org-element-at-point)))))
341 ;; Corner case: orphaned keyword at the end of an element.
342 (should
343 (eq 'keyword
344 (org-test-with-temp-text "- item\n #+name: name\nSome paragraph"
345 (progn (search-forward "name")
346 (org-element-type (org-element-at-point))))))
347 (should-not
348 (org-test-with-temp-text "- item\n #+name: name\nSome paragraph"
349 (progn (search-forward "Some")
350 (org-element-property :name (org-element-at-point))))))
353 ;;;; Babel Call
355 (ert-deftest test-org-element/babel-call-parser ()
356 "Test `babel-call' parsing."
357 ;; Standard test.
358 (should
359 (org-test-with-temp-text "#+CALL: test()"
360 (org-element-map (org-element-parse-buffer) 'babel-call 'identity)))
361 ;; Ignore case.
362 (should
363 (org-test-with-temp-text "#+call: test()"
364 (org-element-map (org-element-parse-buffer) 'babel-call 'identity)))
365 ;; Handle non-empty blank line at the end of buffer.
366 (should
367 (org-test-with-temp-text "#+CALL: test()\n "
368 (= (org-element-property :end (org-element-at-point)) (point-max)))))
371 ;;;; Bold
373 (ert-deftest test-org-element/bold-parser ()
374 "Test `bold' parser."
375 ;; Standard test.
376 (should
377 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
378 (org-test-with-temp-text "*bold*"
379 (org-element-map (org-element-parse-buffer) 'bold 'identity nil t))))
380 ;; Multi-line markup.
381 (should
382 (equal
383 (org-element-contents
384 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
385 (org-test-with-temp-text "*first line\nsecond line*"
386 (org-element-map (org-element-parse-buffer) 'bold 'identity nil t))))
387 '("first line\nsecond line"))))
390 ;;;; Center Block
392 (ert-deftest test-org-element/center-block-parser ()
393 "Test `center-block' parser."
394 ;; Standard test.
395 (should
396 (org-test-with-temp-text "#+BEGIN_CENTER\nText\n#+END_CENTER"
397 (org-element-map (org-element-parse-buffer) 'center-block 'identity)))
398 ;; Ignore case.
399 (should
400 (org-test-with-temp-text "#+begin_center\nText\n#+end_center"
401 (org-element-map (org-element-parse-buffer) 'center-block 'identity)))
402 ;; Ignore incomplete block.
403 (should-not
404 (org-test-with-temp-text "#+BEGIN_CENTER"
405 (org-element-map (org-element-parse-buffer) 'center-block
406 'identity nil t)))
407 ;; Handle non-empty blank line at the end of buffer.
408 (should
409 (org-test-with-temp-text "#+BEGIN_CENTER\nC\n#+END_CENTER\n "
410 (= (org-element-property :end (org-element-at-point)) (point-max)))))
413 ;;;; Clock
415 (ert-deftest test-org-element/clock-parser ()
416 "Test `clock' parser."
417 ;; Running clock.
418 (let ((clock (org-test-with-temp-text "CLOCK: [2012-01-01 sun. 00:01]"
419 (org-element-at-point))))
420 (should (eq (org-element-property :status clock) 'running))
421 (should
422 (equal (org-element-property :raw-value
423 (org-element-property :value clock))
424 "[2012-01-01 sun. 00:01]"))
425 (should-not (org-element-property :duration clock)))
426 ;; Closed clock.
427 (let ((clock
428 (org-test-with-temp-text
429 "CLOCK: [2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02] => 0:01"
430 (org-element-at-point))))
431 (should (eq (org-element-property :status clock) 'closed))
432 (should (equal (org-element-property :raw-value
433 (org-element-property :value clock))
434 "[2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02]"))
435 (should (equal (org-element-property :duration clock) "0:01"))))
438 ;;;; Code
440 (ert-deftest test-org-element/code-parser ()
441 "Test `code' parser."
442 ;; Regular test.
443 (should
444 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
445 (org-test-with-temp-text "~code~"
446 (org-element-map (org-element-parse-buffer) 'code 'identity))))
447 ;; Multi-line markup.
448 (should
449 (equal
450 (org-element-property
451 :value
452 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
453 (org-test-with-temp-text "~first line\nsecond line~"
454 (org-element-map
455 (org-element-parse-buffer) 'code 'identity nil t))))
456 "first line\nsecond line")))
459 ;;;; Comment
461 (ert-deftest test-org-element/comment-parser ()
462 "Test `comment' parser."
463 ;; Regular comment.
464 (should
465 (org-test-with-temp-text "# Comment"
466 (org-element-map (org-element-parse-buffer) 'comment 'identity)))
467 ;; Inline comment.
468 (should
469 (org-test-with-temp-text " # Comment"
470 (org-element-map (org-element-parse-buffer) 'comment 'identity)))
471 ;; Preserve indentation.
472 (should
473 (equal
474 (org-element-property
475 :value
476 (org-test-with-temp-text "# No blank\n# One blank"
477 (org-element-map (org-element-parse-buffer) 'comment 'identity nil t)))
478 "No blank\n One blank"))
479 ;; Comment with blank lines.
480 (should
481 (equal
482 (org-element-property
483 :value
484 (org-test-with-temp-text "# First part\n# \n#\n# Second part"
485 (org-element-map (org-element-parse-buffer) 'comment 'identity nil t)))
486 "First part\n\n\nSecond part"))
487 ;; Do not mix comments and keywords.
488 (should
489 (eq 1
490 (org-test-with-temp-text "#+keyword: value\n# comment\n#+keyword: value"
491 (length (org-element-map (org-element-parse-buffer) 'comment
492 'identity)))))
493 (should
494 (equal "comment"
495 (org-test-with-temp-text "#+keyword: value\n# comment\n#+keyword: value"
496 (org-element-property
497 :value
498 (org-element-map (org-element-parse-buffer) 'comment
499 'identity nil t)))))
500 ;; Correctly handle non-empty blank lines at the end of buffer.
501 (should
502 (org-test-with-temp-text "# A\n "
503 (= (org-element-property :end (org-element-at-point)) (point-max)))))
506 ;;;; Comment Block
508 (ert-deftest test-org-element/comment-block-parser ()
509 "Test `comment-block' parser."
510 ;; Standard test.
511 (should
512 (org-test-with-temp-text "#+BEGIN_COMMENT\nText\n#+END_COMMENT"
513 (org-element-map (org-element-parse-buffer) 'comment-block 'identity)))
514 ;; Ignore case.
515 (should
516 (org-test-with-temp-text "#+begin_comment\nText\n#+end_comment"
517 (org-element-map (org-element-parse-buffer) 'comment-block 'identity)))
518 ;; Ignore incomplete block.
519 (should-not
520 (org-test-with-temp-text "#+BEGIN_COMMENT"
521 (org-element-map (org-element-parse-buffer) 'comment-block
522 'identity nil t)))
523 ;; Handle non-empty blank line at the end of buffer.
524 (should
525 (org-test-with-temp-text "#+BEGIN_COMMENT\nC\n#+END_COMMENT\n "
526 (= (org-element-property :end (org-element-at-point)) (point-max)))))
529 ;;;; Diary Sexp
531 (ert-deftest test-org-element/diary-sexp-parser ()
532 "Test `diary-sexp' parser."
533 ;; Standard test.
534 (should
535 (eq 'diary-sexp
536 (org-test-with-temp-text
537 "%%(org-anniversary 1956 5 14)(2) Arthur Dent is %d years old"
538 (org-element-type (org-element-at-point)))))
539 ;; Diary sexp must live at beginning of line
540 (should-not
541 (eq 'diary-sexp
542 (org-test-with-temp-text " %%(org-bbdb-anniversaries)"
543 (org-element-type (org-element-at-point)))))
544 ;; Handle non-empty blank line at the end of buffer.
545 (should
546 (org-test-with-temp-text "%%(org-bbdb-anniversaries)\n "
547 (= (org-element-property :end (org-element-at-point)) (point-max)))))
550 ;;;; Drawer
552 (ert-deftest test-org-element/drawer-parser ()
553 "Test `drawer' parser."
554 ;; Standard test.
555 (should
556 (org-test-with-temp-text ":TEST:\nText\n:END:"
557 (org-element-map (org-element-parse-buffer) 'drawer 'identity)))
558 ;; Do not mix regular drawers and property drawers.
559 (should-not
560 (org-test-with-temp-text ":PROPERTIES:\n:prop: value\n:END:"
561 (org-element-map (org-element-parse-buffer) 'drawer 'identity nil t)))
562 ;; Ignore incomplete drawer.
563 (should-not
564 (org-test-with-temp-text ":TEST:"
565 (org-element-map (org-element-parse-buffer) 'drawer 'identity nil t)))
566 ;; Handle non-empty blank line at the end of buffer.
567 (should
568 (org-test-with-temp-text ":TEST:\nC\n:END:\n "
569 (= (org-element-property :end (org-element-at-point)) (point-max)))))
572 ;;;; Dynamic Block
574 (ert-deftest test-org-element/dynamic-block-parser ()
575 "Test `dynamic-block' parser."
576 ;; Standard test.
577 (should
578 (org-test-with-temp-text
579 "#+BEGIN: myblock :param1 val1 :param2 val2\nText\n#+END:"
580 (org-element-map (org-element-parse-buffer) 'dynamic-block 'identity)))
581 ;; Ignore case.
582 (should
583 (org-test-with-temp-text
584 "#+begin: myblock :param1 val1 :param2 val2\nText\n#+end:"
585 (org-element-map (org-element-parse-buffer) 'dynamic-block 'identity)))
586 ;; Ignore incomplete block.
587 (should-not
588 (org-test-with-temp-text "#+BEGIN: myblock :param1 val1 :param2 val2"
589 (org-element-map (org-element-parse-buffer) 'dynamic-block
590 'identity nil t)))
591 ;; Handle non-empty blank line at the end of buffer.
592 (should
593 (org-test-with-temp-text "#+BEGIN: myblock :param val1\nC\n#+END:\n "
594 (= (org-element-property :end (org-element-at-point)) (point-max)))))
597 ;;;; Entity
599 (ert-deftest test-org-element/entity-parser ()
600 "Test `entity' parser."
601 ;; Without brackets.
602 (should
603 (org-test-with-temp-text "\\sin"
604 (org-element-map (org-element-parse-buffer) 'entity 'identity)))
605 ;; With brackets.
606 (should
607 (org-element-property
608 :use-brackets-p
609 (org-test-with-temp-text "\\alpha{}text"
610 (org-element-map (org-element-parse-buffer) 'entity 'identity nil t))))
611 ;; User-defined entity.
612 (should
613 (equal
614 (org-element-property
615 :name
616 (let ((org-entities-user
617 '(("test" "test" nil "test" "test" "test" "test"))))
618 (org-test-with-temp-text "\\test"
619 (org-element-map (org-element-parse-buffer) 'entity 'identity nil t))))
620 "test"))
621 ;; Special case: entity at the end of a container.
622 (should
623 (eq 'entity
624 (org-test-with-temp-text "*\\alpha \\beta*"
625 (search-forward "be")
626 (org-element-type (org-element-context))))))
629 ;;;; Example Block
631 (ert-deftest test-org-element/example-block-parser ()
632 "Test `example-block' parser."
633 ;; Standard test.
634 (should
635 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nText\n#+END_EXAMPLE"
636 (org-element-map (org-element-parse-buffer) 'example-block 'identity)))
637 ;; Ignore incomplete block.
638 (should-not
639 (eq 'example-block
640 (org-test-with-temp-text "#+BEGIN_EXAMPLE"
641 (org-element-type (org-element-at-point)))))
642 ;; Properly un-escape code.
643 (should
644 (equal "* Headline\n #+keyword\nText\n"
645 (org-test-with-temp-text
646 "#+BEGIN_EXAMPLE\n,* Headline\n ,#+keyword\nText\n#+END_EXAMPLE"
647 (org-element-property :value (org-element-at-point)))))
648 ;; Remove block indentation according to block boundaries, unless
649 ;; block contents are less indented than block boundaries.
650 (should
651 (equal " L1\nL2\n"
652 (org-test-with-temp-text " #+BEGIN_EXAMPLE\n L1\n L2\n #+END_EXAMPLE"
653 (let ((org-src-preserve-indentation t))
654 (org-element-property :value (org-element-at-point))))))
655 (should
656 (equal
657 " L1\n L2\n"
658 (org-test-with-temp-text " #+BEGIN_EXAMPLE\n L1\n L2\n #+END_EXAMPLE"
659 (let ((org-src-preserve-indentation t))
660 (org-element-property :value (org-element-at-point))))))
661 ;; Handle non-empty blank line at the end of buffer.
662 (should
663 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nC\n#+END_EXAMPLE\n "
664 (= (org-element-property :end (org-element-at-point)) (point-max)))))
666 (ert-deftest test-org-element/block-switches ()
667 "Test `example-block' and `src-block' switches parsing."
668 (let ((org-coderef-label-format "(ref:%s)"))
669 ;; 1. Test "-i" switch.
670 (should-not
671 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
672 (org-element-property :preserve-indent (org-element-at-point))))
673 (should
674 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
675 (org-element-property :preserve-indent (org-element-at-point))))
676 (should-not
677 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nText.\n#+END_EXAMPLE"
678 (org-element-property :preserve-indent (org-element-at-point))))
679 (should
680 (org-test-with-temp-text "#+BEGIN_EXAMPLE -i\nText.\n#+END_EXAMPLE"
681 (org-element-property :preserve-indent (org-element-at-point))))
682 ;; 2. "-n -r -k" combination should number lines, retain labels but
683 ;; not use them in coderefs.
684 (should
685 (org-test-with-temp-text "#+BEGIN_EXAMPLE -n -r -k\nText.\n#+END_EXAMPLE"
686 (let ((element (org-element-at-point)))
687 (and (org-element-property :number-lines element)
688 (org-element-property :retain-labels element)
689 (not (org-element-property :use-labels element))))))
690 (should
691 (org-test-with-temp-text
692 "#+BEGIN_SRC emacs-lisp -n -r -k\n(+ 1 1)\n#+END_SRC"
693 (let ((element (org-element-at-point)))
694 (and (org-element-property :number-lines element)
695 (org-element-property :retain-labels element)
696 (not (org-element-property :use-labels element))))))
697 ;; 3. "-n -r" combination should number-lines remove labels and not
698 ;; use them in coderefs.
699 (should
700 (org-test-with-temp-text "#+BEGIN_EXAMPLE -n -r\nText.\n#+END_EXAMPLE"
701 (let ((element (org-element-at-point)))
702 (and (org-element-property :number-lines element)
703 (not (org-element-property :retain-labels element))
704 (not (org-element-property :use-labels element))))))
705 (should
706 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1)\n#+END_SRC"
707 (let ((element (org-element-at-point)))
708 (and (org-element-property :number-lines element)
709 (not (org-element-property :retain-labels element))
710 (not (org-element-property :use-labels element))))))
711 ;; 4. "-n" or "+n" should number lines, retain labels and use them
712 ;; in coderefs.
713 (should
714 (org-test-with-temp-text "#+BEGIN_EXAMPLE -n\nText.\n#+END_EXAMPLE"
715 (let ((element (org-element-at-point)))
716 (and (org-element-property :number-lines element)
717 (org-element-property :retain-labels element)
718 (org-element-property :use-labels element)))))
719 (should
720 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1)\n#+END_SRC"
721 (let ((element (org-element-at-point)))
722 (and (org-element-property :number-lines element)
723 (org-element-property :retain-labels element)
724 (org-element-property :use-labels element)))))
725 (should
726 (org-test-with-temp-text "#+BEGIN_EXAMPLE +n\nText.\n#+END_EXAMPLE"
727 (let ((element (org-element-at-point)))
728 (and (org-element-property :number-lines element)
729 (org-element-property :retain-labels element)
730 (org-element-property :use-labels element)))))
731 (should
732 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp +n\n(+ 1 1)\n#+END_SRC"
733 (let ((element (org-element-at-point)))
734 (and (org-element-property :number-lines element)
735 (org-element-property :retain-labels element)
736 (org-element-property :use-labels element)))))
737 ;; 5. No switch should not number lines, but retain labels and use
738 ;; them in coderefs.
739 (should
740 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nText.\n#+END_EXAMPLE"
741 (let ((element (org-element-at-point)))
742 (and (not (org-element-property :number-lines element))
743 (org-element-property :retain-labels element)
744 (org-element-property :use-labels element)))))
745 (should
746 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
747 (let ((element (org-element-at-point)))
748 (and (not (org-element-property :number-lines element))
749 (org-element-property :retain-labels element)
750 (org-element-property :use-labels element)))))
751 ;; 6. "-r" switch only: do not number lines, remove labels, and
752 ;; don't use labels in coderefs.
753 (should
754 (org-test-with-temp-text "#+BEGIN_EXAMPLE -r\nText.\n#+END_EXAMPLE"
755 (let ((element (org-element-at-point)))
756 (and (not (org-element-property :number-lines element))
757 (not (org-element-property :retain-labels element))
758 (not (org-element-property :use-labels element))))))
759 (should
760 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1)\n#+END_SRC"
761 (let ((element (org-element-at-point)))
762 (and (not (org-element-property :number-lines element))
763 (not (org-element-property :retain-labels element))
764 (not (org-element-property :use-labels element))))))
765 ;; 7. Recognize coderefs with user-defined syntax.
766 (should
767 (equal
768 "[ref:%s]"
769 (org-test-with-temp-text
770 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText [ref:text]\n#+END_EXAMPLE"
771 (org-element-property :label-fmt (org-element-at-point)))))
772 (should
773 (equal
774 "[ref:%s]"
775 (org-test-with-temp-text
776 "#+BEGIN_SRC emacs-lisp -l \"[ref:%s]\"\n(+ 1 1) [ref:text]\n#+END_SRC"
777 (org-element-property :label-fmt (org-element-at-point)))))))
780 ;;;; Export Block
782 (ert-deftest test-org-element/export-block-parser ()
783 "Test `export-block' parser."
784 ;; Standard test.
785 (should
786 (org-test-with-temp-text "#+BEGIN_LATEX\nText\n#+END_LATEX"
787 (org-element-map
788 (let ((org-element-block-name-alist
789 '(("LATEX" . org-element-export-block-parser))))
790 (org-element-parse-buffer))
791 'export-block 'identity)))
792 ;; Ignore case.
793 (should
794 (let ((org-element-block-name-alist
795 '(("LATEX" . org-element-export-block-parser))))
796 (org-test-with-temp-text "#+begin_latex\nText\n#+end_latex"
797 (org-element-map (org-element-parse-buffer) 'export-block 'identity))))
798 ;; Ignore incomplete block.
799 (should-not
800 (let ((org-element-block-name-alist
801 '(("LATEX" . org-element-export-block-parser))))
802 (org-test-with-temp-text "#+BEGIN_LATEX"
803 (org-element-map (org-element-parse-buffer) 'export-block
804 'identity nil t))))
805 ;; Handle non-empty blank line at the end of buffer.
806 (should
807 (let ((org-element-block-name-alist
808 '(("LATEX" . org-element-export-block-parser))))
809 (org-test-with-temp-text "#+BEGIN_LATEX\nC\n#+END_LATEX\n "
810 (= (org-element-property :end (org-element-at-point)) (point-max))))))
813 ;;;; Export Snippet
815 (ert-deftest test-org-element/export-snippet-parser ()
816 "Test `export-snippet' parser."
817 (should
818 (equal
819 '("back-end" . "contents")
820 (org-test-with-temp-text "@@back-end:contents@@"
821 (org-element-map
822 (org-element-parse-buffer) 'export-snippet
823 (lambda (snippet) (cons (org-element-property :back-end snippet)
824 (org-element-property :value snippet)))
825 nil t)))))
828 ;;;; Fixed Width
830 (ert-deftest test-org-element/fixed-width-parser ()
831 "Test fixed-width area parsing."
832 ;; Preserve indentation.
833 (should
834 (org-test-with-temp-text ": no blank\n: one blank"
835 (org-element-map (org-element-parse-buffer) 'fixed-width 'identity)))
836 ;; Fixed-width with empty lines.
837 (should
838 (org-test-with-temp-text ": first part\n:\n: \n: second part"
839 (org-element-map (org-element-parse-buffer) 'fixed-width 'identity)))
840 ;; Parse indented fixed-width markers.
841 (should
842 (org-test-with-temp-text "Text\n : no blank\n : one blank"
843 (org-element-map (org-element-parse-buffer) 'fixed-width 'identity)))
844 ;; Distinguish fixed-width areas within a list and outside of it.
845 (should
846 (= 2
847 (length
848 (org-test-with-temp-text "
849 - Item
850 : fixed-width inside
851 : fixed-width outside"
852 (org-element-map (org-element-parse-buffer) 'fixed-width 'identity)))))
853 ;; Handle non-empty blank line at the end of buffer.
854 (should
855 (org-test-with-temp-text ": A\n "
856 (= (org-element-property :end (org-element-at-point)) (point-max)))))
859 ;;;; Footnote Definition
861 (ert-deftest test-org-element/footnote-definition-parser ()
862 "Test `footnote-definition' parser."
863 (should
864 (org-test-with-temp-text "[fn:1] Definition"
865 (org-element-map (org-element-parse-buffer) 'footnote-definition
866 'identity nil t)))
867 ;; Footnote with more contents
868 (should
869 (= 29
870 (org-element-property
871 :end
872 (org-test-with-temp-text "[fn:1] Definition\n\n| a | b |"
873 (org-element-map (org-element-parse-buffer) 'footnote-definition
874 'identity nil t)))))
875 ;; Footnote starting with special syntax.
876 (should-not
877 (org-test-with-temp-text "[fn:1] - no item"
878 (org-element-map (org-element-parse-buffer) 'item 'identity)))
879 ;; Correctly handle footnote starting with an empty line.
880 (should
881 (= 9
882 (org-test-with-temp-text "[fn:1]\n\n Body"
883 (org-element-property :contents-begin (org-element-at-point)))))
884 ;; Handle non-empty blank line at the end of buffer.
885 (should
886 (org-test-with-temp-text "[fn:1] Definition\n "
887 (= (org-element-property :end (org-element-at-point)) (point-max)))))
890 ;;;; Footnotes Reference.
892 (ert-deftest test-org-element/footnote-reference-parser ()
893 "Test `footnote-reference' parser."
894 ;; Parse a standard reference.
895 (should
896 (org-test-with-temp-text "Text[fn:label]"
897 (org-element-map
898 (org-element-parse-buffer) 'footnote-reference 'identity)))
899 ;; Parse a normalized reference.
900 (should
901 (org-test-with-temp-text "Text[1]"
902 (org-element-map
903 (org-element-parse-buffer) 'footnote-reference 'identity)))
904 ;; Parse an inline reference.
905 (should
906 (org-test-with-temp-text "Text[fn:test:def]"
907 (org-element-map
908 (org-element-parse-buffer) 'footnote-reference 'identity)))
909 ;; Parse an anonymous reference.
910 (should
911 (org-test-with-temp-text "Text[fn::def]"
912 (org-element-map
913 (org-element-parse-buffer) 'footnote-reference 'identity)))
914 ;; Parse nested footnotes.
915 (should
916 (= 2
917 (length
918 (org-test-with-temp-text "Text[fn::def [fn:label]]"
919 (org-element-map
920 (org-element-parse-buffer) 'footnote-reference 'identity)))))
921 ;; Parse adjacent footnotes.
922 (should
923 (org-test-with-temp-text "Text[fn:label1][fn:label2]"
924 (= 2
925 (length
926 (org-element-map
927 (org-element-parse-buffer) 'footnote-reference 'identity)))))
928 ;; Only properly closed footnotes are recognized as such.
929 (should-not
930 (org-test-with-temp-text "Text[fn:label"
931 (org-element-map
932 (org-element-parse-buffer) 'footnote-reference 'identity))))
935 ;;;; Headline
937 (ert-deftest test-org-element/headline-comment-keyword ()
938 "Test COMMENT keyword recognition."
939 ;; Reference test.
940 (org-test-with-temp-text "* Headline"
941 (let ((org-comment-string "COMMENT"))
942 (should-not (org-element-property :commentedp (org-element-at-point)))))
943 ;; Standard position.
944 (org-test-with-temp-text "* COMMENT Headline"
945 (let ((org-comment-string "COMMENT")
946 (headline (org-element-at-point)))
947 (should (org-element-property :commentedp headline))
948 (should (equal (org-element-property :raw-value headline) "Headline"))))
949 ;; Case sensitivity.
950 (org-test-with-temp-text "* COMMENT Headline"
951 (let* ((org-comment-string "Comment")
952 (headline (org-element-at-point)))
953 (should-not (org-element-property :commentedp headline))
954 (should (equal (org-element-property :raw-value headline)
955 "COMMENT Headline"))))
956 ;; With another keyword.
957 (org-test-with-temp-text "* TODO COMMENT Headline"
958 (let* ((org-comment-string "COMMENT")
959 (org-todo-keywords '((sequence "TODO" "DONE")))
960 (headline (org-element-at-point)))
961 (should (org-element-property :commentedp headline))
962 (should (equal (org-element-property :raw-value headline) "Headline"))))
963 ;; With the keyword only.
964 (org-test-with-temp-text "* COMMENT"
965 (let* ((org-comment-string "COMMENT")
966 (headline (org-element-at-point)))
967 (should (org-element-property :commentedp headline))
968 (should (equal (org-element-property :raw-value headline) "")))))
970 (ert-deftest test-org-element/headline-archive-tag ()
971 "Test ARCHIVE tag recognition."
972 ;; Reference test.
973 (should-not
974 (org-test-with-temp-text "* Headline"
975 (let ((org-archive-tag "ARCHIVE"))
976 (org-element-property :archivedp (org-element-at-point)))))
977 ;; Single tag.
978 (org-test-with-temp-text "* Headline :ARCHIVE:"
979 (let ((org-archive-tag "ARCHIVE"))
980 (let ((headline (org-element-at-point)))
981 (should (org-element-property :archivedp headline))
982 ;; Test tag removal.
983 (should-not (org-element-property :tags headline)))))
984 ;; Multiple tags.
985 (org-test-with-temp-text "* Headline :test:ARCHIVE:"
986 (let ((org-archive-tag "ARCHIVE"))
987 (let ((headline (org-element-at-point)))
988 (should (org-element-property :archivedp headline))
989 ;; Test tag removal.
990 (should (equal (org-element-property :tags headline) '("test"))))))
991 ;; Tag is case-sensitive.
992 (should-not
993 (org-test-with-temp-text "* Headline :ARCHIVE:"
994 (let ((org-archive-tag "Archive"))
995 (org-element-property :archivedp (org-element-at-point))))))
997 (ert-deftest test-org-element/headline-properties ()
998 "Test properties from property drawer."
999 ;; All properties from property drawer have their symbol upper
1000 ;; cased.
1001 (should
1002 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:foo: bar\n:END:"
1003 (org-element-property :FOO (org-element-at-point))))
1004 (should-not
1005 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:foo: bar\n:END:"
1006 (org-element-property :foo (org-element-at-point))))
1007 ;; Also parse properties associated in inlinetasks.
1008 (when (featurep 'org-inlinetask)
1009 (should
1010 (org-test-with-temp-text "*************** Inlinetask
1011 :PROPERTIES:
1012 :foo: bar
1013 :END:
1014 *************** END"
1015 (org-element-property :FOO (org-element-at-point)))))
1016 ;; Do not find property drawer in a verbatim area.
1017 (should-not
1018 (org-test-with-temp-text
1019 "* Headline
1020 #+BEGIN_EXAMPLE
1021 :PROPERTIES:
1022 :foo: bar
1023 :END:
1024 #+END_EXAMPLE"
1025 (org-element-property :FOO (org-element-at-point))))
1026 ;; Do not use properties from a drawer associated to an inlinetask.
1027 (when (featurep 'org-inlinetask)
1028 (should-not
1029 (org-test-with-temp-text
1030 "* Headline
1031 *************** Inlinetask
1032 :PROPERTIES:
1033 :foo: bar
1034 :END:
1035 *************** END"
1036 (org-element-property
1037 :FOO (let ((org-inlinetask-min-level 15)) (org-element-at-point))))))
1038 ;; Do not find incomplete drawers.
1039 (should-not
1040 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:foo: bar"
1041 (org-element-property :FOO (org-element-at-point)))))
1044 ;;;; Horizontal Rule
1046 (ert-deftest test-org-element/horizontal-rule-parser ()
1047 "Test `horizontal-rule' parser."
1048 ;; Standard.
1049 (should
1050 (org-test-with-temp-text "-----"
1051 (org-element-map (org-element-parse-buffer) 'horizontal-rule 'identity)))
1052 ;; Indented.
1053 (should
1054 (org-test-with-temp-text " -----"
1055 (org-element-map (org-element-parse-buffer) 'horizontal-rule 'identity)))
1056 ;; Hyphen must be alone on the line.
1057 (should-not
1058 (org-test-with-temp-text "-----wrong"
1059 (org-element-map (org-element-parse-buffer) 'horizontal-rule 'identity)))
1060 ;; 4 hyphens is too small.
1061 (should-not
1062 (org-test-with-temp-text "----"
1063 (org-element-map (org-element-parse-buffer) 'horizontal-rule 'identity)))
1064 ;; Handle non-empty blank line at the end of buffer.
1065 (should
1066 (org-test-with-temp-text "-----\n "
1067 (= (org-element-property :end (org-element-at-point)) (point-max)))))
1070 ;;;; Inline Babel Call
1072 (ert-deftest test-org-element/inline-babel-call-parser ()
1073 "Test `inline-babel-call' parser."
1074 (should
1075 (org-test-with-temp-text "call_test()"
1076 (org-element-map
1077 (org-element-parse-buffer) 'inline-babel-call 'identity))))
1080 ;;;; Inline Src Block
1082 (ert-deftest test-org-element/inline-src-block-parser ()
1083 "Test `inline-src-block' parser."
1084 (should
1085 (org-test-with-temp-text "src_emacs-lisp{(+ 1 1)}"
1086 (org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
1087 ;; With switches.
1088 (should
1089 (org-test-with-temp-text "src_emacs-lisp[:foo bar]{(+ 1 1)}"
1090 (org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
1091 (should
1092 (org-test-with-temp-text "src_emacs-lisp[ :foo bar]{(+ 1 1)}"
1093 (org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
1094 ;; Empty switches.
1095 (should
1096 (org-test-with-temp-text "src_emacs-lisp[]{(+ 1 1)}"
1097 (org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
1098 ;; Invalid syntax.
1099 (should-not
1100 (org-test-with-temp-text "foosrc_emacs-lisp[]{(+ 1 1)}"
1101 (org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
1102 (should-not
1103 (org-test-with-temp-text "src_emacs-lisp[]foo{(+ 1 1)}"
1104 (org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
1105 ;; Invalid language name
1106 (should-not
1107 (org-test-with-temp-text "src_emacs-\tlisp{(+ 1 1)}"
1108 (org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
1109 ;; Test parsing at the beginning of an item.
1110 (should
1111 (org-test-with-temp-text "- src_emacs-lisp{(+ 1 1)}"
1112 (org-element-map (org-element-parse-buffer) 'inline-src-block 'identity))))
1115 ;;;; Inlinetask
1117 (ert-deftest test-org-element/inlinetask-parser ()
1118 "Test `inlinetask' parser."
1119 (when (featurep 'org-inlinetask)
1120 (let ((org-inlinetask-min-level 15))
1121 ;; Regular inlinetask.
1122 (should
1123 (eq 'inlinetask
1124 (org-test-with-temp-text
1125 "*************** Task\nTest\n*************** END"
1126 (org-element-type (org-element-at-point)))))
1127 ;; Degenerate inlinetask.
1128 (should
1129 (eq 'inlinetask
1130 (org-test-with-temp-text "*************** Task"
1131 (org-element-type (org-element-at-point)))))
1132 ;; Mixed inlinetasks.
1133 (should-not
1134 (org-test-with-temp-text
1136 *************** Task
1137 *************** Task2
1138 Contents
1139 *************** END"
1140 (forward-line)
1141 (goto-char (org-element-property :end (org-element-at-point)))
1142 (eobp)))
1143 ;; TODO keyword.
1144 (should
1145 (equal
1146 "TODO"
1147 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
1148 (org-test-with-temp-text "*************** TODO Task"
1149 (org-element-property :todo-keyword (org-element-at-point))))))
1150 ;; Planning info.
1151 (should
1152 (org-test-with-temp-text "
1153 *************** Task
1154 DEADLINE: <2012-03-29 thu.>"
1155 (forward-line)
1156 (org-element-property :deadline (org-element-at-point))))
1157 ;; Priority.
1158 (should
1161 (org-test-with-temp-text "
1162 *************** [#A] Task"
1163 (forward-line)
1164 (org-element-property :priority (org-element-at-point)))))
1165 ;; Tags.
1166 (should
1167 (equal
1168 '("test")
1169 (org-test-with-temp-text "
1170 *************** Task :test:"
1171 (forward-line)
1172 (org-element-property :tags (org-element-at-point)))))
1173 ;; Regular properties are accessed through upper case keywords.
1174 (should
1175 (org-test-with-temp-text "
1176 *************** Task
1177 :PROPERTIES:
1178 :foo: bar
1179 :END:
1180 *************** END"
1181 (forward-line)
1182 (org-element-property :FOO (org-element-at-point))))
1183 (should-not
1184 (org-test-with-temp-text "
1185 *************** Task
1186 :PROPERTIES:
1187 :foo: bar
1188 :END:
1189 *************** END"
1190 (forward-line)
1191 (org-element-property :foo (org-element-at-point))))
1192 ;; Handle non-empty blank line at the end of buffer.
1193 (should
1194 (org-test-with-temp-text "*************** Task\n*************** END\n "
1195 (= (org-element-property :end (org-element-at-point)) (point-max)))))))
1198 ;;;; Italic
1200 (ert-deftest test-org-element/italic-parser ()
1201 "Test `italic' parser."
1202 ;; Regular test.
1203 (should
1204 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
1205 (org-test-with-temp-text "/italic/"
1206 (org-element-map (org-element-parse-buffer) 'italic 'identity nil t))))
1207 ;; Multi-line markup.
1208 (should
1209 (equal
1210 (org-element-contents
1211 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
1212 (org-test-with-temp-text "/first line\nsecond line/"
1213 (org-element-map (org-element-parse-buffer) 'italic 'identity nil t))))
1214 '("first line\nsecond line"))))
1217 ;;;; Item
1219 (ert-deftest test-org-element/item-parser ()
1220 "Test `item' parser."
1221 ;; Standard test.
1222 (should
1223 (org-test-with-temp-text "- item"
1224 (org-element-map (org-element-parse-buffer) 'item 'identity)))
1225 ;; Counter.
1226 (should
1227 (= 6
1228 (org-element-property
1229 :counter
1230 (org-test-with-temp-text "6. [@6] item"
1231 (org-element-map (org-element-parse-buffer) 'item 'identity nil t)))))
1232 ;; Tag
1233 (should
1234 (equal
1235 '("tag")
1236 (org-element-property
1237 :tag
1238 (org-test-with-temp-text "- tag :: description"
1239 (org-element-map (org-element-parse-buffer) 'item 'identity nil t)))))
1240 ;; No tags in ordered lists.
1241 (should-not
1242 (org-element-property
1243 :tag
1244 (org-test-with-temp-text "1. tag :: description"
1245 (org-element-map (org-element-parse-buffer) 'item 'identity nil t))))
1246 ;; Check-boxes
1247 (should
1248 (equal
1249 '(trans on off)
1250 (org-test-with-temp-text "
1251 - [-] item 1
1252 - [X] item 1.1
1253 - [ ] item 1.2"
1254 (org-element-map
1255 (org-element-parse-buffer) 'item
1256 (lambda (item) (org-element-property :checkbox item))))))
1257 ;; Item starting with special syntax.
1258 (should
1259 (equal '(("- item"))
1260 (org-test-with-temp-text "- - item"
1261 (org-element-map (org-element-parse-buffer) 'paragraph
1262 'org-element-contents))))
1263 ;; Block in an item: ignore indentation within the block.
1264 (should
1265 (org-test-with-temp-text "- item\n #+begin_src emacs-lisp\n(+ 1 1)\n #+end_src"
1266 (forward-char)
1267 (= (org-element-property :end (org-element-at-point)) (point-max)))))
1270 ;;;; Keyword
1272 (ert-deftest test-org-element/keyword-parser ()
1273 "Test `keyword' parser."
1274 ;; Standard test.
1275 (should
1276 (org-test-with-temp-text "#+KEYWORD: value"
1277 (org-element-map (org-element-parse-buffer) 'keyword 'identity)))
1278 ;; Keywords are case-insensitive.
1279 (should
1280 (org-test-with-temp-text "#+keyword: value"
1281 (org-element-map (org-element-parse-buffer) 'keyword 'identity)))
1282 ;; Affiliated keywords are not keywords.
1283 (should-not
1284 (org-test-with-temp-text "#+NAME: value
1285 Paragraph"
1286 (org-element-map (org-element-parse-buffer) 'keyword 'identity)))
1287 ;; Do not mix keywords with Babel calls and dynamic blocks.
1288 (should-not
1289 (org-test-with-temp-text "#+CALL: fun()"
1290 (org-element-map (org-element-parse-buffer) 'keyword 'identity)))
1291 (should-not
1292 (org-test-with-temp-text "#+BEGIN: my-fun\nBody\n#+END:"
1293 (org-element-map (org-element-parse-buffer) 'keyword 'identity)))
1294 ;; Handle non-empty blank line at the end of buffer.
1295 (should
1296 (org-test-with-temp-text "#+KEYWORD: value\n "
1297 (= (org-element-property :end (org-element-at-point)) (point-max)))))
1300 ;;;; Latex Environment
1302 (ert-deftest test-org-element/latex-environment-parser ()
1303 "Test `latex-environment' parser."
1304 (should
1305 (org-test-with-temp-text "\\begin{equation}\ne^{i\\pi}+1=0\n\\end{equation}"
1306 (org-element-map (org-element-parse-buffer) 'latex-environment 'identity)))
1307 ;; Allow nested environments.
1308 (should
1309 (equal
1310 "\\begin{outer}
1311 \\begin{inner}
1312 e^{i\\pi}+1=0
1313 \\end{inner}
1314 \\end{outer}"
1315 (org-test-with-temp-text "
1316 \\begin{outer}
1317 \\begin{inner}
1318 e^{i\\pi}+1=0
1319 \\end{inner}
1320 \\end{outer}"
1321 (org-element-property
1322 :value
1323 (org-element-map
1324 (org-element-parse-buffer) 'latex-environment 'identity nil t)))))
1325 ;; Allow environments with options and arguments.
1326 (should
1327 (eq 'latex-environment
1328 (org-test-with-temp-text
1329 "\\begin{theorem}[Euler]\ne^{i\\pi}+1=0\n\\end{theorem}"
1330 (org-element-type (org-element-at-point)))))
1331 (should
1332 (eq 'latex-environment
1333 (org-test-with-temp-text "\\begin{env}{arg}\nvalue\n\\end{env}"
1334 (org-element-type (org-element-at-point)))))
1335 ;; Allow environments without newline after \begin{.}.
1336 (should
1337 (eq 'latex-environment
1338 (org-test-with-temp-text "\\begin{env}{arg}something\nvalue\n\\end{env}"
1339 (org-element-type (org-element-at-point)))))
1340 ;; Allow one-line environments.
1341 (should
1342 (eq 'latex-environment
1343 (org-test-with-temp-text "\\begin{env}{arg}something\\end{env}"
1344 (org-element-type (org-element-at-point)))))
1345 ;; Should not allow different tags.
1346 (should-not
1347 (eq 'latex-environment
1348 (org-test-with-temp-text "\\begin{env*}{arg}something\\end{env}"
1349 (org-element-type (org-element-at-point)))))
1350 ;; LaTeX environments must be on separate lines.
1351 (should-not
1352 (eq 'latex-environment
1353 (org-test-with-temp-text "\\begin{env} x \\end{env} y"
1354 (org-element-type (org-element-at-point)))))
1355 (should-not
1356 (eq 'latex-environment
1357 (org-test-with-temp-text "y \\begin{env} x<point> \\end{env}"
1358 (org-element-type (org-element-at-point)))))
1359 ;; Handle non-empty blank line at the end of buffer.
1360 (should
1361 (org-test-with-temp-text "\\begin{env}\n\\end{env}\n "
1362 (= (org-element-property :end (org-element-at-point)) (point-max)))))
1365 ;;;; Latex Fragment
1367 (ert-deftest test-org-element/latex-fragment-parser ()
1368 "Test `latex-fragment' parser."
1369 (should
1370 (org-test-with-temp-text "$a$"
1371 (org-element-map (org-element-parse-buffer) 'latex-fragment 'identity)))
1372 (should
1373 (org-test-with-temp-text "$$a$$"
1374 (org-element-map (org-element-parse-buffer) 'latex-fragment 'identity)))
1375 (should
1376 (org-test-with-temp-text "\\(a\\)"
1377 (org-element-map (org-element-parse-buffer) 'latex-fragment 'identity)))
1378 (should
1379 (org-test-with-temp-text "\\[a\\]"
1380 (org-element-map
1381 (org-element-parse-buffer) 'latex-fragment 'identity)))
1382 ;; Test fragment at the beginning of an item.
1383 (should
1384 (eq 'latex-fragment
1385 (org-test-with-temp-text "- $x$"
1386 (progn (search-forward "$")
1387 (org-element-type (org-element-context)))))))
1390 ;;;; Line Break
1392 (ert-deftest test-org-element/line-break-parser ()
1393 "Test `line-break' parser."
1394 ;; Regular test.
1395 (should
1396 (org-test-with-temp-text "Text \\\\"
1397 (org-element-map (org-element-parse-buffer) 'line-break 'identity)))
1398 ;; Line break with trailing white spaces.
1399 (should
1400 (org-test-with-temp-text "Text \\\\ "
1401 (org-element-map (org-element-parse-buffer) 'line-break 'identity)))
1402 ;; Three backslashes are too much.
1403 (should-not
1404 (org-test-with-temp-text "Text \\\\\\"
1405 (org-element-map (org-element-parse-buffer) 'line-break 'identity))))
1408 ;;;; Link
1410 (ert-deftest test-org-element/link-parser ()
1411 "Test `link' parser."
1412 ;; Radio target.
1413 (should
1414 (equal
1415 "radio"
1416 (org-test-with-temp-text "<<<radio>>>A radio link"
1417 (org-update-radio-target-regexp)
1418 (org-element-property
1419 :type
1420 (org-element-map (org-element-parse-buffer) 'link #'identity nil t)))))
1421 ;; Standard link.
1423 ;; ... with description.
1424 (should
1425 (equal
1426 '("Orgmode.org")
1427 (org-test-with-temp-text "[[http://orgmode.org][Orgmode.org]]"
1428 (org-element-contents
1429 (org-element-map (org-element-parse-buffer) 'link 'identity nil t)))))
1430 ;; ... without description.
1431 (should
1432 (equal
1433 "http"
1434 (org-test-with-temp-text "[[http://orgmode.org]]"
1435 (org-element-property
1436 :type
1437 (org-element-map (org-element-parse-buffer) 'link 'identity nil t)))))
1438 ;; ... with expansion.
1439 (should
1440 (equal
1441 "//orgmode.org/worg"
1442 (org-test-with-temp-text "[[Org:worg]]"
1443 (let ((org-link-abbrev-alist '(("Org" . "http://orgmode.org/"))))
1444 (org-element-property
1445 :path
1446 (org-element-map (org-element-parse-buffer) 'link 'identity nil t))))))
1447 ;; ... with translation.
1448 (should
1449 (equal
1450 "127.0.0.1"
1451 (org-test-with-temp-text "[[http://orgmode.org]]"
1452 (flet ((link-translate (type path) (cons type "127.0.0.1")))
1453 (let ((org-link-translation-function 'link-translate))
1454 (org-element-property
1455 :path
1456 (org-element-map (org-element-parse-buffer) 'link
1457 'identity nil t)))))))
1458 ;; ... id link.
1459 (should
1460 (equal
1461 "id"
1462 (org-test-with-temp-text "[[id:aaaa]]"
1463 (org-element-property
1464 :type
1465 (org-element-map (org-element-parse-buffer) 'link 'identity nil t)))))
1466 ;; ... custom-id link.
1467 (should
1468 (equal
1469 "custom-id"
1470 (org-test-with-temp-text "[[#some-id]]"
1471 (org-element-property
1472 :type
1473 (org-element-map (org-element-parse-buffer) 'link 'identity nil t)))))
1474 ;; ... coderef link.
1475 (should
1476 (equal
1477 "coderef"
1478 (org-test-with-temp-text "[[(reference)]]"
1479 (org-element-property
1480 :type
1481 (org-element-map (org-element-parse-buffer) 'link 'identity nil t)))))
1482 ;; ... fuzzy link.
1483 (should
1484 (equal
1485 "fuzzy"
1486 (org-test-with-temp-text "[[target-or-title]]"
1487 (org-element-property
1488 :type
1489 (org-element-map (org-element-parse-buffer) 'link 'identity nil t)))))
1490 ;; ... file-type link with search option.
1491 (should
1492 (equal
1493 '(("file" "projects.org" "*task title"))
1494 (org-test-with-temp-text "[[file:projects.org::*task title]]"
1495 (org-element-map (org-element-parse-buffer) 'link
1496 (lambda (l) (list (org-element-property :type l)
1497 (org-element-property :path l)
1498 (org-element-property :search-option l)))))))
1499 ;; ... file-type link with application...
1500 (should
1501 (equal
1502 '("file" "projects.org" "docview")
1503 (org-test-with-temp-text "[[docview:projects.org]]"
1504 (let ((l (org-element-context)))
1505 (list (org-element-property :type l)
1506 (org-element-property :path l)
1507 (org-element-property :application l))))))
1508 ;; ... `:path' in a file-type link must be compatible with "file"
1509 ;; scheme in URI syntax, even if Org syntax isn't...
1510 (should
1511 (org-test-with-temp-text-in-file ""
1512 (let ((file (expand-file-name (buffer-file-name))))
1513 (insert (format "[[file://%s]]" file))
1514 (equal (org-element-property :path (org-element-context))
1515 (concat "//" file)))))
1516 (should
1517 (org-test-with-temp-text-in-file ""
1518 (let ((file (expand-file-name (buffer-file-name))))
1519 (insert (format "[[file:%s]]" file))
1520 (equal (org-element-property :path (org-element-context))
1521 (concat "//" file)))))
1522 (should
1523 (org-test-with-temp-text-in-file ""
1524 (let ((file (file-relative-name (buffer-file-name))))
1525 (insert (format "[[file:%s]]" file))
1526 (list (org-element-property :path (org-element-context)) file))))
1527 ;; ... multi-line link.
1528 (should
1529 (equal "//orgmode.org"
1530 (org-test-with-temp-text "[[http://orgmode.\norg]]"
1531 (org-element-property :path (org-element-context)))))
1532 ;; Plain link.
1533 (should
1534 (org-test-with-temp-text "A link: http://orgmode.org"
1535 (org-element-map (org-element-parse-buffer) 'link 'identity)))
1536 ;; Angular link.
1537 (should
1538 (org-test-with-temp-text "A link: <http://orgmode.org>"
1539 (org-element-map (org-element-parse-buffer) 'link 'identity nil t)))
1540 ;; Link abbreviation.
1541 (should
1542 (equal "http"
1543 (org-test-with-temp-text
1544 "#+LINK: orgmode http://www.orgmode.org/\n[[orgmode:#docs]]"
1545 (progn (org-mode-restart)
1546 (goto-char (1- (point-max)))
1547 (org-element-property :type (org-element-context))))))
1548 ;; Link abbreviation in a secondary string.
1549 (should
1550 (equal "http"
1551 (org-test-with-temp-text
1552 "#+LINK: orgmode http://www.orgmode.org/\n* H [[orgmode:#docs]]"
1553 (progn (org-mode-restart)
1554 (org-element-map (org-element-parse-buffer) 'link
1555 (lambda (link) (org-element-property :type link))
1556 nil t nil t)))))
1557 ;; Plain links are allowed as description of regular links.
1558 (should
1559 (equal "file"
1560 (org-test-with-temp-text "[[http://orgmode.org][file:unicorn.jpg]]"
1561 (search-forward "file:")
1562 (org-element-property :type (org-element-context))))))
1565 ;;;; Macro
1567 (ert-deftest test-org-element/macro-parser ()
1568 "Test `macro' parser."
1569 ;; Without arguments.
1570 (should
1571 (org-test-with-temp-text "{{{macro}}}"
1572 (org-element-map (org-element-parse-buffer) 'macro 'identity)))
1573 ;; With arguments.
1574 (should
1575 (org-test-with-temp-text "{{{macro(arg1,arg2)}}}"
1576 (org-element-map (org-element-parse-buffer) 'macro 'identity)))
1577 ;; Properly handle protected commas in arguments...
1578 (should
1579 (= 2
1580 (length
1581 (org-test-with-temp-text "{{{macro(arg1\\,arg1,arg2)}}}"
1582 (org-element-property :args (org-element-context))))))
1583 ;; ... even when last argument ends with a protected comma.
1584 (should
1585 (equal '("C-,")
1586 (org-test-with-temp-text "{{{macro(C-\\,)}}}"
1587 (org-element-property :args (org-element-context)))))
1588 ;; Allow to escape escaping character.
1589 (should
1590 (equal '("C-\\" "")
1591 (org-test-with-temp-text "{{{macro(C-\\\\,)}}}"
1592 (org-element-property :args (org-element-context)))))
1593 ;; No need to escape backslashes elsewhere.
1594 (should
1595 (equal '("\\")
1596 (org-test-with-temp-text "{{{macro(\\)}}}"
1597 (org-element-property :args (org-element-context))))))
1600 ;;;; Node Property
1602 (ert-deftest test-org-element/node-property ()
1603 "Test `node-property' parser."
1604 ;; Standard test.
1605 (should
1606 (equal '("abc" "value")
1607 (org-test-with-temp-text ":PROPERTIES:\n<point>:abc: value\n:END:"
1608 (let ((element (org-element-at-point)))
1609 (list (org-element-property :key element)
1610 (org-element-property :value element))))))
1611 ;; Value should be trimmed.
1612 (should
1613 (equal "value"
1614 (org-test-with-temp-text ":PROPERTIES:\n<point>:abc: value \n:END:"
1615 (org-element-property :value (org-element-at-point)))))
1616 ;; A node property requires to be wrapped within a property drawer.
1617 (should-not
1618 (eq 'node-property
1619 (org-test-with-temp-text ":abc: value"
1620 (org-element-type (org-element-at-point)))))
1621 ;; Accept empty properties.
1622 (should
1623 (equal '(("foo" "value") ("bar" ""))
1624 (org-test-with-temp-text ":PROPERTIES:\n:foo: value\n:bar:\n:END:"
1625 (org-element-map (org-element-parse-buffer) 'node-property
1626 (lambda (p)
1627 (list (org-element-property :key p)
1628 (org-element-property :value p)))))))
1629 ;; Ignore all non-property lines in property drawers.
1630 (should
1631 (equal
1632 '(("foo" "value"))
1633 (org-test-with-temp-text ":PROPERTIES:\nWrong1\n:foo: value\nWrong2\n:END:"
1634 (org-element-map (org-element-parse-buffer) 'node-property
1635 (lambda (p)
1636 (list (org-element-property :key p)
1637 (org-element-property :value p))))))))
1640 ;;;; Paragraph
1642 (ert-deftest test-org-element/paragraph-parser ()
1643 "Test `paragraph' parser."
1644 ;; Standard test.
1645 (should
1646 (org-test-with-temp-text "Paragraph"
1647 (org-element-map (org-element-parse-buffer) 'paragraph 'identity nil t)))
1648 ;; Property find end of a paragraph stuck to another element.
1649 (should
1650 (eq ?#
1651 (org-test-with-temp-text "Paragraph\n# Comment"
1652 (org-element-map (org-element-parse-buffer) 'paragraph
1653 (lambda (p) (char-after (org-element-property :end p)))
1654 nil t))))
1655 ;; Include ill-formed Keywords.
1656 (should
1657 (org-test-with-temp-text "#+wrong_keyword something"
1658 (org-element-map (org-element-parse-buffer) 'paragraph 'identity)))
1659 ;; Include incomplete-drawers.
1660 (should
1661 (org-test-with-temp-text ":TEST:\nParagraph"
1662 (let ((elem (org-element-at-point)))
1663 (and (eq (org-element-type elem) 'paragraph)
1664 (= (point-max) (org-element-property :end elem))))))
1665 ;; Include incomplete blocks.
1666 (should
1667 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph"
1668 (let ((elem (org-element-at-point)))
1669 (and (eq (org-element-type elem) 'paragraph)
1670 (= (point-max) (org-element-property :end elem))))))
1671 ;; Include incomplete dynamic blocks.
1672 (should
1673 (org-test-with-temp-text "#+BEGIN: \nParagraph"
1674 (let ((elem (org-element-at-point)))
1675 (and (eq (org-element-type elem) 'paragraph)
1676 (= (point-max) (org-element-property :end elem))))))
1677 ;; Include incomplete latex environments.
1678 (should
1679 (org-test-with-temp-text "\begin{equation}\nParagraph"
1680 (let ((elem (org-element-at-point)))
1681 (and (eq (org-element-type elem) 'paragraph)
1682 (= (point-max) (org-element-property :end elem))))))
1683 ;; Do not steal affiliated keywords from container.
1684 (should
1685 (org-test-with-temp-text "#+ATTR_LATEX: test\n- item 1"
1686 (let ((elem (progn (search-forward "item") (org-element-at-point))))
1687 (and (eq (org-element-type elem) 'paragraph)
1688 (not (org-element-property :attr_latex elem))
1689 (/= (org-element-property :begin elem) 1)))))
1690 ;; Handle non-empty blank line at the end of buffer.
1691 (should
1692 (org-test-with-temp-text "#+BEGIN_CENTER\nC\n#+END_CENTER\n "
1693 (= (org-element-property :end (org-element-at-point)) (point-max)))))
1696 ;;;; Plain List
1698 (ert-deftest test-org-element/plain-list-parser ()
1699 "Test `plain-list' parser."
1700 (org-test-with-temp-text "- item"
1701 (should (org-element-map (org-element-parse-buffer) 'plain-list 'identity)))
1702 ;; Blank lines after the list only belong to outer plain list.
1703 (should
1704 (equal
1705 '(t t)
1706 (org-test-with-temp-text "
1707 - outer
1708 - inner
1710 Outside list"
1711 (let ((endings (org-element-map (org-element-parse-buffer) 'plain-list
1712 (lambda (pl) (org-element-property :end pl)))))
1713 (list
1714 ;; Move to ending of outer list.
1715 (progn (goto-char (car endings)) (looking-at "Outside list"))
1716 ;; Move to ending of inner list.
1717 (progn (goto-char (nth 1 endings)) (looking-at "^$")))))))
1718 ;; Correctly compute end of list if it doesn't end at a line
1719 ;; beginning.
1720 (should
1721 (org-test-with-temp-text "- list\n \n "
1722 (= (org-element-property :end (org-element-at-point)) (point-max)))))
1725 ;;;; Planning
1727 (ert-deftest test-org-element/planning-parser ()
1728 "Test `planning' parser."
1729 ;; Test various keywords.
1730 (should
1731 (org-element-property
1732 :closed
1733 (org-test-with-temp-text "* H\n<point>CLOSED: [2012-03-29 thu.]"
1734 (org-element-at-point))))
1735 (should
1736 (org-element-property
1737 :deadline
1738 (org-test-with-temp-text "* H\n<point>DEADLINE: <2012-03-29 thu.>"
1739 (org-element-at-point))))
1740 (should
1741 (org-element-property
1742 :scheduled
1743 (org-test-with-temp-text "* H\n<point>SCHEDULED: <2012-03-29 thu.>"
1744 (org-element-at-point))))
1745 ;; Planning line only exists right after a headline.
1746 (should-not
1747 (eq 'planning
1748 (org-test-with-temp-text "DEADLINE: <2012-03-29 thu.>"
1749 (org-element-type (org-element-at-point)))))
1750 (should-not
1751 (eq 'planning
1752 (org-test-with-temp-text
1753 "* H\n# Comment\n<point>DEADLINE: <2012-03-29 thu.>"
1754 (org-element-type (org-element-at-point))))))
1757 ;;;; Property Drawer
1759 (ert-deftest test-org-element/property-drawer-parser ()
1760 "Test `property-drawer' parser."
1761 ;; Standard test.
1762 (should
1763 (org-test-with-temp-text ":PROPERTIES:\n:prop: value\n:END:"
1764 (org-element-map
1765 (org-element-parse-buffer) 'property-drawer 'identity nil t)))
1766 ;; Do not mix property drawers and regular drawers.
1767 (should-not
1768 (org-test-with-temp-text ":TEST:\n:prop: value\n:END:"
1769 (org-element-map
1770 (org-element-parse-buffer) 'property-drawer 'identity nil t)))
1771 ;; Ignore incomplete drawer.
1772 (should-not
1773 (org-test-with-temp-text ":PROPERTIES:\n:prop: value"
1774 (org-element-map
1775 (org-element-parse-buffer) 'property-drawer 'identity nil t)))
1776 ;; Handle non-empty blank line at the end of buffer.
1777 (should
1778 (org-test-with-temp-text ":PROPERTIES:\n:END:\n "
1779 (= (org-element-property :end (org-element-at-point)) (point-max)))))
1782 ;;;; Quote Block
1784 (ert-deftest test-org-element/quote-block-parser ()
1785 "Test `quote-block' parser."
1786 ;; Regular test.
1787 (should
1788 (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
1789 (org-element-map (org-element-parse-buffer) 'quote-block 'identity)))
1790 ;; Ignore incomplete block.
1791 (should-not
1792 (org-test-with-temp-text "#+BEGIN_QUOTE"
1793 (org-element-map (org-element-parse-buffer) 'quote-block 'identity nil t)))
1794 ;; Handle non-empty blank line at the end of buffer.
1795 (should
1796 (org-test-with-temp-text "#+BEGIN_QUOTE\nC\n#+END_QUOTE\n "
1797 (= (org-element-property :end (org-element-at-point)) (point-max)))))
1800 ;;;; Radio Target
1802 (ert-deftest test-org-element/radio-target-parser ()
1803 "Test `radio-target' parser."
1804 ;; Standard test.
1805 (should
1806 (eq 'radio-target
1807 (org-test-with-temp-text "<<<radio>>>"
1808 (org-element-type (org-element-context)))))
1809 ;; Radio targets with objects.
1810 (should
1811 (eq 'radio-target
1812 (org-test-with-temp-text "<<<radio \\alpha>>>"
1813 (org-element-type (org-element-context)))))
1814 ;; Radio targets starting with an object.
1815 (should
1816 (eq 'radio-target
1817 (org-test-with-temp-text "<<<\\alpha radio>>>"
1818 (org-element-type (org-element-context)))))
1819 ;; Radio targets cannot begin or end with white space.
1820 (should-not
1821 (eq 'radio-target
1822 (org-test-with-temp-text "<<< radio>>>"
1823 (org-element-type (org-element-context)))))
1824 (should-not
1825 (eq 'radio-target
1826 (org-test-with-temp-text "<<<radio >>>"
1827 (org-element-type (org-element-context))))))
1830 ;;;; Section
1832 (ert-deftest test-org-element/section-parser ()
1833 "Test `section' parser."
1834 ;; Standard test.
1835 (should
1836 (org-test-with-temp-text "* Headline\nText"
1837 (org-element-map (org-element-parse-buffer) 'section 'identity)))
1838 ;; There's a section before the first headline.
1839 (should
1840 (org-test-with-temp-text "Text"
1841 (org-element-map (org-element-parse-buffer) 'section 'identity)))
1842 ;; A section cannot be empty.
1843 (should-not
1844 (org-test-with-temp-text "* Headline 1\n* Headline 2"
1845 (org-element-map (org-element-parse-buffer) 'section 'identity)))
1846 ;; A section doesn't contain sub-trees.
1847 (should-not
1848 (org-test-with-temp-text "* Head\nText\n** Sub-Head"
1849 (org-element-map
1850 (org-element-map (org-element-parse-buffer) 'section 'identity nil t)
1851 'headline 'identity))))
1854 ;;;; Special Block
1856 (ert-deftest test-org-element/special-block-parser ()
1857 "Test `special-block' parser."
1858 ;; Standard test.
1859 (should
1860 (equal "SPECIAL"
1861 (org-test-with-temp-text "#+BEGIN_SPECIAL\nText\n#+END_SPECIAL"
1862 (org-element-property :type (org-element-at-point)))))
1863 ;; Special blocks are case sensitive.
1864 (should
1865 (equal "CaSe"
1866 (org-test-with-temp-text "#+BEGIN_CaSe\nText\n#+END_CaSe"
1867 (org-element-property :type (org-element-at-point)))))
1868 ;; Special blocks can contain paragraphs.
1869 (should
1870 (eq 'paragraph
1871 (org-test-with-temp-text "#+BEGIN_SPECIAL\nText\n#+END_SPECIAL"
1872 (forward-line)
1873 (org-element-type (org-element-at-point)))))
1874 ;; Ignore incomplete block.
1875 (should-not
1876 (eq 'special-block
1877 (org-test-with-temp-text "#+BEGIN_SPECIAL"
1878 (org-element-type (org-element-at-point)))))
1879 ;; Allow special characters in type.
1880 (should
1881 (equal '(special-block "SPECIAL*")
1882 (org-test-with-temp-text "#+BEGIN_SPECIAL*\nContents\n#+END_SPECIAL*"
1883 (let ((element (org-element-at-point)))
1884 (list (org-element-type element)
1885 (org-element-property :type element))))))
1886 ;; Handle non-empty blank line at the end of buffer.
1887 (should
1888 (org-test-with-temp-text "#+BEGIN_SPECIAL\nC\n#+END_SPECIAL\n "
1889 (= (org-element-property :end (org-element-at-point)) (point-max)))))
1892 ;;;; Src Block
1894 (ert-deftest test-org-element/src-block-parser ()
1895 "Test `src-block' parser."
1896 ;; Regular tests.
1897 (should
1898 (org-test-with-temp-text "#+BEGIN_SRC org\nText\n#+END_SRC"
1899 (org-element-map (org-element-parse-buffer) 'src-block 'identity)))
1900 ;; Ignore incomplete block.
1901 (should-not
1902 (org-test-with-temp-text "#+BEGIN_SRC"
1903 (org-element-map (org-element-parse-buffer) 'src-block 'identity)))
1904 ;; Properly un-escape code.
1905 (should
1906 (equal "* Headline\n #+keyword\nText\n"
1907 (org-test-with-temp-text
1908 "#+BEGIN_SRC org\n,* Headline\n ,#+keyword\nText\n#+END_SRC"
1909 (org-element-property :value (org-element-at-point)))))
1910 ;; Remove block indentation according to block boundaries, unless
1911 ;; block contents are less indented than block boundaries.
1912 (should
1913 (equal " L1\nL2\n"
1914 (org-test-with-temp-text " #+BEGIN_SRC org\n L1\n L2\n #+END_SRC"
1915 (let ((org-src-preserve-indentation t))
1916 (org-element-property :value (org-element-at-point))))))
1917 (should
1918 (equal
1919 " L1\n L2\n"
1920 (org-test-with-temp-text " #+BEGIN_SRC org\n L1\n L2\n #+END_SRC"
1921 (let ((org-src-preserve-indentation t))
1922 (org-element-property :value (org-element-at-point))))))
1923 ;; Handle non-empty blank line at the end of buffer.
1924 (should
1925 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\nC\n#+END_SRC\n "
1926 (= (org-element-property :end (org-element-at-point)) (point-max)))))
1929 ;;;; Statistics Cookie
1931 (ert-deftest test-org-element/statistics-cookie ()
1932 "Test `statistics-cookie' parser."
1933 ;; With numbers.
1934 (should
1935 (org-test-with-temp-text "[1/2]"
1936 (org-element-map (org-element-parse-buffer) 'statistics-cookie 'identity)))
1937 ;; With percents.
1938 (should
1939 (org-test-with-temp-text "[33%]"
1940 (org-element-map
1941 (org-element-parse-buffer) 'statistics-cookie 'identity))))
1944 ;;;; Strike Through
1946 (ert-deftest test-org-element/strike-through-parser ()
1947 "Test `strike-through' parser."
1948 ;; Regular test.
1949 (should
1950 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
1951 (org-test-with-temp-text "+strike-through+"
1952 (org-element-map (org-element-parse-buffer) 'strike-through 'identity))))
1953 ;; Multi-line markup.
1954 (should
1955 (equal
1956 (org-element-contents
1957 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
1958 (org-test-with-temp-text "+first line\nsecond line+"
1959 (org-element-map
1960 (org-element-parse-buffer) 'strike-through 'identity nil t))))
1961 '("first line\nsecond line"))))
1964 ;;;; Subscript
1966 (ert-deftest test-org-element/subscript-parser ()
1967 "Test `subscript' parser."
1968 ;; Without braces.
1969 (should
1970 (org-test-with-temp-text "a_b"
1971 (org-element-map (org-element-parse-buffer) 'subscript 'identity)))
1972 ;; With braces.
1973 (should
1974 (org-test-with-temp-text "a_{b}"
1975 (org-element-map (org-element-parse-buffer) 'subscript 'identity)))
1976 ;; Multiple subscripts in a paragraph.
1977 (should
1978 (= 2
1979 (org-test-with-temp-text "a_b and c_d"
1980 (length
1981 (org-element-map (org-element-parse-buffer) 'subscript 'identity))))))
1984 ;;;; Superscript
1986 (ert-deftest test-org-element/superscript-parser ()
1987 "Test `superscript' parser."
1988 ;; Without braces.
1989 (should
1990 (org-test-with-temp-text "a^b"
1991 (org-element-map (org-element-parse-buffer) 'superscript 'identity)))
1992 ;; With braces.
1993 (should
1994 (org-test-with-temp-text "a^{b}"
1995 (org-element-map (org-element-parse-buffer) 'superscript 'identity)))
1996 ;; Multiple superscript in a paragraph.
1997 (should
1998 (= 2
1999 (org-test-with-temp-text "a^b and c^d"
2000 (length
2001 (org-element-map
2002 (org-element-parse-buffer) 'superscript 'identity))))))
2005 ;;;; Table
2007 (ert-deftest test-org-element/table-parser ()
2008 "Test `table' parser."
2009 (should
2010 (org-test-with-temp-text "| a |"
2011 (org-element-map (org-element-parse-buffer) 'table 'identity)))
2012 ;; TBLFM keyword is case insensitive.
2013 (should
2014 (org-test-with-temp-text "| a |\n#+tblfm: test"
2015 (org-element-property
2016 :tblfm
2017 (org-element-map (org-element-parse-buffer) 'table 'identity nil t))))
2018 ;; Handle multiple TBLFM lines.
2019 (should
2020 (= 2
2021 (org-test-with-temp-text "| a |\n#+TBLFM: test1\n#+TBLFM: test2"
2022 (length (org-element-property
2023 :tblfm
2024 (org-element-map
2025 (org-element-parse-buffer) 'table 'identity nil t))))))
2026 ;; Handle non-empty blank line at the end of buffer.
2027 (should
2028 (org-test-with-temp-text "| a |\n "
2029 (= (org-element-property :end (org-element-at-point)) (point-max)))))
2032 ;;;; Table Cell
2034 (ert-deftest test-org-element/table-cell-parser ()
2035 "Test `table-cell' parser."
2036 ;; Regular table cell.
2037 (should
2038 (org-test-with-temp-text "| a |"
2039 (org-element-map (org-element-parse-buffer) 'table-cell 'identity)))
2040 ;; Last vertical bar may be omitted.
2041 (should
2042 (org-test-with-temp-text "| a "
2043 (org-element-map (org-element-parse-buffer) 'table-cell 'identity))))
2046 ;;;; Table Row
2048 (ert-deftest test-org-element/table-row-parser ()
2049 "Test `table-row' parser."
2050 (should
2051 (equal '(standard rule)
2052 (org-test-with-temp-text "| a |\n|---|"
2053 (org-element-map
2054 (org-element-parse-buffer) 'table-row
2055 (lambda (row) (org-element-property :type row)))))))
2058 ;;;; Target
2060 (ert-deftest test-org-element/target-parser ()
2061 "Test `target' parser."
2062 (should
2063 (org-test-with-temp-text "<<target>>"
2064 (org-element-map (org-element-parse-buffer) 'target 'identity))))
2067 ;;;; Timestamp
2069 (ert-deftest test-org-element/timestamp ()
2070 "Test `timestamp' parser."
2071 ;; Active timestamp.
2072 (should
2073 (org-test-with-temp-text "<2012-03-29 16:40>"
2074 (eq (org-element-property :type (org-element-context)) 'active)))
2075 (should-not
2076 (org-test-with-temp-text "<2012-03-29 Thu>"
2077 (let ((timestamp (org-element-context)))
2078 (or (org-element-property :hour-start timestamp)
2079 (org-element-property :minute-start timestamp)))))
2080 (should
2081 (equal '(2012 3 29 16 40)
2082 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
2083 (let ((object (org-element-context)))
2084 (list (org-element-property :year-start object)
2085 (org-element-property :month-start object)
2086 (org-element-property :day-start object)
2087 (org-element-property :hour-start object)
2088 (org-element-property :minute-start object))))))
2089 ;; Inactive timestamp.
2090 (should
2091 (org-test-with-temp-text "[2012-03-29 Thu 16:40]"
2092 (eq (org-element-property :type (org-element-context)) 'inactive)))
2093 ;; Time range.
2094 (should
2095 (equal '(2012 3 29 16 40 7 30)
2096 (org-test-with-temp-text "<2012-03-29 Thu 7:30-16:40>"
2097 (let ((object (org-element-context)))
2098 (list (org-element-property :year-end object)
2099 (org-element-property :month-end object)
2100 (org-element-property :day-end object)
2101 (org-element-property :hour-end object)
2102 (org-element-property :minute-end object)
2103 (org-element-property :hour-start object)
2104 (org-element-property :minute-start object))))))
2105 (should
2106 (eq 'active-range
2107 (org-test-with-temp-text "<2012-03-29 Thu 7:30-16:40>"
2108 (org-element-property :type (org-element-context)))))
2109 ;; Date range.
2110 (should
2111 (org-test-with-temp-text "[2012-03-29 Thu 16:40]--[2012-03-29 Thu 16:41]"
2112 (eq (org-element-property :type (org-element-context)) 'inactive-range)))
2113 (should-not
2114 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
2115 (let ((timestamp (org-element-context)))
2116 (or (org-element-property :hour-end timestamp)
2117 (org-element-property :minute-end timestamp)))))
2118 ;; With repeater, warning delay and both.
2119 (should
2120 (eq 'catch-up
2121 (org-test-with-temp-text "<2012-03-29 Thu ++1y>"
2122 (org-element-property :repeater-type (org-element-context)))))
2123 (should
2124 (eq 'first
2125 (org-test-with-temp-text "<2012-03-29 Thu --1y>"
2126 (org-element-property :warning-type (org-element-context)))))
2127 (should
2128 (equal '(cumulate all)
2129 (org-test-with-temp-text "<2012-03-29 Thu +1y -1y>"
2130 (let ((ts (org-element-context)))
2131 (list (org-element-property :repeater-type ts)
2132 (org-element-property :warning-type ts)))))))
2135 ;;;; Underline
2137 (ert-deftest test-org-element/underline-parser ()
2138 "Test `underline' parser."
2139 ;; Regular test.
2140 (should
2141 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
2142 (org-test-with-temp-text "_underline_"
2143 (org-element-map (org-element-parse-buffer) 'underline 'identity))))
2144 ;; Multi-line markup.
2145 (should
2146 (equal
2147 (org-element-contents
2148 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
2149 (org-test-with-temp-text "_first line\nsecond line_"
2150 (org-element-map
2151 (org-element-parse-buffer) 'underline 'identity nil t))))
2152 '("first line\nsecond line"))))
2155 ;;;; Verbatim
2157 (ert-deftest test-org-element/verbatim-parser ()
2158 "Test `verbatim' parser."
2159 ;; Regular test.
2160 (should
2161 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
2162 (org-test-with-temp-text "=verbatim="
2163 (org-element-map (org-element-parse-buffer) 'verbatim 'identity))))
2164 ;; Multi-line markup.
2165 (should
2166 (equal
2167 (org-element-property
2168 :value
2169 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
2170 (org-test-with-temp-text "=first line\nsecond line="
2171 (org-element-map
2172 (org-element-parse-buffer) 'verbatim 'identity nil t))))
2173 "first line\nsecond line")))
2176 ;;;; Verse Block
2178 (ert-deftest test-org-element/verse-block-parser ()
2179 "Test `verse-block' parser."
2180 ;; Standard test.
2181 (should
2182 (org-test-with-temp-text "#+BEGIN_VERSE\nVerse block\n#+END_VERSE"
2183 (org-element-map (org-element-parse-buffer) 'verse-block 'identity)))
2184 ;; Ignore case.
2185 (should
2186 (org-test-with-temp-text "#+begin_verse\nVerse block\n#+end_verse"
2187 (org-element-map (org-element-parse-buffer) 'verse-block 'identity)))
2188 ;; Parse objects in verse blocks.
2189 (should
2190 (org-test-with-temp-text "#+BEGIN_VERSE\nVerse \\alpha\n#+END_VERSE"
2191 (org-element-map (org-element-parse-buffer) 'entity 'identity)))
2192 ;; Ignore incomplete verse block.
2193 (should-not
2194 (org-test-with-temp-text "#+BEGIN_VERSE"
2195 (org-element-map (org-element-parse-buffer) 'verse-block 'identity nil t)))
2196 ;; Handle non-empty blank line at the end of buffer.
2197 (should
2198 (org-test-with-temp-text "#+BEGIN_VERSE\nC\n#+END_VERSE\n "
2199 (= (org-element-property :end (org-element-at-point)) (point-max)))))
2203 ;;; Test Interpreters.
2205 (ert-deftest test-org-element/interpret-data ()
2206 "Test `org-element-interpret-data' specifications."
2207 ;; Interpret simple affiliated keywords.
2208 (should
2209 (equal
2210 (org-element-interpret-data
2211 '(org-data nil (paragraph (:name "para") "Paragraph")))
2212 "#+NAME: para\nParagraph\n"))
2213 ;; Interpret multiple affiliated keywords.
2214 (should
2215 (equal
2216 (org-element-interpret-data
2217 '(org-data nil (paragraph (:attr_ascii ("line2" "line1")) "Paragraph")))
2218 "#+ATTR_ASCII: line1\n#+ATTR_ASCII: line2\nParagraph\n"))
2219 ;; Interpret parsed affiliated keywords.
2220 (should
2221 (equal
2222 (org-element-interpret-data
2223 '(org-data nil (paragraph (:caption (("caption"))) "Paragraph")))
2224 "#+CAPTION: caption\nParagraph\n"))
2225 ;; Interpret dual affiliated keywords.
2226 (should
2227 (equal
2228 (org-element-interpret-data
2229 '(org-data nil (paragraph (:caption ((("long") "short"))) "Paragraph")))
2230 "#+CAPTION[short]: long\nParagraph\n"))
2231 ;; Interpret multiple parsed dual keywords.
2232 (should
2233 (equal
2234 (org-element-interpret-data
2235 '(org-data nil (paragraph
2236 (:caption ((("l2") "s2") (("l1") "s1"))) "Paragraph")))
2237 "#+CAPTION[s1]: l1\n#+CAPTION[s2]: l2\nParagraph\n"))
2238 ;; Pseudo objects and elements are transparent.
2239 (should
2240 (equal "A B\n"
2241 (org-element-interpret-data
2242 '(paragraph nil (pseudo-object (:post-blank 1) "A") "B")
2243 '(pseudo-object))))
2244 (should
2245 (equal "A\n\nB\n"
2246 (org-element-interpret-data
2247 '(center nil
2248 (pseudo-element (:post-blank 1) (paragraph nil "A"))
2249 (paragraph nil "B"))))))
2251 (ert-deftest test-org-element/center-block-interpreter ()
2252 "Test center block interpreter."
2253 (should
2254 (equal (org-test-parse-and-interpret "#+BEGIN_CENTER\nTest\n#+END_CENTER")
2255 "#+BEGIN_CENTER\nTest\n#+END_CENTER\n")))
2257 (ert-deftest test-org-element/drawer-interpreter ()
2258 "Test drawer interpreter."
2259 (should
2260 (equal (org-test-parse-and-interpret ":TEST:\nTest\n:END:")
2261 ":TEST:\nTest\n:END:\n")))
2263 (ert-deftest test-org-element/dynamic-block-interpreter ()
2264 "Test dynamic block interpreter."
2265 (should
2266 (equal (org-test-parse-and-interpret
2267 "#+BEGIN: myblock :parameter value1\nTest\n#+END:")
2268 "#+BEGIN: myblock :parameter value1\nTest\n#+END:\n")))
2270 (ert-deftest test-org-element/footnote-definition-interpreter ()
2271 "Test footnote definition interpreter."
2272 (should (equal (org-test-parse-and-interpret "[fn:1] Test") "[fn:1] Test\n")))
2274 (ert-deftest test-org-element/headline-interpreter ()
2275 "Test headline and section interpreters."
2276 ;; 1. Standard test.
2277 (should (equal (org-test-parse-and-interpret "* Headline") "* Headline\n"))
2278 ;; 2. With TODO keywords.
2279 (should
2280 (equal (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
2281 (org-test-parse-and-interpret "* TODO Headline"))
2282 "* TODO Headline\n"))
2283 ;; 3. With tags...
2285 ;; 3.1. ... and a positive `org-tags-column' value.
2286 (should
2287 (equal (let ((org-tags-column 20))
2288 (org-test-parse-and-interpret "* Headline :tag:"))
2289 "* Headline :tag:\n"))
2290 ;; 3.2. ... and a negative `org-tags-column' value.
2291 (should
2292 (equal (let ((org-tags-column -20))
2293 (org-test-parse-and-interpret "* Headline :tag:"))
2294 "* Headline :tag:\n"))
2295 ;; 3.3. ... and a null `org-tags-column' value.
2296 (should
2297 (equal (let ((org-tags-column 0))
2298 (org-test-parse-and-interpret "* Headline :tag:"))
2299 "* Headline :tag:\n"))
2300 ;; 4. With priority cookie.
2301 (should
2302 (equal (org-test-parse-and-interpret "* [#B] Headline")
2303 "* [#B] Headline\n"))
2304 ;; 5. With comment keyword.
2305 (should
2306 (equal (let ((org-comment-string "COMMENT"))
2307 (org-test-parse-and-interpret "* COMMENT Headline"))
2308 "* COMMENT Headline\n"))
2309 ;; 6. Keep same number of blank lines before body.
2310 (should
2311 (equal (org-test-parse-and-interpret
2312 "* Headline\n\n\nText after two blank lines.")
2313 "* Headline\n\n\nText after two blank lines.\n"))
2314 ;; 8. Preserve `org-odd-levels-only' state.
2315 (should
2316 (equal "* H\n*** H2\n"
2317 (let ((org-odd-levels-only t))
2318 (org-test-parse-and-interpret "* H\n*** H2")))))
2320 (ert-deftest test-org-element/inlinetask-interpreter ()
2321 "Test inlinetask interpretation."
2322 (when (featurep 'org-inlinetask)
2323 (let ((org-inlinetask-min-level 15))
2324 ;; 1. Regular inlinetask.
2325 (should (equal (org-test-parse-and-interpret
2326 "*************** Task\nTest\n*************** END")
2327 "*************** Task\nTest\n*************** END\n"))
2328 ;; 2. Degenerate inlinetask.
2329 (should (equal (org-test-parse-and-interpret "*************** Task")
2330 "*************** Task\n"))
2331 ;; 3. Prefer degenerate form when there are no contents.
2332 (should (equal (org-test-parse-and-interpret
2333 "*************** Task\n*************** END")
2334 "*************** Task\n"))
2335 ;; 4. With TODO keywords.
2336 (should
2337 (equal (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
2338 (org-test-parse-and-interpret "*************** TODO Task"))
2339 "*************** TODO Task\n"))
2340 ;; 5. With tags...
2342 ;; 5.1. ... and a positive `org-tags-column' value.
2343 (should
2344 (equal (let ((org-tags-column 30))
2345 (org-test-parse-and-interpret "*************** Task :tag:"))
2346 "*************** Task :tag:\n"))
2347 ;; 5.2. ... and a negative `org-tags-column' value.
2348 (should
2349 (equal (let ((org-tags-column -30))
2350 (org-test-parse-and-interpret "*************** Task :tag:"))
2351 "*************** Task :tag:\n"))
2352 ;; 5.3. ... and a null `org-tags-column' value.
2353 (should
2354 (equal (let ((org-tags-column 0))
2355 (org-test-parse-and-interpret "*************** Task :tag:"))
2356 "*************** Task :tag:\n"))
2357 ;; 6. With priority cookie.
2358 (should
2359 (equal (org-test-parse-and-interpret "*************** [#B] Task")
2360 "*************** [#B] Task\n")))))
2362 (ert-deftest test-org-element/plain-list-interpreter ()
2363 "Test plain-list and item interpreters."
2364 (let ((org-list-two-spaces-after-bullet-regexp nil))
2365 ;; Unordered list.
2366 (should (equal (org-test-parse-and-interpret "- item 1") "- item 1\n"))
2367 ;; Description list.
2368 (should
2369 (equal (org-test-parse-and-interpret "- tag :: desc") "- tag :: desc\n"))
2370 ;; Ordered list.
2371 (should
2372 (equal (let ((org-plain-list-ordered-item-terminator t))
2373 (org-test-parse-and-interpret "1. Item"))
2374 "1. Item\n"))
2375 (should
2376 (equal (let ((org-plain-list-ordered-item-terminator ?\)))
2377 (org-test-parse-and-interpret "1) Item"))
2378 "1) Item\n"))
2379 ;; Ordered list with counter.
2380 (should
2381 (equal (let ((org-plain-list-ordered-item-terminator t))
2382 (org-test-parse-and-interpret "1. [@5] Item"))
2383 "5. [@5] Item\n"))
2384 ;; List with check-boxes.
2385 (should
2386 (equal (org-test-parse-and-interpret
2387 "- [-] Item 1\n - [X] Item 2\n - [ ] Item 3")
2388 "- [-] Item 1\n - [X] Item 2\n - [ ] Item 3\n"))
2389 ;; Item not starting with a paragraph.
2390 (should
2391 (equal (org-test-parse-and-interpret "-\n | a | b |")
2392 "- \n | a | b |\n"))
2393 ;; Special case: correctly handle "*" bullets.
2394 (should (org-test-parse-and-interpret " * item"))
2395 ;; Special case: correctly handle empty items.
2396 (should (org-test-parse-and-interpret "-"))))
2398 (ert-deftest test-org-element/quote-block-interpreter ()
2399 "Test quote block interpreter."
2400 (should (equal (org-test-parse-and-interpret
2401 "#+BEGIN_QUOTE\nTest\n#+END_QUOTE")
2402 "#+BEGIN_QUOTE\nTest\n#+END_QUOTE\n")))
2404 (ert-deftest test-org-element/special-block-interpreter ()
2405 "Test special block interpreter."
2406 (should (equal (org-test-parse-and-interpret
2407 "#+BEGIN_SPECIAL\nTest\n#+END_SPECIAL")
2408 "#+BEGIN_SPECIAL\nTest\n#+END_SPECIAL\n")))
2410 (ert-deftest test-org-element/babel-call-interpreter ()
2411 "Test babel call interpreter."
2412 ;; 1. Without argument.
2413 (should (equal (org-test-parse-and-interpret "#+CALL: test()")
2414 "#+CALL: test()\n"))
2415 ;; 2. With argument.
2416 (should (equal (org-test-parse-and-interpret "#+CALL: test(x=2)")
2417 "#+CALL: test(x=2)\n"))
2418 ;; 3. With header arguments.
2419 (should (equal (org-test-parse-and-interpret
2420 "#+CALL: test[:results output]()[:results html]")
2421 "#+CALL: test[:results output]()[:results html]\n")))
2423 (ert-deftest test-org-element/clock-interpreter ()
2424 "Test clock interpreter."
2425 ;; Running clock.
2426 (should
2427 (string-match
2428 "CLOCK: \\[2012-01-01 .* 00:01\\]"
2429 (org-test-parse-and-interpret "CLOCK: [2012-01-01 sun. 00:01]")))
2430 ;; Closed clock.
2431 (should
2432 (string-match
2433 "CLOCK: \\[2012-01-01 .* 00:01\\]--\\[2012-01-01 .* 00:02\\] => 0:01"
2434 (org-test-parse-and-interpret "
2435 CLOCK: [2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02] => 0:01"))))
2437 (ert-deftest test-org-element/comment-interpreter ()
2438 "Test comment interpreter."
2439 ;; Regular comment.
2440 (should (equal (org-test-parse-and-interpret "# Comment") "# Comment\n"))
2441 ;; Inline comment.
2442 (should (equal (org-test-parse-and-interpret " # Comment")
2443 "# Comment\n"))
2444 ;; Preserve indentation.
2445 (should (equal (org-test-parse-and-interpret " # No blank\n# One blank")
2446 "# No blank\n# One blank\n")))
2448 (ert-deftest test-org-element/comment-block-interpreter ()
2449 "Test comment block interpreter."
2450 (should (equal (org-test-parse-and-interpret
2451 "#+BEGIN_COMMENT\nTest\n#+END_COMMENT")
2452 "#+BEGIN_COMMENT\nTest\n#+END_COMMENT\n"))
2453 ;; Accept missing final newline in value.
2454 (should
2455 (equal
2456 "#+BEGIN_COMMENT\nTest\n#+END_COMMENT\n"
2457 (org-element-interpret-data '(comment-block (:value "Test"))))))
2459 (ert-deftest test-org-element/diary-sexp ()
2460 "Test diary-sexp interpreter."
2461 (should
2462 (equal
2463 (org-test-parse-and-interpret
2464 "%%(org-anniversary 1956 5 14)(2) Arthur Dent is %d years old")
2465 "%%(org-anniversary 1956 5 14)(2) Arthur Dent is %d years old\n")))
2467 (ert-deftest test-org-element/example-block-interpreter ()
2468 "Test example block interpreter."
2469 ;; Without switches.
2470 (should (equal (org-test-parse-and-interpret
2471 "#+BEGIN_EXAMPLE\nTest\n#+END_EXAMPLE")
2472 "#+BEGIN_EXAMPLE\nTest\n#+END_EXAMPLE\n"))
2473 ;; With switches.
2474 (should
2475 (equal (org-test-parse-and-interpret
2476 "#+BEGIN_EXAMPLE -n -k\n(+ 1 1)\n#+END_EXAMPLE")
2477 "#+BEGIN_EXAMPLE -n -k\n(+ 1 1)\n#+END_EXAMPLE\n"))
2478 ;; Preserve code escaping.
2479 (should
2480 (equal (org-test-parse-and-interpret
2481 "#+BEGIN_EXAMPLE\n,* Headline\n ,#+keyword\nText #+END_EXAMPLE")
2482 "#+BEGIN_EXAMPLE\n,* Headline\n ,#+keyword\nText #+END_EXAMPLE\n"))
2483 ;; Accept missing final newline in value.
2484 (should
2485 (equal
2486 "#+BEGIN_EXAMPLE\nTest\n#+END_EXAMPLE\n"
2487 (org-element-interpret-data '(example-block (:value "Test"))))))
2489 (ert-deftest test-org-element/export-block-interpreter ()
2490 "Test export block interpreter."
2491 (should (equal (org-test-parse-and-interpret
2492 "#+BEGIN_HTML\nTest\n#+END_HTML")
2493 "#+BEGIN_HTML\nTest\n#+END_HTML\n")))
2495 (ert-deftest test-org-element/fixed-width-interpreter ()
2496 "Test fixed width interpreter."
2497 ;; Standard test.
2498 (should (equal (org-test-parse-and-interpret ": Test") ": Test\n"))
2499 ;; Preserve indentation.
2500 (should (equal (org-test-parse-and-interpret ": 2 blanks\n: 1 blank")
2501 ": 2 blanks\n: 1 blank\n"))
2502 ;; Remove last newline character
2503 (should
2504 (equal (org-element-fixed-width-interpreter
2505 '(fixed-width (:value "Test\n")) nil)
2506 ": Test"))
2507 (should
2508 (equal (org-element-fixed-width-interpreter
2509 '(fixed-width (:value "Test")) nil)
2510 ": Test"))
2511 ;; Handle empty string.
2512 (should
2513 (equal (org-element-fixed-width-interpreter
2514 '(fixed-width (:value "")) nil)
2515 ""))
2516 ;; Handle nil value.
2517 (should-not
2518 (org-element-fixed-width-interpreter
2519 '(fixed-width (:value nil)) nil)))
2521 (ert-deftest test-org-element/horizontal-rule-interpreter ()
2522 "Test horizontal rule interpreter."
2523 (should (equal (org-test-parse-and-interpret "-------") "-----\n")))
2525 (ert-deftest test-org-element/keyword-interpreter ()
2526 "Test keyword interpreter."
2527 (should (equal (org-test-parse-and-interpret "#+KEYWORD: value")
2528 "#+KEYWORD: value\n")))
2530 (ert-deftest test-org-element/latex-environment-interpreter ()
2531 "Test latex environment interpreter."
2532 (should (equal (org-test-parse-and-interpret
2533 "\\begin{equation}\n1+1=2\n\\end{equation}")
2534 "\\begin{equation}\n1+1=2\n\\end{equation}\n"))
2535 (should (equal (org-test-parse-and-interpret
2536 "\\begin{theorem}[me]\n1+1=2\n\\end{theorem}")
2537 "\\begin{theorem}[me]\n1+1=2\n\\end{theorem}\n")))
2539 (ert-deftest test-org-element/planning-interpreter ()
2540 "Test planning interpreter."
2541 (should
2542 (string-match
2543 "\\* Headline
2544 DEADLINE: <2012-03-29 .*?> SCHEDULED: <2012-03-29 .*?> CLOSED: \\[2012-03-29 .*?\\]"
2545 (org-test-parse-and-interpret
2546 "* Headline
2547 DEADLINE: <2012-03-29 thu.> SCHEDULED: <2012-03-29 thu.> CLOSED: [2012-03-29 thu.]"))))
2549 (ert-deftest test-org-element/property-drawer-interpreter ()
2550 "Test property drawer interpreter."
2551 (should (equal (let ((org-property-format "%-10s %s"))
2552 (org-test-parse-and-interpret
2553 ":PROPERTIES:\n:prop: value\n:END:"))
2554 ":PROPERTIES:\n:prop: value\n:END:\n")))
2556 (ert-deftest test-org-element/src-block-interpreter ()
2557 "Test src block interpreter."
2558 ;; With arguments.
2559 (should
2560 (equal (let ((org-edit-src-content-indentation 2))
2561 (org-test-parse-and-interpret
2562 "#+BEGIN_SRC emacs-lisp :results silent\n(+ 1 1)\n#+END_SRC"))
2563 "#+BEGIN_SRC emacs-lisp :results silent\n (+ 1 1)\n#+END_SRC\n"))
2564 ;; With switches.
2565 (should
2566 (equal (let ((org-edit-src-content-indentation 2))
2567 (org-test-parse-and-interpret
2568 "#+BEGIN_SRC emacs-lisp -n -k\n(+ 1 1)\n#+END_SRC"))
2569 "#+BEGIN_SRC emacs-lisp -n -k\n (+ 1 1)\n#+END_SRC\n"))
2570 ;; Preserve code escaping.
2571 (should
2572 (equal (let ((org-edit-src-content-indentation 2))
2573 (org-test-parse-and-interpret
2574 "#+BEGIN_SRC org\n,* Headline\n ,#+keyword\nText #+END_SRC"))
2575 "#+BEGIN_SRC org\n,* Headline\n ,#+keyword\nText #+END_SRC\n"))
2576 ;; Do not apply `org-edit-src-content-indentation' when preserving
2577 ;; indentation.
2578 (should
2579 (equal (let ((org-edit-src-content-indentation 2)
2580 (org-src-preserve-indentation t))
2581 (org-test-parse-and-interpret
2582 "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"))
2583 "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC\n"))
2584 (should
2585 (equal (let ((org-edit-src-content-indentation 2)
2586 (org-src-preserve-indentation nil))
2587 (org-test-parse-and-interpret
2588 "#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"))
2589 "#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC\n"))
2590 ;; Accept missing final newline in value.
2591 (should
2592 (equal
2593 "#+BEGIN_SRC emacs-lisp\n Test\n#+END_SRC\n"
2594 (let ((org-edit-src-content-indentation 2))
2595 (org-element-interpret-data
2596 '(src-block (:language "emacs-lisp" :value "Test")))))))
2598 (ert-deftest test-org-element/table-interpreter ()
2599 "Test table, table-row and table-cell interpreters."
2600 ;; 1. Simple table.
2601 (should (equal (org-test-parse-and-interpret "| a | b |\n| c | d |")
2602 "| a | b |\n| c | d |\n"))
2603 ;; 2. With horizontal rules.
2604 (should (equal (org-test-parse-and-interpret
2605 "| a | b |\n|---+---|\n| c | d |")
2606 "| a | b |\n|---+---|\n| c | d |\n"))
2607 ;; 3. With meta-data.
2608 (should (equal (org-test-parse-and-interpret "| / | < | > |\n| * | 1 | 2 |")
2609 "| / | < | > |\n| * | 1 | 2 |\n"))
2610 ;; 4. With a formula.
2611 (should
2612 (equal (org-test-parse-and-interpret
2613 "| 2 |\n| 4 |\n| 3 |\n#+TBLFM: @3=vmean(@1..@2)")
2614 "| 2 |\n| 4 |\n| 3 |\n#+TBLFM: @3=vmean(@1..@2)\n"))
2615 ;; 5. With multiple formulas.
2616 (should
2617 (equal (org-test-parse-and-interpret
2618 "| 2 |\n| 4 |\n| 3 |\n#+TBLFM: test1\n#+TBLFM: test2")
2619 "| 2 |\n| 4 |\n| 3 |\n#+TBLFM: test1\n#+TBLFM: test2\n")))
2621 (ert-deftest test-org-element/timestamp-interpreter ()
2622 "Test timestamp interpreter."
2623 ;; Active.
2624 (should
2625 (string-match "<2012-03-29 .* 16:40>"
2626 (org-test-parse-and-interpret "<2012-03-29 thu. 16:40>")))
2627 (should
2628 (string-match "<2012-03-29 .* 16:40>"
2629 (org-element-timestamp-interpreter
2630 '(timestamp
2631 (:type active :year-start 2012 :month-start 3 :day-start 29
2632 :hour-start 16 :minute-start 40)) nil)))
2633 ;; Inactive.
2634 (should
2635 (string-match "\\[2012-03-29 .* 16:40\\]"
2636 (org-test-parse-and-interpret "[2012-03-29 thu. 16:40]")))
2637 (should
2638 (string-match
2639 "\\[2012-03-29 .* 16:40\\]"
2640 (org-element-timestamp-interpreter
2641 '(timestamp
2642 (:type inactive :year-start 2012 :month-start 3 :day-start 29
2643 :hour-start 16 :minute-start 40)) nil)))
2644 ;; Active range.
2645 (should
2646 (string-match "<2012-03-29 .* 16:40>--<2012-03-29 .* 16:41>"
2647 (org-test-parse-and-interpret
2648 "<2012-03-29 thu. 16:40>--<2012-03-29 thu. 16:41>")))
2649 (should
2650 (string-match
2651 "<2012-03-29 .* 16:40>--<2012-03-29 .* 16:41>"
2652 (org-element-timestamp-interpreter
2653 '(timestamp
2654 (:type active-range :year-start 2012 :month-start 3 :day-start 29
2655 :hour-start 16 :minute-start 40 :year-end 2012 :month-end 3
2656 :day-end 29 :hour-end 16 :minute-end 41)) nil)))
2657 ;; Inactive range.
2658 (should
2659 (string-match "\\[2012-03-29 .* 16:40\\]--\\[2012-03-29 .* 16:41\\]"
2660 (org-test-parse-and-interpret
2661 "[2012-03-29 thu. 16:40]--[2012-03-29 thu. 16:41]")))
2662 (should
2663 (string-match
2664 "\\[2012-03-29 .* 16:40\\]--\\[2012-03-29 .* 16:41\\]"
2665 (org-element-timestamp-interpreter
2666 '(timestamp
2667 (:type inactive-range :year-start 2012 :month-start 3 :day-start 29
2668 :hour-start 16 :minute-start 40 :year-end 2012 :month-end 3
2669 :day-end 29 :hour-end 16 :minute-end 41)) nil)))
2670 ;; Diary.
2671 (should (equal (org-test-parse-and-interpret "<%%diary-float t 4 2>")
2672 "<%%diary-float t 4 2>\n"))
2673 ;; Timestamp with repeater interval, with delay, with both.
2674 (should
2675 (string-match "<2012-03-29 .* \\+1y>"
2676 (org-test-parse-and-interpret "<2012-03-29 thu. +1y>")))
2677 (should
2678 (string-match
2679 "<2012-03-29 .* \\+1y>"
2680 (org-element-timestamp-interpreter
2681 '(timestamp
2682 (:type active :year-start 2012 :month-start 3 :day-start 29
2683 :repeater-type cumulate :repeater-value 1 :repeater-unit year))
2684 nil)))
2685 (should
2686 (string-match
2687 "<2012-03-29 .* -1y>"
2688 (org-element-timestamp-interpreter
2689 '(timestamp
2690 (:type active :year-start 2012 :month-start 3 :day-start 29
2691 :warning-type all :warning-value 1 :warning-unit year))
2692 nil)))
2693 (should
2694 (string-match
2695 "<2012-03-29 .* \\+1y -1y>"
2696 (org-element-timestamp-interpreter
2697 '(timestamp
2698 (:type active :year-start 2012 :month-start 3 :day-start 29
2699 :warning-type all :warning-value 1 :warning-unit year
2700 :repeater-type cumulate :repeater-value 1 :repeater-unit year))
2701 nil)))
2702 ;; Timestamp range with repeater interval
2703 (should
2704 (string-match "<2012-03-29 .* \\+1y>--<2012-03-30 .* \\+1y>"
2705 (org-test-parse-and-interpret
2706 "<2012-03-29 Thu +1y>--<2012-03-30 Thu +1y>")))
2707 (should
2708 (string-match
2709 "<2012-03-29 .* \\+1y>--<2012-03-30 .* \\+1y>"
2710 (org-element-timestamp-interpreter
2711 '(timestamp
2712 (:type active-range :year-start 2012 :month-start 3 :day-start 29
2713 :year-end 2012 :month-end 3 :day-end 30 :repeater-type cumulate
2714 :repeater-value 1 :repeater-unit year))
2715 nil))))
2717 (ert-deftest test-org-element/verse-block-interpreter ()
2718 "Test verse block interpretation."
2719 (should
2720 (equal (org-test-parse-and-interpret "#+BEGIN_VERSE\nTest\n#+END_VERSE")
2721 "#+BEGIN_VERSE\nTest\n#+END_VERSE\n")))
2723 (ert-deftest test-org-element/bold-interpreter ()
2724 "Test bold interpreter."
2725 (should (equal (org-test-parse-and-interpret "*text*") "*text*\n")))
2727 (ert-deftest test-org-element/code-interpreter ()
2728 "Test code interpreter."
2729 (should (equal (org-test-parse-and-interpret "~text~") "~text~\n")))
2731 (ert-deftest test-org-element/entity-interpreter ()
2732 "Test entity interpreter."
2733 ;; 1. Without brackets.
2734 (should
2735 (equal (org-test-parse-and-interpret "\\alpha text") "\\alpha text\n"))
2736 ;; 2. With brackets.
2737 (should
2738 (equal (org-test-parse-and-interpret "\\alpha{}text") "\\alpha{}text\n")))
2740 (ert-deftest test-org-element/export-snippet-interpreter ()
2741 "Test export snippet interpreter."
2742 (should (equal (org-test-parse-and-interpret "@@back-end:contents@@")
2743 "@@back-end:contents@@\n")))
2745 (ert-deftest test-org-element/footnote-reference-interpreter ()
2746 "Test footnote reference interpreter."
2747 ;; 1. Regular reference.
2748 (should (equal (org-test-parse-and-interpret "Text[fn:1]") "Text[fn:1]\n"))
2749 ;; 2. Normalized reference.
2750 (should (equal (org-test-parse-and-interpret "Text[1]") "Text[1]\n"))
2751 ;; 3. Named reference.
2752 (should (equal (org-test-parse-and-interpret "Text[fn:label]")
2753 "Text[fn:label]\n"))
2754 ;; 4. Inline reference.
2755 (should (equal (org-test-parse-and-interpret "Text[fn:label:def]")
2756 "Text[fn:label:def]\n"))
2757 ;; 5. Anonymous reference.
2758 (should (equal (org-test-parse-and-interpret "Text[fn::def]")
2759 "Text[fn::def]\n")))
2761 (ert-deftest test-org-element/inline-babel-call-interpreter ()
2762 "Test inline babel call interpreter."
2763 ;; 1. Without arguments.
2764 (should (equal (org-test-parse-and-interpret "call_test()") "call_test()\n"))
2765 ;; 2. With arguments.
2766 (should (equal (org-test-parse-and-interpret "call_test(x=2)")
2767 "call_test(x=2)\n"))
2768 ;; 3. With header arguments.
2769 (should (equal (org-test-parse-and-interpret
2770 "call_test[:results output]()[:results html]")
2771 "call_test[:results output]()[:results html]\n")))
2773 (ert-deftest test-org-element/inline-src-block-interpreter ()
2774 "Test inline src block interpreter."
2775 ;; 1. Without header argument.
2776 (should (equal (org-test-parse-and-interpret "src_emacs-lisp{(+ 1 1)}")
2777 "src_emacs-lisp{(+ 1 1)}\n"))
2778 ;; 2. With header arguments.
2779 (should (equal (org-test-parse-and-interpret
2780 "src_emacs-lisp[:results silent]{(+ 1 1)}")
2781 "src_emacs-lisp[:results silent]{(+ 1 1)}\n")))
2783 (ert-deftest test-org-element/italic-interpreter ()
2784 "Test italic interpreter."
2785 (should (equal (org-test-parse-and-interpret "/text/") "/text/\n")))
2787 (ert-deftest test-org-element/latex-fragment-interpreter ()
2788 "Test latex fragment interpreter."
2789 (should (equal (org-test-parse-and-interpret "\\command{}") "\\command{}\n"))
2790 (should (equal (org-test-parse-and-interpret "$x$") "$x$\n"))
2791 (should (equal (org-test-parse-and-interpret "$x+y$") "$x+y$\n"))
2792 (should (equal (org-test-parse-and-interpret "$$x+y$$") "$$x+y$$\n"))
2793 (should (equal (org-test-parse-and-interpret "\\(x+y\\)") "\\(x+y\\)\n"))
2794 (should (equal (org-test-parse-and-interpret "\\[x+y\\]") "\\[x+y\\]\n")))
2796 (ert-deftest test-org-element/line-break-interpreter ()
2797 "Test line break interpreter."
2798 (should (equal (org-test-parse-and-interpret "First line \\\\ \nSecond line")
2799 "First line \\\\\nSecond line\n")))
2801 (ert-deftest test-org-element/link-interpreter ()
2802 "Test link interpreter."
2803 ;; 1. Links targeted from a radio target.
2804 (should (equal (let ((org-target-link-regexp "radio-target"))
2805 (org-test-parse-and-interpret "a radio-target"))
2806 "a radio-target\n"))
2807 ;; 2. Regular links.
2809 ;; 2.1. Without description.
2810 (should (equal (org-test-parse-and-interpret "[[http://orgmode.org]]")
2811 "[[http://orgmode.org]]\n"))
2812 ;; 2.2. With a description.
2813 (should (equal (org-test-parse-and-interpret
2814 "[[http://orgmode.org][Org mode]]")
2815 "[[http://orgmode.org][Org mode]]\n"))
2816 ;; 2.3. Id links.
2817 (should (equal (org-test-parse-and-interpret "[[id:aaaa]]") "[[id:aaaa]]\n"))
2818 ;; 2.4. Custom-id links.
2819 (should (equal (org-test-parse-and-interpret "[[#id]]") "[[#id]]\n"))
2820 ;; 2.5 Code-ref links.
2821 (should (equal (org-test-parse-and-interpret "[[(ref)]]") "[[(ref)]]\n"))
2822 ;; 3. Normalize plain links.
2823 (should (equal (org-test-parse-and-interpret "http://orgmode.org")
2824 "[[http://orgmode.org]]\n"))
2825 ;; 4. Normalize angular links.
2826 (should (equal (org-test-parse-and-interpret "<http://orgmode.org>")
2827 "[[http://orgmode.org]]\n")))
2829 (ert-deftest test-org-element/macro-interpreter ()
2830 "Test macro interpreter."
2831 ;; 1. Without argument.
2832 (should (equal (org-test-parse-and-interpret "{{{test}}}") "{{{test}}}\n"))
2833 ;; 2. With arguments.
2834 (should (equal (org-test-parse-and-interpret "{{{test(arg1,arg2)}}}")
2835 "{{{test(arg1,arg2)}}}\n")))
2837 (ert-deftest test-org-element/radio-target-interpreter ()
2838 "Test radio target interpreter."
2839 (should (equal (org-test-parse-and-interpret "<<<some text>>>")
2840 "<<<some text>>>\n")))
2842 (ert-deftest test-org-element/statistics-cookie-interpreter ()
2843 "Test statistics cookie interpreter."
2844 ;; 1. Without percent
2845 (should (equal (org-test-parse-and-interpret "[0/1]") "[0/1]\n"))
2846 ;; 2. With percent.
2847 (should (equal (org-test-parse-and-interpret "[66%]") "[66%]\n")))
2849 (ert-deftest test-org-element/strike-through-interpreter ()
2850 "Test strike through interpreter."
2851 (should (equal (org-test-parse-and-interpret "+target+") "+target+\n")))
2853 (ert-deftest test-org-element/subscript-interpreter ()
2854 "Test subscript interpreter."
2855 ;; 1. Without brackets.
2856 (should (equal (org-test-parse-and-interpret "a_b") "a_b\n"))
2857 ;; 2. With brackets.
2858 (should (equal (org-test-parse-and-interpret "a_{b}") "a_{b}\n")))
2860 (ert-deftest test-org-element/superscript-interpreter ()
2861 "Test superscript interpreter."
2862 ;; 1. Without brackets.
2863 (should (equal (org-test-parse-and-interpret "a^b") "a^b\n"))
2864 ;; 2. With brackets.
2865 (should (equal (org-test-parse-and-interpret "a^{b}") "a^{b}\n")))
2867 (ert-deftest test-org-element/target-interpreter ()
2868 "Test target interpreter."
2869 (should (equal (org-test-parse-and-interpret "<<target>>") "<<target>>\n")))
2871 (ert-deftest test-org-element/underline-interpreter ()
2872 "Test underline interpreter."
2873 (should (equal (org-test-parse-and-interpret "_text_") "_text_\n")))
2875 (ert-deftest test-org-element/verbatim-interpreter ()
2876 "Test verbatim interpreter."
2877 (should (equal (org-test-parse-and-interpret "=text=") "=text=\n")))
2881 ;;; Test Granularity
2883 (ert-deftest test-org-element/granularity ()
2884 "Test granularity impact on buffer parsing."
2885 (org-test-with-temp-text "
2886 * Head 1
2887 ** Head 2
2888 #+BEGIN_CENTER
2889 Centered paragraph.
2890 #+END_CENTER
2891 Paragraph \\alpha."
2892 ;; 1.1. Granularity set to `headline' should parse every headline
2893 ;; in buffer, and only them.
2894 (let ((tree (org-element-parse-buffer 'headline)))
2895 (should (= 2 (length (org-element-map tree 'headline 'identity))))
2896 (should-not (org-element-map tree 'paragraph 'identity)))
2897 ;; 1.2. Granularity set to `greater-element' should not enter
2898 ;; greater elements excepted headlines and sections.
2899 (let ((tree (org-element-parse-buffer 'greater-element)))
2900 (should (= 1 (length (org-element-map tree 'center-block 'identity))))
2901 (should (= 1 (length (org-element-map tree 'paragraph 'identity))))
2902 (should-not (org-element-map tree 'entity 'identity)))
2903 ;; 1.3. Granularity set to `element' should enter every
2904 ;; greater-element.
2905 (let ((tree (org-element-parse-buffer 'element)))
2906 (should (= 2 (length (org-element-map tree 'paragraph 'identity))))
2907 (should-not (org-element-map tree 'entity 'identity)))
2908 ;; 1.4. Granularity set to `object' can see everything.
2909 (let ((tree (org-element-parse-buffer 'object)))
2910 (should (= 1 (length (org-element-map tree 'entity 'identity)))))))
2912 (ert-deftest test-org-element/secondary-string-parsing ()
2913 "Test if granularity correctly toggles secondary strings parsing."
2914 ;; With a granularity bigger than `object', no secondary string
2915 ;; should be parsed.
2916 (should
2917 (stringp
2918 (org-test-with-temp-text "* Headline"
2919 (let ((headline
2920 (org-element-map (org-element-parse-buffer 'headline) 'headline
2921 #'identity nil 'first-match)))
2922 (org-element-property :title headline)))))
2923 (should
2924 (stringp
2925 (org-test-with-temp-text "* Headline\n- tag :: item"
2926 (let ((item (org-element-map (org-element-parse-buffer 'element) 'item
2927 #'identity nil 'first-match)))
2928 (org-element-property :tag item)))))
2929 (when (featurep 'org-inlinetask)
2930 (should
2931 (stringp
2932 (let ((org-inlinetask-min-level 15))
2933 (org-test-with-temp-text "*************** Inlinetask"
2934 (let ((inlinetask (org-element-map (org-element-parse-buffer 'element)
2935 'inlinetask
2936 #'identity nil 'first-match)))
2937 (org-element-property :title inlinetask)))))))
2938 ;; With a default granularity, secondary strings should be parsed.
2939 (should
2940 (listp
2941 (org-test-with-temp-text "* Headline"
2942 (let ((headline
2943 (org-element-map (org-element-parse-buffer) 'headline
2944 #'identity nil 'first-match)))
2945 (org-element-property :title headline)))))
2946 ;; `org-element-at-point' should never parse a secondary string.
2947 (should-not
2948 (listp
2949 (org-test-with-temp-text "* Headline"
2950 (org-element-property :title (org-element-at-point)))))
2951 ;; Preserve current local variables when parsing a secondary string.
2952 (should
2953 (let ((org-entities nil)
2954 (org-entities-user nil))
2955 (org-test-with-temp-text "
2956 #+CAPTION: \\foo
2957 Text
2958 # Local Variables:
2959 # org-entities-user: ((\"foo\"))
2960 # End:"
2961 (let ((safe-local-variable-values '((org-entities-user . (("foo"))))))
2962 (hack-local-variables))
2963 (org-element-map (org-element-parse-buffer) 'entity
2964 #'identity nil nil nil t)))))
2968 ;;; Test Visible Only Parsing
2970 (ert-deftest test-org-element/parse-buffer-visible ()
2971 "Test `org-element-parse-buffer' with visible only argument."
2972 (should
2973 (equal '("H1" "H3" "H5")
2974 (org-test-with-temp-text
2975 "* H1\n** H2\n** H3 :visible:\n** H4\n** H5 :visible:"
2976 (org-occur ":visible:")
2977 (org-element-map (org-element-parse-buffer nil t) 'headline
2978 (lambda (hl) (org-element-property :raw-value hl)))))))
2982 ;;; Test `:parent' Property
2984 (ert-deftest test-org-element/parent-property ()
2985 "Test `:parent' property."
2986 ;; Elements.
2987 (org-test-with-temp-text "#+BEGIN_CENTER\nText\n#+END_CENTER"
2988 (let* ((tree (org-element-parse-buffer))
2989 (parent (org-element-property
2990 :parent
2991 (org-element-map tree 'paragraph 'identity nil t))))
2992 (should parent)
2993 (should (eq (org-element-map tree 'center-block 'identity nil t)
2994 parent))))
2995 ;; Objects.
2996 (org-test-with-temp-text "a_{/b/}"
2997 (let* ((tree (org-element-parse-buffer))
2998 (parent (org-element-property
2999 :parent
3000 (org-element-map tree 'italic 'identity nil t))))
3001 (should parent)
3002 (should (eq parent
3003 (org-element-map tree 'subscript 'identity nil t)))))
3004 ;; Secondary strings
3005 (org-test-with-temp-text "* /italic/"
3006 (let* ((tree (org-element-parse-buffer))
3007 (parent (org-element-property
3008 :parent (org-element-map tree 'italic 'identity nil t))))
3009 (should parent)
3010 (should (eq parent
3011 (org-element-map tree 'headline 'identity nil t))))))
3015 ;;; Test Normalize Contents
3017 (ert-deftest test-org-element/normalize-contents ()
3018 "Test `org-element-normalize-contents' specifications."
3019 ;; Remove maximum common indentation from element's contents.
3020 (should
3021 (equal
3022 (org-element-normalize-contents
3023 '(paragraph nil " Two spaces\n Three spaces"))
3024 '(paragraph nil "Two spaces\n Three spaces")))
3025 ;; Ignore objects within contents when computing maximum common
3026 ;; indentation.
3027 (should
3028 (equal
3029 (org-element-normalize-contents
3030 '(paragraph nil " One " (emphasis nil "space") "\n Two spaces"))
3031 '(paragraph nil "One " (emphasis nil "space") "\n Two spaces")))
3032 ;; Ignore blank lines.
3033 (should
3034 (equal
3035 (org-element-normalize-contents
3036 '(paragraph nil " Two spaces\n\n \n Two spaces"))
3037 '(paragraph nil "Two spaces\n\n \nTwo spaces")))
3038 (should
3039 (equal
3040 '(paragraph nil " Two spaces\n" (verbatim nil "V") "\n Two spaces")
3041 (org-element-normalize-contents
3042 '(paragraph nil " Two spaces\n " (verbatim nil "V") "\n Two spaces"))))
3043 (should
3044 (equal
3045 '(verse-block nil "line 1\n\nline 2")
3046 (org-element-normalize-contents
3047 '(verse-block nil " line 1\n\n line 2"))))
3048 ;; Recursively enter objects in order to compute common indentation.
3049 (should
3050 (equal
3051 (org-element-normalize-contents
3052 '(paragraph nil " Two spaces " (bold nil " and\n One space")))
3053 '(paragraph nil " Two spaces " (bold nil " and\nOne space"))))
3054 ;; When optional argument is provided, ignore first line
3055 ;; indentation.
3056 (should
3057 (equal
3058 (org-element-normalize-contents
3059 '(paragraph nil "No space\n Two spaces\n Three spaces") t)
3060 '(paragraph nil "No space\nTwo spaces\n Three spaces"))))
3064 ;;; Test Navigation Tools.
3066 (ert-deftest test-org-element/at-point ()
3067 "Test `org-element-at-point' specifications."
3068 ;; Return closest element containing point.
3069 (should
3070 (eq 'paragraph
3071 (org-test-with-temp-text "#+BEGIN_CENTER\nA\n#+END_CENTER"
3072 (progn (search-forward "A")
3073 (org-element-type (org-element-at-point))))))
3074 ;; Correctly set `:parent' property.
3075 (should
3076 (eq 'center-block
3077 (org-test-with-temp-text "#+BEGIN_CENTER\nA\n#+END_CENTER"
3078 (progn (search-forward "A")
3079 (org-element-type
3080 (org-element-property :parent (org-element-at-point)))))))
3081 ;; Special case: at a blank line just below a headline, return that
3082 ;; headline.
3083 (should
3084 (equal "H1" (org-test-with-temp-text "* H1\n \n* H2\n"
3085 (forward-line)
3086 (org-element-property :title (org-element-at-point)))))
3087 ;; Special case: at the very beginning of a table, return `table'
3088 ;; object instead of `table-row'.
3089 (should
3090 (eq 'table
3091 (org-test-with-temp-text "| a | b |"
3092 (org-element-type (org-element-at-point)))))
3093 ;; Special case: at the very beginning of a list or sub-list, return
3094 ;; `plain-list' object instead of `item'.
3095 (should
3096 (eq 'plain-list
3097 (org-test-with-temp-text "- item"
3098 (org-element-type (org-element-at-point)))))
3099 ;; Special case: at the closing line of a greater element, be sure
3100 ;; to return it instead of the last element in its contents.
3101 (should
3102 (eq 'center-block
3103 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph\n#+END_CENTER"
3104 (progn (forward-line 2)
3105 (org-element-type (org-element-at-point))))))
3106 ;; Special case: at a blank line between two items, be sure to
3107 ;; return item above instead of the last element of its contents.
3108 (should
3109 (eq 'item
3110 (org-test-with-temp-text "- Para1\n\n- Para2"
3111 (progn (forward-line)
3112 (org-element-type
3113 (let ((org-list-empty-line-terminates-plain-lists nil))
3114 (org-element-at-point)))))))
3115 ;; Special case: at the last blank line in a plain list, return it
3116 ;; instead of the last item.
3117 (should
3118 (eq 'plain-list
3119 (org-test-with-temp-text "- Para1\n- Para2\n\nPara3"
3120 (progn (forward-line 2)
3121 (org-element-type (org-element-at-point))))))
3122 ;; Special case: when a list ends at the end of buffer and there's
3123 ;; no final newline, return last element in last item.
3124 (should
3125 (eq 'paragraph
3126 (org-test-with-temp-text "- a"
3127 (end-of-line)
3128 (org-element-type (org-element-at-point)))))
3129 ;; Parse a list within a block itself contained in a list.
3130 (should
3131 (eq 'plain-list
3132 (org-test-with-temp-text
3133 "- outer\n #+begin_center\n - inner\n #+end_center"
3134 (search-forward "inner")
3135 (beginning-of-line)
3136 (org-element-type (org-element-at-point)))))
3137 ;; Do not error at eob on an empty line.
3138 (should
3139 (org-test-with-temp-text "* H\n"
3140 (forward-line)
3141 (or (org-element-at-point) t))))
3143 (ert-deftest test-org-element/context ()
3144 "Test `org-element-context' specifications."
3145 ;; Return closest object containing point.
3146 (should
3147 (eq 'underline
3148 (org-test-with-temp-text "Some *text with _underline_ text*"
3149 (progn (search-forward "under")
3150 (org-element-type (org-element-context))))))
3151 ;; Find objects in secondary strings.
3152 (should
3153 (eq 'underline
3154 (org-test-with-temp-text "* Headline _with_ underlining"
3155 (progn (search-forward "w")
3156 (org-element-type (org-element-context))))))
3157 ;; Find objects in objects.
3158 (should
3159 (eq 'macro
3160 (org-test-with-temp-text "| a | {{{macro}}} |"
3161 (progn (search-forward "{")
3162 (org-element-type (org-element-context))))))
3163 (should
3164 (eq 'table-cell
3165 (org-test-with-temp-text "| a | b {{{macro}}} |"
3166 (progn (search-forward "b")
3167 (org-element-type (org-element-context))))))
3168 ;; Find objects in planning lines.
3169 (should
3170 (eq 'timestamp
3171 (org-test-with-temp-text "* H\n SCHEDULED: <2012-03-29 thu.>"
3172 (search-forward "2012")
3173 (org-element-type (org-element-context)))))
3174 (should-not
3175 (eq 'timestamp
3176 (org-test-with-temp-text "* H\n SCHEDULED: <2012-03-29 thu.>"
3177 (search-forward "SCHEDULED")
3178 (org-element-type (org-element-context)))))
3179 ;; Find objects in document keywords.
3180 (should
3181 (eq 'macro
3182 (org-test-with-temp-text "#+DATE: {{{macro}}}"
3183 (progn (search-forward "{")
3184 (org-element-type (org-element-context))))))
3185 ;; Do not find objects in table rules.
3186 (should
3187 (eq 'table-row
3188 (org-test-with-temp-text "| a | b |\n+---+---+\n| c | d |"
3189 (forward-line)
3190 (org-element-type (org-element-context)))))
3191 ;; Find objects in parsed affiliated keywords.
3192 (should
3193 (eq 'macro
3194 (org-test-with-temp-text "#+CAPTION: {{{macro}}}\n| a | b |."
3195 (progn (search-forward "{")
3196 (org-element-type (org-element-context))))))
3197 (should
3198 (eq 'bold
3199 (org-test-with-temp-text "#+caption: *bold*\nParagraph"
3200 (progn (search-forward "*")
3201 (org-element-type (org-element-context))))))
3202 ;; Find objects at the end of buffer.
3203 (should
3204 (eq 'bold
3205 (org-test-with-temp-text "*bold*"
3206 (goto-char (point-max))
3207 (org-element-type (org-element-context)))))
3208 ;; Correctly set `:parent' property.
3209 (should
3210 (eq 'paragraph
3211 (org-test-with-temp-text "Some *bold* text"
3212 (progn (search-forward "bold")
3213 (org-element-type
3214 (org-element-property :parent (org-element-context)))))))
3215 ;; Between two objects, return the second one.
3216 (should
3217 (eq 'macro
3218 (org-test-with-temp-text "<<target>>{{{test}}}"
3219 (progn (search-forward "{")
3220 (backward-char)
3221 (org-element-type (org-element-context))))))
3222 ;; Test optional argument.
3223 (should
3224 (eq 'underline
3225 (org-test-with-temp-text "Some *text with _underline_ text*"
3226 (progn
3227 (search-forward "under")
3228 (org-element-type (org-element-context (org-element-at-point)))))))
3229 ;; Special case: bold object at the beginning of a headline.
3230 (should
3231 (eq 'bold
3232 (org-test-with-temp-text "* *bold*"
3233 (search-forward "bo")
3234 (org-element-type (org-element-context)))))
3235 ;; Special case: incomplete cell at the end of a table row.
3236 (should
3237 (eq 'table-cell
3238 (org-test-with-temp-text "|a|b|c"
3239 (goto-char (point-max))
3240 (org-element-type (org-element-context)))))
3241 ;; Special case: objects in inline footnotes.
3242 (should
3243 (eq 'link
3244 (org-test-with-temp-text "[fn::[[<point>http://orgmode.org]]]"
3245 (org-element-type (org-element-context))))))
3249 ;;; Test Cache.
3251 (ert-deftest test-org-element/cache ()
3252 "Test basic expectations and common pitfalls for cache."
3253 ;; Shift positions.
3254 (should
3255 (equal '(18 . 23)
3256 (org-test-with-temp-text "para1\n\npara2\n\npara3"
3257 (let ((org-element-use-cache t))
3258 (save-excursion (goto-char (point-max)) (org-element-at-point))
3259 (insert "add")
3260 (forward-line 4)
3261 (let ((element (org-element-at-point)))
3262 (cons (org-element-property :begin element)
3263 (org-element-property :end element)))))))
3264 ;; Partial shifting: when the contents of a greater element are
3265 ;; modified, only shift ending positions.
3266 (should
3267 (org-test-with-temp-text
3268 "#+BEGIN_CENTER\nPara1\n\nPara2\n\nPara3\n#+END_CENTER"
3269 (let ((org-element-use-cache t))
3270 (save-excursion (search-forward "3") (org-element-at-point))
3271 (search-forward "Para2")
3272 (insert " ")
3273 (let ((element (org-element-property :parent (org-element-at-point))))
3274 (equal (cons (org-element-property :begin element)
3275 (org-element-property :end element))
3276 (cons (point-min) (point-max)))))))
3277 ;; Re-parent shifted elements.
3278 (should
3279 (eq 'item
3280 (org-test-with-temp-text "- item\n\n\n para1\n para2"
3281 (let ((org-element-use-cache t))
3282 (end-of-line)
3283 (org-element-at-point)
3284 (save-excursion (goto-char (point-max)) (org-element-at-point))
3285 (forward-line)
3286 (delete-char 1)
3287 (goto-char (point-max))
3288 (org-element-type
3289 (org-element-property :parent (org-element-at-point)))))))
3290 ;; Preserve local structures when re-parenting.
3291 (should
3292 (eq 'table
3293 (org-test-with-temp-text
3294 "#+begin_center\nP0\n\n<point>\n\n P1\n | a | b |\n| c | d |\n#+end_center"
3295 (let ((org-element-use-cache t))
3296 (save-excursion (search-forward "| c |") (org-element-at-point))
3297 (insert "- item")
3298 (search-forward "| c |")
3299 (beginning-of-line)
3300 (org-element-type
3301 (org-element-property :parent (org-element-at-point)))))))
3302 (should-not
3303 (eq 'center-block
3304 (org-test-with-temp-text
3305 "#+begin_center\nP0\n\n<point>\n\n P1\n | a | b |\n#+end_center"
3306 (let ((org-element-use-cache t))
3307 (save-excursion (search-forward "| a |") (org-element-at-point))
3308 (insert "- item")
3309 (search-forward "| a |")
3310 (beginning-of-line)
3311 (org-element-type
3312 (org-element-property :parent (org-element-at-point)))))))
3313 ;; When re-parenting, also propagate changes to list structures.
3314 (should
3315 (= 2
3316 (org-test-with-temp-text "\n Para\n - item<point>"
3317 (let ((org-element-use-cache t))
3318 (org-element-at-point)
3319 (goto-char (point-min))
3320 (insert "- Top\n")
3321 (search-forward "- item")
3322 (beginning-of-line)
3323 (length (org-element-property :structure (org-element-at-point)))))))
3324 ;; Modifying the last line of an element alters the element below.
3325 (should
3326 (org-test-with-temp-text "para1\n\npara2"
3327 (let ((org-element-use-cache t))
3328 (goto-char (point-max))
3329 (org-element-at-point)
3330 (forward-line -1)
3331 (insert "merge")
3332 (let ((element (org-element-at-point)))
3333 (equal (cons (org-element-property :begin element)
3334 (org-element-property :end element))
3335 (cons (point-min) (point-max)))))))
3336 ;; Modifying the first line of an element alters the element above.
3337 (should
3338 (org-test-with-temp-text ": fixed-width\n:not-fixed-width"
3339 (let ((org-element-use-cache t))
3340 (goto-char (point-max))
3341 (org-element-at-point)
3342 (search-backward ":")
3343 (forward-char)
3344 (insert " ")
3345 (let ((element (org-element-at-point)))
3346 (equal (cons (org-element-property :begin element)
3347 (org-element-property :end element))
3348 (cons (point-min) (point-max)))))))
3349 ;; Sensitive change: adding a line alters document structure both
3350 ;; above and below.
3351 (should
3352 (eq 'example-block
3353 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nPara1\n\nPara2\n"
3354 (let ((org-element-use-cache t))
3355 (goto-char (point-max))
3356 (org-element-at-point)
3357 (insert "#+END_EXAMPLE")
3358 (search-backward "Para1")
3359 (org-element-type (org-element-at-point))))))
3360 (should
3361 (eq 'example-block
3362 (org-test-with-temp-text "Para1\n\nPara2\n#+END_EXAMPLE"
3363 (let ((org-element-use-cache t))
3364 (save-excursion (goto-char (point-max)) (org-element-at-point))
3365 (insert "#+BEGIN_EXAMPLE\n")
3366 (search-forward "Para2")
3367 (org-element-type (org-element-at-point))))))
3368 ;; Sensitive change: removing a line alters document structure both
3369 ;; above and below.
3370 (should
3371 (eq 'example-block
3372 (org-test-with-temp-text
3373 "# +BEGIN_EXAMPLE\nPara1\n\nPara2\n#+END_EXAMPLE"
3374 (let ((org-element-use-cache t))
3375 (save-excursion (goto-char (point-max)) (org-element-at-point))
3376 (forward-char)
3377 (delete-char 1)
3378 (search-forward "Para2")
3379 (org-element-type (org-element-at-point))))))
3380 (should
3381 (eq 'example-block
3382 (org-test-with-temp-text
3383 "#+BEGIN_EXAMPLE\nPara1\n\nPara2\n# +END_EXAMPLE"
3384 (let ((org-element-use-cache t))
3385 (save-excursion (goto-char (point-max)) (org-element-at-point))
3386 (search-forward "# ")
3387 (delete-char -1)
3388 (search-backward "Para1")
3389 (org-element-type (org-element-at-point)))))))
3392 (provide 'test-org-element)
3394 ;;; test-org-element.el ends here