Let `org-read-date' respect `org-replace-disputed-keys' again
[org-mode.git] / testing / lisp / test-org-element.el
blob7f7c9cb9d0a0cd1bb684cb809d5b8ebc7f66fd31
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 ;; Ignore incomplete drawer.
559 (should-not
560 (org-test-with-temp-text ":TEST:"
561 (org-element-map (org-element-parse-buffer) 'drawer 'identity nil t)))
562 ;; Handle non-empty blank line at the end of buffer.
563 (should
564 (org-test-with-temp-text ":TEST:\nC\n:END:\n "
565 (= (org-element-property :end (org-element-at-point)) (point-max)))))
568 ;;;; Dynamic Block
570 (ert-deftest test-org-element/dynamic-block-parser ()
571 "Test `dynamic-block' parser."
572 ;; Standard test.
573 (should
574 (org-test-with-temp-text
575 "#+BEGIN: myblock :param1 val1 :param2 val2\nText\n#+END:"
576 (org-element-map (org-element-parse-buffer) 'dynamic-block 'identity)))
577 ;; Ignore case.
578 (should
579 (org-test-with-temp-text
580 "#+begin: myblock :param1 val1 :param2 val2\nText\n#+end:"
581 (org-element-map (org-element-parse-buffer) 'dynamic-block 'identity)))
582 ;; Ignore incomplete block.
583 (should-not
584 (org-test-with-temp-text "#+BEGIN: myblock :param1 val1 :param2 val2"
585 (org-element-map (org-element-parse-buffer) 'dynamic-block
586 'identity nil t)))
587 ;; Handle non-empty blank line at the end of buffer.
588 (should
589 (org-test-with-temp-text "#+BEGIN: myblock :param val1\nC\n#+END:\n "
590 (= (org-element-property :end (org-element-at-point)) (point-max)))))
593 ;;;; Entity
595 (ert-deftest test-org-element/entity-parser ()
596 "Test `entity' parser."
597 ;; Without brackets.
598 (should
599 (org-test-with-temp-text "\\sin"
600 (org-element-map (org-element-parse-buffer) 'entity 'identity)))
601 ;; With brackets.
602 (should
603 (org-element-property
604 :use-brackets-p
605 (org-test-with-temp-text "\\alpha{}text"
606 (org-element-map (org-element-parse-buffer) 'entity 'identity nil t))))
607 ;; User-defined entity.
608 (should
609 (equal
610 (org-element-property
611 :name
612 (let ((org-entities-user
613 '(("test" "test" nil "test" "test" "test" "test"))))
614 (org-test-with-temp-text "\\test"
615 (org-element-map (org-element-parse-buffer) 'entity 'identity nil t))))
616 "test"))
617 ;; Special case: entity at the end of a container.
618 (should
619 (eq 'entity
620 (org-test-with-temp-text "*\\alpha \\beta*"
621 (search-forward "be")
622 (org-element-type (org-element-context))))))
625 ;;;; Example Block
627 (ert-deftest test-org-element/example-block-parser ()
628 "Test `example-block' parser."
629 ;; Standard test.
630 (should
631 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nText\n#+END_EXAMPLE"
632 (org-element-map (org-element-parse-buffer) 'example-block 'identity)))
633 ;; Ignore incomplete block.
634 (should-not
635 (eq 'example-block
636 (org-test-with-temp-text "#+BEGIN_EXAMPLE"
637 (org-element-type (org-element-at-point)))))
638 ;; Properly un-escape code.
639 (should
640 (equal "* Headline\n #+keyword\nText\n"
641 (org-test-with-temp-text
642 "#+BEGIN_EXAMPLE\n,* Headline\n ,#+keyword\nText\n#+END_EXAMPLE"
643 (org-element-property :value (org-element-at-point)))))
644 ;; Remove block indentation according to block boundaries, unless
645 ;; block contents are less indented than block boundaries.
646 (should
647 (equal " L1\nL2\n"
648 (org-test-with-temp-text " #+BEGIN_EXAMPLE\n L1\n L2\n #+END_EXAMPLE"
649 (let ((org-src-preserve-indentation t))
650 (org-element-property :value (org-element-at-point))))))
651 (should
652 (equal
653 " L1\n L2\n"
654 (org-test-with-temp-text " #+BEGIN_EXAMPLE\n L1\n L2\n #+END_EXAMPLE"
655 (let ((org-src-preserve-indentation t))
656 (org-element-property :value (org-element-at-point))))))
657 ;; Handle non-empty blank line at the end of buffer.
658 (should
659 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nC\n#+END_EXAMPLE\n "
660 (= (org-element-property :end (org-element-at-point)) (point-max)))))
662 (ert-deftest test-org-element/block-switches ()
663 "Test `example-block' and `src-block' switches parsing."
664 (let ((org-coderef-label-format "(ref:%s)"))
665 ;; 1. Test "-i" switch.
666 (should-not
667 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
668 (org-element-property :preserve-indent (org-element-at-point))))
669 (should
670 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
671 (org-element-property :preserve-indent (org-element-at-point))))
672 (should-not
673 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nText.\n#+END_EXAMPLE"
674 (org-element-property :preserve-indent (org-element-at-point))))
675 (should
676 (org-test-with-temp-text "#+BEGIN_EXAMPLE -i\nText.\n#+END_EXAMPLE"
677 (org-element-property :preserve-indent (org-element-at-point))))
678 ;; 2. "-n -r -k" combination should number lines, retain labels but
679 ;; not use them in coderefs.
680 (should
681 (org-test-with-temp-text "#+BEGIN_EXAMPLE -n -r -k\nText.\n#+END_EXAMPLE"
682 (let ((element (org-element-at-point)))
683 (and (org-element-property :number-lines element)
684 (org-element-property :retain-labels element)
685 (not (org-element-property :use-labels element))))))
686 (should
687 (org-test-with-temp-text
688 "#+BEGIN_SRC emacs-lisp -n -r -k\n(+ 1 1)\n#+END_SRC"
689 (let ((element (org-element-at-point)))
690 (and (org-element-property :number-lines element)
691 (org-element-property :retain-labels element)
692 (not (org-element-property :use-labels element))))))
693 ;; 3. "-n -r" combination should number-lines remove labels and not
694 ;; use them in coderefs.
695 (should
696 (org-test-with-temp-text "#+BEGIN_EXAMPLE -n -r\nText.\n#+END_EXAMPLE"
697 (let ((element (org-element-at-point)))
698 (and (org-element-property :number-lines element)
699 (not (org-element-property :retain-labels element))
700 (not (org-element-property :use-labels element))))))
701 (should
702 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1)\n#+END_SRC"
703 (let ((element (org-element-at-point)))
704 (and (org-element-property :number-lines element)
705 (not (org-element-property :retain-labels element))
706 (not (org-element-property :use-labels element))))))
707 ;; 4. "-n" or "+n" should number lines, retain labels and use them
708 ;; in coderefs.
709 (should
710 (org-test-with-temp-text "#+BEGIN_EXAMPLE -n\nText.\n#+END_EXAMPLE"
711 (let ((element (org-element-at-point)))
712 (and (org-element-property :number-lines element)
713 (org-element-property :retain-labels element)
714 (org-element-property :use-labels element)))))
715 (should
716 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1)\n#+END_SRC"
717 (let ((element (org-element-at-point)))
718 (and (org-element-property :number-lines element)
719 (org-element-property :retain-labels element)
720 (org-element-property :use-labels element)))))
721 (should
722 (org-test-with-temp-text "#+BEGIN_EXAMPLE +n\nText.\n#+END_EXAMPLE"
723 (let ((element (org-element-at-point)))
724 (and (org-element-property :number-lines element)
725 (org-element-property :retain-labels element)
726 (org-element-property :use-labels element)))))
727 (should
728 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp +n\n(+ 1 1)\n#+END_SRC"
729 (let ((element (org-element-at-point)))
730 (and (org-element-property :number-lines element)
731 (org-element-property :retain-labels element)
732 (org-element-property :use-labels element)))))
733 ;; 5. No switch should not number lines, but retain labels and use
734 ;; them in coderefs.
735 (should
736 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nText.\n#+END_EXAMPLE"
737 (let ((element (org-element-at-point)))
738 (and (not (org-element-property :number-lines element))
739 (org-element-property :retain-labels element)
740 (org-element-property :use-labels element)))))
741 (should
742 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
743 (let ((element (org-element-at-point)))
744 (and (not (org-element-property :number-lines element))
745 (org-element-property :retain-labels element)
746 (org-element-property :use-labels element)))))
747 ;; 6. "-r" switch only: do not number lines, remove labels, and
748 ;; don't use labels in coderefs.
749 (should
750 (org-test-with-temp-text "#+BEGIN_EXAMPLE -r\nText.\n#+END_EXAMPLE"
751 (let ((element (org-element-at-point)))
752 (and (not (org-element-property :number-lines element))
753 (not (org-element-property :retain-labels element))
754 (not (org-element-property :use-labels element))))))
755 (should
756 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1)\n#+END_SRC"
757 (let ((element (org-element-at-point)))
758 (and (not (org-element-property :number-lines element))
759 (not (org-element-property :retain-labels element))
760 (not (org-element-property :use-labels element))))))
761 ;; 7. Recognize coderefs with user-defined syntax.
762 (should
763 (equal
764 "[ref:%s]"
765 (org-test-with-temp-text
766 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText [ref:text]\n#+END_EXAMPLE"
767 (org-element-property :label-fmt (org-element-at-point)))))
768 (should
769 (equal
770 "[ref:%s]"
771 (org-test-with-temp-text
772 "#+BEGIN_SRC emacs-lisp -l \"[ref:%s]\"\n(+ 1 1) [ref:text]\n#+END_SRC"
773 (org-element-property :label-fmt (org-element-at-point)))))))
776 ;;;; Export Block
778 (ert-deftest test-org-element/export-block-parser ()
779 "Test `export-block' parser."
780 ;; Standard test.
781 (should
782 (org-test-with-temp-text "#+BEGIN_LATEX\nText\n#+END_LATEX"
783 (org-element-map
784 (let ((org-element-block-name-alist
785 '(("LATEX" . org-element-export-block-parser))))
786 (org-element-parse-buffer))
787 'export-block 'identity)))
788 ;; Ignore case.
789 (should
790 (let ((org-element-block-name-alist
791 '(("LATEX" . org-element-export-block-parser))))
792 (org-test-with-temp-text "#+begin_latex\nText\n#+end_latex"
793 (org-element-map (org-element-parse-buffer) 'export-block 'identity))))
794 ;; Ignore incomplete block.
795 (should-not
796 (let ((org-element-block-name-alist
797 '(("LATEX" . org-element-export-block-parser))))
798 (org-test-with-temp-text "#+BEGIN_LATEX"
799 (org-element-map (org-element-parse-buffer) 'export-block
800 'identity nil t))))
801 ;; Handle non-empty blank line at the end of buffer.
802 (should
803 (let ((org-element-block-name-alist
804 '(("LATEX" . org-element-export-block-parser))))
805 (org-test-with-temp-text "#+BEGIN_LATEX\nC\n#+END_LATEX\n "
806 (= (org-element-property :end (org-element-at-point)) (point-max))))))
809 ;;;; Export Snippet
811 (ert-deftest test-org-element/export-snippet-parser ()
812 "Test `export-snippet' parser."
813 (should
814 (equal
815 '("back-end" . "contents")
816 (org-test-with-temp-text "@@back-end:contents@@"
817 (org-element-map
818 (org-element-parse-buffer) 'export-snippet
819 (lambda (snippet) (cons (org-element-property :back-end snippet)
820 (org-element-property :value snippet)))
821 nil t)))))
824 ;;;; Fixed Width
826 (ert-deftest test-org-element/fixed-width-parser ()
827 "Test fixed-width area parsing."
828 ;; Preserve indentation.
829 (should
830 (org-test-with-temp-text ": no blank\n: one blank"
831 (org-element-map (org-element-parse-buffer) 'fixed-width 'identity)))
832 ;; Fixed-width with empty lines.
833 (should
834 (org-test-with-temp-text ": first part\n:\n: \n: second part"
835 (org-element-map (org-element-parse-buffer) 'fixed-width 'identity)))
836 ;; Parse indented fixed-width markers.
837 (should
838 (org-test-with-temp-text "Text\n : no blank\n : one blank"
839 (org-element-map (org-element-parse-buffer) 'fixed-width 'identity)))
840 ;; Distinguish fixed-width areas within a list and outside of it.
841 (should
842 (= 2
843 (length
844 (org-test-with-temp-text "
845 - Item
846 : fixed-width inside
847 : fixed-width outside"
848 (org-element-map (org-element-parse-buffer) 'fixed-width 'identity)))))
849 ;; Handle non-empty blank line at the end of buffer.
850 (should
851 (org-test-with-temp-text ": A\n "
852 (= (org-element-property :end (org-element-at-point)) (point-max)))))
855 ;;;; Footnote Definition
857 (ert-deftest test-org-element/footnote-definition-parser ()
858 "Test `footnote-definition' parser."
859 (should
860 (org-test-with-temp-text "[fn:1] Definition"
861 (org-element-map (org-element-parse-buffer) 'footnote-definition
862 'identity nil t)))
863 ;; Footnote with more contents
864 (should
865 (= 29
866 (org-element-property
867 :end
868 (org-test-with-temp-text "[fn:1] Definition\n\n| a | b |"
869 (org-element-map (org-element-parse-buffer) 'footnote-definition
870 'identity nil t)))))
871 ;; Footnote starting with special syntax.
872 (should-not
873 (org-test-with-temp-text "[fn:1] - no item"
874 (org-element-map (org-element-parse-buffer) 'item 'identity)))
875 ;; Correctly handle footnote starting with an empty line.
876 (should
877 (= 9
878 (org-test-with-temp-text "[fn:1]\n\n Body"
879 (org-element-property :contents-begin (org-element-at-point)))))
880 ;; Handle non-empty blank line at the end of buffer.
881 (should
882 (org-test-with-temp-text "[fn:1] Definition\n "
883 (= (org-element-property :end (org-element-at-point)) (point-max)))))
886 ;;;; Footnotes Reference.
888 (ert-deftest test-org-element/footnote-reference-parser ()
889 "Test `footnote-reference' parser."
890 ;; Parse a standard reference.
891 (should
892 (org-test-with-temp-text "Text[fn:label]"
893 (org-element-map
894 (org-element-parse-buffer) 'footnote-reference 'identity)))
895 ;; Parse a normalized reference.
896 (should
897 (org-test-with-temp-text "Text[1]"
898 (org-element-map
899 (org-element-parse-buffer) 'footnote-reference 'identity)))
900 ;; Parse an inline reference.
901 (should
902 (org-test-with-temp-text "Text[fn:test:def]"
903 (org-element-map
904 (org-element-parse-buffer) 'footnote-reference 'identity)))
905 ;; Parse an anonymous reference.
906 (should
907 (org-test-with-temp-text "Text[fn::def]"
908 (org-element-map
909 (org-element-parse-buffer) 'footnote-reference 'identity)))
910 ;; Parse nested footnotes.
911 (should
912 (= 2
913 (length
914 (org-test-with-temp-text "Text[fn::def [fn:label]]"
915 (org-element-map
916 (org-element-parse-buffer) 'footnote-reference 'identity)))))
917 ;; Parse adjacent footnotes.
918 (should
919 (org-test-with-temp-text "Text[fn:label1][fn:label2]"
920 (= 2
921 (length
922 (org-element-map
923 (org-element-parse-buffer) 'footnote-reference 'identity)))))
924 ;; Only properly closed footnotes are recognized as such.
925 (should-not
926 (org-test-with-temp-text "Text[fn:label"
927 (org-element-map
928 (org-element-parse-buffer) 'footnote-reference 'identity))))
931 ;;;; Headline
933 (ert-deftest test-org-element/headline-comment-keyword ()
934 "Test COMMENT keyword recognition."
935 ;; Reference test.
936 (org-test-with-temp-text "* Headline"
937 (let ((org-comment-string "COMMENT"))
938 (should-not (org-element-property :commentedp (org-element-at-point)))))
939 ;; Standard position.
940 (org-test-with-temp-text "* COMMENT Headline"
941 (let ((org-comment-string "COMMENT")
942 (headline (org-element-at-point)))
943 (should (org-element-property :commentedp headline))
944 (should (equal (org-element-property :raw-value headline) "Headline"))))
945 ;; Case sensitivity.
946 (org-test-with-temp-text "* COMMENT Headline"
947 (let* ((org-comment-string "Comment")
948 (headline (org-element-at-point)))
949 (should-not (org-element-property :commentedp headline))
950 (should (equal (org-element-property :raw-value headline)
951 "COMMENT Headline"))))
952 ;; With another keyword.
953 (org-test-with-temp-text "* TODO COMMENT Headline"
954 (let* ((org-comment-string "COMMENT")
955 (org-todo-keywords '((sequence "TODO" "DONE")))
956 (headline (org-element-at-point)))
957 (should (org-element-property :commentedp headline))
958 (should (equal (org-element-property :raw-value headline) "Headline"))))
959 ;; With the keyword only.
960 (org-test-with-temp-text "* COMMENT"
961 (let* ((org-comment-string "COMMENT")
962 (headline (org-element-at-point)))
963 (should (org-element-property :commentedp headline))
964 (should (equal (org-element-property :raw-value headline) "")))))
966 (ert-deftest test-org-element/headline-archive-tag ()
967 "Test ARCHIVE tag recognition."
968 ;; Reference test.
969 (should-not
970 (org-test-with-temp-text "* Headline"
971 (let ((org-archive-tag "ARCHIVE"))
972 (org-element-property :archivedp (org-element-at-point)))))
973 ;; Single tag.
974 (org-test-with-temp-text "* Headline :ARCHIVE:"
975 (let ((org-archive-tag "ARCHIVE"))
976 (let ((headline (org-element-at-point)))
977 (should (org-element-property :archivedp headline))
978 ;; Test tag removal.
979 (should-not (org-element-property :tags headline)))))
980 ;; Multiple tags.
981 (org-test-with-temp-text "* Headline :test:ARCHIVE:"
982 (let ((org-archive-tag "ARCHIVE"))
983 (let ((headline (org-element-at-point)))
984 (should (org-element-property :archivedp headline))
985 ;; Test tag removal.
986 (should (equal (org-element-property :tags headline) '("test"))))))
987 ;; Tag is case-sensitive.
988 (should-not
989 (org-test-with-temp-text "* Headline :ARCHIVE:"
990 (let ((org-archive-tag "Archive"))
991 (org-element-property :archivedp (org-element-at-point))))))
993 (ert-deftest test-org-element/headline-properties ()
994 "Test properties from property drawer."
995 ;; All properties from property drawer have their symbol upper
996 ;; cased.
997 (should
998 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:foo: bar\n:END:"
999 (org-element-property :FOO (org-element-at-point))))
1000 (should-not
1001 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:foo: bar\n:END:"
1002 (org-element-property :foo (org-element-at-point))))
1003 ;; Also parse properties associated in inlinetasks.
1004 (when (featurep 'org-inlinetask)
1005 (should
1006 (org-test-with-temp-text "*************** Inlinetask
1007 :PROPERTIES:
1008 :foo: bar
1009 :END:
1010 *************** END"
1011 (org-element-property :FOO (org-element-at-point)))))
1012 ;; Do not find property drawer in a verbatim area.
1013 (should-not
1014 (org-test-with-temp-text
1015 "* Headline
1016 #+BEGIN_EXAMPLE
1017 :PROPERTIES:
1018 :foo: bar
1019 :END:
1020 #+END_EXAMPLE"
1021 (org-element-property :FOO (org-element-at-point))))
1022 ;; Do not use properties from a drawer associated to an inlinetask.
1023 (when (featurep 'org-inlinetask)
1024 (should-not
1025 (org-test-with-temp-text
1026 "* Headline
1027 *************** Inlinetask
1028 :PROPERTIES:
1029 :foo: bar
1030 :END:
1031 *************** END"
1032 (org-element-property
1033 :FOO (let ((org-inlinetask-min-level 15)) (org-element-at-point))))))
1034 ;; Do not find incomplete drawers.
1035 (should-not
1036 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:foo: bar"
1037 (org-element-property :FOO (org-element-at-point)))))
1040 ;;;; Horizontal Rule
1042 (ert-deftest test-org-element/horizontal-rule-parser ()
1043 "Test `horizontal-rule' parser."
1044 ;; Standard.
1045 (should
1046 (org-test-with-temp-text "-----"
1047 (org-element-map (org-element-parse-buffer) 'horizontal-rule 'identity)))
1048 ;; Indented.
1049 (should
1050 (org-test-with-temp-text " -----"
1051 (org-element-map (org-element-parse-buffer) 'horizontal-rule 'identity)))
1052 ;; Hyphen must be alone on the line.
1053 (should-not
1054 (org-test-with-temp-text "-----wrong"
1055 (org-element-map (org-element-parse-buffer) 'horizontal-rule 'identity)))
1056 ;; 4 hyphens is too small.
1057 (should-not
1058 (org-test-with-temp-text "----"
1059 (org-element-map (org-element-parse-buffer) 'horizontal-rule 'identity)))
1060 ;; Handle non-empty blank line at the end of buffer.
1061 (should
1062 (org-test-with-temp-text "-----\n "
1063 (= (org-element-property :end (org-element-at-point)) (point-max)))))
1066 ;;;; Inline Babel Call
1068 (ert-deftest test-org-element/inline-babel-call-parser ()
1069 "Test `inline-babel-call' parser."
1070 (should
1071 (org-test-with-temp-text "call_test()"
1072 (org-element-map
1073 (org-element-parse-buffer) 'inline-babel-call 'identity))))
1076 ;;;; Inline Src Block
1078 (ert-deftest test-org-element/inline-src-block-parser ()
1079 "Test `inline-src-block' parser."
1080 (should
1081 (org-test-with-temp-text "src_emacs-lisp{(+ 1 1)}"
1082 (org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
1083 ;; With switches.
1084 (should
1085 (org-test-with-temp-text "src_emacs-lisp[:foo bar]{(+ 1 1)}"
1086 (org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
1087 (should
1088 (org-test-with-temp-text "src_emacs-lisp[ :foo bar]{(+ 1 1)}"
1089 (org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
1090 ;; Empty switches.
1091 (should
1092 (org-test-with-temp-text "src_emacs-lisp[]{(+ 1 1)}"
1093 (org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
1094 ;; Invalid syntax.
1095 (should-not
1096 (org-test-with-temp-text "foosrc_emacs-lisp[]{(+ 1 1)}"
1097 (org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
1098 (should-not
1099 (org-test-with-temp-text "src_emacs-lisp[]foo{(+ 1 1)}"
1100 (org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
1101 ;; Invalid language name
1102 (should-not
1103 (org-test-with-temp-text "src_emacs-\tlisp{(+ 1 1)}"
1104 (org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
1105 ;; Test parsing at the beginning of an item.
1106 (should
1107 (org-test-with-temp-text "- src_emacs-lisp{(+ 1 1)}"
1108 (org-element-map (org-element-parse-buffer) 'inline-src-block 'identity))))
1111 ;;;; Inlinetask
1113 (ert-deftest test-org-element/inlinetask-parser ()
1114 "Test `inlinetask' parser."
1115 (when (featurep 'org-inlinetask)
1116 (let ((org-inlinetask-min-level 15))
1117 ;; Regular inlinetask.
1118 (should
1119 (eq 'inlinetask
1120 (org-test-with-temp-text
1121 "*************** Task\nTest\n*************** END"
1122 (org-element-type (org-element-at-point)))))
1123 ;; Degenerate inlinetask.
1124 (should
1125 (eq 'inlinetask
1126 (org-test-with-temp-text "*************** Task"
1127 (org-element-type (org-element-at-point)))))
1128 ;; Mixed inlinetasks.
1129 (should-not
1130 (org-test-with-temp-text
1132 *************** Task
1133 *************** Task2
1134 Contents
1135 *************** END"
1136 (forward-line)
1137 (goto-char (org-element-property :end (org-element-at-point)))
1138 (eobp)))
1139 ;; TODO keyword.
1140 (should
1141 (equal
1142 "TODO"
1143 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
1144 (org-test-with-temp-text "*************** TODO Task"
1145 (org-element-property :todo-keyword (org-element-at-point))))))
1146 ;; Planning info.
1147 (should
1148 (org-test-with-temp-text "
1149 *************** Task
1150 DEADLINE: <2012-03-29 thu.>"
1151 (forward-line)
1152 (org-element-property :deadline (org-element-at-point))))
1153 ;; Priority.
1154 (should
1157 (org-test-with-temp-text "
1158 *************** [#A] Task"
1159 (forward-line)
1160 (org-element-property :priority (org-element-at-point)))))
1161 ;; Tags.
1162 (should
1163 (equal
1164 '("test")
1165 (org-test-with-temp-text "
1166 *************** Task :test:"
1167 (forward-line)
1168 (org-element-property :tags (org-element-at-point)))))
1169 ;; Regular properties are accessed through upper case keywords.
1170 (should
1171 (org-test-with-temp-text "
1172 *************** Task
1173 :PROPERTIES:
1174 :foo: bar
1175 :END:
1176 *************** END"
1177 (forward-line)
1178 (org-element-property :FOO (org-element-at-point))))
1179 (should-not
1180 (org-test-with-temp-text "
1181 *************** Task
1182 :PROPERTIES:
1183 :foo: bar
1184 :END:
1185 *************** END"
1186 (forward-line)
1187 (org-element-property :foo (org-element-at-point))))
1188 ;; Handle non-empty blank line at the end of buffer.
1189 (should
1190 (org-test-with-temp-text "*************** Task\n*************** END\n "
1191 (= (org-element-property :end (org-element-at-point)) (point-max)))))))
1194 ;;;; Italic
1196 (ert-deftest test-org-element/italic-parser ()
1197 "Test `italic' parser."
1198 ;; Regular test.
1199 (should
1200 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
1201 (org-test-with-temp-text "/italic/"
1202 (org-element-map (org-element-parse-buffer) 'italic 'identity nil t))))
1203 ;; Multi-line markup.
1204 (should
1205 (equal
1206 (org-element-contents
1207 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
1208 (org-test-with-temp-text "/first line\nsecond line/"
1209 (org-element-map (org-element-parse-buffer) 'italic 'identity nil t))))
1210 '("first line\nsecond line"))))
1213 ;;;; Item
1215 (ert-deftest test-org-element/item-parser ()
1216 "Test `item' parser."
1217 ;; Standard test.
1218 (should
1219 (org-test-with-temp-text "- item"
1220 (org-element-map (org-element-parse-buffer) 'item 'identity)))
1221 ;; Counter.
1222 (should
1223 (= 6
1224 (org-element-property
1225 :counter
1226 (org-test-with-temp-text "6. [@6] item"
1227 (org-element-map (org-element-parse-buffer) 'item 'identity nil t)))))
1228 ;; Tag
1229 (should
1230 (equal
1231 '("tag")
1232 (org-element-property
1233 :tag
1234 (org-test-with-temp-text "- tag :: description"
1235 (org-element-map (org-element-parse-buffer) 'item 'identity nil t)))))
1236 ;; No tags in ordered lists.
1237 (should-not
1238 (org-element-property
1239 :tag
1240 (org-test-with-temp-text "1. tag :: description"
1241 (org-element-map (org-element-parse-buffer) 'item 'identity nil t))))
1242 ;; Check-boxes
1243 (should
1244 (equal
1245 '(trans on off)
1246 (org-test-with-temp-text "
1247 - [-] item 1
1248 - [X] item 1.1
1249 - [ ] item 1.2"
1250 (org-element-map
1251 (org-element-parse-buffer) 'item
1252 (lambda (item) (org-element-property :checkbox item))))))
1253 ;; Item starting with special syntax.
1254 (should
1255 (equal '(("- item"))
1256 (org-test-with-temp-text "- - item"
1257 (org-element-map (org-element-parse-buffer) 'paragraph
1258 'org-element-contents))))
1259 ;; Block in an item: ignore indentation within the block.
1260 (should
1261 (org-test-with-temp-text "- item\n #+begin_src emacs-lisp\n(+ 1 1)\n #+end_src"
1262 (forward-char)
1263 (= (org-element-property :end (org-element-at-point)) (point-max)))))
1266 ;;;; Keyword
1268 (ert-deftest test-org-element/keyword-parser ()
1269 "Test `keyword' parser."
1270 ;; Standard test.
1271 (should
1272 (org-test-with-temp-text "#+KEYWORD: value"
1273 (org-element-map (org-element-parse-buffer) 'keyword 'identity)))
1274 ;; Keywords are case-insensitive.
1275 (should
1276 (org-test-with-temp-text "#+keyword: value"
1277 (org-element-map (org-element-parse-buffer) 'keyword 'identity)))
1278 ;; Affiliated keywords are not keywords.
1279 (should-not
1280 (org-test-with-temp-text "#+NAME: value
1281 Paragraph"
1282 (org-element-map (org-element-parse-buffer) 'keyword 'identity)))
1283 ;; Do not mix keywords with Babel calls and dynamic blocks.
1284 (should-not
1285 (org-test-with-temp-text "#+CALL: fun()"
1286 (org-element-map (org-element-parse-buffer) 'keyword 'identity)))
1287 (should-not
1288 (org-test-with-temp-text "#+BEGIN: my-fun\nBody\n#+END:"
1289 (org-element-map (org-element-parse-buffer) 'keyword 'identity)))
1290 ;; Handle non-empty blank line at the end of buffer.
1291 (should
1292 (org-test-with-temp-text "#+KEYWORD: value\n "
1293 (= (org-element-property :end (org-element-at-point)) (point-max)))))
1296 ;;;; Latex Environment
1298 (ert-deftest test-org-element/latex-environment-parser ()
1299 "Test `latex-environment' parser."
1300 (should
1301 (org-test-with-temp-text "\\begin{equation}\ne^{i\\pi}+1=0\n\\end{equation}"
1302 (org-element-map (org-element-parse-buffer) 'latex-environment 'identity)))
1303 ;; Allow nested environments.
1304 (should
1305 (equal
1306 "\\begin{outer}
1307 \\begin{inner}
1308 e^{i\\pi}+1=0
1309 \\end{inner}
1310 \\end{outer}"
1311 (org-test-with-temp-text "
1312 \\begin{outer}
1313 \\begin{inner}
1314 e^{i\\pi}+1=0
1315 \\end{inner}
1316 \\end{outer}"
1317 (org-element-property
1318 :value
1319 (org-element-map
1320 (org-element-parse-buffer) 'latex-environment 'identity nil t)))))
1321 ;; Allow environments with options and arguments.
1322 (should
1323 (eq 'latex-environment
1324 (org-test-with-temp-text
1325 "\\begin{theorem}[Euler]\ne^{i\\pi}+1=0\n\\end{theorem}"
1326 (org-element-type (org-element-at-point)))))
1327 (should
1328 (eq 'latex-environment
1329 (org-test-with-temp-text "\\begin{env}{arg}\nvalue\n\\end{env}"
1330 (org-element-type (org-element-at-point)))))
1331 ;; Allow environments without newline after \begin{.}.
1332 (should
1333 (eq 'latex-environment
1334 (org-test-with-temp-text "\\begin{env}{arg}something\nvalue\n\\end{env}"
1335 (org-element-type (org-element-at-point)))))
1336 ;; Allow one-line environments.
1337 (should
1338 (eq 'latex-environment
1339 (org-test-with-temp-text "\\begin{env}{arg}something\\end{env}"
1340 (org-element-type (org-element-at-point)))))
1341 ;; Should not allow different tags.
1342 (should-not
1343 (eq 'latex-environment
1344 (org-test-with-temp-text "\\begin{env*}{arg}something\\end{env}"
1345 (org-element-type (org-element-at-point)))))
1346 ;; LaTeX environments must be on separate lines.
1347 (should-not
1348 (eq 'latex-environment
1349 (org-test-with-temp-text "\\begin{env} x \\end{env} y"
1350 (org-element-type (org-element-at-point)))))
1351 (should-not
1352 (eq 'latex-environment
1353 (org-test-with-temp-text "y \\begin{env} x<point> \\end{env}"
1354 (org-element-type (org-element-at-point)))))
1355 ;; Handle non-empty blank line at the end of buffer.
1356 (should
1357 (org-test-with-temp-text "\\begin{env}\n\\end{env}\n "
1358 (= (org-element-property :end (org-element-at-point)) (point-max)))))
1361 ;;;; Latex Fragment
1363 (ert-deftest test-org-element/latex-fragment-parser ()
1364 "Test `latex-fragment' parser."
1365 (should
1366 (org-test-with-temp-text "$a$"
1367 (org-element-map (org-element-parse-buffer) 'latex-fragment 'identity)))
1368 (should
1369 (org-test-with-temp-text "$$a$$"
1370 (org-element-map (org-element-parse-buffer) 'latex-fragment 'identity)))
1371 (should
1372 (org-test-with-temp-text "\\(a\\)"
1373 (org-element-map (org-element-parse-buffer) 'latex-fragment 'identity)))
1374 (should
1375 (org-test-with-temp-text "\\[a\\]"
1376 (org-element-map
1377 (org-element-parse-buffer) 'latex-fragment 'identity)))
1378 ;; Test fragment at the beginning of an item.
1379 (should
1380 (eq 'latex-fragment
1381 (org-test-with-temp-text "- $x$"
1382 (progn (search-forward "$")
1383 (org-element-type (org-element-context)))))))
1386 ;;;; Line Break
1388 (ert-deftest test-org-element/line-break-parser ()
1389 "Test `line-break' parser."
1390 ;; Regular test.
1391 (should
1392 (org-test-with-temp-text "Text \\\\"
1393 (org-element-map (org-element-parse-buffer) 'line-break 'identity)))
1394 ;; Line break with trailing white spaces.
1395 (should
1396 (org-test-with-temp-text "Text \\\\ "
1397 (org-element-map (org-element-parse-buffer) 'line-break 'identity)))
1398 ;; Three backslashes are too much.
1399 (should-not
1400 (org-test-with-temp-text "Text \\\\\\"
1401 (org-element-map (org-element-parse-buffer) 'line-break 'identity))))
1404 ;;;; Link
1406 (ert-deftest test-org-element/link-parser ()
1407 "Test `link' parser."
1408 ;; Radio target.
1409 (should
1410 (equal
1411 "radio"
1412 (org-test-with-temp-text "<<<radio>>>A radio link"
1413 (org-update-radio-target-regexp)
1414 (org-element-property
1415 :type
1416 (org-element-map (org-element-parse-buffer) 'link #'identity nil t)))))
1417 ;; Standard link.
1419 ;; ... with description.
1420 (should
1421 (equal
1422 '("Orgmode.org")
1423 (org-test-with-temp-text "[[http://orgmode.org][Orgmode.org]]"
1424 (org-element-contents
1425 (org-element-map (org-element-parse-buffer) 'link 'identity nil t)))))
1426 ;; ... without description.
1427 (should
1428 (equal
1429 "http"
1430 (org-test-with-temp-text "[[http://orgmode.org]]"
1431 (org-element-property
1432 :type
1433 (org-element-map (org-element-parse-buffer) 'link 'identity nil t)))))
1434 ;; ... with expansion.
1435 (should
1436 (equal
1437 "//orgmode.org/worg"
1438 (org-test-with-temp-text "[[Org:worg]]"
1439 (let ((org-link-abbrev-alist '(("Org" . "http://orgmode.org/"))))
1440 (org-element-property
1441 :path
1442 (org-element-map (org-element-parse-buffer) 'link 'identity nil t))))))
1443 ;; ... with translation.
1444 (should
1445 (equal
1446 "127.0.0.1"
1447 (org-test-with-temp-text "[[http://orgmode.org]]"
1448 (flet ((link-translate (type path) (cons type "127.0.0.1")))
1449 (let ((org-link-translation-function 'link-translate))
1450 (org-element-property
1451 :path
1452 (org-element-map (org-element-parse-buffer) 'link
1453 'identity nil t)))))))
1454 ;; ... id link.
1455 (should
1456 (equal
1457 "id"
1458 (org-test-with-temp-text "[[id:aaaa]]"
1459 (org-element-property
1460 :type
1461 (org-element-map (org-element-parse-buffer) 'link 'identity nil t)))))
1462 ;; ... custom-id link.
1463 (should
1464 (equal
1465 "custom-id"
1466 (org-test-with-temp-text "[[#some-id]]"
1467 (org-element-property
1468 :type
1469 (org-element-map (org-element-parse-buffer) 'link 'identity nil t)))))
1470 ;; ... coderef link.
1471 (should
1472 (equal
1473 "coderef"
1474 (org-test-with-temp-text "[[(reference)]]"
1475 (org-element-property
1476 :type
1477 (org-element-map (org-element-parse-buffer) 'link 'identity nil t)))))
1478 ;; ... fuzzy link.
1479 (should
1480 (equal
1481 "fuzzy"
1482 (org-test-with-temp-text "[[target-or-title]]"
1483 (org-element-property
1484 :type
1485 (org-element-map (org-element-parse-buffer) 'link 'identity nil t)))))
1486 ;; ... file-type link with search option.
1487 (should
1488 (equal
1489 '(("file" "projects.org" "*task title"))
1490 (org-test-with-temp-text "[[file:projects.org::*task title]]"
1491 (org-element-map (org-element-parse-buffer) 'link
1492 (lambda (l) (list (org-element-property :type l)
1493 (org-element-property :path l)
1494 (org-element-property :search-option l)))))))
1495 ;; ... file-type link with application...
1496 (should
1497 (equal
1498 '("file" "projects.org" "docview")
1499 (org-test-with-temp-text "[[docview:projects.org]]"
1500 (let ((l (org-element-context)))
1501 (list (org-element-property :type l)
1502 (org-element-property :path l)
1503 (org-element-property :application l))))))
1504 ;; ... `:path' in a file-type link must be compatible with "file"
1505 ;; scheme in URI syntax, even if Org syntax isn't...
1506 (should
1507 (org-test-with-temp-text-in-file ""
1508 (let ((file (expand-file-name (buffer-file-name))))
1509 (insert (format "[[file://%s]]" file))
1510 (equal (org-element-property :path (org-element-context))
1511 (concat "//" file)))))
1512 (should
1513 (org-test-with-temp-text-in-file ""
1514 (let ((file (expand-file-name (buffer-file-name))))
1515 (insert (format "[[file:%s]]" file))
1516 (equal (org-element-property :path (org-element-context))
1517 (concat "//" file)))))
1518 (should
1519 (org-test-with-temp-text-in-file ""
1520 (let ((file (file-relative-name (buffer-file-name))))
1521 (insert (format "[[file:%s]]" file))
1522 (list (org-element-property :path (org-element-context)) file))))
1523 ;; ... multi-line link.
1524 (should
1525 (equal "//orgmode.org"
1526 (org-test-with-temp-text "[[http://orgmode.\norg]]"
1527 (org-element-property :path (org-element-context)))))
1528 ;; Plain link.
1529 (should
1530 (org-test-with-temp-text "A link: http://orgmode.org"
1531 (org-element-map (org-element-parse-buffer) 'link 'identity)))
1532 ;; Angular link.
1533 (should
1534 (org-test-with-temp-text "A link: <http://orgmode.org>"
1535 (org-element-map (org-element-parse-buffer) 'link 'identity nil t)))
1536 ;; Link abbreviation.
1537 (should
1538 (equal "http"
1539 (org-test-with-temp-text
1540 "#+LINK: orgmode http://www.orgmode.org/\n[[orgmode:#docs]]"
1541 (progn (org-mode-restart)
1542 (goto-char (1- (point-max)))
1543 (org-element-property :type (org-element-context))))))
1544 ;; Link abbreviation in a secondary string.
1545 (should
1546 (equal "http"
1547 (org-test-with-temp-text
1548 "#+LINK: orgmode http://www.orgmode.org/\n* H [[orgmode:#docs]]"
1549 (progn (org-mode-restart)
1550 (org-element-map (org-element-parse-buffer) 'link
1551 (lambda (link) (org-element-property :type link))
1552 nil t nil t)))))
1553 ;; Plain links are allowed as description of regular links.
1554 (should
1555 (equal "file"
1556 (org-test-with-temp-text "[[http://orgmode.org][file:unicorn.jpg]]"
1557 (search-forward "file:")
1558 (org-element-property :type (org-element-context))))))
1561 ;;;; Macro
1563 (ert-deftest test-org-element/macro-parser ()
1564 "Test `macro' parser."
1565 ;; Without arguments.
1566 (should
1567 (org-test-with-temp-text "{{{macro}}}"
1568 (org-element-map (org-element-parse-buffer) 'macro 'identity)))
1569 ;; With arguments.
1570 (should
1571 (org-test-with-temp-text "{{{macro(arg1,arg2)}}}"
1572 (org-element-map (org-element-parse-buffer) 'macro 'identity)))
1573 ;; Properly handle protected commas in arguments...
1574 (should
1575 (= 2
1576 (length
1577 (org-test-with-temp-text "{{{macro(arg1\\,arg1,arg2)}}}"
1578 (org-element-property :args (org-element-context))))))
1579 ;; ... even when last argument ends with a protected comma.
1580 (should
1581 (equal '("C-,")
1582 (org-test-with-temp-text "{{{macro(C-\\,)}}}"
1583 (org-element-property :args (org-element-context)))))
1584 ;; Allow to escape escaping character.
1585 (should
1586 (equal '("C-\\" "")
1587 (org-test-with-temp-text "{{{macro(C-\\\\,)}}}"
1588 (org-element-property :args (org-element-context)))))
1589 ;; No need to escape backslashes elsewhere.
1590 (should
1591 (equal '("\\")
1592 (org-test-with-temp-text "{{{macro(\\)}}}"
1593 (org-element-property :args (org-element-context))))))
1596 ;;;; Node Property
1598 (ert-deftest test-org-element/node-property ()
1599 "Test `node-property' parser."
1600 ;; Standard test.
1601 (should
1602 (equal '("abc" "value")
1603 (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:abc: value\n:END:"
1604 (let ((element (org-element-at-point)))
1605 (list (org-element-property :key element)
1606 (org-element-property :value element))))))
1607 ;; Value should be trimmed.
1608 (should
1609 (equal "value"
1610 (org-test-with-temp-text
1611 "* H\n:PROPERTIES:\n<point>:abc: value \n:END:"
1612 (org-element-property :value (org-element-at-point)))))
1613 ;; A node property requires to be wrapped within a property drawer.
1614 (should-not
1615 (eq 'node-property
1616 (org-test-with-temp-text ":abc: value"
1617 (org-element-type (org-element-at-point)))))
1618 ;; Accept empty properties.
1619 (should
1620 (equal '(("foo" "value") ("bar" ""))
1621 (org-test-with-temp-text "* H\n:PROPERTIES:\n:foo: value\n:bar:\n:END:"
1622 (org-element-map (org-element-parse-buffer) 'node-property
1623 (lambda (p)
1624 (list (org-element-property :key p)
1625 (org-element-property :value p))))))))
1628 ;;;; Paragraph
1630 (ert-deftest test-org-element/paragraph-parser ()
1631 "Test `paragraph' parser."
1632 ;; Standard test.
1633 (should
1634 (org-test-with-temp-text "Paragraph"
1635 (org-element-map (org-element-parse-buffer) 'paragraph 'identity nil t)))
1636 ;; Property find end of a paragraph stuck to another element.
1637 (should
1638 (eq ?#
1639 (org-test-with-temp-text "Paragraph\n# Comment"
1640 (org-element-map (org-element-parse-buffer) 'paragraph
1641 (lambda (p) (char-after (org-element-property :end p)))
1642 nil t))))
1643 ;; Include ill-formed Keywords.
1644 (should
1645 (org-test-with-temp-text "#+wrong_keyword something"
1646 (org-element-map (org-element-parse-buffer) 'paragraph 'identity)))
1647 ;; Include incomplete-drawers.
1648 (should
1649 (org-test-with-temp-text ":TEST:\nParagraph"
1650 (let ((elem (org-element-at-point)))
1651 (and (eq (org-element-type elem) 'paragraph)
1652 (= (point-max) (org-element-property :end elem))))))
1653 ;; Include incomplete blocks.
1654 (should
1655 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph"
1656 (let ((elem (org-element-at-point)))
1657 (and (eq (org-element-type elem) 'paragraph)
1658 (= (point-max) (org-element-property :end elem))))))
1659 ;; Include incomplete dynamic blocks.
1660 (should
1661 (org-test-with-temp-text "#+BEGIN: \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 latex environments.
1666 (should
1667 (org-test-with-temp-text "\begin{equation}\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 ;; Do not steal affiliated keywords from container.
1672 (should
1673 (org-test-with-temp-text "#+ATTR_LATEX: test\n- item 1"
1674 (let ((elem (progn (search-forward "item") (org-element-at-point))))
1675 (and (eq (org-element-type elem) 'paragraph)
1676 (not (org-element-property :attr_latex elem))
1677 (/= (org-element-property :begin elem) 1)))))
1678 ;; Handle non-empty blank line at the end of buffer.
1679 (should
1680 (org-test-with-temp-text "#+BEGIN_CENTER\nC\n#+END_CENTER\n "
1681 (= (org-element-property :end (org-element-at-point)) (point-max)))))
1684 ;;;; Plain List
1686 (ert-deftest test-org-element/plain-list-parser ()
1687 "Test `plain-list' parser."
1688 (org-test-with-temp-text "- item"
1689 (should (org-element-map (org-element-parse-buffer) 'plain-list 'identity)))
1690 ;; Blank lines after the list only belong to outer plain list.
1691 (should
1692 (equal
1693 '(t t)
1694 (org-test-with-temp-text "
1695 - outer
1696 - inner
1698 Outside list"
1699 (let ((endings (org-element-map (org-element-parse-buffer) 'plain-list
1700 (lambda (pl) (org-element-property :end pl)))))
1701 (list
1702 ;; Move to ending of outer list.
1703 (progn (goto-char (car endings)) (looking-at "Outside list"))
1704 ;; Move to ending of inner list.
1705 (progn (goto-char (nth 1 endings)) (looking-at "^$")))))))
1706 ;; Correctly compute end of list if it doesn't end at a line
1707 ;; beginning.
1708 (should
1709 (org-test-with-temp-text "- list\n \n "
1710 (= (org-element-property :end (org-element-at-point)) (point-max)))))
1713 ;;;; Planning
1715 (ert-deftest test-org-element/planning-parser ()
1716 "Test `planning' parser."
1717 ;; Test various keywords.
1718 (should
1719 (org-element-property
1720 :closed
1721 (org-test-with-temp-text "* H\n<point>CLOSED: [2012-03-29 thu.]"
1722 (org-element-at-point))))
1723 (should
1724 (org-element-property
1725 :deadline
1726 (org-test-with-temp-text "* H\n<point>DEADLINE: <2012-03-29 thu.>"
1727 (org-element-at-point))))
1728 (should
1729 (org-element-property
1730 :scheduled
1731 (org-test-with-temp-text "* H\n<point>SCHEDULED: <2012-03-29 thu.>"
1732 (org-element-at-point))))
1733 ;; Planning line only exists right after a headline.
1734 (should-not
1735 (eq 'planning
1736 (org-test-with-temp-text "DEADLINE: <2012-03-29 thu.>"
1737 (org-element-type (org-element-at-point)))))
1738 (should-not
1739 (eq 'planning
1740 (org-test-with-temp-text
1741 "* H\n# Comment\n<point>DEADLINE: <2012-03-29 thu.>"
1742 (org-element-type (org-element-at-point))))))
1745 ;;;; Property Drawer
1747 (ert-deftest test-org-element/property-drawer-parser ()
1748 "Test `property-drawer' parser."
1749 ;; Standard test.
1750 (should
1751 (eq 'property-drawer
1752 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:prop: value\n:END:"
1753 (org-element-type (org-element-at-point)))))
1754 (should
1755 (eq 'property-drawer
1756 (org-test-with-temp-text
1757 "* H\nDEADLINE: <2014-03-04 tue.>\n<point>:PROPERTIES:\n:prop: value\n:END:"
1758 (org-element-type (org-element-at-point)))))
1759 ;; Allow properties without value and no property at all.
1760 (should
1761 (eq 'property-drawer
1762 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:prop:\n:END:"
1763 (org-element-type (org-element-at-point)))))
1764 (should
1765 (eq 'property-drawer
1766 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:END:"
1767 (org-element-type (org-element-at-point)))))
1768 ;; Ignore incomplete drawer, drawer at a wrong location or with
1769 ;; wrong contents.
1770 (should-not
1771 (eq 'property-drawer
1772 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:prop: value"
1773 (org-element-type (org-element-at-point)))))
1774 (should-not
1775 (eq 'property-drawer
1776 (org-test-with-temp-text
1777 "* H\nParagraph\n<point>:PROPERTIES:\n:prop: value\n:END:"
1778 (org-element-type (org-element-at-point)))))
1779 (should-not
1780 (eq 'property-drawer
1781 (org-test-with-temp-text
1782 "* H\nParagraph\n<point>:PROPERTIES:\nparagraph\n:END:"
1783 (org-element-type (org-element-at-point)))))
1784 ;; Handle non-empty blank line at the end of buffer.
1785 (should
1786 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:END:\n "
1787 (= (org-element-property :end (org-element-at-point)) (point-max)))))
1790 ;;;; Quote Block
1792 (ert-deftest test-org-element/quote-block-parser ()
1793 "Test `quote-block' parser."
1794 ;; Regular test.
1795 (should
1796 (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
1797 (org-element-map (org-element-parse-buffer) 'quote-block 'identity)))
1798 ;; Ignore incomplete block.
1799 (should-not
1800 (org-test-with-temp-text "#+BEGIN_QUOTE"
1801 (org-element-map (org-element-parse-buffer) 'quote-block 'identity nil t)))
1802 ;; Handle non-empty blank line at the end of buffer.
1803 (should
1804 (org-test-with-temp-text "#+BEGIN_QUOTE\nC\n#+END_QUOTE\n "
1805 (= (org-element-property :end (org-element-at-point)) (point-max)))))
1808 ;;;; Radio Target
1810 (ert-deftest test-org-element/radio-target-parser ()
1811 "Test `radio-target' parser."
1812 ;; Standard test.
1813 (should
1814 (eq 'radio-target
1815 (org-test-with-temp-text "<<<radio>>>"
1816 (org-element-type (org-element-context)))))
1817 ;; Radio targets with objects.
1818 (should
1819 (eq 'radio-target
1820 (org-test-with-temp-text "<<<radio \\alpha>>>"
1821 (org-element-type (org-element-context)))))
1822 ;; Radio targets starting with an object.
1823 (should
1824 (eq 'radio-target
1825 (org-test-with-temp-text "<<<\\alpha radio>>>"
1826 (org-element-type (org-element-context)))))
1827 ;; Radio targets cannot begin or end with white space.
1828 (should-not
1829 (eq 'radio-target
1830 (org-test-with-temp-text "<<< radio>>>"
1831 (org-element-type (org-element-context)))))
1832 (should-not
1833 (eq 'radio-target
1834 (org-test-with-temp-text "<<<radio >>>"
1835 (org-element-type (org-element-context))))))
1838 ;;;; Section
1840 (ert-deftest test-org-element/section-parser ()
1841 "Test `section' parser."
1842 ;; Standard test.
1843 (should
1844 (org-test-with-temp-text "* Headline\nText"
1845 (org-element-map (org-element-parse-buffer) 'section 'identity)))
1846 ;; There's a section before the first headline.
1847 (should
1848 (org-test-with-temp-text "Text"
1849 (org-element-map (org-element-parse-buffer) 'section 'identity)))
1850 ;; A section cannot be empty.
1851 (should-not
1852 (org-test-with-temp-text "* Headline 1\n* Headline 2"
1853 (org-element-map (org-element-parse-buffer) 'section 'identity)))
1854 ;; A section doesn't contain sub-trees.
1855 (should-not
1856 (org-test-with-temp-text "* Head\nText\n** Sub-Head"
1857 (org-element-map
1858 (org-element-map (org-element-parse-buffer) 'section 'identity nil t)
1859 'headline 'identity))))
1862 ;;;; Special Block
1864 (ert-deftest test-org-element/special-block-parser ()
1865 "Test `special-block' parser."
1866 ;; Standard test.
1867 (should
1868 (equal "SPECIAL"
1869 (org-test-with-temp-text "#+BEGIN_SPECIAL\nText\n#+END_SPECIAL"
1870 (org-element-property :type (org-element-at-point)))))
1871 ;; Special blocks are case sensitive.
1872 (should
1873 (equal "CaSe"
1874 (org-test-with-temp-text "#+BEGIN_CaSe\nText\n#+END_CaSe"
1875 (org-element-property :type (org-element-at-point)))))
1876 ;; Special blocks can contain paragraphs.
1877 (should
1878 (eq 'paragraph
1879 (org-test-with-temp-text "#+BEGIN_SPECIAL\nText\n#+END_SPECIAL"
1880 (forward-line)
1881 (org-element-type (org-element-at-point)))))
1882 ;; Ignore incomplete block.
1883 (should-not
1884 (eq 'special-block
1885 (org-test-with-temp-text "#+BEGIN_SPECIAL"
1886 (org-element-type (org-element-at-point)))))
1887 ;; Allow special characters in type.
1888 (should
1889 (equal '(special-block "SPECIAL*")
1890 (org-test-with-temp-text "#+BEGIN_SPECIAL*\nContents\n#+END_SPECIAL*"
1891 (let ((element (org-element-at-point)))
1892 (list (org-element-type element)
1893 (org-element-property :type element))))))
1894 ;; Handle non-empty blank line at the end of buffer.
1895 (should
1896 (org-test-with-temp-text "#+BEGIN_SPECIAL\nC\n#+END_SPECIAL\n "
1897 (= (org-element-property :end (org-element-at-point)) (point-max)))))
1900 ;;;; Src Block
1902 (ert-deftest test-org-element/src-block-parser ()
1903 "Test `src-block' parser."
1904 ;; Regular tests.
1905 (should
1906 (org-test-with-temp-text "#+BEGIN_SRC org\nText\n#+END_SRC"
1907 (org-element-map (org-element-parse-buffer) 'src-block 'identity)))
1908 ;; Ignore incomplete block.
1909 (should-not
1910 (org-test-with-temp-text "#+BEGIN_SRC"
1911 (org-element-map (org-element-parse-buffer) 'src-block 'identity)))
1912 ;; Properly un-escape code.
1913 (should
1914 (equal "* Headline\n #+keyword\nText\n"
1915 (org-test-with-temp-text
1916 "#+BEGIN_SRC org\n,* Headline\n ,#+keyword\nText\n#+END_SRC"
1917 (org-element-property :value (org-element-at-point)))))
1918 ;; Remove block indentation according to block boundaries, unless
1919 ;; block contents are less indented than block boundaries.
1920 (should
1921 (equal " L1\nL2\n"
1922 (org-test-with-temp-text " #+BEGIN_SRC org\n L1\n L2\n #+END_SRC"
1923 (let ((org-src-preserve-indentation t))
1924 (org-element-property :value (org-element-at-point))))))
1925 (should
1926 (equal
1927 " L1\n L2\n"
1928 (org-test-with-temp-text " #+BEGIN_SRC org\n L1\n L2\n #+END_SRC"
1929 (let ((org-src-preserve-indentation t))
1930 (org-element-property :value (org-element-at-point))))))
1931 ;; Handle non-empty blank line at the end of buffer.
1932 (should
1933 (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\nC\n#+END_SRC\n "
1934 (= (org-element-property :end (org-element-at-point)) (point-max)))))
1937 ;;;; Statistics Cookie
1939 (ert-deftest test-org-element/statistics-cookie ()
1940 "Test `statistics-cookie' parser."
1941 ;; With numbers.
1942 (should
1943 (org-test-with-temp-text "[1/2]"
1944 (org-element-map (org-element-parse-buffer) 'statistics-cookie 'identity)))
1945 ;; With percents.
1946 (should
1947 (org-test-with-temp-text "[33%]"
1948 (org-element-map
1949 (org-element-parse-buffer) 'statistics-cookie 'identity))))
1952 ;;;; Strike Through
1954 (ert-deftest test-org-element/strike-through-parser ()
1955 "Test `strike-through' parser."
1956 ;; Regular test.
1957 (should
1958 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
1959 (org-test-with-temp-text "+strike-through+"
1960 (org-element-map (org-element-parse-buffer) 'strike-through 'identity))))
1961 ;; Multi-line markup.
1962 (should
1963 (equal
1964 (org-element-contents
1965 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
1966 (org-test-with-temp-text "+first line\nsecond line+"
1967 (org-element-map
1968 (org-element-parse-buffer) 'strike-through 'identity nil t))))
1969 '("first line\nsecond line"))))
1972 ;;;; Subscript
1974 (ert-deftest test-org-element/subscript-parser ()
1975 "Test `subscript' parser."
1976 ;; Without braces.
1977 (should
1978 (org-test-with-temp-text "a_b"
1979 (org-element-map (org-element-parse-buffer) 'subscript 'identity)))
1980 ;; With braces.
1981 (should
1982 (org-test-with-temp-text "a_{b}"
1983 (org-element-map (org-element-parse-buffer) 'subscript 'identity)))
1984 ;; Multiple subscripts in a paragraph.
1985 (should
1986 (= 2
1987 (org-test-with-temp-text "a_b and c_d"
1988 (length
1989 (org-element-map (org-element-parse-buffer) 'subscript 'identity))))))
1992 ;;;; Superscript
1994 (ert-deftest test-org-element/superscript-parser ()
1995 "Test `superscript' parser."
1996 ;; Without braces.
1997 (should
1998 (org-test-with-temp-text "a^b"
1999 (org-element-map (org-element-parse-buffer) 'superscript 'identity)))
2000 ;; With braces.
2001 (should
2002 (org-test-with-temp-text "a^{b}"
2003 (org-element-map (org-element-parse-buffer) 'superscript 'identity)))
2004 ;; Multiple superscript in a paragraph.
2005 (should
2006 (= 2
2007 (org-test-with-temp-text "a^b and c^d"
2008 (length
2009 (org-element-map
2010 (org-element-parse-buffer) 'superscript 'identity))))))
2013 ;;;; Table
2015 (ert-deftest test-org-element/table-parser ()
2016 "Test `table' parser."
2017 (should
2018 (org-test-with-temp-text "| a |"
2019 (org-element-map (org-element-parse-buffer) 'table 'identity)))
2020 ;; TBLFM keyword is case insensitive.
2021 (should
2022 (org-test-with-temp-text "| a |\n#+tblfm: test"
2023 (org-element-property
2024 :tblfm
2025 (org-element-map (org-element-parse-buffer) 'table 'identity nil t))))
2026 ;; Handle multiple TBLFM lines.
2027 (should
2028 (= 2
2029 (org-test-with-temp-text "| a |\n#+TBLFM: test1\n#+TBLFM: test2"
2030 (length (org-element-property
2031 :tblfm
2032 (org-element-map
2033 (org-element-parse-buffer) 'table 'identity nil t))))))
2034 ;; Handle non-empty blank line at the end of buffer.
2035 (should
2036 (org-test-with-temp-text "| a |\n "
2037 (= (org-element-property :end (org-element-at-point)) (point-max)))))
2040 ;;;; Table Cell
2042 (ert-deftest test-org-element/table-cell-parser ()
2043 "Test `table-cell' parser."
2044 ;; Regular table cell.
2045 (should
2046 (org-test-with-temp-text "| a |"
2047 (org-element-map (org-element-parse-buffer) 'table-cell 'identity)))
2048 ;; Last vertical bar may be omitted.
2049 (should
2050 (org-test-with-temp-text "| a "
2051 (org-element-map (org-element-parse-buffer) 'table-cell 'identity))))
2054 ;;;; Table Row
2056 (ert-deftest test-org-element/table-row-parser ()
2057 "Test `table-row' parser."
2058 (should
2059 (equal '(standard rule)
2060 (org-test-with-temp-text "| a |\n|---|"
2061 (org-element-map
2062 (org-element-parse-buffer) 'table-row
2063 (lambda (row) (org-element-property :type row)))))))
2066 ;;;; Target
2068 (ert-deftest test-org-element/target-parser ()
2069 "Test `target' parser."
2070 (should
2071 (org-test-with-temp-text "<<target>>"
2072 (org-element-map (org-element-parse-buffer) 'target 'identity))))
2075 ;;;; Timestamp
2077 (ert-deftest test-org-element/timestamp ()
2078 "Test `timestamp' parser."
2079 ;; Active timestamp.
2080 (should
2081 (org-test-with-temp-text "<2012-03-29 16:40>"
2082 (eq (org-element-property :type (org-element-context)) 'active)))
2083 (should-not
2084 (org-test-with-temp-text "<2012-03-29 Thu>"
2085 (let ((timestamp (org-element-context)))
2086 (or (org-element-property :hour-start timestamp)
2087 (org-element-property :minute-start timestamp)))))
2088 (should
2089 (equal '(2012 3 29 16 40)
2090 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
2091 (let ((object (org-element-context)))
2092 (list (org-element-property :year-start object)
2093 (org-element-property :month-start object)
2094 (org-element-property :day-start object)
2095 (org-element-property :hour-start object)
2096 (org-element-property :minute-start object))))))
2097 ;; Inactive timestamp.
2098 (should
2099 (org-test-with-temp-text "[2012-03-29 Thu 16:40]"
2100 (eq (org-element-property :type (org-element-context)) 'inactive)))
2101 ;; Time range.
2102 (should
2103 (equal '(2012 3 29 16 40 7 30)
2104 (org-test-with-temp-text "<2012-03-29 Thu 7:30-16:40>"
2105 (let ((object (org-element-context)))
2106 (list (org-element-property :year-end object)
2107 (org-element-property :month-end object)
2108 (org-element-property :day-end object)
2109 (org-element-property :hour-end object)
2110 (org-element-property :minute-end object)
2111 (org-element-property :hour-start object)
2112 (org-element-property :minute-start object))))))
2113 (should
2114 (eq 'active-range
2115 (org-test-with-temp-text "<2012-03-29 Thu 7:30-16:40>"
2116 (org-element-property :type (org-element-context)))))
2117 ;; Date range.
2118 (should
2119 (org-test-with-temp-text "[2012-03-29 Thu 16:40]--[2012-03-29 Thu 16:41]"
2120 (eq (org-element-property :type (org-element-context)) 'inactive-range)))
2121 (should-not
2122 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
2123 (let ((timestamp (org-element-context)))
2124 (or (org-element-property :hour-end timestamp)
2125 (org-element-property :minute-end timestamp)))))
2126 ;; With repeater, warning delay and both.
2127 (should
2128 (eq 'catch-up
2129 (org-test-with-temp-text "<2012-03-29 Thu ++1y>"
2130 (org-element-property :repeater-type (org-element-context)))))
2131 (should
2132 (eq 'first
2133 (org-test-with-temp-text "<2012-03-29 Thu --1y>"
2134 (org-element-property :warning-type (org-element-context)))))
2135 (should
2136 (equal '(cumulate all)
2137 (org-test-with-temp-text "<2012-03-29 Thu +1y -1y>"
2138 (let ((ts (org-element-context)))
2139 (list (org-element-property :repeater-type ts)
2140 (org-element-property :warning-type ts)))))))
2143 ;;;; Underline
2145 (ert-deftest test-org-element/underline-parser ()
2146 "Test `underline' parser."
2147 ;; Regular test.
2148 (should
2149 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
2150 (org-test-with-temp-text "_underline_"
2151 (org-element-map (org-element-parse-buffer) 'underline 'identity))))
2152 ;; Multi-line markup.
2153 (should
2154 (equal
2155 (org-element-contents
2156 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
2157 (org-test-with-temp-text "_first line\nsecond line_"
2158 (org-element-map
2159 (org-element-parse-buffer) 'underline 'identity nil t))))
2160 '("first line\nsecond line"))))
2163 ;;;; Verbatim
2165 (ert-deftest test-org-element/verbatim-parser ()
2166 "Test `verbatim' parser."
2167 ;; Regular test.
2168 (should
2169 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
2170 (org-test-with-temp-text "=verbatim="
2171 (org-element-map (org-element-parse-buffer) 'verbatim 'identity))))
2172 ;; Multi-line markup.
2173 (should
2174 (equal
2175 (org-element-property
2176 :value
2177 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^ \n,\"']\\|[^ \n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^ \n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
2178 (org-test-with-temp-text "=first line\nsecond line="
2179 (org-element-map
2180 (org-element-parse-buffer) 'verbatim 'identity nil t))))
2181 "first line\nsecond line")))
2184 ;;;; Verse Block
2186 (ert-deftest test-org-element/verse-block-parser ()
2187 "Test `verse-block' parser."
2188 ;; Standard test.
2189 (should
2190 (org-test-with-temp-text "#+BEGIN_VERSE\nVerse block\n#+END_VERSE"
2191 (org-element-map (org-element-parse-buffer) 'verse-block 'identity)))
2192 ;; Ignore case.
2193 (should
2194 (org-test-with-temp-text "#+begin_verse\nVerse block\n#+end_verse"
2195 (org-element-map (org-element-parse-buffer) 'verse-block 'identity)))
2196 ;; Parse objects in verse blocks.
2197 (should
2198 (org-test-with-temp-text "#+BEGIN_VERSE\nVerse \\alpha\n#+END_VERSE"
2199 (org-element-map (org-element-parse-buffer) 'entity 'identity)))
2200 ;; Ignore incomplete verse block.
2201 (should-not
2202 (org-test-with-temp-text "#+BEGIN_VERSE"
2203 (org-element-map (org-element-parse-buffer) 'verse-block 'identity nil t)))
2204 ;; Handle non-empty blank line at the end of buffer.
2205 (should
2206 (org-test-with-temp-text "#+BEGIN_VERSE\nC\n#+END_VERSE\n "
2207 (= (org-element-property :end (org-element-at-point)) (point-max)))))
2211 ;;; Test Interpreters.
2213 (ert-deftest test-org-element/interpret-data ()
2214 "Test `org-element-interpret-data' specifications."
2215 ;; Interpret simple affiliated keywords.
2216 (should
2217 (equal
2218 (org-element-interpret-data
2219 '(org-data nil (paragraph (:name "para") "Paragraph")))
2220 "#+NAME: para\nParagraph\n"))
2221 ;; Interpret multiple affiliated keywords.
2222 (should
2223 (equal
2224 (org-element-interpret-data
2225 '(org-data nil (paragraph (:attr_ascii ("line2" "line1")) "Paragraph")))
2226 "#+ATTR_ASCII: line1\n#+ATTR_ASCII: line2\nParagraph\n"))
2227 ;; Interpret parsed affiliated keywords.
2228 (should
2229 (equal
2230 (org-element-interpret-data
2231 '(org-data nil (paragraph (:caption (("caption"))) "Paragraph")))
2232 "#+CAPTION: caption\nParagraph\n"))
2233 ;; Interpret dual affiliated keywords.
2234 (should
2235 (equal
2236 (org-element-interpret-data
2237 '(org-data nil (paragraph (:caption ((("long") "short"))) "Paragraph")))
2238 "#+CAPTION[short]: long\nParagraph\n"))
2239 ;; Interpret multiple parsed dual keywords.
2240 (should
2241 (equal
2242 (org-element-interpret-data
2243 '(org-data nil (paragraph
2244 (:caption ((("l2") "s2") (("l1") "s1"))) "Paragraph")))
2245 "#+CAPTION[s1]: l1\n#+CAPTION[s2]: l2\nParagraph\n"))
2246 ;; Pseudo objects and elements are transparent.
2247 (should
2248 (equal "A B\n"
2249 (org-element-interpret-data
2250 '(paragraph nil (pseudo-object (:post-blank 1) "A") "B")
2251 '(pseudo-object))))
2252 (should
2253 (equal "A\n\nB\n"
2254 (org-element-interpret-data
2255 '(center nil
2256 (pseudo-element (:post-blank 1) (paragraph nil "A"))
2257 (paragraph nil "B"))))))
2259 (ert-deftest test-org-element/center-block-interpreter ()
2260 "Test center block interpreter."
2261 (should
2262 (equal (org-test-parse-and-interpret "#+BEGIN_CENTER\nTest\n#+END_CENTER")
2263 "#+BEGIN_CENTER\nTest\n#+END_CENTER\n")))
2265 (ert-deftest test-org-element/drawer-interpreter ()
2266 "Test drawer interpreter."
2267 (should
2268 (equal (org-test-parse-and-interpret ":TEST:\nTest\n:END:")
2269 ":TEST:\nTest\n:END:\n")))
2271 (ert-deftest test-org-element/dynamic-block-interpreter ()
2272 "Test dynamic block interpreter."
2273 (should
2274 (equal (org-test-parse-and-interpret
2275 "#+BEGIN: myblock :parameter value1\nTest\n#+END:")
2276 "#+BEGIN: myblock :parameter value1\nTest\n#+END:\n")))
2278 (ert-deftest test-org-element/footnote-definition-interpreter ()
2279 "Test footnote definition interpreter."
2280 (should (equal (org-test-parse-and-interpret "[fn:1] Test") "[fn:1] Test\n")))
2282 (ert-deftest test-org-element/headline-interpreter ()
2283 "Test headline and section interpreters."
2284 ;; 1. Standard test.
2285 (should (equal (org-test-parse-and-interpret "* Headline") "* Headline\n"))
2286 ;; 2. With TODO keywords.
2287 (should
2288 (equal (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
2289 (org-test-parse-and-interpret "* TODO Headline"))
2290 "* TODO Headline\n"))
2291 ;; 3. With tags...
2293 ;; 3.1. ... and a positive `org-tags-column' value.
2294 (should
2295 (equal (let ((org-tags-column 20))
2296 (org-test-parse-and-interpret "* Headline :tag:"))
2297 "* Headline :tag:\n"))
2298 ;; 3.2. ... and a negative `org-tags-column' value.
2299 (should
2300 (equal (let ((org-tags-column -20))
2301 (org-test-parse-and-interpret "* Headline :tag:"))
2302 "* Headline :tag:\n"))
2303 ;; 3.3. ... and a null `org-tags-column' value.
2304 (should
2305 (equal (let ((org-tags-column 0))
2306 (org-test-parse-and-interpret "* Headline :tag:"))
2307 "* Headline :tag:\n"))
2308 ;; 4. With priority cookie.
2309 (should
2310 (equal (org-test-parse-and-interpret "* [#B] Headline")
2311 "* [#B] Headline\n"))
2312 ;; 5. With comment keyword.
2313 (should
2314 (equal (let ((org-comment-string "COMMENT"))
2315 (org-test-parse-and-interpret "* COMMENT Headline"))
2316 "* COMMENT Headline\n"))
2317 ;; 6. Keep same number of blank lines before body.
2318 (should
2319 (equal (org-test-parse-and-interpret
2320 "* Headline\n\n\nText after two blank lines.")
2321 "* Headline\n\n\nText after two blank lines.\n"))
2322 ;; 8. Preserve `org-odd-levels-only' state.
2323 (should
2324 (equal "* H\n*** H2\n"
2325 (let ((org-odd-levels-only t))
2326 (org-test-parse-and-interpret "* H\n*** H2")))))
2328 (ert-deftest test-org-element/inlinetask-interpreter ()
2329 "Test inlinetask interpretation."
2330 (when (featurep 'org-inlinetask)
2331 (let ((org-inlinetask-min-level 15))
2332 ;; 1. Regular inlinetask.
2333 (should (equal (org-test-parse-and-interpret
2334 "*************** Task\nTest\n*************** END")
2335 "*************** Task\nTest\n*************** END\n"))
2336 ;; 2. Degenerate inlinetask.
2337 (should (equal (org-test-parse-and-interpret "*************** Task")
2338 "*************** Task\n"))
2339 ;; 3. Prefer degenerate form when there are no contents.
2340 (should (equal (org-test-parse-and-interpret
2341 "*************** Task\n*************** END")
2342 "*************** Task\n"))
2343 ;; 4. With TODO keywords.
2344 (should
2345 (equal (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
2346 (org-test-parse-and-interpret "*************** TODO Task"))
2347 "*************** TODO Task\n"))
2348 ;; 5. With tags...
2350 ;; 5.1. ... and a positive `org-tags-column' value.
2351 (should
2352 (equal (let ((org-tags-column 30))
2353 (org-test-parse-and-interpret "*************** Task :tag:"))
2354 "*************** Task :tag:\n"))
2355 ;; 5.2. ... and a negative `org-tags-column' value.
2356 (should
2357 (equal (let ((org-tags-column -30))
2358 (org-test-parse-and-interpret "*************** Task :tag:"))
2359 "*************** Task :tag:\n"))
2360 ;; 5.3. ... and a null `org-tags-column' value.
2361 (should
2362 (equal (let ((org-tags-column 0))
2363 (org-test-parse-and-interpret "*************** Task :tag:"))
2364 "*************** Task :tag:\n"))
2365 ;; 6. With priority cookie.
2366 (should
2367 (equal (org-test-parse-and-interpret "*************** [#B] Task")
2368 "*************** [#B] Task\n")))))
2370 (ert-deftest test-org-element/plain-list-interpreter ()
2371 "Test plain-list and item interpreters."
2372 (let ((org-list-two-spaces-after-bullet-regexp nil))
2373 ;; Unordered list.
2374 (should (equal (org-test-parse-and-interpret "- item 1") "- item 1\n"))
2375 ;; Description list.
2376 (should
2377 (equal (org-test-parse-and-interpret "- tag :: desc") "- tag :: desc\n"))
2378 ;; Ordered list.
2379 (should
2380 (equal (let ((org-plain-list-ordered-item-terminator t))
2381 (org-test-parse-and-interpret "1. Item"))
2382 "1. Item\n"))
2383 (should
2384 (equal (let ((org-plain-list-ordered-item-terminator ?\)))
2385 (org-test-parse-and-interpret "1) Item"))
2386 "1) Item\n"))
2387 ;; Ordered list with counter.
2388 (should
2389 (equal (let ((org-plain-list-ordered-item-terminator t))
2390 (org-test-parse-and-interpret "1. [@5] Item"))
2391 "5. [@5] Item\n"))
2392 ;; List with check-boxes.
2393 (should
2394 (equal (org-test-parse-and-interpret
2395 "- [-] Item 1\n - [X] Item 2\n - [ ] Item 3")
2396 "- [-] Item 1\n - [X] Item 2\n - [ ] Item 3\n"))
2397 ;; Item not starting with a paragraph.
2398 (should
2399 (equal (org-test-parse-and-interpret "-\n | a | b |")
2400 "- \n | a | b |\n"))
2401 ;; Special case: correctly handle "*" bullets.
2402 (should (org-test-parse-and-interpret " * item"))
2403 ;; Special case: correctly handle empty items.
2404 (should (org-test-parse-and-interpret "-"))))
2406 (ert-deftest test-org-element/quote-block-interpreter ()
2407 "Test quote block interpreter."
2408 (should (equal (org-test-parse-and-interpret
2409 "#+BEGIN_QUOTE\nTest\n#+END_QUOTE")
2410 "#+BEGIN_QUOTE\nTest\n#+END_QUOTE\n")))
2412 (ert-deftest test-org-element/special-block-interpreter ()
2413 "Test special block interpreter."
2414 (should (equal (org-test-parse-and-interpret
2415 "#+BEGIN_SPECIAL\nTest\n#+END_SPECIAL")
2416 "#+BEGIN_SPECIAL\nTest\n#+END_SPECIAL\n")))
2418 (ert-deftest test-org-element/babel-call-interpreter ()
2419 "Test babel call interpreter."
2420 ;; 1. Without argument.
2421 (should (equal (org-test-parse-and-interpret "#+CALL: test()")
2422 "#+CALL: test()\n"))
2423 ;; 2. With argument.
2424 (should (equal (org-test-parse-and-interpret "#+CALL: test(x=2)")
2425 "#+CALL: test(x=2)\n"))
2426 ;; 3. With header arguments.
2427 (should (equal (org-test-parse-and-interpret
2428 "#+CALL: test[:results output]()[:results html]")
2429 "#+CALL: test[:results output]()[:results html]\n")))
2431 (ert-deftest test-org-element/clock-interpreter ()
2432 "Test clock interpreter."
2433 ;; Running clock.
2434 (should
2435 (string-match
2436 "CLOCK: \\[2012-01-01 .* 00:01\\]"
2437 (org-test-parse-and-interpret "CLOCK: [2012-01-01 sun. 00:01]")))
2438 ;; Closed clock.
2439 (should
2440 (string-match
2441 "CLOCK: \\[2012-01-01 .* 00:01\\]--\\[2012-01-01 .* 00:02\\] => 0:01"
2442 (org-test-parse-and-interpret "
2443 CLOCK: [2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02] => 0:01"))))
2445 (ert-deftest test-org-element/comment-interpreter ()
2446 "Test comment interpreter."
2447 ;; Regular comment.
2448 (should (equal (org-test-parse-and-interpret "# Comment") "# Comment\n"))
2449 ;; Inline comment.
2450 (should (equal (org-test-parse-and-interpret " # Comment")
2451 "# Comment\n"))
2452 ;; Preserve indentation.
2453 (should (equal (org-test-parse-and-interpret " # No blank\n# One blank")
2454 "# No blank\n# One blank\n")))
2456 (ert-deftest test-org-element/comment-block-interpreter ()
2457 "Test comment block interpreter."
2458 (should (equal (org-test-parse-and-interpret
2459 "#+BEGIN_COMMENT\nTest\n#+END_COMMENT")
2460 "#+BEGIN_COMMENT\nTest\n#+END_COMMENT\n"))
2461 ;; Accept missing final newline in value.
2462 (should
2463 (equal
2464 "#+BEGIN_COMMENT\nTest\n#+END_COMMENT\n"
2465 (org-element-interpret-data '(comment-block (:value "Test"))))))
2467 (ert-deftest test-org-element/diary-sexp ()
2468 "Test diary-sexp interpreter."
2469 (should
2470 (equal
2471 (org-test-parse-and-interpret
2472 "%%(org-anniversary 1956 5 14)(2) Arthur Dent is %d years old")
2473 "%%(org-anniversary 1956 5 14)(2) Arthur Dent is %d years old\n")))
2475 (ert-deftest test-org-element/example-block-interpreter ()
2476 "Test example block interpreter."
2477 ;; Without switches.
2478 (should (equal (org-test-parse-and-interpret
2479 "#+BEGIN_EXAMPLE\nTest\n#+END_EXAMPLE")
2480 "#+BEGIN_EXAMPLE\nTest\n#+END_EXAMPLE\n"))
2481 ;; With switches.
2482 (should
2483 (equal (org-test-parse-and-interpret
2484 "#+BEGIN_EXAMPLE -n -k\n(+ 1 1)\n#+END_EXAMPLE")
2485 "#+BEGIN_EXAMPLE -n -k\n(+ 1 1)\n#+END_EXAMPLE\n"))
2486 ;; Preserve code escaping.
2487 (should
2488 (equal (org-test-parse-and-interpret
2489 "#+BEGIN_EXAMPLE\n,* Headline\n ,#+keyword\nText #+END_EXAMPLE")
2490 "#+BEGIN_EXAMPLE\n,* Headline\n ,#+keyword\nText #+END_EXAMPLE\n"))
2491 ;; Accept missing final newline in value.
2492 (should
2493 (equal
2494 "#+BEGIN_EXAMPLE\nTest\n#+END_EXAMPLE\n"
2495 (org-element-interpret-data '(example-block (:value "Test"))))))
2497 (ert-deftest test-org-element/export-block-interpreter ()
2498 "Test export block interpreter."
2499 (should (equal (org-test-parse-and-interpret
2500 "#+BEGIN_HTML\nTest\n#+END_HTML")
2501 "#+BEGIN_HTML\nTest\n#+END_HTML\n")))
2503 (ert-deftest test-org-element/fixed-width-interpreter ()
2504 "Test fixed width interpreter."
2505 ;; Standard test.
2506 (should (equal (org-test-parse-and-interpret ": Test") ": Test\n"))
2507 ;; Preserve indentation.
2508 (should (equal (org-test-parse-and-interpret ": 2 blanks\n: 1 blank")
2509 ": 2 blanks\n: 1 blank\n"))
2510 ;; Remove last newline character
2511 (should
2512 (equal (org-element-fixed-width-interpreter
2513 '(fixed-width (:value "Test\n")) nil)
2514 ": Test"))
2515 (should
2516 (equal (org-element-fixed-width-interpreter
2517 '(fixed-width (:value "Test")) nil)
2518 ": Test"))
2519 ;; Handle empty string.
2520 (should
2521 (equal (org-element-fixed-width-interpreter
2522 '(fixed-width (:value "")) nil)
2523 ""))
2524 ;; Handle nil value.
2525 (should-not
2526 (org-element-fixed-width-interpreter
2527 '(fixed-width (:value nil)) nil)))
2529 (ert-deftest test-org-element/horizontal-rule-interpreter ()
2530 "Test horizontal rule interpreter."
2531 (should (equal (org-test-parse-and-interpret "-------") "-----\n")))
2533 (ert-deftest test-org-element/keyword-interpreter ()
2534 "Test keyword interpreter."
2535 (should (equal (org-test-parse-and-interpret "#+KEYWORD: value")
2536 "#+KEYWORD: value\n")))
2538 (ert-deftest test-org-element/latex-environment-interpreter ()
2539 "Test latex environment interpreter."
2540 (should (equal (org-test-parse-and-interpret
2541 "\\begin{equation}\n1+1=2\n\\end{equation}")
2542 "\\begin{equation}\n1+1=2\n\\end{equation}\n"))
2543 (should (equal (org-test-parse-and-interpret
2544 "\\begin{theorem}[me]\n1+1=2\n\\end{theorem}")
2545 "\\begin{theorem}[me]\n1+1=2\n\\end{theorem}\n")))
2547 (ert-deftest test-org-element/planning-interpreter ()
2548 "Test planning interpreter."
2549 (should
2550 (string-match
2551 "\\* Headline
2552 DEADLINE: <2012-03-29 .*?> SCHEDULED: <2012-03-29 .*?> CLOSED: \\[2012-03-29 .*?\\]"
2553 (org-test-parse-and-interpret
2554 "* Headline
2555 DEADLINE: <2012-03-29 thu.> SCHEDULED: <2012-03-29 thu.> CLOSED: [2012-03-29 thu.]"))))
2557 (ert-deftest test-org-element/property-drawer-interpreter ()
2558 "Test property drawer interpreter."
2559 (should (equal (let ((org-property-format "%-10s %s"))
2560 (org-test-parse-and-interpret
2561 "* H\n:PROPERTIES:\n:prop: value\n:END:"))
2562 "* H\n:PROPERTIES:\n:prop: value\n:END:\n")))
2564 (ert-deftest test-org-element/src-block-interpreter ()
2565 "Test src block interpreter."
2566 ;; With arguments.
2567 (should
2568 (equal (let ((org-edit-src-content-indentation 2))
2569 (org-test-parse-and-interpret
2570 "#+BEGIN_SRC emacs-lisp :results silent\n(+ 1 1)\n#+END_SRC"))
2571 "#+BEGIN_SRC emacs-lisp :results silent\n (+ 1 1)\n#+END_SRC\n"))
2572 ;; With switches.
2573 (should
2574 (equal (let ((org-edit-src-content-indentation 2))
2575 (org-test-parse-and-interpret
2576 "#+BEGIN_SRC emacs-lisp -n -k\n(+ 1 1)\n#+END_SRC"))
2577 "#+BEGIN_SRC emacs-lisp -n -k\n (+ 1 1)\n#+END_SRC\n"))
2578 ;; Preserve code escaping.
2579 (should
2580 (equal (let ((org-edit-src-content-indentation 2))
2581 (org-test-parse-and-interpret
2582 "#+BEGIN_SRC org\n,* Headline\n ,#+keyword\nText #+END_SRC"))
2583 "#+BEGIN_SRC org\n,* Headline\n ,#+keyword\nText #+END_SRC\n"))
2584 ;; Do not apply `org-edit-src-content-indentation' when preserving
2585 ;; indentation.
2586 (should
2587 (equal (let ((org-edit-src-content-indentation 2)
2588 (org-src-preserve-indentation t))
2589 (org-test-parse-and-interpret
2590 "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"))
2591 "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC\n"))
2592 (should
2593 (equal (let ((org-edit-src-content-indentation 2)
2594 (org-src-preserve-indentation nil))
2595 (org-test-parse-and-interpret
2596 "#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"))
2597 "#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC\n"))
2598 ;; Accept missing final newline in value.
2599 (should
2600 (equal
2601 "#+BEGIN_SRC emacs-lisp\n Test\n#+END_SRC\n"
2602 (let ((org-edit-src-content-indentation 2))
2603 (org-element-interpret-data
2604 '(src-block (:language "emacs-lisp" :value "Test")))))))
2606 (ert-deftest test-org-element/table-interpreter ()
2607 "Test table, table-row and table-cell interpreters."
2608 ;; 1. Simple table.
2609 (should (equal (org-test-parse-and-interpret "| a | b |\n| c | d |")
2610 "| a | b |\n| c | d |\n"))
2611 ;; 2. With horizontal rules.
2612 (should (equal (org-test-parse-and-interpret
2613 "| a | b |\n|---+---|\n| c | d |")
2614 "| a | b |\n|---+---|\n| c | d |\n"))
2615 ;; 3. With meta-data.
2616 (should (equal (org-test-parse-and-interpret "| / | < | > |\n| * | 1 | 2 |")
2617 "| / | < | > |\n| * | 1 | 2 |\n"))
2618 ;; 4. With a formula.
2619 (should
2620 (equal (org-test-parse-and-interpret
2621 "| 2 |\n| 4 |\n| 3 |\n#+TBLFM: @3=vmean(@1..@2)")
2622 "| 2 |\n| 4 |\n| 3 |\n#+TBLFM: @3=vmean(@1..@2)\n"))
2623 ;; 5. With multiple formulas.
2624 (should
2625 (equal (org-test-parse-and-interpret
2626 "| 2 |\n| 4 |\n| 3 |\n#+TBLFM: test1\n#+TBLFM: test2")
2627 "| 2 |\n| 4 |\n| 3 |\n#+TBLFM: test1\n#+TBLFM: test2\n")))
2629 (ert-deftest test-org-element/timestamp-interpreter ()
2630 "Test timestamp interpreter."
2631 ;; Active.
2632 (should
2633 (string-match "<2012-03-29 .* 16:40>"
2634 (org-test-parse-and-interpret "<2012-03-29 thu. 16:40>")))
2635 (should
2636 (string-match "<2012-03-29 .* 16:40>"
2637 (org-element-timestamp-interpreter
2638 '(timestamp
2639 (:type active :year-start 2012 :month-start 3 :day-start 29
2640 :hour-start 16 :minute-start 40)) nil)))
2641 ;; Inactive.
2642 (should
2643 (string-match "\\[2012-03-29 .* 16:40\\]"
2644 (org-test-parse-and-interpret "[2012-03-29 thu. 16:40]")))
2645 (should
2646 (string-match
2647 "\\[2012-03-29 .* 16:40\\]"
2648 (org-element-timestamp-interpreter
2649 '(timestamp
2650 (:type inactive :year-start 2012 :month-start 3 :day-start 29
2651 :hour-start 16 :minute-start 40)) nil)))
2652 ;; Active range.
2653 (should
2654 (string-match "<2012-03-29 .* 16:40>--<2012-03-29 .* 16:41>"
2655 (org-test-parse-and-interpret
2656 "<2012-03-29 thu. 16:40>--<2012-03-29 thu. 16:41>")))
2657 (should
2658 (string-match
2659 "<2012-03-29 .* 16:40>--<2012-03-29 .* 16:41>"
2660 (org-element-timestamp-interpreter
2661 '(timestamp
2662 (:type active-range :year-start 2012 :month-start 3 :day-start 29
2663 :hour-start 16 :minute-start 40 :year-end 2012 :month-end 3
2664 :day-end 29 :hour-end 16 :minute-end 41)) nil)))
2665 ;; Inactive range.
2666 (should
2667 (string-match "\\[2012-03-29 .* 16:40\\]--\\[2012-03-29 .* 16:41\\]"
2668 (org-test-parse-and-interpret
2669 "[2012-03-29 thu. 16:40]--[2012-03-29 thu. 16:41]")))
2670 (should
2671 (string-match
2672 "\\[2012-03-29 .* 16:40\\]--\\[2012-03-29 .* 16:41\\]"
2673 (org-element-timestamp-interpreter
2674 '(timestamp
2675 (:type inactive-range :year-start 2012 :month-start 3 :day-start 29
2676 :hour-start 16 :minute-start 40 :year-end 2012 :month-end 3
2677 :day-end 29 :hour-end 16 :minute-end 41)) nil)))
2678 ;; Diary.
2679 (should (equal (org-test-parse-and-interpret "<%%diary-float t 4 2>")
2680 "<%%diary-float t 4 2>\n"))
2681 ;; Timestamp with repeater interval, with delay, with both.
2682 (should
2683 (string-match "<2012-03-29 .* \\+1y>"
2684 (org-test-parse-and-interpret "<2012-03-29 thu. +1y>")))
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 :repeater-type cumulate :repeater-value 1 :repeater-unit year))
2692 nil)))
2693 (should
2694 (string-match
2695 "<2012-03-29 .* -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 nil)))
2701 (should
2702 (string-match
2703 "<2012-03-29 .* \\+1y -1y>"
2704 (org-element-timestamp-interpreter
2705 '(timestamp
2706 (:type active :year-start 2012 :month-start 3 :day-start 29
2707 :warning-type all :warning-value 1 :warning-unit year
2708 :repeater-type cumulate :repeater-value 1 :repeater-unit year))
2709 nil)))
2710 ;; Timestamp range with repeater interval
2711 (should
2712 (string-match "<2012-03-29 .* \\+1y>--<2012-03-30 .* \\+1y>"
2713 (org-test-parse-and-interpret
2714 "<2012-03-29 Thu +1y>--<2012-03-30 Thu +1y>")))
2715 (should
2716 (string-match
2717 "<2012-03-29 .* \\+1y>--<2012-03-30 .* \\+1y>"
2718 (org-element-timestamp-interpreter
2719 '(timestamp
2720 (:type active-range :year-start 2012 :month-start 3 :day-start 29
2721 :year-end 2012 :month-end 3 :day-end 30 :repeater-type cumulate
2722 :repeater-value 1 :repeater-unit year))
2723 nil))))
2725 (ert-deftest test-org-element/verse-block-interpreter ()
2726 "Test verse block interpretation."
2727 (should
2728 (equal (org-test-parse-and-interpret "#+BEGIN_VERSE\nTest\n#+END_VERSE")
2729 "#+BEGIN_VERSE\nTest\n#+END_VERSE\n")))
2731 (ert-deftest test-org-element/bold-interpreter ()
2732 "Test bold interpreter."
2733 (should (equal (org-test-parse-and-interpret "*text*") "*text*\n")))
2735 (ert-deftest test-org-element/code-interpreter ()
2736 "Test code interpreter."
2737 (should (equal (org-test-parse-and-interpret "~text~") "~text~\n")))
2739 (ert-deftest test-org-element/entity-interpreter ()
2740 "Test entity interpreter."
2741 ;; 1. Without brackets.
2742 (should
2743 (equal (org-test-parse-and-interpret "\\alpha text") "\\alpha text\n"))
2744 ;; 2. With brackets.
2745 (should
2746 (equal (org-test-parse-and-interpret "\\alpha{}text") "\\alpha{}text\n")))
2748 (ert-deftest test-org-element/export-snippet-interpreter ()
2749 "Test export snippet interpreter."
2750 (should (equal (org-test-parse-and-interpret "@@back-end:contents@@")
2751 "@@back-end:contents@@\n")))
2753 (ert-deftest test-org-element/footnote-reference-interpreter ()
2754 "Test footnote reference interpreter."
2755 ;; 1. Regular reference.
2756 (should (equal (org-test-parse-and-interpret "Text[fn:1]") "Text[fn:1]\n"))
2757 ;; 2. Normalized reference.
2758 (should (equal (org-test-parse-and-interpret "Text[1]") "Text[1]\n"))
2759 ;; 3. Named reference.
2760 (should (equal (org-test-parse-and-interpret "Text[fn:label]")
2761 "Text[fn:label]\n"))
2762 ;; 4. Inline reference.
2763 (should (equal (org-test-parse-and-interpret "Text[fn:label:def]")
2764 "Text[fn:label:def]\n"))
2765 ;; 5. Anonymous reference.
2766 (should (equal (org-test-parse-and-interpret "Text[fn::def]")
2767 "Text[fn::def]\n")))
2769 (ert-deftest test-org-element/inline-babel-call-interpreter ()
2770 "Test inline babel call interpreter."
2771 ;; 1. Without arguments.
2772 (should (equal (org-test-parse-and-interpret "call_test()") "call_test()\n"))
2773 ;; 2. With arguments.
2774 (should (equal (org-test-parse-and-interpret "call_test(x=2)")
2775 "call_test(x=2)\n"))
2776 ;; 3. With header arguments.
2777 (should (equal (org-test-parse-and-interpret
2778 "call_test[:results output]()[:results html]")
2779 "call_test[:results output]()[:results html]\n")))
2781 (ert-deftest test-org-element/inline-src-block-interpreter ()
2782 "Test inline src block interpreter."
2783 ;; 1. Without header argument.
2784 (should (equal (org-test-parse-and-interpret "src_emacs-lisp{(+ 1 1)}")
2785 "src_emacs-lisp{(+ 1 1)}\n"))
2786 ;; 2. With header arguments.
2787 (should (equal (org-test-parse-and-interpret
2788 "src_emacs-lisp[:results silent]{(+ 1 1)}")
2789 "src_emacs-lisp[:results silent]{(+ 1 1)}\n")))
2791 (ert-deftest test-org-element/italic-interpreter ()
2792 "Test italic interpreter."
2793 (should (equal (org-test-parse-and-interpret "/text/") "/text/\n")))
2795 (ert-deftest test-org-element/latex-fragment-interpreter ()
2796 "Test latex fragment interpreter."
2797 (should (equal (org-test-parse-and-interpret "\\command{}") "\\command{}\n"))
2798 (should (equal (org-test-parse-and-interpret "$x$") "$x$\n"))
2799 (should (equal (org-test-parse-and-interpret "$x+y$") "$x+y$\n"))
2800 (should (equal (org-test-parse-and-interpret "$$x+y$$") "$$x+y$$\n"))
2801 (should (equal (org-test-parse-and-interpret "\\(x+y\\)") "\\(x+y\\)\n"))
2802 (should (equal (org-test-parse-and-interpret "\\[x+y\\]") "\\[x+y\\]\n")))
2804 (ert-deftest test-org-element/line-break-interpreter ()
2805 "Test line break interpreter."
2806 (should (equal (org-test-parse-and-interpret "First line \\\\ \nSecond line")
2807 "First line \\\\\nSecond line\n")))
2809 (ert-deftest test-org-element/link-interpreter ()
2810 "Test link interpreter."
2811 ;; 1. Links targeted from a radio target.
2812 (should (equal (let ((org-target-link-regexp "radio-target"))
2813 (org-test-parse-and-interpret "a radio-target"))
2814 "a radio-target\n"))
2815 ;; 2. Regular links.
2817 ;; 2.1. Without description.
2818 (should (equal (org-test-parse-and-interpret "[[http://orgmode.org]]")
2819 "[[http://orgmode.org]]\n"))
2820 ;; 2.2. With a description.
2821 (should (equal (org-test-parse-and-interpret
2822 "[[http://orgmode.org][Org mode]]")
2823 "[[http://orgmode.org][Org mode]]\n"))
2824 ;; 2.3. Id links.
2825 (should (equal (org-test-parse-and-interpret "[[id:aaaa]]") "[[id:aaaa]]\n"))
2826 ;; 2.4. Custom-id links.
2827 (should (equal (org-test-parse-and-interpret "[[#id]]") "[[#id]]\n"))
2828 ;; 2.5 Code-ref links.
2829 (should (equal (org-test-parse-and-interpret "[[(ref)]]") "[[(ref)]]\n"))
2830 ;; 3. Normalize plain links.
2831 (should (equal (org-test-parse-and-interpret "http://orgmode.org")
2832 "[[http://orgmode.org]]\n"))
2833 ;; 4. Normalize angular links.
2834 (should (equal (org-test-parse-and-interpret "<http://orgmode.org>")
2835 "[[http://orgmode.org]]\n")))
2837 (ert-deftest test-org-element/macro-interpreter ()
2838 "Test macro interpreter."
2839 ;; 1. Without argument.
2840 (should (equal (org-test-parse-and-interpret "{{{test}}}") "{{{test}}}\n"))
2841 ;; 2. With arguments.
2842 (should (equal (org-test-parse-and-interpret "{{{test(arg1,arg2)}}}")
2843 "{{{test(arg1,arg2)}}}\n")))
2845 (ert-deftest test-org-element/radio-target-interpreter ()
2846 "Test radio target interpreter."
2847 (should (equal (org-test-parse-and-interpret "<<<some text>>>")
2848 "<<<some text>>>\n")))
2850 (ert-deftest test-org-element/statistics-cookie-interpreter ()
2851 "Test statistics cookie interpreter."
2852 ;; 1. Without percent
2853 (should (equal (org-test-parse-and-interpret "[0/1]") "[0/1]\n"))
2854 ;; 2. With percent.
2855 (should (equal (org-test-parse-and-interpret "[66%]") "[66%]\n")))
2857 (ert-deftest test-org-element/strike-through-interpreter ()
2858 "Test strike through interpreter."
2859 (should (equal (org-test-parse-and-interpret "+target+") "+target+\n")))
2861 (ert-deftest test-org-element/subscript-interpreter ()
2862 "Test subscript interpreter."
2863 ;; 1. Without brackets.
2864 (should (equal (org-test-parse-and-interpret "a_b") "a_b\n"))
2865 ;; 2. With brackets.
2866 (should (equal (org-test-parse-and-interpret "a_{b}") "a_{b}\n")))
2868 (ert-deftest test-org-element/superscript-interpreter ()
2869 "Test superscript interpreter."
2870 ;; 1. Without brackets.
2871 (should (equal (org-test-parse-and-interpret "a^b") "a^b\n"))
2872 ;; 2. With brackets.
2873 (should (equal (org-test-parse-and-interpret "a^{b}") "a^{b}\n")))
2875 (ert-deftest test-org-element/target-interpreter ()
2876 "Test target interpreter."
2877 (should (equal (org-test-parse-and-interpret "<<target>>") "<<target>>\n")))
2879 (ert-deftest test-org-element/underline-interpreter ()
2880 "Test underline interpreter."
2881 (should (equal (org-test-parse-and-interpret "_text_") "_text_\n")))
2883 (ert-deftest test-org-element/verbatim-interpreter ()
2884 "Test verbatim interpreter."
2885 (should (equal (org-test-parse-and-interpret "=text=") "=text=\n")))
2889 ;;; Test Granularity
2891 (ert-deftest test-org-element/granularity ()
2892 "Test granularity impact on buffer parsing."
2893 (org-test-with-temp-text "
2894 * Head 1
2895 ** Head 2
2896 #+BEGIN_CENTER
2897 Centered paragraph.
2898 #+END_CENTER
2899 Paragraph \\alpha."
2900 ;; 1.1. Granularity set to `headline' should parse every headline
2901 ;; in buffer, and only them.
2902 (let ((tree (org-element-parse-buffer 'headline)))
2903 (should (= 2 (length (org-element-map tree 'headline 'identity))))
2904 (should-not (org-element-map tree 'paragraph 'identity)))
2905 ;; 1.2. Granularity set to `greater-element' should not enter
2906 ;; greater elements excepted headlines and sections.
2907 (let ((tree (org-element-parse-buffer 'greater-element)))
2908 (should (= 1 (length (org-element-map tree 'center-block 'identity))))
2909 (should (= 1 (length (org-element-map tree 'paragraph 'identity))))
2910 (should-not (org-element-map tree 'entity 'identity)))
2911 ;; 1.3. Granularity set to `element' should enter every
2912 ;; greater-element.
2913 (let ((tree (org-element-parse-buffer 'element)))
2914 (should (= 2 (length (org-element-map tree 'paragraph 'identity))))
2915 (should-not (org-element-map tree 'entity 'identity)))
2916 ;; 1.4. Granularity set to `object' can see everything.
2917 (let ((tree (org-element-parse-buffer 'object)))
2918 (should (= 1 (length (org-element-map tree 'entity 'identity)))))))
2920 (ert-deftest test-org-element/secondary-string-parsing ()
2921 "Test if granularity correctly toggles secondary strings parsing."
2922 ;; With a granularity bigger than `object', no secondary string
2923 ;; should be parsed.
2924 (should
2925 (stringp
2926 (org-test-with-temp-text "* Headline"
2927 (let ((headline
2928 (org-element-map (org-element-parse-buffer 'headline) 'headline
2929 #'identity nil 'first-match)))
2930 (org-element-property :title headline)))))
2931 (should
2932 (stringp
2933 (org-test-with-temp-text "* Headline\n- tag :: item"
2934 (let ((item (org-element-map (org-element-parse-buffer 'element) 'item
2935 #'identity nil 'first-match)))
2936 (org-element-property :tag item)))))
2937 (when (featurep 'org-inlinetask)
2938 (should
2939 (stringp
2940 (let ((org-inlinetask-min-level 15))
2941 (org-test-with-temp-text "*************** Inlinetask"
2942 (let ((inlinetask (org-element-map (org-element-parse-buffer 'element)
2943 'inlinetask
2944 #'identity nil 'first-match)))
2945 (org-element-property :title inlinetask)))))))
2946 ;; With a default granularity, secondary strings should be parsed.
2947 (should
2948 (listp
2949 (org-test-with-temp-text "* Headline"
2950 (let ((headline
2951 (org-element-map (org-element-parse-buffer) 'headline
2952 #'identity nil 'first-match)))
2953 (org-element-property :title headline)))))
2954 ;; `org-element-at-point' should never parse a secondary string.
2955 (should-not
2956 (listp
2957 (org-test-with-temp-text "* Headline"
2958 (org-element-property :title (org-element-at-point)))))
2959 ;; Preserve current local variables when parsing a secondary string.
2960 (should
2961 (let ((org-entities nil)
2962 (org-entities-user nil))
2963 (org-test-with-temp-text "
2964 #+CAPTION: \\foo
2965 Text
2966 # Local Variables:
2967 # org-entities-user: ((\"foo\"))
2968 # End:"
2969 (let ((safe-local-variable-values '((org-entities-user . (("foo"))))))
2970 (hack-local-variables))
2971 (org-element-map (org-element-parse-buffer) 'entity
2972 #'identity nil nil nil t)))))
2976 ;;; Test Visible Only Parsing
2978 (ert-deftest test-org-element/parse-buffer-visible ()
2979 "Test `org-element-parse-buffer' with visible only argument."
2980 (should
2981 (equal '("H1" "H3" "H5")
2982 (org-test-with-temp-text
2983 "* H1\n** H2\n** H3 :visible:\n** H4\n** H5 :visible:"
2984 (org-occur ":visible:")
2985 (org-element-map (org-element-parse-buffer nil t) 'headline
2986 (lambda (hl) (org-element-property :raw-value hl)))))))
2990 ;;; Test `:parent' Property
2992 (ert-deftest test-org-element/parent-property ()
2993 "Test `:parent' property."
2994 ;; Elements.
2995 (org-test-with-temp-text "#+BEGIN_CENTER\nText\n#+END_CENTER"
2996 (let* ((tree (org-element-parse-buffer))
2997 (parent (org-element-property
2998 :parent
2999 (org-element-map tree 'paragraph 'identity nil t))))
3000 (should parent)
3001 (should (eq (org-element-map tree 'center-block 'identity nil t)
3002 parent))))
3003 ;; Objects.
3004 (org-test-with-temp-text "a_{/b/}"
3005 (let* ((tree (org-element-parse-buffer))
3006 (parent (org-element-property
3007 :parent
3008 (org-element-map tree 'italic 'identity nil t))))
3009 (should parent)
3010 (should (eq parent
3011 (org-element-map tree 'subscript 'identity nil t)))))
3012 ;; Secondary strings
3013 (org-test-with-temp-text "* /italic/"
3014 (let* ((tree (org-element-parse-buffer))
3015 (parent (org-element-property
3016 :parent (org-element-map tree 'italic 'identity nil t))))
3017 (should parent)
3018 (should (eq parent
3019 (org-element-map tree 'headline 'identity nil t))))))
3023 ;;; Test Normalize Contents
3025 (ert-deftest test-org-element/normalize-contents ()
3026 "Test `org-element-normalize-contents' specifications."
3027 ;; Remove maximum common indentation from element's contents.
3028 (should
3029 (equal
3030 (org-element-normalize-contents
3031 '(paragraph nil " Two spaces\n Three spaces"))
3032 '(paragraph nil "Two spaces\n Three spaces")))
3033 ;; Ignore objects within contents when computing maximum common
3034 ;; indentation.
3035 (should
3036 (equal
3037 (org-element-normalize-contents
3038 '(paragraph nil " One " (emphasis nil "space") "\n Two spaces"))
3039 '(paragraph nil "One " (emphasis nil "space") "\n Two spaces")))
3040 ;; Ignore blank lines.
3041 (should
3042 (equal
3043 (org-element-normalize-contents
3044 '(paragraph nil " Two spaces\n\n \n Two spaces"))
3045 '(paragraph nil "Two spaces\n\n \nTwo spaces")))
3046 (should
3047 (equal
3048 '(paragraph nil " Two spaces\n" (verbatim nil "V") "\n Two spaces")
3049 (org-element-normalize-contents
3050 '(paragraph nil " Two spaces\n " (verbatim nil "V") "\n Two spaces"))))
3051 (should
3052 (equal
3053 '(verse-block nil "line 1\n\nline 2")
3054 (org-element-normalize-contents
3055 '(verse-block nil " line 1\n\n line 2"))))
3056 ;; Recursively enter objects in order to compute common indentation.
3057 (should
3058 (equal
3059 (org-element-normalize-contents
3060 '(paragraph nil " Two spaces " (bold nil " and\n One space")))
3061 '(paragraph nil " Two spaces " (bold nil " and\nOne space"))))
3062 ;; When optional argument is provided, ignore first line
3063 ;; indentation.
3064 (should
3065 (equal
3066 (org-element-normalize-contents
3067 '(paragraph nil "No space\n Two spaces\n Three spaces") t)
3068 '(paragraph nil "No space\nTwo spaces\n Three spaces"))))
3072 ;;; Test Navigation Tools.
3074 (ert-deftest test-org-element/at-point ()
3075 "Test `org-element-at-point' specifications."
3076 ;; Return closest element containing point.
3077 (should
3078 (eq 'paragraph
3079 (org-test-with-temp-text "#+BEGIN_CENTER\nA\n#+END_CENTER"
3080 (progn (search-forward "A")
3081 (org-element-type (org-element-at-point))))))
3082 ;; Correctly set `:parent' property.
3083 (should
3084 (eq 'center-block
3085 (org-test-with-temp-text "#+BEGIN_CENTER\nA\n#+END_CENTER"
3086 (progn (search-forward "A")
3087 (org-element-type
3088 (org-element-property :parent (org-element-at-point)))))))
3089 ;; Special case: at a blank line just below a headline, return that
3090 ;; headline.
3091 (should
3092 (equal "H1" (org-test-with-temp-text "* H1\n \n* H2\n"
3093 (forward-line)
3094 (org-element-property :title (org-element-at-point)))))
3095 ;; Special case: at the very beginning of a table, return `table'
3096 ;; object instead of `table-row'.
3097 (should
3098 (eq 'table
3099 (org-test-with-temp-text "| a | b |"
3100 (org-element-type (org-element-at-point)))))
3101 ;; Special case: at the very beginning of a list or sub-list, return
3102 ;; `plain-list' object instead of `item'.
3103 (should
3104 (eq 'plain-list
3105 (org-test-with-temp-text "- item"
3106 (org-element-type (org-element-at-point)))))
3107 ;; Special case: at the closing line of a greater element, be sure
3108 ;; to return it instead of the last element in its contents.
3109 (should
3110 (eq 'center-block
3111 (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph\n#+END_CENTER"
3112 (progn (forward-line 2)
3113 (org-element-type (org-element-at-point))))))
3114 ;; Special case: at a blank line between two items, be sure to
3115 ;; return item above instead of the last element of its contents.
3116 (should
3117 (eq 'item
3118 (org-test-with-temp-text "- Para1\n\n- Para2"
3119 (progn (forward-line)
3120 (org-element-type
3121 (let ((org-list-empty-line-terminates-plain-lists nil))
3122 (org-element-at-point)))))))
3123 ;; Special case: at the last blank line in a plain list, return it
3124 ;; instead of the last item.
3125 (should
3126 (eq 'plain-list
3127 (org-test-with-temp-text "- Para1\n- Para2\n\nPara3"
3128 (progn (forward-line 2)
3129 (org-element-type (org-element-at-point))))))
3130 ;; Special case: when a list ends at the end of buffer and there's
3131 ;; no final newline, return last element in last item.
3132 (should
3133 (eq 'paragraph
3134 (org-test-with-temp-text "- a"
3135 (end-of-line)
3136 (org-element-type (org-element-at-point)))))
3137 ;; Parse a list within a block itself contained in a list.
3138 (should
3139 (eq 'plain-list
3140 (org-test-with-temp-text
3141 "- outer\n #+begin_center\n - inner\n #+end_center"
3142 (search-forward "inner")
3143 (beginning-of-line)
3144 (org-element-type (org-element-at-point)))))
3145 ;; Do not error at eob on an empty line.
3146 (should
3147 (org-test-with-temp-text "* H\n"
3148 (forward-line)
3149 (or (org-element-at-point) t))))
3151 (ert-deftest test-org-element/context ()
3152 "Test `org-element-context' specifications."
3153 ;; Return closest object containing point.
3154 (should
3155 (eq 'underline
3156 (org-test-with-temp-text "Some *text with _underline_ text*"
3157 (progn (search-forward "under")
3158 (org-element-type (org-element-context))))))
3159 ;; Find objects in secondary strings.
3160 (should
3161 (eq 'underline
3162 (org-test-with-temp-text "* Headline _with_ underlining"
3163 (progn (search-forward "w")
3164 (org-element-type (org-element-context))))))
3165 ;; Find objects in objects.
3166 (should
3167 (eq 'macro
3168 (org-test-with-temp-text "| a | {{{macro}}} |"
3169 (progn (search-forward "{")
3170 (org-element-type (org-element-context))))))
3171 (should
3172 (eq 'table-cell
3173 (org-test-with-temp-text "| a | b {{{macro}}} |"
3174 (progn (search-forward "b")
3175 (org-element-type (org-element-context))))))
3176 ;; Find objects in planning lines.
3177 (should
3178 (eq 'timestamp
3179 (org-test-with-temp-text "* H\n SCHEDULED: <2012-03-29 thu.>"
3180 (search-forward "2012")
3181 (org-element-type (org-element-context)))))
3182 (should-not
3183 (eq 'timestamp
3184 (org-test-with-temp-text "* H\n SCHEDULED: <2012-03-29 thu.>"
3185 (search-forward "SCHEDULED")
3186 (org-element-type (org-element-context)))))
3187 ;; Find objects in document keywords.
3188 (should
3189 (eq 'macro
3190 (org-test-with-temp-text "#+DATE: {{{macro}}}"
3191 (progn (search-forward "{")
3192 (org-element-type (org-element-context))))))
3193 ;; Do not find objects in table rules.
3194 (should
3195 (eq 'table-row
3196 (org-test-with-temp-text "| a | b |\n+---+---+\n| c | d |"
3197 (forward-line)
3198 (org-element-type (org-element-context)))))
3199 ;; Find objects in parsed affiliated keywords.
3200 (should
3201 (eq 'macro
3202 (org-test-with-temp-text "#+CAPTION: {{{macro}}}\n| a | b |."
3203 (progn (search-forward "{")
3204 (org-element-type (org-element-context))))))
3205 (should
3206 (eq 'bold
3207 (org-test-with-temp-text "#+caption: *bold*\nParagraph"
3208 (progn (search-forward "*")
3209 (org-element-type (org-element-context))))))
3210 ;; Find objects at the end of buffer.
3211 (should
3212 (eq 'bold
3213 (org-test-with-temp-text "*bold*"
3214 (goto-char (point-max))
3215 (org-element-type (org-element-context)))))
3216 ;; Correctly set `:parent' property.
3217 (should
3218 (eq 'paragraph
3219 (org-test-with-temp-text "Some *bold* text"
3220 (progn (search-forward "bold")
3221 (org-element-type
3222 (org-element-property :parent (org-element-context)))))))
3223 ;; Between two objects, return the second one.
3224 (should
3225 (eq 'macro
3226 (org-test-with-temp-text "<<target>>{{{test}}}"
3227 (progn (search-forward "{")
3228 (backward-char)
3229 (org-element-type (org-element-context))))))
3230 ;; Test optional argument.
3231 (should
3232 (eq 'underline
3233 (org-test-with-temp-text "Some *text with _underline_ text*"
3234 (progn
3235 (search-forward "under")
3236 (org-element-type (org-element-context (org-element-at-point)))))))
3237 ;; Special case: bold object at the beginning of a headline.
3238 (should
3239 (eq 'bold
3240 (org-test-with-temp-text "* *bold*"
3241 (search-forward "bo")
3242 (org-element-type (org-element-context)))))
3243 ;; Special case: incomplete cell at the end of a table row.
3244 (should
3245 (eq 'table-cell
3246 (org-test-with-temp-text "|a|b|c"
3247 (goto-char (point-max))
3248 (org-element-type (org-element-context)))))
3249 ;; Special case: objects in inline footnotes.
3250 (should
3251 (eq 'link
3252 (org-test-with-temp-text "[fn::[[<point>http://orgmode.org]]]"
3253 (org-element-type (org-element-context))))))
3257 ;;; Test Cache.
3259 (ert-deftest test-org-element/cache ()
3260 "Test basic expectations and common pitfalls for cache."
3261 ;; Shift positions.
3262 (should
3263 (equal '(18 . 23)
3264 (org-test-with-temp-text "para1\n\npara2\n\npara3"
3265 (let ((org-element-use-cache t))
3266 (save-excursion (goto-char (point-max)) (org-element-at-point))
3267 (insert "add")
3268 (forward-line 4)
3269 (let ((element (org-element-at-point)))
3270 (cons (org-element-property :begin element)
3271 (org-element-property :end element)))))))
3272 ;; Partial shifting: when the contents of a greater element are
3273 ;; modified, only shift ending positions.
3274 (should
3275 (org-test-with-temp-text
3276 "#+BEGIN_CENTER\nPara1\n\nPara2\n\nPara3\n#+END_CENTER"
3277 (let ((org-element-use-cache t))
3278 (save-excursion (search-forward "3") (org-element-at-point))
3279 (search-forward "Para2")
3280 (insert " ")
3281 (let ((element (org-element-property :parent (org-element-at-point))))
3282 (equal (cons (org-element-property :begin element)
3283 (org-element-property :end element))
3284 (cons (point-min) (point-max)))))))
3285 ;; Re-parent shifted elements.
3286 (should
3287 (eq 'item
3288 (org-test-with-temp-text "- item\n\n\n para1\n para2"
3289 (let ((org-element-use-cache t))
3290 (end-of-line)
3291 (org-element-at-point)
3292 (save-excursion (goto-char (point-max)) (org-element-at-point))
3293 (forward-line)
3294 (delete-char 1)
3295 (goto-char (point-max))
3296 (org-element-type
3297 (org-element-property :parent (org-element-at-point)))))))
3298 ;; Preserve local structures when re-parenting.
3299 (should
3300 (eq 'table
3301 (org-test-with-temp-text
3302 "#+begin_center\nP0\n\n<point>\n\n P1\n | a | b |\n| c | d |\n#+end_center"
3303 (let ((org-element-use-cache t))
3304 (save-excursion (search-forward "| c |") (org-element-at-point))
3305 (insert "- item")
3306 (search-forward "| c |")
3307 (beginning-of-line)
3308 (org-element-type
3309 (org-element-property :parent (org-element-at-point)))))))
3310 (should-not
3311 (eq 'center-block
3312 (org-test-with-temp-text
3313 "#+begin_center\nP0\n\n<point>\n\n P1\n | a | b |\n#+end_center"
3314 (let ((org-element-use-cache t))
3315 (save-excursion (search-forward "| a |") (org-element-at-point))
3316 (insert "- item")
3317 (search-forward "| a |")
3318 (beginning-of-line)
3319 (org-element-type
3320 (org-element-property :parent (org-element-at-point)))))))
3321 ;; When re-parenting, also propagate changes to list structures.
3322 (should
3323 (= 2
3324 (org-test-with-temp-text "\n Para\n - item<point>"
3325 (let ((org-element-use-cache t))
3326 (org-element-at-point)
3327 (goto-char (point-min))
3328 (insert "- Top\n")
3329 (search-forward "- item")
3330 (beginning-of-line)
3331 (length (org-element-property :structure (org-element-at-point)))))))
3332 ;; Modifying the last line of an element alters the element below.
3333 (should
3334 (org-test-with-temp-text "para1\n\npara2"
3335 (let ((org-element-use-cache t))
3336 (goto-char (point-max))
3337 (org-element-at-point)
3338 (forward-line -1)
3339 (insert "merge")
3340 (let ((element (org-element-at-point)))
3341 (equal (cons (org-element-property :begin element)
3342 (org-element-property :end element))
3343 (cons (point-min) (point-max)))))))
3344 ;; Modifying the first line of an element alters the element above.
3345 (should
3346 (org-test-with-temp-text ": fixed-width\n:not-fixed-width"
3347 (let ((org-element-use-cache t))
3348 (goto-char (point-max))
3349 (org-element-at-point)
3350 (search-backward ":")
3351 (forward-char)
3352 (insert " ")
3353 (let ((element (org-element-at-point)))
3354 (equal (cons (org-element-property :begin element)
3355 (org-element-property :end element))
3356 (cons (point-min) (point-max)))))))
3357 ;; Sensitive change: adding a line alters document structure both
3358 ;; above and below.
3359 (should
3360 (eq 'example-block
3361 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nPara1\n\nPara2\n"
3362 (let ((org-element-use-cache t))
3363 (goto-char (point-max))
3364 (org-element-at-point)
3365 (insert "#+END_EXAMPLE")
3366 (search-backward "Para1")
3367 (org-element-type (org-element-at-point))))))
3368 (should
3369 (eq 'example-block
3370 (org-test-with-temp-text "Para1\n\nPara2\n#+END_EXAMPLE"
3371 (let ((org-element-use-cache t))
3372 (save-excursion (goto-char (point-max)) (org-element-at-point))
3373 (insert "#+BEGIN_EXAMPLE\n")
3374 (search-forward "Para2")
3375 (org-element-type (org-element-at-point))))))
3376 ;; Sensitive change: removing a line alters document structure both
3377 ;; above and below.
3378 (should
3379 (eq 'example-block
3380 (org-test-with-temp-text
3381 "# +BEGIN_EXAMPLE\nPara1\n\nPara2\n#+END_EXAMPLE"
3382 (let ((org-element-use-cache t))
3383 (save-excursion (goto-char (point-max)) (org-element-at-point))
3384 (forward-char)
3385 (delete-char 1)
3386 (search-forward "Para2")
3387 (org-element-type (org-element-at-point))))))
3388 (should
3389 (eq 'example-block
3390 (org-test-with-temp-text
3391 "#+BEGIN_EXAMPLE\nPara1\n\nPara2\n# +END_EXAMPLE"
3392 (let ((org-element-use-cache t))
3393 (save-excursion (goto-char (point-max)) (org-element-at-point))
3394 (search-forward "# ")
3395 (delete-char -1)
3396 (search-backward "Para1")
3397 (org-element-type (org-element-at-point)))))))
3400 (provide 'test-org-element)
3402 ;;; test-org-element.el ends here