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/>.
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."
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.
42 (org-test-with-temp-text "Some text \alpha
48 (org-element-parse-buffer) 'plain-text
49 (lambda (s) (when (string-match "text" s
) (incf count
))))
51 ;; Applies to secondary strings
53 (org-element-map '("some " (bold nil
"bold") "text") 'bold
'identity
))
54 ;; Enter secondary strings before entering contents.
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.
64 (org-test-with-temp-text "#+BEGIN_CENTER\n\\alpha\n#+END_CENTER"
66 (org-element-parse-buffer) 'entity
'identity nil nil
'center-block
)))
67 ;; Use WITH-AFFILIATED argument.
71 (org-test-with-temp-text "#+CAPTION[a]: 1\n#+CAPTION[b]: 2\nParagraph"
73 (org-element-at-point) 'plain-text
'identity nil nil nil t
)))))
79 (ert-deftest test-org-element
/put-property
()
80 "Test `org-element-put-property' specifications."
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.
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.
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.
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
))))))
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.
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.
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
))
136 ;; Outside a secondary string, return nil.
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
)))
143 (ert-deftest test-org-element
/adopt-elements
()
144 "Test `org-element-adopt-elements' specifications."
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
)))))))
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.
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
)
175 ;; Extract an element.
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
)
185 ;; Extract an object, even in a secondary string.
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
)
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
)
204 ;; Return value doesn't have any :parent set.
206 (org-element-property
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."
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.
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.
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.
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.
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"))
261 (org-element-property
262 :parent
(org-element-map tree
'italic
'identity nil t
)))))))
263 ;; Allow to replace strings with elements.
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.
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.
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
))))))
292 ;;;; Affiliated Keywords
294 (ert-deftest test-org-element
/affiliated-keywords-parser
()
295 "Test affiliated keywords parsing."
296 ;; Read simple keywords.
299 (org-element-property
301 (org-test-with-temp-text "#+NAME: para\nParagraph"
302 (org-element-at-point)))))
305 (org-element-property
307 (org-test-with-temp-text "#+NAME: para\nParagraph"
308 (org-element-at-point)))))
309 ;; Parse multiple keywords.
313 (org-element-property
315 (org-test-with-temp-text
316 "#+ATTR_ASCII: line1\n#+ATTR_ASCII: line2\nParagraph"
317 (org-element-at-point)))))
318 ;; Parse "parsed" keywords.
322 (org-test-with-temp-text "#+CAPTION: caption\nParagraph"
323 (car (org-element-property :caption
(org-element-at-point))))))
324 ;; Parse dual keywords.
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.
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)))))
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.
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))))))
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))))))
355 (ert-deftest test-org-element
/babel-call-parser
()
356 "Test `babel-call' parsing."
359 (org-test-with-temp-text "#+CALL: test()"
360 (org-element-map (org-element-parse-buffer) 'babel-call
'identity
)))
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.
367 (org-test-with-temp-text "#+CALL: test()\n "
368 (= (org-element-property :end
(org-element-at-point)) (point-max)))))
373 (ert-deftest test-org-element
/bold-parser
()
374 "Test `bold' parser."
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.
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"))))
392 (ert-deftest test-org-element
/center-block-parser
()
393 "Test `center-block' parser."
396 (org-test-with-temp-text "#+BEGIN_CENTER\nText\n#+END_CENTER"
397 (org-element-map (org-element-parse-buffer) 'center-block
'identity
)))
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.
404 (org-test-with-temp-text "#+BEGIN_CENTER"
405 (org-element-map (org-element-parse-buffer) 'center-block
407 ;; Handle non-empty blank line at the end of buffer.
409 (org-test-with-temp-text "#+BEGIN_CENTER\nC\n#+END_CENTER\n "
410 (= (org-element-property :end
(org-element-at-point)) (point-max)))))
415 (ert-deftest test-org-element
/clock-parser
()
416 "Test `clock' parser."
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
))
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
)))
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"))))
440 (ert-deftest test-org-element
/code-parser
()
441 "Test `code' parser."
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.
450 (org-element-property
452 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^
\n,\"']\\|[^
\n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^
\n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
453 (org-test-with-temp-text "~first line\nsecond line~"
455 (org-element-parse-buffer) 'code
'identity nil t
))))
456 "first line\nsecond line")))
461 (ert-deftest test-org-element
/comment-parser
()
462 "Test `comment' parser."
465 (org-test-with-temp-text "# Comment"
466 (org-element-map (org-element-parse-buffer) 'comment
'identity
)))
469 (org-test-with-temp-text " # Comment"
470 (org-element-map (org-element-parse-buffer) 'comment
'identity
)))
471 ;; Preserve indentation.
474 (org-element-property
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.
482 (org-element-property
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.
490 (org-test-with-temp-text "#+keyword: value\n# comment\n#+keyword: value"
491 (length (org-element-map (org-element-parse-buffer) 'comment
495 (org-test-with-temp-text "#+keyword: value\n# comment\n#+keyword: value"
496 (org-element-property
498 (org-element-map (org-element-parse-buffer) 'comment
500 ;; Correctly handle non-empty blank lines at the end of buffer.
502 (org-test-with-temp-text "# A\n "
503 (= (org-element-property :end
(org-element-at-point)) (point-max)))))
508 (ert-deftest test-org-element
/comment-block-parser
()
509 "Test `comment-block' parser."
512 (org-test-with-temp-text "#+BEGIN_COMMENT\nText\n#+END_COMMENT"
513 (org-element-map (org-element-parse-buffer) 'comment-block
'identity
)))
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.
520 (org-test-with-temp-text "#+BEGIN_COMMENT"
521 (org-element-map (org-element-parse-buffer) 'comment-block
523 ;; Handle non-empty blank line at the end of buffer.
525 (org-test-with-temp-text "#+BEGIN_COMMENT\nC\n#+END_COMMENT\n "
526 (= (org-element-property :end
(org-element-at-point)) (point-max)))))
531 (ert-deftest test-org-element
/diary-sexp-parser
()
532 "Test `diary-sexp' parser."
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
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.
546 (org-test-with-temp-text "%%(org-bbdb-anniversaries)\n "
547 (= (org-element-property :end
(org-element-at-point)) (point-max)))))
552 (ert-deftest test-org-element
/drawer-parser
()
553 "Test `drawer' parser."
556 (org-test-with-temp-text ":TEST:\nText\n:END:"
557 (org-element-map (org-element-parse-buffer) 'drawer
'identity
)))
558 ;; Ignore incomplete drawer.
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.
564 (org-test-with-temp-text ":TEST:\nC\n:END:\n "
565 (= (org-element-property :end
(org-element-at-point)) (point-max)))))
570 (ert-deftest test-org-element
/dynamic-block-parser
()
571 "Test `dynamic-block' parser."
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
)))
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.
584 (org-test-with-temp-text "#+BEGIN: myblock :param1 val1 :param2 val2"
585 (org-element-map (org-element-parse-buffer) 'dynamic-block
587 ;; Handle non-empty blank line at the end of buffer.
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)))))
595 (ert-deftest test-org-element
/entity-parser
()
596 "Test `entity' parser."
599 (org-test-with-temp-text "\\sin"
600 (org-element-map (org-element-parse-buffer) 'entity
'identity
)))
603 (org-element-property
605 (org-test-with-temp-text "\\alpha{}text"
606 (org-element-map (org-element-parse-buffer) 'entity
'identity nil t
))))
607 ;; User-defined entity.
610 (org-element-property
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
))))
617 ;; Special case: entity at the end of a container.
620 (org-test-with-temp-text "*\\alpha \\beta*"
621 (search-forward "be")
622 (org-element-type (org-element-context))))))
627 (ert-deftest test-org-element
/example-block-parser
()
628 "Test `example-block' parser."
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.
636 (org-test-with-temp-text "#+BEGIN_EXAMPLE"
637 (org-element-type (org-element-at-point)))))
638 ;; Properly un-escape code.
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.
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))))))
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.
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.
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))))
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))))
673 (org-test-with-temp-text "#+BEGIN_EXAMPLE\nText.\n#+END_EXAMPLE"
674 (org-element-property :preserve-indent
(org-element-at-point))))
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.
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
))))))
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.
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
))))))
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
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
)))))
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
)))))
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
)))))
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
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
)))))
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.
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
))))))
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.
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)))))
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)))))))
778 (ert-deftest test-org-element
/export-block-parser
()
779 "Test `export-block' parser."
782 (org-test-with-temp-text "#+BEGIN_LATEX\nText\n#+END_LATEX"
784 (let ((org-element-block-name-alist
785 '(("LATEX" . org-element-export-block-parser
))))
786 (org-element-parse-buffer))
787 'export-block
'identity
)))
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.
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
801 ;; Handle non-empty blank line at the end of buffer.
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))))))
811 (ert-deftest test-org-element
/export-snippet-parser
()
812 "Test `export-snippet' parser."
815 '("back-end" .
"contents")
816 (org-test-with-temp-text "@@back-end:contents@@"
818 (org-element-parse-buffer) 'export-snippet
819 (lambda (snippet) (cons (org-element-property :back-end snippet
)
820 (org-element-property :value snippet
)))
826 (ert-deftest test-org-element
/fixed-width-parser
()
827 "Test fixed-width area parsing."
828 ;; Preserve indentation.
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.
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.
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.
844 (org-test-with-temp-text "
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.
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."
860 (org-test-with-temp-text "[fn:1] Definition"
861 (org-element-map (org-element-parse-buffer) 'footnote-definition
863 ;; Footnote with more contents
866 (org-element-property
868 (org-test-with-temp-text "[fn:1] Definition\n\n| a | b |"
869 (org-element-map (org-element-parse-buffer) 'footnote-definition
871 ;; Footnote starting with special syntax.
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.
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.
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.
892 (org-test-with-temp-text "Text[fn:label]"
894 (org-element-parse-buffer) 'footnote-reference
'identity
)))
895 ;; Parse a normalized reference.
897 (org-test-with-temp-text "Text[1]"
899 (org-element-parse-buffer) 'footnote-reference
'identity
)))
900 ;; Parse an inline reference.
902 (org-test-with-temp-text "Text[fn:test:def]"
904 (org-element-parse-buffer) 'footnote-reference
'identity
)))
905 ;; Parse an anonymous reference.
907 (org-test-with-temp-text "Text[fn::def]"
909 (org-element-parse-buffer) 'footnote-reference
'identity
)))
910 ;; Parse nested footnotes.
914 (org-test-with-temp-text "Text[fn::def [fn:label]]"
916 (org-element-parse-buffer) 'footnote-reference
'identity
)))))
917 ;; Parse adjacent footnotes.
919 (org-test-with-temp-text "Text[fn:label1][fn:label2]"
923 (org-element-parse-buffer) 'footnote-reference
'identity
)))))
924 ;; Only properly closed footnotes are recognized as such.
926 (org-test-with-temp-text "Text[fn:label"
928 (org-element-parse-buffer) 'footnote-reference
'identity
))))
933 (ert-deftest test-org-element
/headline-comment-keyword
()
934 "Test COMMENT keyword recognition."
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"))))
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."
970 (org-test-with-temp-text "* Headline"
971 (let ((org-archive-tag "ARCHIVE"))
972 (org-element-property :archivedp
(org-element-at-point)))))
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
))
979 (should-not (org-element-property :tags headline
)))))
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
))
986 (should (equal (org-element-property :tags headline
) '("test"))))))
987 ;; Tag is case-sensitive.
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
998 (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:foo: bar\n:END:"
999 (org-element-property :FOO
(org-element-at-point))))
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
)
1006 (org-test-with-temp-text "*************** Inlinetask
1010 *************** END"
1011 (org-element-property :FOO
(org-element-at-point)))))
1012 ;; Do not find property drawer in a verbatim area.
1014 (org-test-with-temp-text
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
)
1025 (org-test-with-temp-text
1027 *************** Inlinetask
1031 *************** END"
1032 (org-element-property
1033 :FOO
(let ((org-inlinetask-min-level 15)) (org-element-at-point))))))
1034 ;; Do not find incomplete drawers.
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."
1046 (org-test-with-temp-text "-----"
1047 (org-element-map (org-element-parse-buffer) 'horizontal-rule
'identity
)))
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.
1054 (org-test-with-temp-text "-----wrong"
1055 (org-element-map (org-element-parse-buffer) 'horizontal-rule
'identity
)))
1056 ;; 4 hyphens is too small.
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.
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."
1071 (org-test-with-temp-text "call_test()"
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."
1081 (org-test-with-temp-text "src_emacs-lisp{(+ 1 1)}"
1082 (org-element-map (org-element-parse-buffer) 'inline-src-block
'identity
)))
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
)))
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
)))
1092 (org-test-with-temp-text "src_emacs-lisp[]{(+ 1 1)}"
1093 (org-element-map (org-element-parse-buffer) 'inline-src-block
'identity
)))
1096 (org-test-with-temp-text "foosrc_emacs-lisp[]{(+ 1 1)}"
1097 (org-element-map (org-element-parse-buffer) 'inline-src-block
'identity
)))
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
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.
1107 (org-test-with-temp-text "- src_emacs-lisp{(+ 1 1)}"
1108 (org-element-map (org-element-parse-buffer) 'inline-src-block
'identity
))))
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.
1120 (org-test-with-temp-text
1121 "*************** Task\nTest\n*************** END"
1122 (org-element-type (org-element-at-point)))))
1123 ;; Degenerate inlinetask.
1126 (org-test-with-temp-text "*************** Task"
1127 (org-element-type (org-element-at-point)))))
1128 ;; Mixed inlinetasks.
1130 (org-test-with-temp-text
1132 *************** Task
1133 *************** Task2
1135 *************** END"
1137 (goto-char (org-element-property :end
(org-element-at-point)))
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))))))
1148 (org-test-with-temp-text "
1149 *************** Task
1150 DEADLINE: <2012-03-29 thu.>"
1152 (org-element-property :deadline
(org-element-at-point))))
1157 (org-test-with-temp-text "
1158 *************** [#A] Task"
1160 (org-element-property :priority
(org-element-at-point)))))
1165 (org-test-with-temp-text "
1166 *************** Task :test:"
1168 (org-element-property :tags
(org-element-at-point)))))
1169 ;; Regular properties are accessed through upper case keywords.
1171 (org-test-with-temp-text "
1172 *************** Task
1176 *************** END"
1178 (org-element-property :FOO
(org-element-at-point))))
1180 (org-test-with-temp-text "
1181 *************** Task
1185 *************** END"
1187 (org-element-property :foo
(org-element-at-point))))
1188 ;; Handle non-empty blank line at the end of buffer.
1190 (org-test-with-temp-text "*************** Task\n*************** END\n "
1191 (= (org-element-property :end
(org-element-at-point)) (point-max)))))))
1196 (ert-deftest test-org-element
/italic-parser
()
1197 "Test `italic' parser."
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.
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"))))
1215 (ert-deftest test-org-element
/item-parser
()
1216 "Test `item' parser."
1219 (org-test-with-temp-text "- item"
1220 (org-element-map (org-element-parse-buffer) 'item
'identity
)))
1224 (org-element-property
1226 (org-test-with-temp-text "6. [@6] item"
1227 (org-element-map (org-element-parse-buffer) 'item
'identity nil t
)))))
1232 (org-element-property
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.
1238 (org-element-property
1240 (org-test-with-temp-text "1. tag :: description"
1241 (org-element-map (org-element-parse-buffer) 'item
'identity nil t
))))
1246 (org-test-with-temp-text "
1251 (org-element-parse-buffer) 'item
1252 (lambda (item) (org-element-property :checkbox item
))))))
1253 ;; Item starting with special syntax.
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.
1261 (org-test-with-temp-text "- item\n #+begin_src emacs-lisp\n(+ 1 1)\n #+end_src"
1263 (= (org-element-property :end
(org-element-at-point)) (point-max)))))
1268 (ert-deftest test-org-element
/keyword-parser
()
1269 "Test `keyword' parser."
1272 (org-test-with-temp-text "#+KEYWORD: value"
1273 (org-element-map (org-element-parse-buffer) 'keyword
'identity
)))
1274 ;; Keywords are case-insensitive.
1276 (org-test-with-temp-text "#+keyword: value"
1277 (org-element-map (org-element-parse-buffer) 'keyword
'identity
)))
1278 ;; Affiliated keywords are not keywords.
1280 (org-test-with-temp-text "#+NAME: value
1282 (org-element-map (org-element-parse-buffer) 'keyword
'identity
)))
1283 ;; Do not mix keywords with Babel calls and dynamic blocks.
1285 (org-test-with-temp-text "#+CALL: fun()"
1286 (org-element-map (org-element-parse-buffer) 'keyword
'identity
)))
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.
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."
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.
1311 (org-test-with-temp-text "
1317 (org-element-property
1320 (org-element-parse-buffer) 'latex-environment
'identity nil t
)))))
1321 ;; Allow environments with options and arguments.
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)))))
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{.}.
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.
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.
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.
1348 (eq 'latex-environment
1349 (org-test-with-temp-text "\\begin{env} x \\end{env} y"
1350 (org-element-type (org-element-at-point)))))
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.
1357 (org-test-with-temp-text "\\begin{env}\n\\end{env}\n "
1358 (= (org-element-property :end
(org-element-at-point)) (point-max)))))
1363 (ert-deftest test-org-element
/latex-fragment-parser
()
1364 "Test `latex-fragment' parser."
1366 (org-test-with-temp-text "$a$"
1367 (org-element-map (org-element-parse-buffer) 'latex-fragment
'identity
)))
1369 (org-test-with-temp-text "$$a$$"
1370 (org-element-map (org-element-parse-buffer) 'latex-fragment
'identity
)))
1372 (org-test-with-temp-text "\\(a\\)"
1373 (org-element-map (org-element-parse-buffer) 'latex-fragment
'identity
)))
1375 (org-test-with-temp-text "\\[a\\]"
1377 (org-element-parse-buffer) 'latex-fragment
'identity
)))
1378 ;; Test fragment at the beginning of an item.
1381 (org-test-with-temp-text "- $x$"
1382 (progn (search-forward "$")
1383 (org-element-type (org-element-context)))))))
1388 (ert-deftest test-org-element
/line-break-parser
()
1389 "Test `line-break' parser."
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.
1396 (org-test-with-temp-text "Text \\\\ "
1397 (org-element-map (org-element-parse-buffer) 'line-break
'identity
)))
1398 ;; Three backslashes are too much.
1400 (org-test-with-temp-text "Text \\\\\\"
1401 (org-element-map (org-element-parse-buffer) 'line-break
'identity
))))
1406 (ert-deftest test-org-element
/link-parser
()
1407 "Test `link' parser."
1412 (org-test-with-temp-text "<<<radio>>>A radio link"
1413 (org-update-radio-target-regexp)
1414 (org-element-property
1416 (org-element-map (org-element-parse-buffer) 'link
#'identity nil t
)))))
1419 ;; ... with description.
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.
1430 (org-test-with-temp-text "[[http://orgmode.org]]"
1431 (org-element-property
1433 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
)))))
1434 ;; ... with expansion.
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
1442 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
))))))
1443 ;; ... with translation.
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
1452 (org-element-map (org-element-parse-buffer) 'link
1453 'identity nil t
)))))))
1458 (org-test-with-temp-text "[[id:aaaa]]"
1459 (org-element-property
1461 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
)))))
1462 ;; ... custom-id link.
1466 (org-test-with-temp-text "[[#some-id]]"
1467 (org-element-property
1469 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
)))))
1470 ;; ... coderef link.
1474 (org-test-with-temp-text "[[(reference)]]"
1475 (org-element-property
1477 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
)))))
1482 (org-test-with-temp-text "[[target-or-title]]"
1483 (org-element-property
1485 (org-element-map (org-element-parse-buffer) 'link
'identity nil t
)))))
1486 ;; ... file-type link with search option.
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...
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...
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
)))))
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
)))))
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.
1525 (equal "//orgmode.org"
1526 (org-test-with-temp-text "[[http://orgmode.\norg]]"
1527 (org-element-property :path
(org-element-context)))))
1530 (org-test-with-temp-text "A link: http://orgmode.org"
1531 (org-element-map (org-element-parse-buffer) 'link
'identity
)))
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.
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.
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
))
1553 ;; Plain links are allowed as description of regular links.
1556 (org-test-with-temp-text "[[http://orgmode.org][file:unicorn.jpg]]"
1557 (search-forward "file:")
1558 (org-element-property :type
(org-element-context))))))
1563 (ert-deftest test-org-element
/macro-parser
()
1564 "Test `macro' parser."
1565 ;; Without arguments.
1567 (org-test-with-temp-text "{{{macro}}}"
1568 (org-element-map (org-element-parse-buffer) 'macro
'identity
)))
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...
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.
1582 (org-test-with-temp-text "{{{macro(C-\\,)}}}"
1583 (org-element-property :args
(org-element-context)))))
1584 ;; Allow to escape escaping character.
1587 (org-test-with-temp-text "{{{macro(C-\\\\,)}}}"
1588 (org-element-property :args
(org-element-context)))))
1589 ;; No need to escape backslashes elsewhere.
1592 (org-test-with-temp-text "{{{macro(\\)}}}"
1593 (org-element-property :args
(org-element-context))))))
1598 (ert-deftest test-org-element
/node-property
()
1599 "Test `node-property' parser."
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.
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.
1616 (org-test-with-temp-text ":abc: value"
1617 (org-element-type (org-element-at-point)))))
1618 ;; Accept empty properties.
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
1624 (list (org-element-property :key p
)
1625 (org-element-property :value p
))))))))
1630 (ert-deftest test-org-element
/paragraph-parser
()
1631 "Test `paragraph' parser."
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.
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
)))
1643 ;; Include ill-formed Keywords.
1645 (org-test-with-temp-text "#+wrong_keyword something"
1646 (org-element-map (org-element-parse-buffer) 'paragraph
'identity
)))
1647 ;; Include incomplete-drawers.
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.
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.
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.
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.
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.
1680 (org-test-with-temp-text "#+BEGIN_CENTER\nC\n#+END_CENTER\n "
1681 (= (org-element-property :end
(org-element-at-point)) (point-max)))))
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.
1694 (org-test-with-temp-text "
1699 (let ((endings (org-element-map (org-element-parse-buffer) 'plain-list
1700 (lambda (pl) (org-element-property :end pl
)))))
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
1709 (org-test-with-temp-text "- list\n \n "
1710 (= (org-element-property :end
(org-element-at-point)) (point-max)))))
1715 (ert-deftest test-org-element
/planning-parser
()
1716 "Test `planning' parser."
1717 ;; Test various keywords.
1719 (org-element-property
1721 (org-test-with-temp-text "* H\n<point>CLOSED: [2012-03-29 thu.]"
1722 (org-element-at-point))))
1724 (org-element-property
1726 (org-test-with-temp-text "* H\n<point>DEADLINE: <2012-03-29 thu.>"
1727 (org-element-at-point))))
1729 (org-element-property
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.
1736 (org-test-with-temp-text "DEADLINE: <2012-03-29 thu.>"
1737 (org-element-type (org-element-at-point)))))
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."
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)))))
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.
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)))))
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
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)))))
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)))))
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.
1786 (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:END:\n "
1787 (= (org-element-property :end
(org-element-at-point)) (point-max)))))
1792 (ert-deftest test-org-element
/quote-block-parser
()
1793 "Test `quote-block' parser."
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.
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.
1804 (org-test-with-temp-text "#+BEGIN_QUOTE\nC\n#+END_QUOTE\n "
1805 (= (org-element-property :end
(org-element-at-point)) (point-max)))))
1810 (ert-deftest test-org-element
/radio-target-parser
()
1811 "Test `radio-target' parser."
1815 (org-test-with-temp-text "<<<radio>>>"
1816 (org-element-type (org-element-context)))))
1817 ;; Radio targets with objects.
1820 (org-test-with-temp-text "<<<radio \\alpha>>>"
1821 (org-element-type (org-element-context)))))
1822 ;; Radio targets starting with an object.
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.
1830 (org-test-with-temp-text "<<< radio>>>"
1831 (org-element-type (org-element-context)))))
1834 (org-test-with-temp-text "<<<radio >>>"
1835 (org-element-type (org-element-context))))))
1840 (ert-deftest test-org-element
/section-parser
()
1841 "Test `section' parser."
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.
1848 (org-test-with-temp-text "Text"
1849 (org-element-map (org-element-parse-buffer) 'section
'identity
)))
1850 ;; A section cannot be empty.
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.
1856 (org-test-with-temp-text "* Head\nText\n** Sub-Head"
1858 (org-element-map (org-element-parse-buffer) 'section
'identity nil t
)
1859 'headline
'identity
))))
1864 (ert-deftest test-org-element
/special-block-parser
()
1865 "Test `special-block' parser."
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.
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.
1879 (org-test-with-temp-text "#+BEGIN_SPECIAL\nText\n#+END_SPECIAL"
1881 (org-element-type (org-element-at-point)))))
1882 ;; Ignore incomplete block.
1885 (org-test-with-temp-text "#+BEGIN_SPECIAL"
1886 (org-element-type (org-element-at-point)))))
1887 ;; Allow special characters in type.
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.
1896 (org-test-with-temp-text "#+BEGIN_SPECIAL\nC\n#+END_SPECIAL\n "
1897 (= (org-element-property :end
(org-element-at-point)) (point-max)))))
1902 (ert-deftest test-org-element
/src-block-parser
()
1903 "Test `src-block' parser."
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.
1910 (org-test-with-temp-text "#+BEGIN_SRC"
1911 (org-element-map (org-element-parse-buffer) 'src-block
'identity
)))
1912 ;; Properly un-escape code.
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.
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))))))
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.
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."
1943 (org-test-with-temp-text "[1/2]"
1944 (org-element-map (org-element-parse-buffer) 'statistics-cookie
'identity
)))
1947 (org-test-with-temp-text "[33%]"
1949 (org-element-parse-buffer) 'statistics-cookie
'identity
))))
1954 (ert-deftest test-org-element
/strike-through-parser
()
1955 "Test `strike-through' parser."
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.
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+"
1968 (org-element-parse-buffer) 'strike-through
'identity nil t
))))
1969 '("first line\nsecond line"))))
1974 (ert-deftest test-org-element
/subscript-parser
()
1975 "Test `subscript' parser."
1978 (org-test-with-temp-text "a_b"
1979 (org-element-map (org-element-parse-buffer) 'subscript
'identity
)))
1982 (org-test-with-temp-text "a_{b}"
1983 (org-element-map (org-element-parse-buffer) 'subscript
'identity
)))
1984 ;; Multiple subscripts in a paragraph.
1987 (org-test-with-temp-text "a_b and c_d"
1989 (org-element-map (org-element-parse-buffer) 'subscript
'identity
))))))
1994 (ert-deftest test-org-element
/superscript-parser
()
1995 "Test `superscript' parser."
1998 (org-test-with-temp-text "a^b"
1999 (org-element-map (org-element-parse-buffer) 'superscript
'identity
)))
2002 (org-test-with-temp-text "a^{b}"
2003 (org-element-map (org-element-parse-buffer) 'superscript
'identity
)))
2004 ;; Multiple superscript in a paragraph.
2007 (org-test-with-temp-text "a^b and c^d"
2010 (org-element-parse-buffer) 'superscript
'identity
))))))
2015 (ert-deftest test-org-element
/table-parser
()
2016 "Test `table' parser."
2018 (org-test-with-temp-text "| a |"
2019 (org-element-map (org-element-parse-buffer) 'table
'identity
)))
2020 ;; TBLFM keyword is case insensitive.
2022 (org-test-with-temp-text "| a |\n#+tblfm: test"
2023 (org-element-property
2025 (org-element-map (org-element-parse-buffer) 'table
'identity nil t
))))
2026 ;; Handle multiple TBLFM lines.
2029 (org-test-with-temp-text "| a |\n#+TBLFM: test1\n#+TBLFM: test2"
2030 (length (org-element-property
2033 (org-element-parse-buffer) 'table
'identity nil t
))))))
2034 ;; Handle non-empty blank line at the end of buffer.
2036 (org-test-with-temp-text "| a |\n "
2037 (= (org-element-property :end
(org-element-at-point)) (point-max)))))
2042 (ert-deftest test-org-element
/table-cell-parser
()
2043 "Test `table-cell' parser."
2044 ;; Regular table cell.
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.
2050 (org-test-with-temp-text "| a "
2051 (org-element-map (org-element-parse-buffer) 'table-cell
'identity
))))
2056 (ert-deftest test-org-element
/table-row-parser
()
2057 "Test `table-row' parser."
2059 (equal '(standard rule
)
2060 (org-test-with-temp-text "| a |\n|---|"
2062 (org-element-parse-buffer) 'table-row
2063 (lambda (row) (org-element-property :type row
)))))))
2068 (ert-deftest test-org-element
/target-parser
()
2069 "Test `target' parser."
2071 (org-test-with-temp-text "<<target>>"
2072 (org-element-map (org-element-parse-buffer) 'target
'identity
))))
2077 (ert-deftest test-org-element
/timestamp
()
2078 "Test `timestamp' parser."
2079 ;; Active timestamp.
2081 (org-test-with-temp-text "<2012-03-29 16:40>"
2082 (eq (org-element-property :type
(org-element-context)) 'active
)))
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
)))))
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.
2099 (org-test-with-temp-text "[2012-03-29 Thu 16:40]"
2100 (eq (org-element-property :type
(org-element-context)) 'inactive
)))
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
))))))
2115 (org-test-with-temp-text "<2012-03-29 Thu 7:30-16:40>"
2116 (org-element-property :type
(org-element-context)))))
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
)))
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.
2129 (org-test-with-temp-text "<2012-03-29 Thu ++1y>"
2130 (org-element-property :repeater-type
(org-element-context)))))
2133 (org-test-with-temp-text "<2012-03-29 Thu --1y>"
2134 (org-element-property :warning-type
(org-element-context)))))
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
)))))))
2145 (ert-deftest test-org-element
/underline-parser
()
2146 "Test `underline' parser."
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.
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_"
2159 (org-element-parse-buffer) 'underline
'identity nil t
))))
2160 '("first line\nsecond line"))))
2165 (ert-deftest test-org-element
/verbatim-parser
()
2166 "Test `verbatim' parser."
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.
2175 (org-element-property
2177 (let ((org-emph-re "\\([ ('\"{]\\|^\\)\\(\\([+*/_=~]\\)\\([^
\n,\"']\\|[^
\n,\"'].*?\\(?:\n.*?\\)\\{0,1\\}[^
\n,\"']\\)\\3\\)\\([- .,:!?;'\")}\\]\\|$\\)"))
2178 (org-test-with-temp-text "=first line\nsecond line="
2180 (org-element-parse-buffer) 'verbatim
'identity nil t
))))
2181 "first line\nsecond line")))
2186 (ert-deftest test-org-element
/verse-block-parser
()
2187 "Test `verse-block' parser."
2190 (org-test-with-temp-text "#+BEGIN_VERSE\nVerse block\n#+END_VERSE"
2191 (org-element-map (org-element-parse-buffer) 'verse-block
'identity
)))
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.
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.
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.
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.
2218 (org-element-interpret-data
2219 '(org-data nil
(paragraph (:name
"para") "Paragraph")))
2220 "#+NAME: para\nParagraph\n"))
2221 ;; Interpret multiple affiliated keywords.
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.
2230 (org-element-interpret-data
2231 '(org-data nil
(paragraph (:caption
(("caption"))) "Paragraph")))
2232 "#+CAPTION: caption\nParagraph\n"))
2233 ;; Interpret dual affiliated keywords.
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.
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.
2249 (org-element-interpret-data
2250 '(paragraph nil
(pseudo-object (:post-blank
1) "A") "B")
2254 (org-element-interpret-data
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."
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."
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."
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.
2288 (equal (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
2289 (org-test-parse-and-interpret "* TODO Headline"))
2290 "* TODO Headline\n"))
2293 ;; 3.1. ... and a positive `org-tags-column' value.
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.
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.
2305 (equal (let ((org-tags-column 0))
2306 (org-test-parse-and-interpret "* Headline :tag:"))
2307 "* Headline :tag:\n"))
2308 ;; 4. With priority cookie.
2310 (equal (org-test-parse-and-interpret "* [#B] Headline")
2311 "* [#B] Headline\n"))
2312 ;; 5. With comment keyword.
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.
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.
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.
2345 (equal (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
2346 (org-test-parse-and-interpret "*************** TODO Task"))
2347 "*************** TODO Task\n"))
2350 ;; 5.1. ... and a positive `org-tags-column' value.
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.
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.
2362 (equal (let ((org-tags-column 0))
2363 (org-test-parse-and-interpret "*************** Task :tag:"))
2364 "*************** Task :tag:\n"))
2365 ;; 6. With priority cookie.
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
))
2374 (should (equal (org-test-parse-and-interpret "- item 1") "- item 1\n"))
2375 ;; Description list.
2377 (equal (org-test-parse-and-interpret "- tag :: desc") "- tag :: desc\n"))
2380 (equal (let ((org-plain-list-ordered-item-terminator t
))
2381 (org-test-parse-and-interpret "1. Item"))
2384 (equal (let ((org-plain-list-ordered-item-terminator ?\
)))
2385 (org-test-parse-and-interpret "1) Item"))
2387 ;; Ordered list with counter.
2389 (equal (let ((org-plain-list-ordered-item-terminator t
))
2390 (org-test-parse-and-interpret "1. [@5] Item"))
2392 ;; List with check-boxes.
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.
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."
2436 "CLOCK: \\[2012-01-01 .* 00:01\\]"
2437 (org-test-parse-and-interpret "CLOCK: [2012-01-01 sun. 00:01]")))
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."
2448 (should (equal (org-test-parse-and-interpret "# Comment") "# Comment\n"))
2450 (should (equal (org-test-parse-and-interpret " # Comment")
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.
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."
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"))
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.
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.
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."
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
2512 (equal (org-element-fixed-width-interpreter
2513 '(fixed-width (:value
"Test\n")) nil
)
2516 (equal (org-element-fixed-width-interpreter
2517 '(fixed-width (:value
"Test")) nil
)
2519 ;; Handle empty string.
2521 (equal (org-element-fixed-width-interpreter
2522 '(fixed-width (:value
"")) nil
)
2524 ;; Handle nil value.
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."
2552 DEADLINE: <2012-03-29 .*?> SCHEDULED: <2012-03-29 .*?> CLOSED: \\[2012-03-29 .*?\\]"
2553 (org-test-parse-and-interpret
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."
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"))
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.
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
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"))
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.
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."
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.
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.
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."
2633 (string-match "<2012-03-29 .* 16:40>"
2634 (org-test-parse-and-interpret "<2012-03-29 thu. 16:40>")))
2636 (string-match "<2012-03-29 .* 16:40>"
2637 (org-element-timestamp-interpreter
2639 (:type active
:year-start
2012 :month-start
3 :day-start
29
2640 :hour-start
16 :minute-start
40)) nil
)))
2643 (string-match "\\[2012-03-29 .* 16:40\\]"
2644 (org-test-parse-and-interpret "[2012-03-29 thu. 16:40]")))
2647 "\\[2012-03-29 .* 16:40\\]"
2648 (org-element-timestamp-interpreter
2650 (:type inactive
:year-start
2012 :month-start
3 :day-start
29
2651 :hour-start
16 :minute-start
40)) nil
)))
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>")))
2659 "<2012-03-29 .* 16:40>--<2012-03-29 .* 16:41>"
2660 (org-element-timestamp-interpreter
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
)))
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]")))
2672 "\\[2012-03-29 .* 16:40\\]--\\[2012-03-29 .* 16:41\\]"
2673 (org-element-timestamp-interpreter
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
)))
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.
2683 (string-match "<2012-03-29 .* \\+1y>"
2684 (org-test-parse-and-interpret "<2012-03-29 thu. +1y>")))
2687 "<2012-03-29 .* \\+1y>"
2688 (org-element-timestamp-interpreter
2690 (:type active
:year-start
2012 :month-start
3 :day-start
29
2691 :repeater-type cumulate
:repeater-value
1 :repeater-unit year
))
2695 "<2012-03-29 .* -1y>"
2696 (org-element-timestamp-interpreter
2698 (:type active
:year-start
2012 :month-start
3 :day-start
29
2699 :warning-type all
:warning-value
1 :warning-unit year
))
2703 "<2012-03-29 .* \\+1y -1y>"
2704 (org-element-timestamp-interpreter
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
))
2710 ;; Timestamp range with repeater interval
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>")))
2717 "<2012-03-29 .* \\+1y>--<2012-03-30 .* \\+1y>"
2718 (org-element-timestamp-interpreter
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
))
2725 (ert-deftest test-org-element
/verse-block-interpreter
()
2726 "Test verse block interpretation."
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.
2743 (equal (org-test-parse-and-interpret "\\alpha text") "\\alpha text\n"))
2744 ;; 2. With brackets.
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"))
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"))
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 "
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
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.
2926 (org-test-with-temp-text "* Headline"
2928 (org-element-map (org-element-parse-buffer 'headline
) 'headline
2929 #'identity nil
'first-match
)))
2930 (org-element-property :title headline
)))))
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
)
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
)
2944 #'identity nil
'first-match
)))
2945 (org-element-property :title inlinetask
)))))))
2946 ;; With a default granularity, secondary strings should be parsed.
2949 (org-test-with-temp-text "* 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.
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.
2961 (let ((org-entities nil
)
2962 (org-entities-user nil
))
2963 (org-test-with-temp-text "
2967 # org-entities-user: ((\"foo\"))
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."
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."
2995 (org-test-with-temp-text "#+BEGIN_CENTER\nText\n#+END_CENTER"
2996 (let* ((tree (org-element-parse-buffer))
2997 (parent (org-element-property
2999 (org-element-map tree
'paragraph
'identity nil t
))))
3001 (should (eq (org-element-map tree
'center-block
'identity nil t
)
3004 (org-test-with-temp-text "a_{/b/}"
3005 (let* ((tree (org-element-parse-buffer))
3006 (parent (org-element-property
3008 (org-element-map tree
'italic
'identity nil t
))))
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
))))
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.
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
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.
3043 (org-element-normalize-contents
3044 '(paragraph nil
" Two spaces\n\n \n Two spaces"))
3045 '(paragraph nil
"Two spaces\n\n \nTwo spaces")))
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"))))
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.
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
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.
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.
3085 (org-test-with-temp-text "#+BEGIN_CENTER\nA\n#+END_CENTER"
3086 (progn (search-forward "A")
3088 (org-element-property :parent
(org-element-at-point)))))))
3089 ;; Special case: at a blank line just below a headline, return that
3092 (equal "H1" (org-test-with-temp-text "* H1\n \n* H2\n"
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'.
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'.
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.
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.
3118 (org-test-with-temp-text "- Para1\n\n- Para2"
3119 (progn (forward-line)
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.
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.
3134 (org-test-with-temp-text "- a"
3136 (org-element-type (org-element-at-point)))))
3137 ;; Parse a list within a block itself contained in a list.
3140 (org-test-with-temp-text
3141 "- outer\n #+begin_center\n - inner\n #+end_center"
3142 (search-forward "inner")
3144 (org-element-type (org-element-at-point)))))
3145 ;; Do not error at eob on an empty line.
3147 (org-test-with-temp-text "* H\n"
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.
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.
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.
3168 (org-test-with-temp-text "| a | {{{macro}}} |"
3169 (progn (search-forward "{")
3170 (org-element-type (org-element-context))))))
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.
3179 (org-test-with-temp-text "* H\n SCHEDULED: <2012-03-29 thu.>"
3180 (search-forward "2012")
3181 (org-element-type (org-element-context)))))
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.
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.
3196 (org-test-with-temp-text "| a | b |\n+---+---+\n| c | d |"
3198 (org-element-type (org-element-context)))))
3199 ;; Find objects in parsed affiliated keywords.
3202 (org-test-with-temp-text "#+CAPTION: {{{macro}}}\n| a | b |."
3203 (progn (search-forward "{")
3204 (org-element-type (org-element-context))))))
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.
3213 (org-test-with-temp-text "*bold*"
3214 (goto-char (point-max))
3215 (org-element-type (org-element-context)))))
3216 ;; Correctly set `:parent' property.
3219 (org-test-with-temp-text "Some *bold* text"
3220 (progn (search-forward "bold")
3222 (org-element-property :parent
(org-element-context)))))))
3223 ;; Between two objects, return the second one.
3226 (org-test-with-temp-text "<<target>>{{{test}}}"
3227 (progn (search-forward "{")
3229 (org-element-type (org-element-context))))))
3230 ;; Test optional argument.
3233 (org-test-with-temp-text "Some *text with _underline_ text*"
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.
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.
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.
3252 (org-test-with-temp-text "[fn::[[<point>http://orgmode.org]]]"
3253 (org-element-type (org-element-context))))))
3259 (ert-deftest test-org-element
/cache
()
3260 "Test basic expectations and common pitfalls for cache."
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))
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.
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")
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.
3288 (org-test-with-temp-text "- item\n\n\n para1\n para2"
3289 (let ((org-element-use-cache t
))
3291 (org-element-at-point)
3292 (save-excursion (goto-char (point-max)) (org-element-at-point))
3295 (goto-char (point-max))
3297 (org-element-property :parent
(org-element-at-point)))))))
3298 ;; Preserve local structures when re-parenting.
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))
3306 (search-forward "| c |")
3309 (org-element-property :parent
(org-element-at-point)))))))
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))
3317 (search-forward "| a |")
3320 (org-element-property :parent
(org-element-at-point)))))))
3321 ;; When re-parenting, also propagate changes to list structures.
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))
3329 (search-forward "- item")
3331 (length (org-element-property :structure
(org-element-at-point)))))))
3332 ;; Modifying the last line of an element alters the element below.
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)
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.
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 ":")
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
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))))))
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
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))
3386 (search-forward "Para2")
3387 (org-element-type (org-element-at-point))))))
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 "# ")
3396 (search-backward "Para1")
3397 (org-element-type (org-element-at-point)))))))
3400 (provide 'test-org-element
)
3402 ;;; test-org-element.el ends here