2012-02-23 15:28:13 +00:00
|
|
|
|
;;; test-org-element.el --- Tests for org-element.el
|
|
|
|
|
|
2019-01-01 10:50:56 +00:00
|
|
|
|
;; Copyright (C) 2012-2015, 2019 Nicolas Goaziou
|
2012-02-23 15:28:13 +00:00
|
|
|
|
|
|
|
|
|
;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
|
|
|
|
|
|
|
|
|
|
;; This program is free software; you can redistribute it and/or modify
|
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
;; This program is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2021-03-20 07:27:57 +00:00
|
|
|
|
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2012-02-23 15:28:13 +00:00
|
|
|
|
|
2012-12-13 16:24:19 +00:00
|
|
|
|
;;; Code:
|
|
|
|
|
|
2018-05-10 03:18:04 +00:00
|
|
|
|
(eval-and-compile (require 'cl-lib))
|
|
|
|
|
|
2012-02-29 17:38:54 +00:00
|
|
|
|
(unless (featurep 'org-element)
|
|
|
|
|
(signal 'missing-test-dependency "org-element"))
|
2012-02-23 15:28:13 +00:00
|
|
|
|
|
2012-04-27 15:16:17 +00:00
|
|
|
|
(defun org-test-parse-and-interpret (text)
|
|
|
|
|
"Parse TEXT as Org syntax and interpret it.
|
|
|
|
|
Return interpreted string."
|
|
|
|
|
(with-temp-buffer
|
|
|
|
|
(org-mode)
|
|
|
|
|
(insert text)
|
|
|
|
|
(org-element-interpret-data (org-element-parse-buffer))))
|
|
|
|
|
|
2012-02-23 15:28:13 +00:00
|
|
|
|
|
2012-05-05 13:56:12 +00:00
|
|
|
|
|
|
|
|
|
;;; Test `org-element-map'
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/map ()
|
|
|
|
|
"Test `org-element-map'."
|
|
|
|
|
;; Can map to `plain-text' objects.
|
|
|
|
|
(should
|
|
|
|
|
(= 2
|
|
|
|
|
(org-test-with-temp-text "Some text \alpha
|
|
|
|
|
#+BEGIN_CENTER
|
|
|
|
|
Some other text
|
|
|
|
|
#+END_CENTER"
|
|
|
|
|
(let ((count 0))
|
|
|
|
|
(org-element-map
|
|
|
|
|
(org-element-parse-buffer) 'plain-text
|
2018-05-10 03:18:04 +00:00
|
|
|
|
(lambda (s) (when (string-match "text" s) (cl-incf count))))
|
2012-05-05 13:56:12 +00:00
|
|
|
|
count))))
|
|
|
|
|
;; Applies to secondary strings
|
|
|
|
|
(should
|
|
|
|
|
(org-element-map '("some " (bold nil "bold") "text") 'bold 'identity))
|
|
|
|
|
;; Enter secondary strings before entering contents.
|
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
"alpha"
|
|
|
|
|
(org-element-property
|
|
|
|
|
:name
|
|
|
|
|
(org-test-with-temp-text "* Some \\alpha headline\n\\beta entity."
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'entity 'identity nil t)))))
|
|
|
|
|
;; Apply NO-RECURSION argument.
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_CENTER\n\\alpha\n#+END_CENTER"
|
|
|
|
|
(org-element-map
|
2012-09-30 20:13:47 +00:00
|
|
|
|
(org-element-parse-buffer) 'entity 'identity nil nil 'center-block)))
|
|
|
|
|
;; Use WITH-AFFILIATED argument.
|
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
'("a" "1" "b" "2")
|
|
|
|
|
(org-test-with-temp-text "#+CAPTION[a]: 1\n#+CAPTION[b]: 2\nParagraph"
|
|
|
|
|
(org-element-map
|
|
|
|
|
(org-element-at-point) 'plain-text 'identity nil nil nil t)))))
|
2012-05-05 13:56:12 +00:00
|
|
|
|
|
2012-07-10 15:21:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Test Setters
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/put-property ()
|
|
|
|
|
"Test `org-element-put-property' specifications."
|
2012-10-25 19:33:57 +00:00
|
|
|
|
;; Standard test.
|
2012-07-11 12:17:02 +00:00
|
|
|
|
(org-test-with-temp-text "* Headline\n *a*"
|
|
|
|
|
(let ((tree (org-element-parse-buffer)))
|
|
|
|
|
(org-element-put-property
|
|
|
|
|
(org-element-map tree 'bold 'identity nil t) :test 1)
|
|
|
|
|
(should (org-element-property
|
2012-10-25 19:33:57 +00:00
|
|
|
|
:test (org-element-map tree 'bold 'identity nil t)))))
|
|
|
|
|
;; Put property on a string.
|
|
|
|
|
(should
|
|
|
|
|
(org-element-property :test (org-element-put-property "Paragraph" :test t))))
|
2012-07-10 15:21:36 +00:00
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/set-contents ()
|
|
|
|
|
"Test `org-element-set-contents' specifications."
|
|
|
|
|
;; Accept multiple entries.
|
|
|
|
|
(should
|
|
|
|
|
(equal '("b" (italic nil "a"))
|
2012-07-11 12:17:02 +00:00
|
|
|
|
(org-test-with-temp-text "* Headline\n *a*"
|
|
|
|
|
(let ((tree (org-element-parse-buffer)))
|
|
|
|
|
(org-element-set-contents
|
|
|
|
|
(org-element-map tree 'bold 'identity nil t) "b" '(italic nil "a"))
|
|
|
|
|
(org-element-contents
|
|
|
|
|
(org-element-map tree 'bold 'identity nil t))))))
|
2012-07-10 15:21:36 +00:00
|
|
|
|
;; Accept atoms and elements.
|
|
|
|
|
(should
|
|
|
|
|
(equal '("b")
|
2012-07-11 12:17:02 +00:00
|
|
|
|
(org-test-with-temp-text "* Headline\n *a*"
|
|
|
|
|
(let ((tree (org-element-parse-buffer)))
|
|
|
|
|
(org-element-set-contents
|
|
|
|
|
(org-element-map tree 'bold 'identity nil t) "b")
|
|
|
|
|
(org-element-contents
|
|
|
|
|
(org-element-map tree 'bold 'identity nil t))))))
|
2012-07-10 15:21:36 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal '((italic nil "b"))
|
2012-07-11 12:17:02 +00:00
|
|
|
|
(org-test-with-temp-text "* Headline\n *a*"
|
|
|
|
|
(let ((tree (org-element-parse-buffer)))
|
|
|
|
|
(org-element-set-contents
|
|
|
|
|
(org-element-map tree 'bold 'identity nil t) '(italic nil "b"))
|
|
|
|
|
(org-element-contents
|
|
|
|
|
(org-element-map tree 'bold 'identity nil t))))))
|
2012-07-10 15:21:36 +00:00
|
|
|
|
;; Allow nil contents.
|
|
|
|
|
(should-not
|
2012-07-11 12:17:02 +00:00
|
|
|
|
(org-test-with-temp-text "* Headline\n *a*"
|
|
|
|
|
(let ((tree (org-element-parse-buffer)))
|
|
|
|
|
(org-element-set-contents (org-element-map tree 'bold 'identity nil t))
|
|
|
|
|
(org-element-contents (org-element-map tree 'bold 'identity nil t))))))
|
2012-07-10 15:21:36 +00:00
|
|
|
|
|
2013-11-30 14:23:07 +00:00
|
|
|
|
(ert-deftest test-org-element/secondary-p ()
|
|
|
|
|
"Test `org-element-secondary-p' specifications."
|
|
|
|
|
;; In a secondary string, return property name.
|
|
|
|
|
(should
|
|
|
|
|
(eq :title
|
|
|
|
|
(org-test-with-temp-text "* Headline *object*"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'bold
|
|
|
|
|
(lambda (object) (org-element-secondary-p object))
|
|
|
|
|
nil t))))
|
|
|
|
|
;; Outside a secondary string, return nil.
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "Paragraph *object*"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'bold
|
|
|
|
|
(lambda (object) (org-element-type (org-element-secondary-p object)))
|
|
|
|
|
nil t))))
|
|
|
|
|
|
2016-12-29 17:48:20 +00:00
|
|
|
|
;; FIXME: `org-element-class' is a defsubst and cannot be tested
|
|
|
|
|
;; properly (i.e., "make test" fails).
|
|
|
|
|
;;
|
|
|
|
|
;; (ert-deftest test-org-element/class ()
|
|
|
|
|
;; "Test `org-element-class' specifications."
|
|
|
|
|
;; ;; Regular tests.
|
|
|
|
|
;; (should (eq 'element (org-element-class '(paragraph nil) nil)))
|
|
|
|
|
;; (should (eq 'object (org-element-class '(target nil) nil)))
|
|
|
|
|
;; ;; Special types.
|
|
|
|
|
;; (should (eq 'element (org-element-class '(org-data nil) nil)))
|
|
|
|
|
;; (should (eq 'object (org-element-class "text" nil)))
|
|
|
|
|
;; (should (eq 'object (org-element-class '("secondary " "string") nil)))
|
|
|
|
|
;; ;; Pseudo elements.
|
|
|
|
|
;; (should (eq 'element (org-element-class '(foo nil) nil)))
|
|
|
|
|
;; (should (eq 'element (org-element-class '(foo nil) '(center-block nil))))
|
|
|
|
|
;; (should (eq 'element (org-element-class '(foo nil) '(org-data nil))))
|
|
|
|
|
;; ;; Pseudo objects.
|
|
|
|
|
;; (should (eq 'object (org-element-class '(foo nil) '(bold nil))))
|
|
|
|
|
;; (should (eq 'object (org-element-class '(foo nil) '(paragraph nil))))
|
|
|
|
|
;; (should (eq 'object (org-element-class '(foo nil) '("secondary"))))
|
|
|
|
|
;; (should
|
|
|
|
|
;; (eq 'object
|
|
|
|
|
;; (let* ((datum '(foo nil))
|
|
|
|
|
;; (headline `(headline (:title (,datum)))))
|
|
|
|
|
;; (org-element-put-property datum :parent headline)
|
|
|
|
|
;; (org-element-class datum)))))
|
2016-10-25 11:13:26 +00:00
|
|
|
|
|
2012-08-18 08:13:35 +00:00
|
|
|
|
(ert-deftest test-org-element/adopt-elements ()
|
|
|
|
|
"Test `org-element-adopt-elements' specifications."
|
2012-07-10 15:21:36 +00:00
|
|
|
|
;; Adopt an element.
|
|
|
|
|
(should
|
2012-08-18 08:13:35 +00:00
|
|
|
|
(equal '(plain-text italic)
|
2012-07-11 12:17:02 +00:00
|
|
|
|
(org-test-with-temp-text "* Headline\n *a*"
|
|
|
|
|
(let ((tree (org-element-parse-buffer)))
|
2012-08-18 08:13:35 +00:00
|
|
|
|
(org-element-adopt-elements
|
2012-07-11 12:17:02 +00:00
|
|
|
|
(org-element-map tree 'bold 'identity nil t) '(italic nil "a"))
|
|
|
|
|
(mapcar (lambda (blob) (org-element-type blob))
|
|
|
|
|
(org-element-contents
|
|
|
|
|
(org-element-map tree 'bold 'identity nil t)))))))
|
2012-07-10 15:21:36 +00:00
|
|
|
|
;; Adopt a string.
|
|
|
|
|
(should
|
|
|
|
|
(equal '("a" "b")
|
2012-07-11 12:17:02 +00:00
|
|
|
|
(org-test-with-temp-text "* Headline\n *a*"
|
|
|
|
|
(let ((tree (org-element-parse-buffer)))
|
2012-08-18 08:13:35 +00:00
|
|
|
|
(org-element-adopt-elements
|
|
|
|
|
(org-element-map tree 'bold 'identity nil t) "b")
|
2012-07-11 12:17:02 +00:00
|
|
|
|
(org-element-contents
|
|
|
|
|
(org-element-map tree 'bold 'identity nil t)))))))
|
2012-07-10 15:21:36 +00:00
|
|
|
|
|
2013-11-30 13:25:55 +00:00
|
|
|
|
(ert-deftest test-org-element/extract-element ()
|
|
|
|
|
"Test `org-element-extract-element' specifications."
|
|
|
|
|
;; Extract a greater element.
|
|
|
|
|
(should
|
|
|
|
|
(equal '(org-data nil)
|
|
|
|
|
(org-test-with-temp-text "* Headline"
|
|
|
|
|
(let* ((tree (org-element-parse-buffer))
|
|
|
|
|
(element (org-element-map tree 'headline 'identity nil t)))
|
|
|
|
|
(org-element-extract-element element)
|
|
|
|
|
tree))))
|
|
|
|
|
;; Extract an element.
|
|
|
|
|
(should-not
|
|
|
|
|
(org-element-map
|
|
|
|
|
(org-test-with-temp-text "Paragraph"
|
|
|
|
|
(let* ((tree (org-element-parse-buffer))
|
|
|
|
|
(element (org-element-map tree 'paragraph 'identity nil t)))
|
|
|
|
|
(org-element-extract-element element)
|
|
|
|
|
tree))
|
|
|
|
|
'paragraph
|
|
|
|
|
'identity))
|
|
|
|
|
;; Extract an object, even in a secondary string.
|
|
|
|
|
(should-not
|
|
|
|
|
(org-element-map
|
|
|
|
|
(org-test-with-temp-text "*bold*"
|
|
|
|
|
(let* ((tree (org-element-parse-buffer))
|
|
|
|
|
(element (org-element-map tree 'bold 'identity nil t)))
|
|
|
|
|
(org-element-extract-element element)
|
|
|
|
|
tree))
|
|
|
|
|
'bold
|
|
|
|
|
'identity))
|
|
|
|
|
(should-not
|
|
|
|
|
(org-element-map
|
|
|
|
|
(org-test-with-temp-text "* Headline *bold*"
|
|
|
|
|
(let* ((tree (org-element-parse-buffer))
|
|
|
|
|
(element (org-element-map tree 'bold 'identity nil t)))
|
|
|
|
|
(org-element-extract-element element)
|
|
|
|
|
tree))
|
|
|
|
|
'bold
|
|
|
|
|
'identity))
|
|
|
|
|
;; Return value doesn't have any :parent set.
|
|
|
|
|
(should-not
|
|
|
|
|
(org-element-property
|
|
|
|
|
:parent
|
|
|
|
|
(org-test-with-temp-text "* Headline\n Paragraph with *bold* text."
|
|
|
|
|
(let* ((tree (org-element-parse-buffer))
|
|
|
|
|
(element (org-element-map tree 'bold 'identity nil t)))
|
|
|
|
|
(org-element-extract-element element))))))
|
|
|
|
|
|
2013-11-30 22:31:42 +00:00
|
|
|
|
(ert-deftest test-org-element/insert-before ()
|
|
|
|
|
"Test `org-element-insert-before' specifications."
|
|
|
|
|
;; Standard test.
|
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
'(italic entity bold)
|
|
|
|
|
(org-test-with-temp-text "/some/ *paragraph*"
|
|
|
|
|
(let* ((tree (org-element-parse-buffer))
|
|
|
|
|
(paragraph (org-element-map tree 'paragraph 'identity nil t))
|
|
|
|
|
(bold (org-element-map tree 'bold 'identity nil t)))
|
|
|
|
|
(org-element-insert-before '(entity (:name "\\alpha")) bold)
|
|
|
|
|
(org-element-map tree '(bold entity italic) #'org-element-type nil)))))
|
|
|
|
|
;; Insert an object in a secondary string.
|
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
'(entity italic)
|
|
|
|
|
(org-test-with-temp-text "* /A/\n Paragraph."
|
|
|
|
|
(let* ((tree (org-element-parse-buffer))
|
|
|
|
|
(headline (org-element-map tree 'headline 'identity nil t))
|
|
|
|
|
(italic (org-element-map tree 'italic 'identity nil t)))
|
|
|
|
|
(org-element-insert-before '(entity (:name "\\alpha")) italic)
|
|
|
|
|
(org-element-map (org-element-property :title headline) '(entity italic)
|
|
|
|
|
#'org-element-type))))))
|
|
|
|
|
|
2013-12-01 14:48:54 +00:00
|
|
|
|
(ert-deftest test-org-element/set-element ()
|
|
|
|
|
"Test `org-element-set-element' specifications."
|
|
|
|
|
;; Check if new element is inserted.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "* Headline\n*a*"
|
|
|
|
|
(let* ((tree (org-element-parse-buffer))
|
|
|
|
|
(bold (org-element-map tree 'bold 'identity nil t)))
|
|
|
|
|
(org-element-set-element bold '(italic nil "b"))
|
|
|
|
|
(org-element-map tree 'italic 'identity))))
|
|
|
|
|
;; Check if old element is removed.
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "* Headline\n*a*"
|
|
|
|
|
(let* ((tree (org-element-parse-buffer))
|
|
|
|
|
(bold (org-element-map tree 'bold 'identity nil t)))
|
|
|
|
|
(org-element-set-element bold '(italic nil "b"))
|
|
|
|
|
(org-element-map tree 'bold 'identity))))
|
|
|
|
|
;; Check if :parent property is correctly set.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'paragraph
|
|
|
|
|
(org-test-with-temp-text "* Headline\n*a*"
|
|
|
|
|
(let* ((tree (org-element-parse-buffer))
|
|
|
|
|
(bold (org-element-map tree 'bold 'identity nil t)))
|
|
|
|
|
(org-element-set-element bold '(italic nil "b"))
|
|
|
|
|
(org-element-type
|
|
|
|
|
(org-element-property
|
|
|
|
|
:parent (org-element-map tree 'italic 'identity nil t)))))))
|
|
|
|
|
;; Allow to replace strings with elements.
|
|
|
|
|
(should
|
|
|
|
|
(equal '("b")
|
|
|
|
|
(org-test-with-temp-text "* Headline"
|
|
|
|
|
(let* ((tree (org-element-parse-buffer))
|
|
|
|
|
(text (org-element-map tree 'plain-text 'identity nil t)))
|
|
|
|
|
(org-element-set-element text (list 'bold nil "b"))
|
|
|
|
|
(org-element-map tree 'plain-text 'identity)))))
|
|
|
|
|
;; Allow to replace elements with strings.
|
|
|
|
|
(should
|
|
|
|
|
(equal "a"
|
|
|
|
|
(org-test-with-temp-text "* =verbatim="
|
|
|
|
|
(let* ((tree (org-element-parse-buffer))
|
|
|
|
|
(verb (org-element-map tree 'verbatim 'identity nil t)))
|
|
|
|
|
(org-element-set-element verb "a")
|
|
|
|
|
(org-element-map tree 'plain-text 'identity nil t)))))
|
|
|
|
|
;; Allow to replace strings with strings.
|
|
|
|
|
(should
|
|
|
|
|
(equal "b"
|
|
|
|
|
(org-test-with-temp-text "a"
|
|
|
|
|
(let* ((tree (org-element-parse-buffer))
|
|
|
|
|
(text (org-element-map tree 'plain-text 'identity nil t)))
|
|
|
|
|
(org-element-set-element text "b")
|
|
|
|
|
(org-element-map tree 'plain-text 'identity nil t))))))
|
|
|
|
|
|
2015-02-09 09:07:34 +00:00
|
|
|
|
(ert-deftest test-org-element/copy ()
|
|
|
|
|
"Test `org-element-copy' specifications."
|
|
|
|
|
;; Preserve type.
|
|
|
|
|
(should (eq 'bold
|
|
|
|
|
(org-test-with-temp-text "*bold*"
|
|
|
|
|
(org-element-type (org-element-copy (org-element-context))))))
|
|
|
|
|
(should (eq 'plain-text
|
|
|
|
|
(org-test-with-temp-text "*bold*"
|
|
|
|
|
(org-element-type
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'plain-text
|
|
|
|
|
#'org-element-copy nil t)))))
|
|
|
|
|
;; Preserve properties except `:parent'.
|
|
|
|
|
(should (= 7
|
|
|
|
|
(org-test-with-temp-text "*bold*"
|
|
|
|
|
(org-element-property
|
|
|
|
|
:end (org-element-copy (org-element-context))))))
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "*bold*"
|
|
|
|
|
(org-element-property
|
|
|
|
|
:parent (org-element-copy (org-element-context)))))
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "*bold*"
|
|
|
|
|
(org-element-property
|
|
|
|
|
:parent
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'plain-text
|
|
|
|
|
#'org-element-copy nil t))))
|
|
|
|
|
;; Copying nil returns nil.
|
|
|
|
|
(should-not (org-element-copy nil))
|
|
|
|
|
;; Return a copy secondary strings.
|
|
|
|
|
(should (equal '("text") (org-element-copy '("text"))))
|
|
|
|
|
(should-not (eq '("text") (org-element-copy '("text")))))
|
|
|
|
|
|
2012-07-10 15:21:36 +00:00
|
|
|
|
|
2012-02-23 15:28:13 +00:00
|
|
|
|
|
2012-04-30 15:20:57 +00:00
|
|
|
|
;;; Test Parsers
|
2012-02-23 15:28:13 +00:00
|
|
|
|
|
2012-09-13 11:03:55 +00:00
|
|
|
|
;;;; Affiliated Keywords
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/affiliated-keywords-parser ()
|
|
|
|
|
"Test affiliated keywords parsing."
|
|
|
|
|
;; Read simple keywords.
|
|
|
|
|
(should
|
|
|
|
|
(equal "para"
|
|
|
|
|
(org-element-property
|
|
|
|
|
:name
|
|
|
|
|
(org-test-with-temp-text "#+NAME: para\nParagraph"
|
|
|
|
|
(org-element-at-point)))))
|
2012-09-23 07:49:32 +00:00
|
|
|
|
(should
|
|
|
|
|
(= 1
|
|
|
|
|
(org-element-property
|
|
|
|
|
:begin
|
|
|
|
|
(org-test-with-temp-text "#+NAME: para\nParagraph"
|
|
|
|
|
(org-element-at-point)))))
|
2012-09-13 11:03:55 +00:00
|
|
|
|
;; Parse multiple keywords.
|
|
|
|
|
(should
|
|
|
|
|
(equal
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 17:10:39 +00:00
|
|
|
|
'("line2" "line1")
|
2012-09-13 11:03:55 +00:00
|
|
|
|
(org-element-property
|
|
|
|
|
:attr_ascii
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"#+ATTR_ASCII: line1\n#+ATTR_ASCII: line2\nParagraph"
|
|
|
|
|
(org-element-at-point)))))
|
2019-06-08 22:51:53 +00:00
|
|
|
|
;; Parse "parsed" keywords, unless granularity prevents it.
|
2012-09-13 11:03:55 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal
|
2012-09-13 14:51:54 +00:00
|
|
|
|
'(("caption"))
|
2012-09-13 11:03:55 +00:00
|
|
|
|
(org-test-with-temp-text "#+CAPTION: caption\nParagraph"
|
|
|
|
|
(car (org-element-property :caption (org-element-at-point))))))
|
2019-06-08 22:51:53 +00:00
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "#+CAPTION: *caption*\nParagraph"
|
|
|
|
|
(org-element-map (org-element-map (org-element-parse-buffer)
|
|
|
|
|
'paragraph
|
|
|
|
|
(lambda (e) (org-element-property :caption e)) nil t)
|
|
|
|
|
'bold
|
|
|
|
|
#'org-element-type nil t)))
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "#+CAPTION: *caption*\nParagraph"
|
|
|
|
|
(org-element-map (org-element-map (org-element-parse-buffer 'element)
|
|
|
|
|
'paragraph
|
|
|
|
|
(lambda (e) (org-element-property :caption e)) nil t)
|
|
|
|
|
'bold
|
|
|
|
|
#'org-element-type nil t)))
|
2012-09-13 11:03:55 +00:00
|
|
|
|
;; Parse dual keywords.
|
|
|
|
|
(should
|
|
|
|
|
(equal
|
2012-09-13 14:51:54 +00:00
|
|
|
|
'((("long") "short"))
|
2012-09-13 11:03:55 +00:00
|
|
|
|
(org-test-with-temp-text "#+CAPTION[short]: long\nParagraph"
|
2012-09-13 14:51:54 +00:00
|
|
|
|
(org-element-property :caption (org-element-at-point)))))
|
|
|
|
|
;; Allow multiple caption keywords.
|
|
|
|
|
(should
|
|
|
|
|
(equal
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 17:10:39 +00:00
|
|
|
|
'((("l2") "s2") (("l1") "s1"))
|
2012-09-13 14:51:54 +00:00
|
|
|
|
(org-test-with-temp-text "#+CAPTION[s1]: l1\n#+CAPTION[s2]: l2\nParagraph"
|
2012-10-28 21:43:50 +00:00
|
|
|
|
(org-element-property :caption (org-element-at-point)))))
|
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
'((("l1")) (nil "s1"))
|
|
|
|
|
(org-test-with-temp-text "#+CAPTION[s1]:\n#+CAPTION: l1\nParagraph"
|
2013-02-11 13:42:16 +00:00
|
|
|
|
(org-element-property :caption (org-element-at-point)))))
|
|
|
|
|
;; Corner case: orphaned keyword at the end of an element.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'keyword
|
|
|
|
|
(org-test-with-temp-text "- item\n #+name: name\nSome paragraph"
|
|
|
|
|
(progn (search-forward "name")
|
|
|
|
|
(org-element-type (org-element-at-point))))))
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "- item\n #+name: name\nSome paragraph"
|
|
|
|
|
(progn (search-forward "Some")
|
|
|
|
|
(org-element-property :name (org-element-at-point))))))
|
2012-09-13 11:03:55 +00:00
|
|
|
|
|
|
|
|
|
|
2012-05-04 17:24:51 +00:00
|
|
|
|
;;;; Babel Call
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/babel-call-parser ()
|
|
|
|
|
"Test `babel-call' parsing."
|
2012-05-05 17:57:37 +00:00
|
|
|
|
;; Standard test.
|
2012-05-04 17:24:51 +00:00
|
|
|
|
(should
|
2015-04-21 09:54:22 +00:00
|
|
|
|
(eq 'babel-call
|
|
|
|
|
(org-test-with-temp-text "#+CALL: test()"
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
;; Ignore case.
|
|
|
|
|
(should
|
2015-04-21 09:54:22 +00:00
|
|
|
|
(eq 'babel-call
|
|
|
|
|
(org-test-with-temp-text "#+call: test()"
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
2013-11-10 10:28:14 +00:00
|
|
|
|
;; Handle non-empty blank line at the end of buffer.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "#+CALL: test()\n "
|
2015-04-21 09:54:22 +00:00
|
|
|
|
(= (org-element-property :end (org-element-at-point)) (point-max))))
|
|
|
|
|
;; Parse call name.
|
|
|
|
|
(should
|
|
|
|
|
(equal "test"
|
|
|
|
|
(org-test-with-temp-text "#+CALL: test()"
|
|
|
|
|
(org-element-property :call (org-element-at-point)))))
|
2017-06-20 19:20:30 +00:00
|
|
|
|
;; Parse inside header. It may contain paired square brackets.
|
2015-04-21 09:54:22 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal ":results output"
|
|
|
|
|
(org-test-with-temp-text "#+CALL: test[:results output]()"
|
|
|
|
|
(org-element-property :inside-header (org-element-at-point)))))
|
2017-06-20 19:20:30 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal ":results output, a=table[1:2], b=2"
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"#+CALL: test[:results output, a=table[1:2], b=2]()"
|
|
|
|
|
(org-element-property :inside-header (org-element-at-point)))))
|
|
|
|
|
;; Parse arguments, which can be nested. However, stop at paired
|
|
|
|
|
;; parenthesis, even when, e.g.,end header contains some.
|
2015-04-21 09:54:22 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal "n=4"
|
|
|
|
|
(org-test-with-temp-text "#+CALL: test(n=4)"
|
|
|
|
|
(org-element-property :arguments (org-element-at-point)))))
|
2015-07-02 22:33:45 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal "test()"
|
|
|
|
|
(org-test-with-temp-text "#+CALL: test(test())"
|
|
|
|
|
(org-element-property :arguments (org-element-at-point)))))
|
2017-06-20 19:20:30 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal "a=1"
|
|
|
|
|
(org-test-with-temp-text "#+CALL: test(a=1) :post another-call()"
|
|
|
|
|
(org-element-property :arguments (org-element-at-point)))))
|
2015-04-21 09:54:22 +00:00
|
|
|
|
;; Parse end header.
|
|
|
|
|
(should
|
|
|
|
|
(equal ":results html"
|
|
|
|
|
(org-test-with-temp-text "#+CALL: test() :results html"
|
|
|
|
|
(org-element-property :end-header (org-element-at-point))))))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Bold
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/bold-parser ()
|
|
|
|
|
"Test `bold' parser."
|
2012-05-05 17:57:37 +00:00
|
|
|
|
;; Standard test.
|
2012-05-04 17:24:51 +00:00
|
|
|
|
(should
|
2016-12-08 08:44:26 +00:00
|
|
|
|
(org-test-with-temp-text "*bold*"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'bold #'identity nil t)))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
;; Multi-line markup.
|
|
|
|
|
(should
|
|
|
|
|
(equal
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(org-element-contents
|
2016-12-08 08:44:26 +00:00
|
|
|
|
(org-test-with-temp-text "*first line\nsecond line*"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'bold #'identity nil t)))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
'("first line\nsecond line"))))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Center Block
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/center-block-parser ()
|
|
|
|
|
"Test `center-block' parser."
|
2012-05-05 17:57:37 +00:00
|
|
|
|
;; Standard test.
|
2012-05-04 17:24:51 +00:00
|
|
|
|
(should
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(org-test-with-temp-text "#+BEGIN_CENTER\nText\n#+END_CENTER"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'center-block 'identity)))
|
|
|
|
|
;; Ignore case.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "#+begin_center\nText\n#+end_center"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'center-block 'identity)))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
;; Ignore incomplete block.
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_CENTER"
|
2013-11-10 10:28:14 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'center-block
|
|
|
|
|
'identity nil t)))
|
|
|
|
|
;; Handle non-empty blank line at the end of buffer.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_CENTER\nC\n#+END_CENTER\n "
|
|
|
|
|
(= (org-element-property :end (org-element-at-point)) (point-max)))))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
|
|
|
|
|
|
2020-04-25 14:39:40 +00:00
|
|
|
|
;;;; Citation
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/citation-parser ()
|
|
|
|
|
"Test `citation' parser"
|
|
|
|
|
;; Parse citations. They must contain at least a bare key.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'citation
|
|
|
|
|
(org-test-with-temp-text "[cite:@key]"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
(should-not
|
|
|
|
|
(eq 'citation
|
|
|
|
|
(org-test-with-temp-text "[cite:text]"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
;; Citation may contain a style.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'citation
|
|
|
|
|
(org-test-with-temp-text "[cite/style:@key]"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
(should
|
|
|
|
|
(equal "style"
|
|
|
|
|
(org-test-with-temp-text "[cite/style:@key]"
|
|
|
|
|
(org-element-property :style (org-element-context)))))
|
|
|
|
|
;; Handle multi citations separated with semi-columns.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'citation
|
|
|
|
|
(org-test-with-temp-text "[cite:@a;@b;@c]"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
(should
|
|
|
|
|
(equal '("a" "b" "c")
|
|
|
|
|
(org-test-with-temp-text "[cite:@a;@b;@c]"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'citation-reference
|
|
|
|
|
(lambda (r) (org-element-property :key r))))))
|
|
|
|
|
(should
|
|
|
|
|
(eq 'citation
|
|
|
|
|
(org-test-with-temp-text "[cite:@a;-@b]"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
(should
|
|
|
|
|
(equal '("a" "b")
|
|
|
|
|
(org-test-with-temp-text "[cite:@a;-@b]"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'citation-reference
|
|
|
|
|
(lambda (r) (org-element-property :key r))))))
|
|
|
|
|
;; Multi citations accept `:prefix' and `:suffix' properties.
|
|
|
|
|
(should
|
|
|
|
|
(equal '("common-prefix")
|
|
|
|
|
(org-test-with-temp-text "[cite:common-prefix;@a]"
|
|
|
|
|
(org-element-property :prefix (org-element-context)))))
|
|
|
|
|
(should
|
|
|
|
|
(equal '("common-suffix")
|
|
|
|
|
(org-test-with-temp-text "[cite:@a;common-suffix]"
|
|
|
|
|
(org-element-property :suffix (org-element-context)))))
|
|
|
|
|
;; White spaces right after "cite" tags are ignored. So are white
|
|
|
|
|
;; spaces at the end of the citation.
|
|
|
|
|
(should
|
|
|
|
|
(equal '("common-prefix ")
|
|
|
|
|
(org-test-with-temp-text "[cite: common-prefix ;@a]"
|
|
|
|
|
(org-element-property :prefix (org-element-context)))))
|
|
|
|
|
(should
|
|
|
|
|
(equal '(" common-suffix")
|
|
|
|
|
(org-test-with-temp-text "[cite: @a; common-suffix ]"
|
2021-07-28 08:32:29 +00:00
|
|
|
|
(org-element-property :suffix (org-element-context)))))
|
|
|
|
|
;; Allow citations in a table cell.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'citation
|
|
|
|
|
(org-test-with-temp-text "| <point>[cite:@key] |"
|
|
|
|
|
(org-element-type (org-element-context))))))
|
2020-04-25 14:39:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Citation Reference
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/citation-reference-parser ()
|
|
|
|
|
"Test `citation' reference parser."
|
|
|
|
|
;; Parse bare keys.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'citation-reference
|
|
|
|
|
(org-test-with-temp-text "[cite:<point>@key]"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
;; Bare keys can contain any word character, and some punctuation,
|
|
|
|
|
;; but not semicolon, square brackets, and space.
|
|
|
|
|
(should
|
|
|
|
|
(equal "_key"
|
|
|
|
|
(org-test-with-temp-text "[cite:@_k<point>ey]"
|
|
|
|
|
(org-element-property :key (org-element-context)))))
|
|
|
|
|
(should
|
|
|
|
|
(eq 'citation-reference
|
|
|
|
|
(org-test-with-temp-text "[cite:<point>@a]"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
(should
|
|
|
|
|
(eq 'citation-reference
|
|
|
|
|
(org-test-with-temp-text "[cite:<point>@ö]"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
(should
|
|
|
|
|
(eq 'citation-reference
|
|
|
|
|
(org-test-with-temp-text "[cite:<point>@_]"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
(should
|
|
|
|
|
(equal "a:.#$%&-+?<>~/1"
|
|
|
|
|
(org-test-with-temp-text "[cite:<point>@a:.#$%&-+?<>~/1]"
|
|
|
|
|
(org-element-property :key (org-element-context)))))
|
|
|
|
|
(should-not
|
|
|
|
|
(eq 'citation-reference
|
|
|
|
|
(org-test-with-temp-text "[cite:<point>@;]"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
(should-not
|
|
|
|
|
(equal "key"
|
|
|
|
|
(org-test-with-temp-text "[cite:<point>@[]]"
|
|
|
|
|
(org-element-property :key (org-element-context)))))
|
|
|
|
|
;; References in citations accept optional `:prefix' and `:suffix'
|
|
|
|
|
;; properties.
|
|
|
|
|
(should
|
|
|
|
|
(equal '("pre ")
|
|
|
|
|
(org-test-with-temp-text "[cite:pre <point>@key]"
|
|
|
|
|
(org-element-property :prefix (org-element-context)))))
|
|
|
|
|
(should
|
|
|
|
|
(equal '(" post")
|
|
|
|
|
(org-test-with-temp-text "[cite:<point>@key post]"
|
|
|
|
|
(org-element-property :suffix (org-element-context)))))
|
|
|
|
|
;; White spaces between "cite" tag and prefix are ignored.
|
|
|
|
|
(should
|
|
|
|
|
(equal '("pre ")
|
|
|
|
|
(org-test-with-temp-text "[cite: pre <point>@key]"
|
|
|
|
|
(org-element-property :prefix (org-element-context)))))
|
|
|
|
|
;; Semicolons do not belong to prefix or suffix.
|
|
|
|
|
(should
|
|
|
|
|
(equal '("pre ")
|
|
|
|
|
(org-test-with-temp-text "[cite:@key1;pre <point>@key2]"
|
|
|
|
|
(org-element-property :prefix (org-element-context)))))
|
|
|
|
|
(should
|
|
|
|
|
(equal '(" post")
|
|
|
|
|
(org-test-with-temp-text "[cite:@key1 <point>post;@key2]"
|
|
|
|
|
(org-element-property :suffix (org-element-context)))))
|
|
|
|
|
(should
|
|
|
|
|
(equal '("pre ")
|
|
|
|
|
(org-test-with-temp-text "[cite:global prefix;pre<point> @key1]"
|
|
|
|
|
(org-element-property :prefix (org-element-context)))))
|
|
|
|
|
(should
|
|
|
|
|
(equal '(" post")
|
|
|
|
|
(org-test-with-temp-text "[cite:@key1 <point>post; global suffix]"
|
|
|
|
|
(org-element-property :suffix (org-element-context))))))
|
|
|
|
|
|
2012-05-04 17:24:51 +00:00
|
|
|
|
;;;; Clock
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/clock-parser ()
|
|
|
|
|
"Test `clock' parser."
|
|
|
|
|
;; Running clock.
|
2013-10-29 13:53:21 +00:00
|
|
|
|
(let ((clock (org-test-with-temp-text "CLOCK: [2012-01-01 sun. 00:01]"
|
|
|
|
|
(org-element-at-point))))
|
2012-06-08 18:16:57 +00:00
|
|
|
|
(should (eq (org-element-property :status clock) 'running))
|
2012-09-28 12:50:21 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal (org-element-property :raw-value
|
|
|
|
|
(org-element-property :value clock))
|
|
|
|
|
"[2012-01-01 sun. 00:01]"))
|
|
|
|
|
(should-not (org-element-property :duration clock)))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
;; Closed clock.
|
2013-10-29 13:53:21 +00:00
|
|
|
|
(let ((clock
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"CLOCK: [2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02] => 0:01"
|
|
|
|
|
(org-element-at-point))))
|
2012-06-08 18:16:57 +00:00
|
|
|
|
(should (eq (org-element-property :status clock) 'closed))
|
2012-09-28 12:50:21 +00:00
|
|
|
|
(should (equal (org-element-property :raw-value
|
|
|
|
|
(org-element-property :value clock))
|
2012-06-08 18:16:57 +00:00
|
|
|
|
"[2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02]"))
|
2012-09-28 12:50:21 +00:00
|
|
|
|
(should (equal (org-element-property :duration clock) "0:01"))))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Code
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/code-parser ()
|
|
|
|
|
"Test `code' parser."
|
|
|
|
|
;; Regular test.
|
|
|
|
|
(should
|
2016-12-08 08:44:26 +00:00
|
|
|
|
(org-test-with-temp-text "~code~"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'code #'identity)))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
;; Multi-line markup.
|
|
|
|
|
(should
|
|
|
|
|
(equal
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(org-element-property
|
|
|
|
|
:value
|
2016-12-08 08:44:26 +00:00
|
|
|
|
(org-test-with-temp-text "~first line\nsecond line~"
|
|
|
|
|
(org-element-map
|
|
|
|
|
(org-element-parse-buffer) 'code #'identity nil t)))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
"first line\nsecond line")))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Comment
|
2012-05-02 15:18:14 +00:00
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/comment-parser ()
|
2012-05-04 17:24:51 +00:00
|
|
|
|
"Test `comment' parser."
|
2012-05-02 15:18:14 +00:00
|
|
|
|
;; Regular comment.
|
2019-12-15 13:06:20 +00:00
|
|
|
|
(should (eq 'comment
|
|
|
|
|
(org-test-with-temp-text "# Comment"
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
2012-05-02 15:18:14 +00:00
|
|
|
|
;; Inline comment.
|
2019-12-15 13:06:20 +00:00
|
|
|
|
(should (eq 'comment
|
|
|
|
|
(org-test-with-temp-text " # Comment"
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
2012-05-02 15:18:14 +00:00
|
|
|
|
;; Preserve indentation.
|
|
|
|
|
(should
|
2019-12-15 13:06:20 +00:00
|
|
|
|
(equal "No blank\n One blank"
|
|
|
|
|
(org-element-property
|
|
|
|
|
:value
|
|
|
|
|
(org-test-with-temp-text "# No blank\n# One blank"
|
|
|
|
|
(org-element-at-point)))))
|
2012-05-02 15:18:14 +00:00
|
|
|
|
;; Comment with blank lines.
|
|
|
|
|
(should
|
2019-12-15 13:06:20 +00:00
|
|
|
|
(equal "First part\n\n\nSecond part"
|
|
|
|
|
(org-element-property
|
|
|
|
|
:value
|
|
|
|
|
(org-test-with-temp-text "# First part\n# \n#\n# Second part"
|
|
|
|
|
(org-element-at-point)))))
|
2012-08-02 17:47:14 +00:00
|
|
|
|
;; Do not mix comments and keywords.
|
|
|
|
|
(should
|
|
|
|
|
(eq 1
|
|
|
|
|
(org-test-with-temp-text "#+keyword: value\n# comment\n#+keyword: value"
|
2013-11-10 09:18:17 +00:00
|
|
|
|
(length (org-element-map (org-element-parse-buffer) 'comment
|
2019-12-15 13:06:20 +00:00
|
|
|
|
#'identity)))))
|
2012-08-02 17:47:14 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal "comment"
|
2019-12-15 13:06:20 +00:00
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"#+key: value\n<point># comment\n#+key: value"
|
|
|
|
|
(org-element-property :value (org-element-at-point)))))
|
2013-11-10 09:18:17 +00:00
|
|
|
|
;; Correctly handle non-empty blank lines at the end of buffer.
|
|
|
|
|
(should
|
2013-11-10 10:28:14 +00:00
|
|
|
|
(org-test-with-temp-text "# A\n "
|
|
|
|
|
(= (org-element-property :end (org-element-at-point)) (point-max)))))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Comment Block
|
2012-05-02 15:18:14 +00:00
|
|
|
|
|
2012-05-04 17:24:51 +00:00
|
|
|
|
(ert-deftest test-org-element/comment-block-parser ()
|
|
|
|
|
"Test `comment-block' parser."
|
2012-05-05 17:57:37 +00:00
|
|
|
|
;; Standard test.
|
2012-05-04 17:24:51 +00:00
|
|
|
|
(should
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(org-test-with-temp-text "#+BEGIN_COMMENT\nText\n#+END_COMMENT"
|
2013-11-10 10:28:14 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'comment-block 'identity)))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
;; Ignore case.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "#+begin_comment\nText\n#+end_comment"
|
2013-11-10 10:28:14 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'comment-block 'identity)))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
;; Ignore incomplete block.
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_COMMENT"
|
2013-11-10 10:28:14 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'comment-block
|
|
|
|
|
'identity nil t)))
|
|
|
|
|
;; Handle non-empty blank line at the end of buffer.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_COMMENT\nC\n#+END_COMMENT\n "
|
|
|
|
|
(= (org-element-property :end (org-element-at-point)) (point-max)))))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
|
|
|
|
|
|
2012-10-27 12:23:37 +00:00
|
|
|
|
;;;; Diary Sexp
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/diary-sexp-parser ()
|
|
|
|
|
"Test `diary-sexp' parser."
|
|
|
|
|
;; Standard test.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'diary-sexp
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"%%(org-anniversary 1956 5 14)(2) Arthur Dent is %d years old"
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
|
|
|
|
;; Diary sexp must live at beginning of line
|
|
|
|
|
(should-not
|
|
|
|
|
(eq 'diary-sexp
|
|
|
|
|
(org-test-with-temp-text " %%(org-bbdb-anniversaries)"
|
2013-11-10 10:28:14 +00:00
|
|
|
|
(org-element-type (org-element-at-point)))))
|
|
|
|
|
;; Handle non-empty blank line at the end of buffer.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "%%(org-bbdb-anniversaries)\n "
|
|
|
|
|
(= (org-element-property :end (org-element-at-point)) (point-max)))))
|
2012-10-27 12:23:37 +00:00
|
|
|
|
|
|
|
|
|
|
2012-05-04 17:24:51 +00:00
|
|
|
|
;;;; Drawer
|
2012-05-02 15:18:14 +00:00
|
|
|
|
|
2012-05-04 17:24:51 +00:00
|
|
|
|
(ert-deftest test-org-element/drawer-parser ()
|
|
|
|
|
"Test `drawer' parser."
|
2012-05-05 17:57:37 +00:00
|
|
|
|
;; Standard test.
|
2012-05-04 17:24:51 +00:00
|
|
|
|
(should
|
2013-10-20 12:40:09 +00:00
|
|
|
|
(org-test-with-temp-text ":TEST:\nText\n:END:"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'drawer 'identity)))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
;; Ignore incomplete drawer.
|
|
|
|
|
(should-not
|
2013-10-20 12:40:09 +00:00
|
|
|
|
(org-test-with-temp-text ":TEST:"
|
2013-11-10 10:47:06 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'drawer 'identity nil t)))
|
2021-05-16 08:14:54 +00:00
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text ":END:"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'drawer 'identity nil t)))
|
2013-11-10 10:28:14 +00:00
|
|
|
|
;; Handle non-empty blank line at the end of buffer.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text ":TEST:\nC\n:END:\n "
|
|
|
|
|
(= (org-element-property :end (org-element-at-point)) (point-max)))))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Dynamic Block
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/dynamic-block-parser ()
|
|
|
|
|
"Test `dynamic-block' parser."
|
2012-05-05 17:57:37 +00:00
|
|
|
|
;; Standard test.
|
2012-05-04 17:24:51 +00:00
|
|
|
|
(should
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"#+BEGIN: myblock :param1 val1 :param2 val2\nText\n#+END:"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'dynamic-block 'identity)))
|
|
|
|
|
;; Ignore case.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"#+begin: myblock :param1 val1 :param2 val2\nText\n#+end:"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'dynamic-block 'identity)))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
;; Ignore incomplete block.
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN: myblock :param1 val1 :param2 val2"
|
2013-11-10 10:28:14 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'dynamic-block
|
|
|
|
|
'identity nil t)))
|
|
|
|
|
;; Handle non-empty blank line at the end of buffer.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN: myblock :param val1\nC\n#+END:\n "
|
|
|
|
|
(= (org-element-property :end (org-element-at-point)) (point-max)))))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Entity
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/entity-parser ()
|
|
|
|
|
"Test `entity' parser."
|
|
|
|
|
;; Without brackets.
|
|
|
|
|
(should
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(org-test-with-temp-text "\\sin"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'entity 'identity)))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
;; With brackets.
|
|
|
|
|
(should
|
|
|
|
|
(org-element-property
|
|
|
|
|
:use-brackets-p
|
|
|
|
|
(org-test-with-temp-text "\\alpha{}text"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'entity 'identity nil t))))
|
|
|
|
|
;; User-defined entity.
|
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
(org-element-property
|
|
|
|
|
:name
|
|
|
|
|
(let ((org-entities-user
|
|
|
|
|
'(("test" "test" nil "test" "test" "test" "test"))))
|
|
|
|
|
(org-test-with-temp-text "\\test"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'entity 'identity nil t))))
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 11:29:51 +00:00
|
|
|
|
"test"))
|
|
|
|
|
;; Special case: entity at the end of a container.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'entity
|
|
|
|
|
(org-test-with-temp-text "*\\alpha \\beta*"
|
|
|
|
|
(search-forward "be")
|
|
|
|
|
(org-element-type (org-element-context))))))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Example Block
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/example-block-parser ()
|
|
|
|
|
"Test `example-block' parser."
|
2012-05-05 17:57:37 +00:00
|
|
|
|
;; Standard test.
|
2012-05-04 17:24:51 +00:00
|
|
|
|
(should
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(org-test-with-temp-text "#+BEGIN_EXAMPLE\nText\n#+END_EXAMPLE"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'example-block 'identity)))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
;; Ignore incomplete block.
|
|
|
|
|
(should-not
|
2013-05-25 12:18:48 +00:00
|
|
|
|
(eq 'example-block
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_EXAMPLE"
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
2012-09-30 15:45:21 +00:00
|
|
|
|
;; Properly un-escape code.
|
|
|
|
|
(should
|
2018-01-24 11:56:25 +00:00
|
|
|
|
(equal "* Headline\n #+keyword:\nText\n"
|
2012-09-30 15:45:21 +00:00
|
|
|
|
(org-test-with-temp-text
|
2018-01-24 11:56:25 +00:00
|
|
|
|
"#+BEGIN_EXAMPLE\n,* Headline\n ,#+keyword:\nText\n#+END_EXAMPLE"
|
2013-05-25 12:18:48 +00:00
|
|
|
|
(org-element-property :value (org-element-at-point)))))
|
2013-11-10 10:28:14 +00:00
|
|
|
|
;; Handle non-empty blank line at the end of buffer.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_EXAMPLE\nC\n#+END_EXAMPLE\n "
|
|
|
|
|
(= (org-element-property :end (org-element-at-point)) (point-max)))))
|
2012-03-10 10:37:13 +00:00
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/block-switches ()
|
|
|
|
|
"Test `example-block' and `src-block' switches parsing."
|
|
|
|
|
(let ((org-coderef-label-format "(ref:%s)"))
|
|
|
|
|
;; 1. Test "-i" switch.
|
2013-05-25 12:18:48 +00:00
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
|
org-element: Rename a few internal functions
* contrib/lisp/org-element.el (org-element--parse-elements): Renamed
from `org-element-parse-elements'.
(org-element--parse-objects): Renamed from `org-element-parse-objects'.
(org-element--get-next-object-candidates): Renamed from
`org-element-get-next-object-candidates'.
(org-element--interpret-affiliated-keywords): Renamed from
`org-element-interpret--affiliated-keywords'.
(org-element--current-element): Renamed from
`org-element-current-element'.
(org-element--collect-affiliated-keywords): Renamed from
`org-element-collect-affiliated-keywords'.
(org-element-center-block-parser, org-element-drawer-parser,
org-element-dynamic-block-parser,
org-element-footnote-definition-parser, org-element-inlinetask-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-example-block-parser,
org-element-export-block-parser, org-element-fixed-width-parser,
org-element-horizontal-rule-parser,
org-element-latex-environment-parser, org-element-paragraph-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser, org-element-fill-paragraph,
org-element-context, org-element-at-point, org-element-interpret-data,
org-element-parse-secondary-string, org-element-parse-buffer): Apply
name change.
* contrib/lisp/org-export.el (org-export-get-buffer-attributes): Apply
name change.
* testing/lisp/test-org-element.el: Update tests accordingly.
* testing/lisp/test-org-export.el: Update tests accordingly.
2012-07-19 09:23:43 +00:00
|
|
|
|
(org-element-property :preserve-indent (org-element-at-point))))
|
2013-05-25 12:18:48 +00:00
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
|
|
|
|
|
(org-element-property :preserve-indent (org-element-at-point))))
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_EXAMPLE\nText.\n#+END_EXAMPLE"
|
|
|
|
|
(org-element-property :preserve-indent (org-element-at-point))))
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_EXAMPLE -i\nText.\n#+END_EXAMPLE"
|
org-element: Rename a few internal functions
* contrib/lisp/org-element.el (org-element--parse-elements): Renamed
from `org-element-parse-elements'.
(org-element--parse-objects): Renamed from `org-element-parse-objects'.
(org-element--get-next-object-candidates): Renamed from
`org-element-get-next-object-candidates'.
(org-element--interpret-affiliated-keywords): Renamed from
`org-element-interpret--affiliated-keywords'.
(org-element--current-element): Renamed from
`org-element-current-element'.
(org-element--collect-affiliated-keywords): Renamed from
`org-element-collect-affiliated-keywords'.
(org-element-center-block-parser, org-element-drawer-parser,
org-element-dynamic-block-parser,
org-element-footnote-definition-parser, org-element-inlinetask-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-comment-parser,
org-element-comment-block-parser, org-element-example-block-parser,
org-element-export-block-parser, org-element-fixed-width-parser,
org-element-horizontal-rule-parser,
org-element-latex-environment-parser, org-element-paragraph-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser, org-element-fill-paragraph,
org-element-context, org-element-at-point, org-element-interpret-data,
org-element-parse-secondary-string, org-element-parse-buffer): Apply
name change.
* contrib/lisp/org-export.el (org-export-get-buffer-attributes): Apply
name change.
* testing/lisp/test-org-element.el: Update tests accordingly.
* testing/lisp/test-org-export.el: Update tests accordingly.
2012-07-19 09:23:43 +00:00
|
|
|
|
(org-element-property :preserve-indent (org-element-at-point))))
|
2012-03-10 10:37:13 +00:00
|
|
|
|
;; 2. "-n -r -k" combination should number lines, retain labels but
|
|
|
|
|
;; not use them in coderefs.
|
2015-01-22 05:59:04 +00:00
|
|
|
|
(org-test-with-temp-text "#+BEGIN_EXAMPLE -n -r -k\nText.\n#+END_EXAMPLE"
|
|
|
|
|
(let ((element (org-element-at-point)))
|
|
|
|
|
(should (org-element-property :number-lines element))
|
|
|
|
|
(should (org-element-property :retain-labels element))
|
|
|
|
|
(should-not (org-element-property :use-labels element))))
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"#+BEGIN_SRC emacs-lisp -n -r -k\n(+ 1 1)\n#+END_SRC"
|
|
|
|
|
(let ((element (org-element-at-point)))
|
|
|
|
|
(should (org-element-property :number-lines element))
|
|
|
|
|
(should (org-element-property :retain-labels element))
|
|
|
|
|
(should-not (org-element-property :use-labels element))))
|
2012-03-10 10:37:13 +00:00
|
|
|
|
;; 3. "-n -r" combination should number-lines remove labels and not
|
|
|
|
|
;; use them in coderefs.
|
2015-01-22 05:59:04 +00:00
|
|
|
|
(org-test-with-temp-text "#+BEGIN_EXAMPLE -n -r\nText.\n#+END_EXAMPLE"
|
|
|
|
|
(let ((element (org-element-at-point)))
|
|
|
|
|
(should (org-element-property :number-lines element))
|
|
|
|
|
(should-not (org-element-property :retain-labels element))
|
|
|
|
|
(should-not (org-element-property :use-labels element))))
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1)\n#+END_SRC"
|
|
|
|
|
(let ((element (org-element-at-point)))
|
|
|
|
|
(should (org-element-property :number-lines element))
|
|
|
|
|
(should-not (org-element-property :retain-labels element))
|
|
|
|
|
(should-not (org-element-property :use-labels element))))
|
2012-03-10 10:37:13 +00:00
|
|
|
|
;; 4. "-n" or "+n" should number lines, retain labels and use them
|
|
|
|
|
;; in coderefs.
|
2013-05-25 12:18:48 +00:00
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_EXAMPLE -n\nText.\n#+END_EXAMPLE"
|
|
|
|
|
(let ((element (org-element-at-point)))
|
|
|
|
|
(and (org-element-property :number-lines element)
|
|
|
|
|
(org-element-property :retain-labels element)
|
|
|
|
|
(org-element-property :use-labels element)))))
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1)\n#+END_SRC"
|
|
|
|
|
(let ((element (org-element-at-point)))
|
|
|
|
|
(and (org-element-property :number-lines element)
|
|
|
|
|
(org-element-property :retain-labels element)
|
|
|
|
|
(org-element-property :use-labels element)))))
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_EXAMPLE +n\nText.\n#+END_EXAMPLE"
|
|
|
|
|
(let ((element (org-element-at-point)))
|
|
|
|
|
(and (org-element-property :number-lines element)
|
|
|
|
|
(org-element-property :retain-labels element)
|
|
|
|
|
(org-element-property :use-labels element)))))
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp +n\n(+ 1 1)\n#+END_SRC"
|
|
|
|
|
(let ((element (org-element-at-point)))
|
|
|
|
|
(and (org-element-property :number-lines element)
|
|
|
|
|
(org-element-property :retain-labels element)
|
|
|
|
|
(org-element-property :use-labels element)))))
|
2012-03-10 10:37:13 +00:00
|
|
|
|
;; 5. No switch should not number lines, but retain labels and use
|
|
|
|
|
;; them in coderefs.
|
2015-01-22 05:59:04 +00:00
|
|
|
|
(org-test-with-temp-text "#+BEGIN_EXAMPLE\nText.\n#+END_EXAMPLE"
|
|
|
|
|
(let ((element (org-element-at-point)))
|
|
|
|
|
(should (not (org-element-property :number-lines element)))
|
|
|
|
|
(should (org-element-property :retain-labels element))
|
|
|
|
|
(should (org-element-property :use-labels element))))
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
|
|
|
|
|
(let ((element (org-element-at-point)))
|
|
|
|
|
(should (not (org-element-property :number-lines element)))
|
|
|
|
|
(should (org-element-property :retain-labels element))
|
|
|
|
|
(should (org-element-property :use-labels element))))
|
2012-03-10 10:37:13 +00:00
|
|
|
|
;; 6. "-r" switch only: do not number lines, remove labels, and
|
|
|
|
|
;; don't use labels in coderefs.
|
2015-01-22 05:59:04 +00:00
|
|
|
|
(org-test-with-temp-text "#+BEGIN_EXAMPLE -r\nText.\n#+END_EXAMPLE"
|
|
|
|
|
(let ((element (org-element-at-point)))
|
|
|
|
|
(should (not (org-element-property :number-lines element)))
|
|
|
|
|
(should (not (org-element-property :retain-labels element)))
|
|
|
|
|
(should (not (org-element-property :use-labels element)))))
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1)\n#+END_SRC"
|
|
|
|
|
(let ((element (org-element-at-point)))
|
|
|
|
|
(should (not (org-element-property :number-lines element)))
|
|
|
|
|
(should (not (org-element-property :retain-labels element)))
|
|
|
|
|
(should (not (org-element-property :use-labels element)))))
|
2012-03-10 10:37:13 +00:00
|
|
|
|
;; 7. Recognize coderefs with user-defined syntax.
|
2013-05-25 12:18:48 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
"[ref:%s]"
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText [ref:text]\n#+END_EXAMPLE"
|
|
|
|
|
(org-element-property :label-fmt (org-element-at-point)))))
|
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
"[ref:%s]"
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"#+BEGIN_SRC emacs-lisp -l \"[ref:%s]\"\n(+ 1 1) [ref:text]\n#+END_SRC"
|
|
|
|
|
(org-element-property :label-fmt (org-element-at-point)))))))
|
2012-03-10 10:37:13 +00:00
|
|
|
|
|
|
|
|
|
|
2014-09-08 09:57:27 +00:00
|
|
|
|
;;;; Export Block
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/export-block-parser ()
|
|
|
|
|
"Test `export-block' parser."
|
|
|
|
|
;; Standard test.
|
|
|
|
|
(should
|
2015-02-03 15:16:54 +00:00
|
|
|
|
(eq 'export-block
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_EXPORT LATEX\nText\n#+END_EXPORT"
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
|
|
|
|
(should
|
|
|
|
|
(equal "LATEX"
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_EXPORT LATEX\nText\n#+END_EXPORT"
|
|
|
|
|
(org-element-property :type (org-element-at-point)))))
|
2014-09-08 09:57:27 +00:00
|
|
|
|
;; Ignore case.
|
|
|
|
|
(should
|
2015-02-03 15:16:54 +00:00
|
|
|
|
(eq 'export-block
|
|
|
|
|
(org-test-with-temp-text "#+begin_export latex\nText\n#+end_export"
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
2014-09-08 09:57:27 +00:00
|
|
|
|
;; Ignore incomplete block.
|
|
|
|
|
(should-not
|
2015-02-03 15:16:54 +00:00
|
|
|
|
(eq 'export-block
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_EXPORT"
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
2014-09-08 09:57:27 +00:00
|
|
|
|
;; Handle non-empty blank line at the end of buffer.
|
|
|
|
|
(should
|
2015-02-03 15:16:54 +00:00
|
|
|
|
(org-test-with-temp-text "#+BEGIN_EXPORT latex\nC\n#+END_EXPORT\n "
|
2016-05-13 15:53:22 +00:00
|
|
|
|
(= (org-element-property :end (org-element-at-point)) (point-max))))
|
|
|
|
|
;; Un-escape commas in `:value'.
|
|
|
|
|
(should
|
|
|
|
|
(equal "* H\n"
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_EXPORT org\n,* H\n#+END_EXPORT\n "
|
|
|
|
|
(org-element-property :value (org-element-at-point))))))
|
2014-09-08 09:57:27 +00:00
|
|
|
|
|
|
|
|
|
|
2012-05-04 17:24:51 +00:00
|
|
|
|
;;;; Export Snippet
|
2012-04-30 15:20:57 +00:00
|
|
|
|
|
2012-05-01 13:08:08 +00:00
|
|
|
|
(ert-deftest test-org-element/export-snippet-parser ()
|
2012-05-04 17:24:51 +00:00
|
|
|
|
"Test `export-snippet' parser."
|
2012-04-30 15:20:57 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal
|
2012-05-05 17:57:37 +00:00
|
|
|
|
'("back-end" . "contents")
|
2012-06-30 08:01:28 +00:00
|
|
|
|
(org-test-with-temp-text "@@back-end:contents@@"
|
2012-04-30 15:20:57 +00:00
|
|
|
|
(org-element-map
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(org-element-parse-buffer) 'export-snippet
|
|
|
|
|
(lambda (snippet) (cons (org-element-property :back-end snippet)
|
|
|
|
|
(org-element-property :value snippet)))
|
|
|
|
|
nil t)))))
|
2012-04-30 15:20:57 +00:00
|
|
|
|
|
|
|
|
|
|
2012-05-04 17:24:51 +00:00
|
|
|
|
;;;; Fixed Width
|
2012-05-02 15:18:14 +00:00
|
|
|
|
|
2013-11-10 10:28:14 +00:00
|
|
|
|
(ert-deftest test-org-element/fixed-width-parser ()
|
2012-05-02 15:18:14 +00:00
|
|
|
|
"Test fixed-width area parsing."
|
|
|
|
|
;; Preserve indentation.
|
|
|
|
|
(should
|
2018-07-01 22:24:38 +00:00
|
|
|
|
(equal "no blank\n one blank"
|
|
|
|
|
(org-test-with-temp-text ": no blank\n: one blank"
|
|
|
|
|
(org-element-property :value (org-element-at-point)))))
|
2012-05-02 15:18:14 +00:00
|
|
|
|
;; Fixed-width with empty lines.
|
|
|
|
|
(should
|
2018-07-01 22:24:38 +00:00
|
|
|
|
(equal "first part\n\n\nsecond part"
|
|
|
|
|
(org-test-with-temp-text ": first part\n:\n: \n: second part"
|
|
|
|
|
(org-element-property :value (org-element-at-point)))))
|
2012-05-02 15:18:14 +00:00
|
|
|
|
;; Parse indented fixed-width markers.
|
|
|
|
|
(should
|
2018-07-01 22:24:38 +00:00
|
|
|
|
(eq 'fixed-width
|
|
|
|
|
(org-test-with-temp-text "Text\n<point> : no blank\n : one blank"
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
2012-05-02 15:18:14 +00:00
|
|
|
|
;; Distinguish fixed-width areas within a list and outside of it.
|
|
|
|
|
(should
|
2018-07-01 22:24:38 +00:00
|
|
|
|
(org-test-with-temp-text "
|
2012-05-02 15:18:14 +00:00
|
|
|
|
- Item
|
2018-07-01 22:24:38 +00:00
|
|
|
|
: fixed-width inside<point>
|
2012-05-02 15:18:14 +00:00
|
|
|
|
: fixed-width outside"
|
2018-07-01 22:24:38 +00:00
|
|
|
|
(= (org-element-property :end (org-element-at-point))
|
|
|
|
|
(line-beginning-position 2))))
|
2013-11-10 10:28:14 +00:00
|
|
|
|
;; Handle non-empty blank line at the end of buffer.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text ": A\n "
|
2018-07-01 22:24:38 +00:00
|
|
|
|
(= (org-element-property :end (org-element-at-point))
|
|
|
|
|
(point-max)))))
|
2012-05-02 15:18:14 +00:00
|
|
|
|
|
|
|
|
|
|
2012-05-05 17:57:37 +00:00
|
|
|
|
;;;; Footnote Definition
|
2012-05-04 17:24:51 +00:00
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/footnote-definition-parser ()
|
|
|
|
|
"Test `footnote-definition' parser."
|
|
|
|
|
(should
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(org-test-with-temp-text "[fn:1] Definition"
|
2017-06-07 21:45:17 +00:00
|
|
|
|
(eq (org-element-type (org-element-at-point)) 'footnote-definition)))
|
|
|
|
|
;; Footnote with more contents.
|
2012-05-04 23:38:11 +00:00
|
|
|
|
(should
|
2017-06-07 21:45:17 +00:00
|
|
|
|
(= 29 (org-test-with-temp-text "[fn:1] Definition\n\n| a | b |"
|
|
|
|
|
(org-element-property :end (org-element-at-point)))))
|
|
|
|
|
;; Test difference between :contents-end and :end property
|
|
|
|
|
(should
|
|
|
|
|
(< (org-test-with-temp-text "[fn:1] Definition\n\n\n"
|
|
|
|
|
(org-element-property :contents-end (org-element-at-point)))
|
|
|
|
|
(org-test-with-temp-text "[fn:1] Definition\n\n\n"
|
|
|
|
|
(org-element-property :end (org-element-at-point)))))
|
2012-09-12 13:40:13 +00:00
|
|
|
|
;; Footnote starting with special syntax.
|
|
|
|
|
(should-not
|
2017-06-07 21:45:17 +00:00
|
|
|
|
(org-test-with-temp-text "[fn:1] <point>- no item"
|
|
|
|
|
(eq (org-element-type (org-element-at-point)) 'item)))
|
2013-09-11 15:07:09 +00:00
|
|
|
|
;; Correctly handle footnote starting with an empty line.
|
|
|
|
|
(should
|
|
|
|
|
(= 9
|
|
|
|
|
(org-test-with-temp-text "[fn:1]\n\n Body"
|
2013-11-10 10:28:14 +00:00
|
|
|
|
(org-element-property :contents-begin (org-element-at-point)))))
|
|
|
|
|
;; Handle non-empty blank line at the end of buffer.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "[fn:1] Definition\n "
|
2016-01-14 08:31:24 +00:00
|
|
|
|
(= (org-element-property :end (org-element-at-point)) (point-max))))
|
|
|
|
|
;; Footnote with attributes.
|
|
|
|
|
(should
|
|
|
|
|
(= 1
|
|
|
|
|
(org-test-with-temp-text "#+attr_latex: :offset 0in\n[fn:1] A footnote."
|
|
|
|
|
(length
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'footnote-definition
|
|
|
|
|
#'identity)))))
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "[fn:1] 1\n\n#+attr_latex: :offset 0in\n[fn:2] 2"
|
|
|
|
|
(goto-char (org-element-property :end (org-element-at-point)))
|
2017-06-07 21:45:17 +00:00
|
|
|
|
(looking-at "#")))
|
|
|
|
|
;; An empty footnote has no contents.
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "[fn:1]\n\n"
|
|
|
|
|
(let ((footnote (org-element-at-point)))
|
|
|
|
|
(or (org-element-property :contents-begin footnote)
|
2017-11-09 21:47:35 +00:00
|
|
|
|
(org-element-property :contents-end footnote)))))
|
|
|
|
|
;; Parse `:pre-blank'.
|
|
|
|
|
(should
|
|
|
|
|
(= 0
|
|
|
|
|
(org-test-with-temp-text "[fn:1] A"
|
|
|
|
|
(org-element-property :pre-blank (org-element-at-point)))))
|
|
|
|
|
(should
|
|
|
|
|
(= 1
|
|
|
|
|
(org-test-with-temp-text "[fn:1]\nA"
|
|
|
|
|
(org-element-property :pre-blank (org-element-at-point)))))
|
|
|
|
|
(should
|
|
|
|
|
(= 2
|
|
|
|
|
(org-test-with-temp-text "[fn:1]\n\nA"
|
|
|
|
|
(org-element-property :pre-blank (org-element-at-point))))))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
|
|
|
|
|
|
2012-05-05 17:57:37 +00:00
|
|
|
|
;;;; Footnotes Reference.
|
2012-04-06 21:50:00 +00:00
|
|
|
|
|
2012-05-01 13:08:08 +00:00
|
|
|
|
(ert-deftest test-org-element/footnote-reference-parser ()
|
2012-05-04 17:24:51 +00:00
|
|
|
|
"Test `footnote-reference' parser."
|
2014-07-06 09:08:57 +00:00
|
|
|
|
;; Parse a standard reference.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "Text[fn:label]"
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(org-element-map
|
2014-07-06 09:08:57 +00:00
|
|
|
|
(org-element-parse-buffer) 'footnote-reference 'identity)))
|
|
|
|
|
;; Parse an inline reference.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "Text[fn:test:def]"
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(org-element-map
|
2014-07-06 09:08:57 +00:00
|
|
|
|
(org-element-parse-buffer) 'footnote-reference 'identity)))
|
|
|
|
|
;; Parse an anonymous reference.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "Text[fn::def]"
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(org-element-map
|
2014-07-06 09:08:57 +00:00
|
|
|
|
(org-element-parse-buffer) 'footnote-reference 'identity)))
|
2022-02-28 14:25:08 +00:00
|
|
|
|
;; Parse inline references with syntax loaded characters.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'footnote-reference
|
|
|
|
|
(org-test-with-temp-text "Text[fn<point>::(def]"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
(should
|
|
|
|
|
(eq 'footnote-reference
|
|
|
|
|
(org-test-with-temp-text "Text[fn<point>::\"def]"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
2014-07-06 09:08:57 +00:00
|
|
|
|
;; Parse nested footnotes.
|
|
|
|
|
(should
|
|
|
|
|
(= 2
|
|
|
|
|
(length
|
|
|
|
|
(org-test-with-temp-text "Text[fn::def [fn:label]]"
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(org-element-map
|
2014-07-06 09:08:57 +00:00
|
|
|
|
(org-element-parse-buffer) 'footnote-reference 'identity)))))
|
|
|
|
|
;; Parse adjacent footnotes.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "Text[fn:label1][fn:label2]"
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(= 2
|
|
|
|
|
(length
|
|
|
|
|
(org-element-map
|
2014-07-06 09:08:57 +00:00
|
|
|
|
(org-element-parse-buffer) 'footnote-reference 'identity)))))
|
|
|
|
|
;; Only properly closed footnotes are recognized as such.
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "Text[fn:label"
|
2012-04-06 21:50:00 +00:00
|
|
|
|
(org-element-map
|
2014-07-06 09:08:57 +00:00
|
|
|
|
(org-element-parse-buffer) 'footnote-reference 'identity))))
|
2012-04-06 21:50:00 +00:00
|
|
|
|
|
|
|
|
|
|
2012-05-05 17:57:37 +00:00
|
|
|
|
;;;; Headline
|
2012-04-30 15:20:57 +00:00
|
|
|
|
|
2018-06-06 13:41:50 +00:00
|
|
|
|
(ert-deftest test-org-element/headline-todo-keyword ()
|
|
|
|
|
"Test todo keyword recognition."
|
|
|
|
|
;; Reference test.
|
|
|
|
|
(org-test-with-temp-text "* TODO Headline"
|
|
|
|
|
(let ((org-todo-keywords '((sequence "TODO" "DONE"))))
|
|
|
|
|
(should (org-element-property :todo-keyword (org-element-at-point)))))
|
|
|
|
|
;; Todo keyword is prefix of headlines first word.
|
|
|
|
|
(org-test-with-temp-text "* TODOHeadline"
|
|
|
|
|
(let ((org-todo-keywords '((sequence "TODO" "DONE"))))
|
|
|
|
|
(should-not (org-element-property :todo-keyword (org-element-at-point))))))
|
|
|
|
|
|
2012-04-30 15:20:57 +00:00
|
|
|
|
(ert-deftest test-org-element/headline-comment-keyword ()
|
|
|
|
|
"Test COMMENT keyword recognition."
|
|
|
|
|
;; Reference test.
|
|
|
|
|
(org-test-with-temp-text "* Headline"
|
|
|
|
|
(let ((org-comment-string "COMMENT"))
|
|
|
|
|
(should-not (org-element-property :commentedp (org-element-at-point)))))
|
|
|
|
|
;; Standard position.
|
|
|
|
|
(org-test-with-temp-text "* COMMENT Headline"
|
2012-09-29 07:46:09 +00:00
|
|
|
|
(let ((org-comment-string "COMMENT")
|
|
|
|
|
(headline (org-element-at-point)))
|
|
|
|
|
(should (org-element-property :commentedp headline))
|
|
|
|
|
(should (equal (org-element-property :raw-value headline) "Headline"))))
|
|
|
|
|
;; Case sensitivity.
|
|
|
|
|
(org-test-with-temp-text "* COMMENT Headline"
|
|
|
|
|
(let* ((org-comment-string "Comment")
|
|
|
|
|
(headline (org-element-at-point)))
|
|
|
|
|
(should-not (org-element-property :commentedp headline))
|
|
|
|
|
(should (equal (org-element-property :raw-value headline)
|
|
|
|
|
"COMMENT Headline"))))
|
2012-04-30 15:20:57 +00:00
|
|
|
|
;; With another keyword.
|
|
|
|
|
(org-test-with-temp-text "* TODO COMMENT Headline"
|
2012-09-29 07:46:09 +00:00
|
|
|
|
(let* ((org-comment-string "COMMENT")
|
|
|
|
|
(org-todo-keywords '((sequence "TODO" "DONE")))
|
|
|
|
|
(headline (org-element-at-point)))
|
|
|
|
|
(should (org-element-property :commentedp headline))
|
|
|
|
|
(should (equal (org-element-property :raw-value headline) "Headline"))))
|
2012-09-29 06:54:46 +00:00
|
|
|
|
;; With the keyword only.
|
|
|
|
|
(org-test-with-temp-text "* COMMENT"
|
2012-09-29 07:46:09 +00:00
|
|
|
|
(let* ((org-comment-string "COMMENT")
|
|
|
|
|
(headline (org-element-at-point)))
|
|
|
|
|
(should (org-element-property :commentedp headline))
|
|
|
|
|
(should (equal (org-element-property :raw-value headline) "")))))
|
2012-04-30 15:20:57 +00:00
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/headline-archive-tag ()
|
|
|
|
|
"Test ARCHIVE tag recognition."
|
|
|
|
|
;; Reference test.
|
org-element: Implement caching for dynamic parser
* lisp/org-element.el (org-element-use-cache, org-element--cache,
org-element--cache-sync-idle-time,
org-element--cache-merge-changes-threshold, org-element--cache-status,
org-element--cache-opening-line, org-element--cache-closing-line): New
variables.
(org-element-cache-reset, org-element--cache-pending-changes-p,
org-element--cache-push-change, org-element--cache-cancel-changes,
org-element--cache-get-key, org-element-cache-get,
org-element-cache-put, org-element--shift-positions,
org-element--cache-before-change, org-element--cache-record-change,
org-element--cache-sync): New functions.
(org-element-at-point, org-element-context): Use cache when possible.
* lisp/org.el (org-mode, org-set-modules): Reset cache.
* lisp/org-footnote.el (org-footnote-section): Reset cache.
* testing/lisp/test-org-element.el: Update tests.
This patch gives a boost to `org-element-at-point' and, to a lesser
extent, to `org-element-context'.
2013-10-27 10:09:17 +00:00
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "* Headline"
|
|
|
|
|
(let ((org-archive-tag "ARCHIVE"))
|
|
|
|
|
(org-element-property :archivedp (org-element-at-point)))))
|
2012-04-30 15:20:57 +00:00
|
|
|
|
;; Single tag.
|
|
|
|
|
(org-test-with-temp-text "* Headline :ARCHIVE:"
|
|
|
|
|
(let ((org-archive-tag "ARCHIVE"))
|
|
|
|
|
(let ((headline (org-element-at-point)))
|
2015-04-24 12:28:17 +00:00
|
|
|
|
(should (org-element-property :archivedp headline)))))
|
2012-04-30 15:20:57 +00:00
|
|
|
|
;; Multiple tags.
|
|
|
|
|
(org-test-with-temp-text "* Headline :test:ARCHIVE:"
|
|
|
|
|
(let ((org-archive-tag "ARCHIVE"))
|
|
|
|
|
(let ((headline (org-element-at-point)))
|
2015-04-24 12:28:17 +00:00
|
|
|
|
(should (org-element-property :archivedp headline)))))
|
org-element: Implement caching for dynamic parser
* lisp/org-element.el (org-element-use-cache, org-element--cache,
org-element--cache-sync-idle-time,
org-element--cache-merge-changes-threshold, org-element--cache-status,
org-element--cache-opening-line, org-element--cache-closing-line): New
variables.
(org-element-cache-reset, org-element--cache-pending-changes-p,
org-element--cache-push-change, org-element--cache-cancel-changes,
org-element--cache-get-key, org-element-cache-get,
org-element-cache-put, org-element--shift-positions,
org-element--cache-before-change, org-element--cache-record-change,
org-element--cache-sync): New functions.
(org-element-at-point, org-element-context): Use cache when possible.
* lisp/org.el (org-mode, org-set-modules): Reset cache.
* lisp/org-footnote.el (org-footnote-section): Reset cache.
* testing/lisp/test-org-element.el: Update tests.
This patch gives a boost to `org-element-at-point' and, to a lesser
extent, to `org-element-context'.
2013-10-27 10:09:17 +00:00
|
|
|
|
;; Tag is case-sensitive.
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "* Headline :ARCHIVE:"
|
|
|
|
|
(let ((org-archive-tag "Archive"))
|
|
|
|
|
(org-element-property :archivedp (org-element-at-point))))))
|
2012-04-30 15:20:57 +00:00
|
|
|
|
|
2013-02-18 07:58:59 +00:00
|
|
|
|
(ert-deftest test-org-element/headline-properties ()
|
|
|
|
|
"Test properties from property drawer."
|
|
|
|
|
;; All properties from property drawer have their symbol upper
|
|
|
|
|
;; cased.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "* Headline\n:PROPERTIES:\n:foo: bar\n:END:"
|
|
|
|
|
(org-element-property :FOO (org-element-at-point))))
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "* Headline\n:PROPERTIES:\n:foo: bar\n:END:"
|
2014-06-18 21:28:19 +00:00
|
|
|
|
(org-element-property :foo (org-element-at-point))))
|
2014-06-29 13:23:22 +00:00
|
|
|
|
;; Also parse properties associated in inlinetasks.
|
|
|
|
|
(when (featurep 'org-inlinetask)
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "*************** Inlinetask
|
|
|
|
|
:PROPERTIES:
|
|
|
|
|
:foo: bar
|
|
|
|
|
:END:
|
|
|
|
|
*************** END"
|
|
|
|
|
(org-element-property :FOO (org-element-at-point)))))
|
2014-06-18 21:28:19 +00:00
|
|
|
|
;; Do not find property drawer in a verbatim area.
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"* Headline
|
|
|
|
|
#+BEGIN_EXAMPLE
|
|
|
|
|
:PROPERTIES:
|
|
|
|
|
:foo: bar
|
|
|
|
|
:END:
|
|
|
|
|
#+END_EXAMPLE"
|
|
|
|
|
(org-element-property :FOO (org-element-at-point))))
|
|
|
|
|
;; Do not use properties from a drawer associated to an inlinetask.
|
|
|
|
|
(when (featurep 'org-inlinetask)
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"* Headline
|
|
|
|
|
*************** Inlinetask
|
|
|
|
|
:PROPERTIES:
|
|
|
|
|
:foo: bar
|
|
|
|
|
:END:
|
|
|
|
|
*************** END"
|
|
|
|
|
(org-element-property
|
|
|
|
|
:FOO (let ((org-inlinetask-min-level 15)) (org-element-at-point))))))
|
|
|
|
|
;; Do not find incomplete drawers.
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "* Headline\n:PROPERTIES:\n:foo: bar"
|
|
|
|
|
(org-element-property :FOO (org-element-at-point)))))
|
2013-02-18 07:58:59 +00:00
|
|
|
|
|
2012-04-30 15:20:57 +00:00
|
|
|
|
|
2012-05-05 17:57:37 +00:00
|
|
|
|
;;;; Horizontal Rule
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/horizontal-rule-parser ()
|
|
|
|
|
"Test `horizontal-rule' parser."
|
|
|
|
|
;; Standard.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "-----"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'horizontal-rule 'identity)))
|
|
|
|
|
;; Indented.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text " -----"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'horizontal-rule 'identity)))
|
|
|
|
|
;; Hyphen must be alone on the line.
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "-----wrong"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'horizontal-rule 'identity)))
|
|
|
|
|
;; 4 hyphens is too small.
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "----"
|
2013-11-10 10:28:14 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'horizontal-rule 'identity)))
|
|
|
|
|
;; Handle non-empty blank line at the end of buffer.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "-----\n "
|
|
|
|
|
(= (org-element-property :end (org-element-at-point)) (point-max)))))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Inline Babel Call
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/inline-babel-call-parser ()
|
|
|
|
|
"Test `inline-babel-call' parser."
|
2015-04-21 09:54:22 +00:00
|
|
|
|
;; Standard test.
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(should
|
2015-04-21 09:54:22 +00:00
|
|
|
|
(eq 'inline-babel-call
|
|
|
|
|
(org-test-with-temp-text "call_test()"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
(should
|
|
|
|
|
(eq 'inline-babel-call
|
|
|
|
|
(org-test-with-temp-text "call_test[:results output](x=2)[:results html]"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
;; Parse call name.
|
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
"test"
|
|
|
|
|
(org-test-with-temp-text "call_test[:results output](x=2)[:results html]"
|
|
|
|
|
(org-element-property :call (org-element-context)))))
|
|
|
|
|
;; Parse inside header.
|
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
":results output"
|
|
|
|
|
(org-test-with-temp-text "call_test[:results output](x=2)[:results html]"
|
|
|
|
|
(org-element-property :inside-header (org-element-context)))))
|
|
|
|
|
;; Parse arguments.
|
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
"x=2"
|
|
|
|
|
(org-test-with-temp-text "call_test[:results output](x=2)[:results html]"
|
|
|
|
|
(org-element-property :arguments (org-element-context)))))
|
|
|
|
|
;; Parse end header.
|
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
":results html"
|
|
|
|
|
(org-test-with-temp-text "call_test[:results output](x=2)[:results html]"
|
2015-12-30 22:59:57 +00:00
|
|
|
|
(org-element-property :end-header (org-element-context)))))
|
|
|
|
|
;; Handle multi-line babel calls.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'inline-babel-call
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"call_test[:results\noutput](x=2)[:results html]"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
(should
|
|
|
|
|
(eq 'inline-babel-call
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"call_test[:results output](x=2\ny=3)[:results html]"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
(should
|
|
|
|
|
(eq 'inline-babel-call
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"call_test[:results output](x=2)[:results\nhtml]"
|
2016-06-10 21:42:50 +00:00
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
;; Parse parameters containing round brackets.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'inline-babel-call
|
|
|
|
|
(org-test-with-temp-text "call_test[:var x='(1)](x=2)"
|
2015-12-30 22:59:57 +00:00
|
|
|
|
(org-element-type (org-element-context))))))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Inline Src Block
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/inline-src-block-parser ()
|
|
|
|
|
"Test `inline-src-block' parser."
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "src_emacs-lisp{(+ 1 1)}"
|
2012-09-20 17:12:39 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
|
2014-06-13 13:32:54 +00:00
|
|
|
|
;; With switches.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "src_emacs-lisp[:foo bar]{(+ 1 1)}"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "src_emacs-lisp[ :foo bar]{(+ 1 1)}"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
|
|
|
|
|
;; Empty switches.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "src_emacs-lisp[]{(+ 1 1)}"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
|
|
|
|
|
;; Invalid syntax.
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "src_emacs-lisp[]foo{(+ 1 1)}"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
|
2018-02-03 23:30:00 +00:00
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "foosrc_emacs-lisp[]{(+ 1 1)}"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
|
2014-06-13 13:32:54 +00:00
|
|
|
|
;; Invalid language name
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "src_emacs-\tlisp{(+ 1 1)}"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
|
2012-09-20 17:12:39 +00:00
|
|
|
|
;; Test parsing at the beginning of an item.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "- src_emacs-lisp{(+ 1 1)}"
|
2015-12-30 22:59:57 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'inline-src-block 'identity)))
|
|
|
|
|
;; Test parsing multi-line source blocks.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'inline-src-block
|
|
|
|
|
(org-test-with-temp-text "src_emacs-lisp{(+ 1\n 1)}"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
(should
|
|
|
|
|
(eq 'inline-src-block
|
|
|
|
|
(org-test-with-temp-text "src_emacs-lisp[\n:foo bar]{(+ 1 1)}"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
(should
|
|
|
|
|
(eq 'inline-src-block
|
|
|
|
|
(org-test-with-temp-text "src_emacs-lisp[:foo\nbar]{(+ 1 1)}"
|
2016-03-16 17:13:52 +00:00
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
;; Besides curly brackets, ignore any other bracket type.
|
|
|
|
|
(should
|
|
|
|
|
(equal "[foo"
|
|
|
|
|
(org-test-with-temp-text "src_emacs-lisp{[foo}"
|
|
|
|
|
(org-element-property :value (org-element-context)))))
|
|
|
|
|
(should
|
|
|
|
|
(equal "foo]"
|
|
|
|
|
(org-test-with-temp-text "src_emacs-lisp{foo]}"
|
|
|
|
|
(org-element-property :value (org-element-context)))))
|
|
|
|
|
(should
|
|
|
|
|
(equal "(foo"
|
2016-03-16 17:17:50 +00:00
|
|
|
|
(org-test-with-temp-text "src_emacs-lisp{(foo}"
|
2016-03-16 17:13:52 +00:00
|
|
|
|
(org-element-property :value (org-element-context)))))
|
|
|
|
|
(should
|
|
|
|
|
(equal "foo)"
|
|
|
|
|
(org-test-with-temp-text "src_emacs-lisp{foo)}"
|
2016-06-10 21:42:50 +00:00
|
|
|
|
(org-element-property :value (org-element-context)))))
|
|
|
|
|
;; Parse parameters containing square brackets.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'inline-src-block
|
|
|
|
|
(org-test-with-temp-text "src_emacs-lisp[:var table=t[1,1]]{(+ 1 1)}"
|
|
|
|
|
(org-element-type (org-element-context))))))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Inlinetask
|
2012-05-04 17:24:51 +00:00
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/inlinetask-parser ()
|
|
|
|
|
"Test `inlinetask' parser."
|
|
|
|
|
(when (featurep 'org-inlinetask)
|
|
|
|
|
(let ((org-inlinetask-min-level 15))
|
2014-02-17 21:59:25 +00:00
|
|
|
|
;; Regular inlinetask.
|
2012-05-04 17:24:51 +00:00
|
|
|
|
(should
|
2014-02-17 21:59:25 +00:00
|
|
|
|
(eq 'inlinetask
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"*************** Task\nTest\n*************** END"
|
2016-11-09 22:25:53 +00:00
|
|
|
|
(org-element-type (org-element-at-point)))))
|
|
|
|
|
(should
|
|
|
|
|
(eq 'inlinetask
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"*************** Task\nTest\n*************** END"
|
2014-02-17 21:59:25 +00:00
|
|
|
|
(org-element-type (org-element-at-point)))))
|
|
|
|
|
;; Degenerate inlinetask.
|
2012-05-04 17:24:51 +00:00
|
|
|
|
(should
|
2014-02-17 21:59:25 +00:00
|
|
|
|
(eq 'inlinetask
|
|
|
|
|
(org-test-with-temp-text "*************** Task"
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
|
|
|
|
;; Mixed inlinetasks.
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"
|
|
|
|
|
*************** Task
|
|
|
|
|
*************** Task2
|
|
|
|
|
Contents
|
|
|
|
|
*************** END"
|
|
|
|
|
(forward-line)
|
|
|
|
|
(goto-char (org-element-property :end (org-element-at-point)))
|
|
|
|
|
(eobp)))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
;; TODO keyword.
|
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
"TODO"
|
|
|
|
|
(let ((org-todo-keywords '((sequence "TODO" "DONE"))))
|
|
|
|
|
(org-test-with-temp-text "*************** TODO Task"
|
2014-02-17 21:59:25 +00:00
|
|
|
|
(org-element-property :todo-keyword (org-element-at-point))))))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
;; Planning info.
|
|
|
|
|
(should
|
2014-02-17 21:59:25 +00:00
|
|
|
|
(org-test-with-temp-text "
|
2015-10-16 21:19:06 +00:00
|
|
|
|
*************** Task<point>
|
2014-12-24 09:47:46 +00:00
|
|
|
|
DEADLINE: <2012-03-29 thu.>
|
|
|
|
|
*************** END"
|
|
|
|
|
(org-element-property :deadline (org-element-at-point))))
|
2015-10-16 21:19:06 +00:00
|
|
|
|
(should
|
|
|
|
|
(eq 'planning
|
|
|
|
|
(org-test-with-temp-text "
|
|
|
|
|
*************** Task
|
|
|
|
|
<point>DEADLINE: <2012-03-29 thu.>
|
|
|
|
|
*************** END"
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
2014-12-24 09:47:46 +00:00
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "
|
2015-10-16 21:19:06 +00:00
|
|
|
|
*************** Task<point>
|
2012-05-04 17:24:51 +00:00
|
|
|
|
DEADLINE: <2012-03-29 thu.>"
|
2014-02-17 21:59:25 +00:00
|
|
|
|
(org-element-property :deadline (org-element-at-point))))
|
2015-10-16 21:19:06 +00:00
|
|
|
|
(should-not
|
|
|
|
|
(eq 'planning
|
|
|
|
|
(org-test-with-temp-text "
|
|
|
|
|
*************** Task
|
|
|
|
|
<point>DEADLINE: <2012-03-29 thu.>"
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
;; Priority.
|
|
|
|
|
(should
|
2014-02-17 21:59:25 +00:00
|
|
|
|
(eq
|
2012-05-04 17:24:51 +00:00
|
|
|
|
?A
|
|
|
|
|
(org-test-with-temp-text "
|
|
|
|
|
*************** [#A] Task"
|
2014-02-17 21:59:25 +00:00
|
|
|
|
(forward-line)
|
|
|
|
|
(org-element-property :priority (org-element-at-point)))))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
;; Tags.
|
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
'("test")
|
|
|
|
|
(org-test-with-temp-text "
|
|
|
|
|
*************** Task :test:"
|
2014-02-17 21:59:25 +00:00
|
|
|
|
(forward-line)
|
|
|
|
|
(org-element-property :tags (org-element-at-point)))))
|
2013-02-18 07:58:59 +00:00
|
|
|
|
;; Regular properties are accessed through upper case keywords.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "
|
|
|
|
|
*************** Task
|
|
|
|
|
:PROPERTIES:
|
|
|
|
|
:foo: bar
|
|
|
|
|
:END:
|
|
|
|
|
*************** END"
|
|
|
|
|
(forward-line)
|
|
|
|
|
(org-element-property :FOO (org-element-at-point))))
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "
|
|
|
|
|
*************** Task
|
|
|
|
|
:PROPERTIES:
|
|
|
|
|
:foo: bar
|
|
|
|
|
:END:
|
|
|
|
|
*************** END"
|
|
|
|
|
(forward-line)
|
2013-11-10 10:28:14 +00:00
|
|
|
|
(org-element-property :foo (org-element-at-point))))
|
|
|
|
|
;; Handle non-empty blank line at the end of buffer.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "*************** Task\n*************** END\n "
|
|
|
|
|
(= (org-element-property :end (org-element-at-point)) (point-max)))))))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
|
|
|
|
|
|
2012-05-05 17:57:37 +00:00
|
|
|
|
;;;; Italic
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/italic-parser ()
|
|
|
|
|
"Test `italic' parser."
|
|
|
|
|
;; Regular test.
|
|
|
|
|
(should
|
2016-12-08 08:44:26 +00:00
|
|
|
|
(org-test-with-temp-text "/italic/"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'italic #'identity nil t)))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
;; Multi-line markup.
|
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
(org-element-contents
|
2016-12-08 08:44:26 +00:00
|
|
|
|
(org-test-with-temp-text "/first line\nsecond line/"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'italic #'identity nil t)))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
'("first line\nsecond line"))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Item
|
2012-05-04 17:24:51 +00:00
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/item-parser ()
|
|
|
|
|
"Test `item' parser."
|
|
|
|
|
;; Standard test.
|
|
|
|
|
(should
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(org-test-with-temp-text "- item"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'item 'identity)))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
;; Counter.
|
|
|
|
|
(should
|
|
|
|
|
(= 6
|
|
|
|
|
(org-element-property
|
|
|
|
|
:counter
|
|
|
|
|
(org-test-with-temp-text "6. [@6] item"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'item 'identity nil t)))))
|
|
|
|
|
;; Tag
|
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
'("tag")
|
|
|
|
|
(org-element-property
|
|
|
|
|
:tag
|
|
|
|
|
(org-test-with-temp-text "- tag :: description"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'item 'identity nil t)))))
|
2012-08-18 10:37:39 +00:00
|
|
|
|
;; No tags in ordered lists.
|
|
|
|
|
(should-not
|
|
|
|
|
(org-element-property
|
|
|
|
|
:tag
|
|
|
|
|
(org-test-with-temp-text "1. tag :: description"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'item 'identity nil t))))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
;; Check-boxes
|
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
'(trans on off)
|
|
|
|
|
(org-test-with-temp-text "
|
|
|
|
|
- [-] item 1
|
|
|
|
|
- [X] item 1.1
|
|
|
|
|
- [ ] item 1.2"
|
2017-11-09 21:47:35 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'item
|
|
|
|
|
(lambda (item) (org-element-property :checkbox item))))))
|
2012-09-12 13:40:13 +00:00
|
|
|
|
;; Item starting with special syntax.
|
|
|
|
|
(should
|
|
|
|
|
(equal '(("- item"))
|
|
|
|
|
(org-test-with-temp-text "- - item"
|
2013-11-10 10:28:14 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'paragraph
|
|
|
|
|
'org-element-contents))))
|
2013-10-16 08:36:48 +00:00
|
|
|
|
;; Block in an item: ignore indentation within the block.
|
|
|
|
|
(should
|
2017-11-04 20:50:11 +00:00
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"-<point> item\n #+begin_src emacs-lisp\n(+ 1 1)\n #+end_src"
|
|
|
|
|
(= (org-element-property :end (org-element-at-point)) (point-max))))
|
2017-11-09 21:47:35 +00:00
|
|
|
|
;; Parse `:pre-blank'.
|
|
|
|
|
(should
|
|
|
|
|
(= 0
|
|
|
|
|
(org-test-with-temp-text "-<point> A"
|
|
|
|
|
(org-element-property :pre-blank (org-element-at-point)))))
|
|
|
|
|
(should
|
|
|
|
|
(= 1
|
|
|
|
|
(org-test-with-temp-text "-<point>\n A"
|
|
|
|
|
(org-element-property :pre-blank (org-element-at-point)))))
|
|
|
|
|
(should
|
|
|
|
|
(= 2
|
|
|
|
|
(org-test-with-temp-text "-<point>\n\n A"
|
|
|
|
|
(org-element-property :pre-blank (org-element-at-point)))))
|
2017-11-04 20:50:11 +00:00
|
|
|
|
;; Last item in a list or sub-list has no `:post-blank' lines, since
|
|
|
|
|
;; those belong to the plain-list.
|
|
|
|
|
(should
|
|
|
|
|
(= 0
|
|
|
|
|
(org-test-with-temp-text "- A\n\n- <point>B\n\nEnd list"
|
|
|
|
|
(org-element-property :post-blank (org-element-at-point)))))
|
|
|
|
|
(should
|
|
|
|
|
(= 0
|
|
|
|
|
(org-test-with-temp-text "- A\n\n - B\n\n<point> - C\n\n End sub-list"
|
|
|
|
|
(org-element-property :post-blank (org-element-at-point))))))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
|
|
|
|
|
|
2012-05-05 17:57:37 +00:00
|
|
|
|
;;;; Keyword
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/keyword-parser ()
|
|
|
|
|
"Test `keyword' parser."
|
|
|
|
|
;; Standard test.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "#+KEYWORD: value"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'keyword 'identity)))
|
|
|
|
|
;; Keywords are case-insensitive.
|
|
|
|
|
(should
|
2012-06-08 18:16:57 +00:00
|
|
|
|
(org-test-with-temp-text "#+keyword: value"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'keyword 'identity)))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
;; Affiliated keywords are not keywords.
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "#+NAME: value
|
|
|
|
|
Paragraph"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'keyword 'identity)))
|
|
|
|
|
;; Do not mix keywords with Babel calls and dynamic blocks.
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "#+CALL: fun()"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'keyword 'identity)))
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN: my-fun\nBody\n#+END:"
|
2013-11-10 10:28:14 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'keyword 'identity)))
|
|
|
|
|
;; Handle non-empty blank line at the end of buffer.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "#+KEYWORD: value\n "
|
|
|
|
|
(= (org-element-property :end (org-element-at-point)) (point-max)))))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Latex Environment
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/latex-environment-parser ()
|
|
|
|
|
"Test `latex-environment' parser."
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "\\begin{equation}\ne^{i\\pi}+1=0\n\\end{equation}"
|
2013-04-28 07:34:42 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'latex-environment 'identity)))
|
2012-05-10 20:55:12 +00:00
|
|
|
|
;; Allow nested environments.
|
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
"\\begin{outer}
|
|
|
|
|
\\begin{inner}
|
|
|
|
|
e^{i\\pi}+1=0
|
|
|
|
|
\\end{inner}
|
|
|
|
|
\\end{outer}"
|
|
|
|
|
(org-test-with-temp-text "
|
|
|
|
|
\\begin{outer}
|
|
|
|
|
\\begin{inner}
|
|
|
|
|
e^{i\\pi}+1=0
|
|
|
|
|
\\end{inner}
|
|
|
|
|
\\end{outer}"
|
|
|
|
|
(org-element-property
|
|
|
|
|
:value
|
|
|
|
|
(org-element-map
|
2013-04-28 07:34:42 +00:00
|
|
|
|
(org-element-parse-buffer) 'latex-environment 'identity nil t)))))
|
2013-05-12 15:15:06 +00:00
|
|
|
|
;; Allow environments with options and arguments.
|
2013-04-28 07:34:42 +00:00
|
|
|
|
(should
|
|
|
|
|
(eq 'latex-environment
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"\\begin{theorem}[Euler]\ne^{i\\pi}+1=0\n\\end{theorem}"
|
2013-05-12 15:15:06 +00:00
|
|
|
|
(org-element-type (org-element-at-point)))))
|
|
|
|
|
(should
|
|
|
|
|
(eq 'latex-environment
|
|
|
|
|
(org-test-with-temp-text "\\begin{env}{arg}\nvalue\n\\end{env}"
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
2014-07-22 13:09:03 +00:00
|
|
|
|
;; Allow environments without newline after \begin{.}.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'latex-environment
|
|
|
|
|
(org-test-with-temp-text "\\begin{env}{arg}something\nvalue\n\\end{env}"
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
|
|
|
|
;; Allow one-line environments.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'latex-environment
|
|
|
|
|
(org-test-with-temp-text "\\begin{env}{arg}something\\end{env}"
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
|
|
|
|
;; Should not allow different tags.
|
|
|
|
|
(should-not
|
|
|
|
|
(eq 'latex-environment
|
|
|
|
|
(org-test-with-temp-text "\\begin{env*}{arg}something\\end{env}"
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
|
|
|
|
;; LaTeX environments must be on separate lines.
|
|
|
|
|
(should-not
|
|
|
|
|
(eq 'latex-environment
|
|
|
|
|
(org-test-with-temp-text "\\begin{env} x \\end{env} y"
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
2013-05-12 15:15:06 +00:00
|
|
|
|
(should-not
|
|
|
|
|
(eq 'latex-environment
|
2014-07-22 13:09:03 +00:00
|
|
|
|
(org-test-with-temp-text "y \\begin{env} x<point> \\end{env}"
|
2013-11-10 10:28:14 +00:00
|
|
|
|
(org-element-type (org-element-at-point)))))
|
|
|
|
|
;; Handle non-empty blank line at the end of buffer.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "\\begin{env}\n\\end{env}\n "
|
|
|
|
|
(= (org-element-property :end (org-element-at-point)) (point-max)))))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Latex Fragment
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/latex-fragment-parser ()
|
|
|
|
|
"Test `latex-fragment' parser."
|
2017-06-26 20:07:05 +00:00
|
|
|
|
;; Basic $...$ test.
|
2013-10-24 15:15:23 +00:00
|
|
|
|
(should
|
2015-05-09 08:01:35 +00:00
|
|
|
|
(eq 'latex-fragment
|
|
|
|
|
(org-test-with-temp-text "$a$"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
2017-06-26 20:07:05 +00:00
|
|
|
|
;; Test valid characters after $...$ construct.
|
|
|
|
|
(should-not
|
|
|
|
|
(eq 'latex-fragment
|
|
|
|
|
(org-test-with-temp-text "$a$a"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
2013-10-24 15:15:23 +00:00
|
|
|
|
(should
|
2015-05-09 08:01:35 +00:00
|
|
|
|
(eq 'latex-fragment
|
|
|
|
|
(org-test-with-temp-text "$a$!"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
2013-10-24 15:15:23 +00:00
|
|
|
|
(should
|
2015-05-09 08:01:35 +00:00
|
|
|
|
(eq 'latex-fragment
|
|
|
|
|
(org-test-with-temp-text "$a$,"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
2013-10-24 15:15:23 +00:00
|
|
|
|
(should
|
2015-05-09 08:01:35 +00:00
|
|
|
|
(eq 'latex-fragment
|
|
|
|
|
(org-test-with-temp-text "$a$\""
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
(should
|
|
|
|
|
(eq 'latex-fragment
|
|
|
|
|
(org-test-with-temp-text "$a$)"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
(should
|
|
|
|
|
(eq 'latex-fragment
|
|
|
|
|
(org-test-with-temp-text "$a$ "
|
|
|
|
|
(org-element-type (org-element-context)))))
|
2017-05-13 07:18:07 +00:00
|
|
|
|
(should
|
|
|
|
|
(eq 'latex-fragment
|
|
|
|
|
(org-test-with-temp-text "$a$'"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
2017-06-26 20:07:05 +00:00
|
|
|
|
;; Test forbidden characters inside $...$.
|
2015-05-09 08:01:35 +00:00
|
|
|
|
(should-not
|
|
|
|
|
(eq 'latex-fragment
|
2017-06-26 20:07:05 +00:00
|
|
|
|
(org-test-with-temp-text "$.a$"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
(should-not
|
|
|
|
|
(eq 'latex-fragment
|
|
|
|
|
(org-test-with-temp-text "$,a$"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
(should-not
|
|
|
|
|
(eq 'latex-fragment
|
|
|
|
|
(org-test-with-temp-text "$;a$"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
(should-not
|
|
|
|
|
(eq 'latex-fragment
|
|
|
|
|
(org-test-with-temp-text "$ a$"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
(should-not
|
|
|
|
|
(eq 'latex-fragment
|
|
|
|
|
(org-test-with-temp-text "$a.$"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
(should-not
|
|
|
|
|
(eq 'latex-fragment
|
|
|
|
|
(org-test-with-temp-text "$a,$"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
(should-not
|
|
|
|
|
(eq 'latex-fragment
|
|
|
|
|
(org-test-with-temp-text "$a $"
|
2015-05-09 08:01:35 +00:00
|
|
|
|
(org-element-type (org-element-context)))))
|
2017-06-26 20:07:05 +00:00
|
|
|
|
;; Test $$...$$.
|
2015-05-09 08:01:35 +00:00
|
|
|
|
(should
|
|
|
|
|
(eq 'latex-fragment
|
|
|
|
|
(org-test-with-temp-text "$$a$$"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
2017-06-26 20:07:05 +00:00
|
|
|
|
;; Test \(...\).
|
2015-05-09 08:01:35 +00:00
|
|
|
|
(should
|
|
|
|
|
(eq 'latex-fragment
|
|
|
|
|
(org-test-with-temp-text "\\(a\\)"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
2017-06-26 20:07:05 +00:00
|
|
|
|
;; Test \[...\].
|
2015-05-09 08:01:35 +00:00
|
|
|
|
(should
|
|
|
|
|
(eq 'latex-fragment
|
|
|
|
|
(org-test-with-temp-text "\\[a\\]"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
2013-10-24 15:15:23 +00:00
|
|
|
|
;; Test fragment at the beginning of an item.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'latex-fragment
|
2015-05-09 08:01:35 +00:00
|
|
|
|
(org-test-with-temp-text "- $<point>x$"
|
|
|
|
|
(org-element-type (org-element-context))))))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Line Break
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/line-break-parser ()
|
|
|
|
|
"Test `line-break' parser."
|
|
|
|
|
;; Regular test.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "Text \\\\"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'line-break 'identity)))
|
|
|
|
|
;; Line break with trailing white spaces.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "Text \\\\ "
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'line-break 'identity)))
|
|
|
|
|
;; Three backslashes are too much.
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "Text \\\\\\"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'line-break 'identity))))
|
|
|
|
|
|
|
|
|
|
|
2012-05-04 17:24:51 +00:00
|
|
|
|
;;;; Link
|
2012-05-01 13:08:08 +00:00
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/link-parser ()
|
2012-05-04 17:24:51 +00:00
|
|
|
|
"Test `link' parser."
|
2013-02-25 20:32:15 +00:00
|
|
|
|
;; Radio target.
|
2012-05-01 13:08:08 +00:00
|
|
|
|
(should
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(equal
|
|
|
|
|
"radio"
|
2014-04-10 20:23:27 +00:00
|
|
|
|
(org-test-with-temp-text "<<<radio>>>A radio link"
|
|
|
|
|
(org-update-radio-target-regexp)
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(org-element-property
|
|
|
|
|
:type
|
2014-04-10 20:23:27 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'link #'identity nil t)))))
|
2016-10-26 22:41:19 +00:00
|
|
|
|
;; Pathological case: radio target of length 1 at beginning of line
|
|
|
|
|
;; not followed by spaces.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "* <<<a>>>\n<point>a-bug"
|
|
|
|
|
(org-update-radio-target-regexp)
|
|
|
|
|
(org-element-parse-buffer)))
|
2017-04-15 15:27:01 +00:00
|
|
|
|
;; Pathological case: radio target in an emphasis environment.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'bold
|
|
|
|
|
(org-test-with-temp-text "* <<<radio>>>\n<point>*radio*"
|
|
|
|
|
(org-update-radio-target-regexp)
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
(should
|
|
|
|
|
(eq 'link
|
|
|
|
|
(org-test-with-temp-text "* <<<radio>>>\n*<point>radio*"
|
|
|
|
|
(org-update-radio-target-regexp)
|
|
|
|
|
(org-element-type (org-element-context)))))
|
2013-02-25 20:32:15 +00:00
|
|
|
|
;; Standard link.
|
2012-05-01 13:08:08 +00:00
|
|
|
|
;;
|
2013-02-25 20:32:15 +00:00
|
|
|
|
;; ... with description.
|
2012-05-01 13:08:08 +00:00
|
|
|
|
(should
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(equal
|
|
|
|
|
'("Orgmode.org")
|
2018-01-16 18:42:57 +00:00
|
|
|
|
(org-test-with-temp-text "[[https://orgmode.org][Orgmode.org]]"
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(org-element-contents
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'link 'identity nil t)))))
|
2013-02-25 20:32:15 +00:00
|
|
|
|
;; ... without description.
|
2012-05-01 13:08:08 +00:00
|
|
|
|
(should
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(equal
|
2018-01-16 18:42:57 +00:00
|
|
|
|
"https"
|
|
|
|
|
(org-test-with-temp-text "[[https://orgmode.org]]"
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(org-element-property
|
|
|
|
|
:type
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'link 'identity nil t)))))
|
2013-02-25 20:32:15 +00:00
|
|
|
|
;; ... with expansion.
|
2012-05-01 13:08:08 +00:00
|
|
|
|
(should
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(equal
|
2014-04-17 06:41:14 +00:00
|
|
|
|
"//orgmode.org/worg"
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(org-test-with-temp-text "[[Org:worg]]"
|
2018-01-16 18:42:57 +00:00
|
|
|
|
(let ((org-link-abbrev-alist '(("Org" . "https://orgmode.org/"))))
|
2014-04-17 06:41:14 +00:00
|
|
|
|
(org-element-property
|
|
|
|
|
:path
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'link 'identity nil t))))))
|
2013-02-25 20:32:15 +00:00
|
|
|
|
;; ... with translation.
|
2012-05-01 13:08:08 +00:00
|
|
|
|
(should
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(equal
|
|
|
|
|
"127.0.0.1"
|
2018-01-16 18:42:57 +00:00
|
|
|
|
(org-test-with-temp-text "[[https://orgmode.org]]"
|
2016-06-04 19:48:02 +00:00
|
|
|
|
(let ((org-link-translation-function
|
|
|
|
|
(lambda (type _) (cons type "127.0.0.1"))))
|
|
|
|
|
(org-element-property
|
|
|
|
|
:path
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'link
|
|
|
|
|
#'identity nil t))))))
|
2013-02-25 20:32:15 +00:00
|
|
|
|
;; ... custom-id link.
|
2012-05-01 13:08:08 +00:00
|
|
|
|
(should
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(equal
|
|
|
|
|
"custom-id"
|
|
|
|
|
(org-test-with-temp-text "[[#some-id]]"
|
|
|
|
|
(org-element-property
|
|
|
|
|
:type
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'link 'identity nil t)))))
|
2013-02-25 20:32:15 +00:00
|
|
|
|
;; ... coderef link.
|
2012-05-01 13:08:08 +00:00
|
|
|
|
(should
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(equal
|
|
|
|
|
"coderef"
|
|
|
|
|
(org-test-with-temp-text "[[(reference)]]"
|
|
|
|
|
(org-element-property
|
|
|
|
|
:type
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'link 'identity nil t)))))
|
2013-02-25 20:32:15 +00:00
|
|
|
|
;; ... fuzzy link.
|
2012-05-01 13:08:08 +00:00
|
|
|
|
(should
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(equal
|
|
|
|
|
"fuzzy"
|
|
|
|
|
(org-test-with-temp-text "[[target-or-title]]"
|
|
|
|
|
(org-element-property
|
|
|
|
|
:type
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'link 'identity nil t)))))
|
2013-02-25 20:32:15 +00:00
|
|
|
|
;; ... file-type link with search option.
|
2012-08-25 08:38:25 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
'(("file" "projects.org" "*task title"))
|
|
|
|
|
(org-test-with-temp-text "[[file:projects.org::*task title]]"
|
2013-02-25 20:32:15 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'link
|
|
|
|
|
(lambda (l) (list (org-element-property :type l)
|
2015-04-20 10:35:41 +00:00
|
|
|
|
(org-element-property :path l)
|
|
|
|
|
(org-element-property :search-option l)))))))
|
2014-07-26 08:47:29 +00:00
|
|
|
|
;; ... file-type link with application...
|
2012-08-25 08:38:25 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal
|
2015-02-03 22:00:21 +00:00
|
|
|
|
'("file" "projects.org" "emacs")
|
|
|
|
|
(org-test-with-temp-text "[[file+emacs:projects.org]]"
|
2014-07-26 08:47:29 +00:00
|
|
|
|
(let ((l (org-element-context)))
|
|
|
|
|
(list (org-element-property :type l)
|
|
|
|
|
(org-element-property :path l)
|
|
|
|
|
(org-element-property :application l))))))
|
2014-04-19 19:28:34 +00:00
|
|
|
|
;; ... `:path' in a file-type link must be compatible with "file"
|
2014-07-26 13:10:22 +00:00
|
|
|
|
;; scheme in URI syntax, even if Org syntax isn't...
|
2014-04-19 19:28:34 +00:00
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text-in-file ""
|
|
|
|
|
(let ((file (expand-file-name (buffer-file-name))))
|
|
|
|
|
(insert (format "[[file://%s]]" file))
|
2015-04-20 10:35:41 +00:00
|
|
|
|
(equal (org-element-property :path (org-element-context)) file))))
|
2014-04-19 19:28:34 +00:00
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text-in-file ""
|
|
|
|
|
(let ((file (expand-file-name (buffer-file-name))))
|
|
|
|
|
(insert (format "[[file:%s]]" file))
|
2015-04-20 10:35:41 +00:00
|
|
|
|
(equal (org-element-property :path (org-element-context)) file))))
|
2014-04-19 19:28:34 +00:00
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text-in-file ""
|
2015-04-20 10:35:41 +00:00
|
|
|
|
(let ((file (expand-file-name (buffer-file-name))))
|
2014-04-19 19:28:34 +00:00
|
|
|
|
(insert (format "[[file:%s]]" file))
|
2015-04-20 10:35:41 +00:00
|
|
|
|
(equal (org-element-property :path (org-element-context)) file))))
|
2014-07-26 08:47:29 +00:00
|
|
|
|
;; ... multi-line link.
|
|
|
|
|
(should
|
2015-08-04 14:40:25 +00:00
|
|
|
|
(equal "ls *.org"
|
|
|
|
|
(org-test-with-temp-text "[[shell:ls\n*.org]]"
|
2014-07-26 08:47:29 +00:00
|
|
|
|
(org-element-property :path (org-element-context)))))
|
2014-07-26 13:11:38 +00:00
|
|
|
|
;; Plain link.
|
2012-05-01 13:08:08 +00:00
|
|
|
|
(should
|
2018-01-16 18:42:57 +00:00
|
|
|
|
(org-test-with-temp-text "A link: https://orgmode.org"
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'link 'identity)))
|
2015-08-04 14:40:25 +00:00
|
|
|
|
;; Angular link. Follow RFC 3986.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'link
|
2018-01-16 18:42:57 +00:00
|
|
|
|
(org-test-with-temp-text "A link: <point><https://orgmode.org>"
|
2015-08-04 14:40:25 +00:00
|
|
|
|
(org-element-type (org-element-context)))))
|
2012-05-01 13:08:08 +00:00
|
|
|
|
(should
|
2015-08-04 14:40:25 +00:00
|
|
|
|
(equal "//orgmode.org"
|
2018-01-16 18:42:57 +00:00
|
|
|
|
(org-test-with-temp-text "A link: <point><https://orgmode\n.org>"
|
2016-04-06 09:08:53 +00:00
|
|
|
|
(org-element-property :path (org-element-context)))))
|
2012-12-18 21:16:01 +00:00
|
|
|
|
;; Link abbreviation.
|
|
|
|
|
(should
|
2018-01-16 18:42:57 +00:00
|
|
|
|
(equal "https"
|
2012-12-18 21:16:01 +00:00
|
|
|
|
(org-test-with-temp-text
|
2018-01-16 18:42:57 +00:00
|
|
|
|
"#+LINK: orgmode https://www.orgmode.org/\n[[orgmode:#docs]]"
|
2012-12-18 21:16:01 +00:00
|
|
|
|
(progn (org-mode-restart)
|
org-element: Fix parsing error in `org-element-context'
* lisp/org-element.el (org-element-text-markup-successor,
org-element-latex-or-entity-successor,
org-element-export-snippet-successor,
org-element-footnote-reference-successor,
org-element-inline-babel-call-successor,
org-element-inline-src-block-successor,
org-element-line-break-successor, org-element-link-successor,
org-element-plain-link-successor, org-element-macro-successor,
org-element-radio-target-successor,
org-element-statistics-cookie-successor,
org-element-sub/superscript-successor,
org-element-table-cell-successor, org-element-target-successor,
org-element-timestamp-successor): Remove LIMIT argument.
(org-element--parse-objects, org-element--get-next-object-candidates):
Apply signature change to successors.
(org-element-context): Narrow buffer around object containers so
parsing of objects when using this function is done under the same
restrictions as in buffer parsing.
* testing/lisp/test-org-element.el: Add test.
2013-08-30 11:29:51 +00:00
|
|
|
|
(goto-char (1- (point-max)))
|
2012-12-18 21:16:01 +00:00
|
|
|
|
(org-element-property :type (org-element-context))))))
|
|
|
|
|
;; Link abbreviation in a secondary string.
|
|
|
|
|
(should
|
2018-01-16 18:42:57 +00:00
|
|
|
|
(equal "https"
|
2012-12-18 21:16:01 +00:00
|
|
|
|
(org-test-with-temp-text
|
2018-01-16 18:42:57 +00:00
|
|
|
|
"#+LINK: orgmode https://www.orgmode.org/\n* H [[orgmode:#docs]]"
|
2012-12-18 21:16:01 +00:00
|
|
|
|
(progn (org-mode-restart)
|
2013-02-25 20:32:15 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'link
|
|
|
|
|
(lambda (link) (org-element-property :type link))
|
2016-12-17 10:35:50 +00:00
|
|
|
|
nil t nil t))))))
|
2012-05-01 13:08:08 +00:00
|
|
|
|
|
2012-05-04 17:24:51 +00:00
|
|
|
|
|
2012-05-05 17:57:37 +00:00
|
|
|
|
;;;; Macro
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/macro-parser ()
|
|
|
|
|
"Test `macro' parser."
|
|
|
|
|
;; Without arguments.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "{{{macro}}}"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'macro 'identity)))
|
|
|
|
|
;; With arguments.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "{{{macro(arg1,arg2)}}}"
|
2013-01-31 21:15:15 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'macro 'identity)))
|
|
|
|
|
;; Properly handle protected commas in arguments...
|
|
|
|
|
(should
|
|
|
|
|
(= 2
|
|
|
|
|
(length
|
|
|
|
|
(org-test-with-temp-text "{{{macro(arg1\\,arg1,arg2)}}}"
|
|
|
|
|
(org-element-property :args (org-element-context))))))
|
|
|
|
|
;; ... even when last argument ends with a protected comma.
|
|
|
|
|
(should
|
|
|
|
|
(equal '("C-,")
|
|
|
|
|
(org-test-with-temp-text "{{{macro(C-\\,)}}}"
|
org-element: Allow to escape escaping character before a comma
* lisp/org-element.el (org-element-macro-parser): Allow to escape
escaping character before a comma. Also do not trim spaces at
argument boundaries.
* doc/org.texi (Macro replacement): Update documentation about
possible locations and escaping mechanism.
* testing/lisp/test-org-element.el: Add tests.
With this patch, macro's arguments are read as the following:
"a,b" -> '("a" "b")
"a\,b" -> '("a,b")
"a\\,b" -> '("a\" "b")
"a\\\,b" -> '("a\,b")
"a\\\\,b" -> '(a"\\" "b")
Note that with the patch, you only need to escape backslashes before
a comma:
"a\\b\,c" -> '("a\\b,c")
2013-03-23 18:10:41 +00:00
|
|
|
|
(org-element-property :args (org-element-context)))))
|
|
|
|
|
;; Allow to escape escaping character.
|
|
|
|
|
(should
|
|
|
|
|
(equal '("C-\\" "")
|
|
|
|
|
(org-test-with-temp-text "{{{macro(C-\\\\,)}}}"
|
|
|
|
|
(org-element-property :args (org-element-context)))))
|
|
|
|
|
;; No need to escape backslashes elsewhere.
|
|
|
|
|
(should
|
|
|
|
|
(equal '("\\")
|
|
|
|
|
(org-test-with-temp-text "{{{macro(\\)}}}"
|
2013-01-31 21:15:15 +00:00
|
|
|
|
(org-element-property :args (org-element-context))))))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
|
|
|
|
|
|
2012-09-23 13:52:02 +00:00
|
|
|
|
;;;; Node Property
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/node-property ()
|
|
|
|
|
"Test `node-property' parser."
|
|
|
|
|
;; Standard test.
|
|
|
|
|
(should
|
|
|
|
|
(equal '("abc" "value")
|
2014-09-13 20:43:45 +00:00
|
|
|
|
(org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:abc: value\n:END:"
|
2014-08-31 09:10:56 +00:00
|
|
|
|
(let ((element (org-element-at-point)))
|
|
|
|
|
(list (org-element-property :key element)
|
|
|
|
|
(org-element-property :value element))))))
|
Org document property-drawers
Add functionality to define property-blocks on document level, in
addition to at headline level.
* doc/org-manual.org:
* etc/ORG-NEWS: Document new functionality.
* lisp/org.el (org-keyword-regexp): Define constant instead of
hardcoding.
(org-file-properties): Renamed, see next line.
(org-keyword-properties): Renamed from above. Due to the fact that
properties can be defined for the whole document using property
drawers this local variable needs a rename to make its name less
ambigous.
(org-refresh-properties, org-refresh-property, org-entry-properties)
(org-refresh-category-properties, org-get-property-block)
(org-entry-get-with-inheritance, org-entry-put)
(org-insert-property-drawer, org-end-of-subtree): Made to work before
first headline.
(org-at-property-block-p): New function to validate if point is at the
start of a property block.
(org-property-global-value): Renamed, see next line.
(org-property-global-or-keyword-value): Renamed from above to match
its functionality better.
(org-back-to-heading-or-point-min): New function to make a document
work as a level 0 node in the outline.
(org-at-keyword-p): Predicate function to answer to if we're currently
at a keyword line or not.
(org-up-heading-or-point-min): New function to make a document work as
a level 0 node in the outline.
* lisp/org-element.el (org-element--current-element): Can now detect
property-blocks before first headline according to it's positional
rules.
* lisp/org-attach.el (org-attach): Make it possible to call the
attachment dispatcher also before the first headline, since document
property drawers make attachments possible for the whole document
now.
* lisp/org-capture.el: Modified only due to rename of function in
org.el.
* lisp/org-compat.el (org-file-properties)
(org-property-global-value): Renamed functions declared obsolete.
* testing/lisp/test-org.el (org/insert-property-drawer)
(org/set-property, org/delete-property, org/delete-property-globally):
Additions of tests to check if they work before first headline.
(org/at-property-p, org/at-property-block-p, org/get-property-block)
(org/entry-get, org/refresh-properties): New tests
* testing/examples/property-inheritance.org: Switch from
property-keywords to a property-drawer in the testfile.
Functionality should be the same, but now using a document drawer
instead of property-keywords.
Reason for switching is that I'd like us to slowly depricate
property-keywords.
* testing/lisp/test-org-element.el:
* contrib/lisp/ox-taskjuggler.el: A comment is modified only due to
rename of function in org.el.
2019-05-26 20:13:09 +00:00
|
|
|
|
;; The insides of property blocks on document level are parsed the
|
|
|
|
|
;; same way as headline property blocks. I.e. the concept of
|
|
|
|
|
;; `node-property' apply also for properties in those blocks.
|
|
|
|
|
(should
|
|
|
|
|
(equal '("abc" "value")
|
|
|
|
|
(org-test-with-temp-text ":PROPERTIES:\n<point>:abc: value\n:END:"
|
|
|
|
|
(let ((element (org-element-at-point)))
|
|
|
|
|
(list (org-element-property :key element)
|
|
|
|
|
(org-element-property :value element))))))
|
2012-09-23 13:52:02 +00:00
|
|
|
|
;; Value should be trimmed.
|
|
|
|
|
(should
|
|
|
|
|
(equal "value"
|
2014-09-13 20:43:45 +00:00
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"* H\n:PROPERTIES:\n<point>:abc: value \n:END:"
|
2014-08-31 09:10:56 +00:00
|
|
|
|
(org-element-property :value (org-element-at-point)))))
|
2012-09-23 13:52:02 +00:00
|
|
|
|
;; A node property requires to be wrapped within a property drawer.
|
|
|
|
|
(should-not
|
|
|
|
|
(eq 'node-property
|
|
|
|
|
(org-test-with-temp-text ":abc: value"
|
2014-08-31 09:10:56 +00:00
|
|
|
|
(org-element-type (org-element-at-point)))))
|
|
|
|
|
;; Accept empty properties.
|
|
|
|
|
(should
|
2014-09-02 10:30:57 +00:00
|
|
|
|
(equal '(("foo" "value") ("bar" ""))
|
2014-09-13 20:43:45 +00:00
|
|
|
|
(org-test-with-temp-text "* H\n:PROPERTIES:\n:foo: value\n:bar:\n:END:"
|
2014-08-31 09:10:56 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'node-property
|
|
|
|
|
(lambda (p)
|
|
|
|
|
(list (org-element-property :key p)
|
2014-09-13 20:43:45 +00:00
|
|
|
|
(org-element-property :value p))))))))
|
2012-09-23 13:52:02 +00:00
|
|
|
|
|
|
|
|
|
|
2012-07-28 12:35:35 +00:00
|
|
|
|
;;;; Paragraph
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/paragraph-parser ()
|
|
|
|
|
"Test `paragraph' parser."
|
|
|
|
|
;; Standard test.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "Paragraph"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'paragraph 'identity nil t)))
|
|
|
|
|
;; Property find end of a paragraph stuck to another element.
|
|
|
|
|
(should
|
|
|
|
|
(eq ?#
|
|
|
|
|
(org-test-with-temp-text "Paragraph\n# Comment"
|
2013-11-10 10:28:14 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'paragraph
|
|
|
|
|
(lambda (p) (char-after (org-element-property :end p)))
|
|
|
|
|
nil t))))
|
2012-08-17 15:24:33 +00:00
|
|
|
|
;; Include ill-formed Keywords.
|
2012-08-17 13:22:36 +00:00
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "#+wrong_keyword something"
|
2012-08-17 15:24:33 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'paragraph 'identity)))
|
|
|
|
|
;; Include incomplete-drawers.
|
|
|
|
|
(should
|
2013-10-20 12:40:09 +00:00
|
|
|
|
(org-test-with-temp-text ":TEST:\nParagraph"
|
|
|
|
|
(let ((elem (org-element-at-point)))
|
|
|
|
|
(and (eq (org-element-type elem) 'paragraph)
|
|
|
|
|
(= (point-max) (org-element-property :end elem))))))
|
2012-08-17 15:24:33 +00:00
|
|
|
|
;; Include incomplete blocks.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_CENTER\nParagraph"
|
|
|
|
|
(let ((elem (org-element-at-point)))
|
|
|
|
|
(and (eq (org-element-type elem) 'paragraph)
|
|
|
|
|
(= (point-max) (org-element-property :end elem))))))
|
|
|
|
|
;; Include incomplete dynamic blocks.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN: \nParagraph"
|
|
|
|
|
(let ((elem (org-element-at-point)))
|
|
|
|
|
(and (eq (org-element-type elem) 'paragraph)
|
2012-08-25 13:26:33 +00:00
|
|
|
|
(= (point-max) (org-element-property :end elem))))))
|
|
|
|
|
;; Include incomplete latex environments.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "\begin{equation}\nParagraph"
|
|
|
|
|
(let ((elem (org-element-at-point)))
|
|
|
|
|
(and (eq (org-element-type elem) 'paragraph)
|
|
|
|
|
(= (point-max) (org-element-property :end elem))))))
|
2015-04-27 20:24:00 +00:00
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "Paragraph\n\begin{equation}"
|
|
|
|
|
(let ((elem (org-element-at-point)))
|
|
|
|
|
(and (eq (org-element-type elem) 'paragraph)
|
|
|
|
|
(= (point-max) (org-element-property :end elem))))))
|
|
|
|
|
;; Stop at affiliated keywords.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "Paragraph\n#+NAME: test\n| table |"
|
|
|
|
|
(let ((elem (org-element-at-point)))
|
|
|
|
|
(and (eq (org-element-type elem) 'paragraph)
|
|
|
|
|
(not (org-element-property :name elem))
|
|
|
|
|
(= (org-element-property :end elem) (line-beginning-position 2))))))
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"Paragraph\n#+CAPTION[with short caption]: test\n| table |"
|
|
|
|
|
(let ((elem (org-element-at-point)))
|
|
|
|
|
(and (eq (org-element-type elem) 'paragraph)
|
|
|
|
|
(not (org-element-property :name elem))
|
|
|
|
|
(= (org-element-property :end elem) (line-beginning-position 2))))))
|
2012-08-25 13:26:33 +00:00
|
|
|
|
;; Do not steal affiliated keywords from container.
|
|
|
|
|
(should
|
2015-04-27 20:24:00 +00:00
|
|
|
|
(org-test-with-temp-text "#+ATTR_LATEX: test\n- item<point> 1"
|
|
|
|
|
(let ((elem (org-element-at-point)))
|
2012-08-25 13:26:33 +00:00
|
|
|
|
(and (eq (org-element-type elem) 'paragraph)
|
|
|
|
|
(not (org-element-property :attr_latex elem))
|
2013-11-10 10:28:14 +00:00
|
|
|
|
(/= (org-element-property :begin elem) 1)))))
|
|
|
|
|
;; Handle non-empty blank line at the end of buffer.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_CENTER\nC\n#+END_CENTER\n "
|
|
|
|
|
(= (org-element-property :end (org-element-at-point)) (point-max)))))
|
2012-07-28 12:35:35 +00:00
|
|
|
|
|
|
|
|
|
|
2012-05-05 17:57:37 +00:00
|
|
|
|
;;;; Plain List
|
2012-05-04 17:24:51 +00:00
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/plain-list-parser ()
|
|
|
|
|
"Test `plain-list' parser."
|
2013-06-01 19:38:15 +00:00
|
|
|
|
(org-test-with-temp-text "- item"
|
|
|
|
|
(should (org-element-map (org-element-parse-buffer) 'plain-list 'identity)))
|
2017-11-04 20:50:11 +00:00
|
|
|
|
;; Blank lines after a list or sub-list belongs to that list.
|
|
|
|
|
(should
|
|
|
|
|
(= 1
|
|
|
|
|
(org-test-with-temp-text "- A\n\n- B\n\nEnd list"
|
|
|
|
|
(org-element-property :post-blank (org-element-at-point)))))
|
|
|
|
|
(should
|
|
|
|
|
(= 1
|
|
|
|
|
(org-test-with-temp-text "- A\n\n<point> - B\n\n - C\n\n End sub-list"
|
|
|
|
|
(org-element-property :post-blank (org-element-at-point)))))
|
|
|
|
|
;; Blank lines after the list only belong to outer plain list,
|
|
|
|
|
;; however.
|
2013-06-01 19:38:15 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
'(t t)
|
|
|
|
|
(org-test-with-temp-text "
|
2012-05-04 17:24:51 +00:00
|
|
|
|
- outer
|
|
|
|
|
- inner
|
|
|
|
|
|
|
|
|
|
Outside list"
|
2013-06-01 19:38:15 +00:00
|
|
|
|
(let ((endings (org-element-map (org-element-parse-buffer) 'plain-list
|
|
|
|
|
(lambda (pl) (org-element-property :end pl)))))
|
|
|
|
|
(list
|
|
|
|
|
;; Move to ending of outer list.
|
|
|
|
|
(progn (goto-char (car endings)) (looking-at "Outside list"))
|
|
|
|
|
;; Move to ending of inner list.
|
2013-07-21 13:54:08 +00:00
|
|
|
|
(progn (goto-char (nth 1 endings)) (looking-at "^$")))))))
|
2013-07-21 13:51:14 +00:00
|
|
|
|
;; Correctly compute end of list if it doesn't end at a line
|
|
|
|
|
;; beginning.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "- list\n \n "
|
|
|
|
|
(= (org-element-property :end (org-element-at-point)) (point-max)))))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
|
|
|
|
|
|
2012-05-05 17:57:37 +00:00
|
|
|
|
;;;; Planning
|
2012-05-04 17:24:51 +00:00
|
|
|
|
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(ert-deftest test-org-element/planning-parser ()
|
|
|
|
|
"Test `planning' parser."
|
2014-08-31 13:39:35 +00:00
|
|
|
|
;; Test various keywords.
|
2012-05-04 17:24:51 +00:00
|
|
|
|
(should
|
2014-08-31 13:39:35 +00:00
|
|
|
|
(org-element-property
|
|
|
|
|
:closed
|
|
|
|
|
(org-test-with-temp-text "* H\n<point>CLOSED: [2012-03-29 thu.]"
|
|
|
|
|
(org-element-at-point))))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(should
|
2014-08-31 13:39:35 +00:00
|
|
|
|
(org-element-property
|
|
|
|
|
:deadline
|
|
|
|
|
(org-test-with-temp-text "* H\n<point>DEADLINE: <2012-03-29 thu.>"
|
|
|
|
|
(org-element-at-point))))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(should
|
2014-08-31 13:39:35 +00:00
|
|
|
|
(org-element-property
|
|
|
|
|
:scheduled
|
|
|
|
|
(org-test-with-temp-text "* H\n<point>SCHEDULED: <2012-03-29 thu.>"
|
|
|
|
|
(org-element-at-point))))
|
|
|
|
|
;; Planning line only exists right after a headline.
|
|
|
|
|
(should-not
|
|
|
|
|
(eq 'planning
|
|
|
|
|
(org-test-with-temp-text "DEADLINE: <2012-03-29 thu.>"
|
2014-09-13 20:31:06 +00:00
|
|
|
|
(org-element-type (org-element-at-point)))))
|
|
|
|
|
(should-not
|
|
|
|
|
(eq 'planning
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"* H\n# Comment\n<point>DEADLINE: <2012-03-29 thu.>"
|
2016-11-09 23:25:34 +00:00
|
|
|
|
(org-element-type (org-element-at-point)))))
|
|
|
|
|
(should-not
|
|
|
|
|
(eq 'planning
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"* H\n\n<point>DEADLINE: <2012-03-29 thu.>"
|
2014-08-31 13:39:35 +00:00
|
|
|
|
(org-element-type (org-element-at-point))))))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Property Drawer
|
|
|
|
|
|
2013-11-10 10:28:14 +00:00
|
|
|
|
(ert-deftest test-org-element/property-drawer-parser ()
|
2012-05-05 17:57:37 +00:00
|
|
|
|
"Test `property-drawer' parser."
|
|
|
|
|
;; Standard test.
|
|
|
|
|
(should
|
2014-09-13 20:43:45 +00:00
|
|
|
|
(eq 'property-drawer
|
|
|
|
|
(org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:prop: value\n:END:"
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
|
|
|
|
(should
|
|
|
|
|
(eq 'property-drawer
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"* H\nDEADLINE: <2014-03-04 tue.>\n<point>:PROPERTIES:\n:prop: value\n:END:"
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
2019-12-15 12:34:30 +00:00
|
|
|
|
;; Parse property drawer at the beginning of the document, possibly
|
|
|
|
|
;; after some initial comments.
|
Org document property-drawers
Add functionality to define property-blocks on document level, in
addition to at headline level.
* doc/org-manual.org:
* etc/ORG-NEWS: Document new functionality.
* lisp/org.el (org-keyword-regexp): Define constant instead of
hardcoding.
(org-file-properties): Renamed, see next line.
(org-keyword-properties): Renamed from above. Due to the fact that
properties can be defined for the whole document using property
drawers this local variable needs a rename to make its name less
ambigous.
(org-refresh-properties, org-refresh-property, org-entry-properties)
(org-refresh-category-properties, org-get-property-block)
(org-entry-get-with-inheritance, org-entry-put)
(org-insert-property-drawer, org-end-of-subtree): Made to work before
first headline.
(org-at-property-block-p): New function to validate if point is at the
start of a property block.
(org-property-global-value): Renamed, see next line.
(org-property-global-or-keyword-value): Renamed from above to match
its functionality better.
(org-back-to-heading-or-point-min): New function to make a document
work as a level 0 node in the outline.
(org-at-keyword-p): Predicate function to answer to if we're currently
at a keyword line or not.
(org-up-heading-or-point-min): New function to make a document work as
a level 0 node in the outline.
* lisp/org-element.el (org-element--current-element): Can now detect
property-blocks before first headline according to it's positional
rules.
* lisp/org-attach.el (org-attach): Make it possible to call the
attachment dispatcher also before the first headline, since document
property drawers make attachments possible for the whole document
now.
* lisp/org-capture.el: Modified only due to rename of function in
org.el.
* lisp/org-compat.el (org-file-properties)
(org-property-global-value): Renamed functions declared obsolete.
* testing/lisp/test-org.el (org/insert-property-drawer)
(org/set-property, org/delete-property, org/delete-property-globally):
Additions of tests to check if they work before first headline.
(org/at-property-p, org/at-property-block-p, org/get-property-block)
(org/entry-get, org/refresh-properties): New tests
* testing/examples/property-inheritance.org: Switch from
property-keywords to a property-drawer in the testfile.
Functionality should be the same, but now using a document drawer
instead of property-keywords.
Reason for switching is that I'd like us to slowly depricate
property-keywords.
* testing/lisp/test-org-element.el:
* contrib/lisp/ox-taskjuggler.el: A comment is modified only due to
rename of function in org.el.
2019-05-26 20:13:09 +00:00
|
|
|
|
(should
|
|
|
|
|
(eq 'property-drawer
|
|
|
|
|
(org-test-with-temp-text "<point>:PROPERTIES:\n:prop: value\n:END:"
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
|
|
|
|
(should
|
|
|
|
|
(eq 'property-drawer
|
|
|
|
|
(org-test-with-temp-text "# C\n# C\n<point>:PROPERTIES:\n:prop: value\n:END:"
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
|
|
|
|
(should-not
|
|
|
|
|
(eq 'property-drawer
|
|
|
|
|
(org-test-with-temp-text "\n<point>:PROPERTIES:\n:prop: value\n:END:"
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
2014-09-13 20:43:45 +00:00
|
|
|
|
;; Allow properties without value and no property at all.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'property-drawer
|
|
|
|
|
(org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:prop:\n:END:"
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
|
|
|
|
(should
|
|
|
|
|
(eq 'property-drawer
|
|
|
|
|
(org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:END:"
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
|
|
|
|
;; Ignore incomplete drawer, drawer at a wrong location or with
|
|
|
|
|
;; wrong contents.
|
2012-05-04 17:24:51 +00:00
|
|
|
|
(should-not
|
2014-09-13 20:43:45 +00:00
|
|
|
|
(eq 'property-drawer
|
|
|
|
|
(org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:prop: value"
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(should-not
|
2014-09-13 20:43:45 +00:00
|
|
|
|
(eq 'property-drawer
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"* H\nParagraph\n<point>:PROPERTIES:\n:prop: value\n:END:"
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
|
|
|
|
(should-not
|
|
|
|
|
(eq 'property-drawer
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"* H\nParagraph\n<point>:PROPERTIES:\nparagraph\n:END:"
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
2016-11-09 23:25:34 +00:00
|
|
|
|
(should-not
|
|
|
|
|
(eq 'property-drawer
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"* H\n\n<point>:PROPERTIES:\n:prop: value\n:END:"
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
2014-09-13 20:43:45 +00:00
|
|
|
|
;; Handle non-empty blank line at the end of buffer.
|
2013-11-10 10:28:14 +00:00
|
|
|
|
(should
|
2014-09-13 20:43:45 +00:00
|
|
|
|
(org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:END:\n "
|
2013-11-10 10:28:14 +00:00
|
|
|
|
(= (org-element-property :end (org-element-at-point)) (point-max)))))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Quote Block
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/quote-block-parser ()
|
|
|
|
|
"Test `quote-block' parser."
|
|
|
|
|
;; Regular test.
|
|
|
|
|
(should
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'quote-block 'identity)))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
;; Ignore incomplete block.
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_QUOTE"
|
2013-11-10 10:28:14 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'quote-block 'identity nil t)))
|
|
|
|
|
;; Handle non-empty blank line at the end of buffer.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_QUOTE\nC\n#+END_QUOTE\n "
|
|
|
|
|
(= (org-element-property :end (org-element-at-point)) (point-max)))))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
|
|
|
|
|
|
2012-05-05 17:57:37 +00:00
|
|
|
|
;;;; Radio Target
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/radio-target-parser ()
|
|
|
|
|
"Test `radio-target' parser."
|
|
|
|
|
;; Standard test.
|
|
|
|
|
(should
|
2014-03-23 10:28:26 +00:00
|
|
|
|
(eq 'radio-target
|
|
|
|
|
(org-test-with-temp-text "<<<radio>>>"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
;; Radio targets with objects.
|
|
|
|
|
(should
|
2014-03-23 10:28:26 +00:00
|
|
|
|
(eq 'radio-target
|
|
|
|
|
(org-test-with-temp-text "<<<radio \\alpha>>>"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
;; Radio targets starting with an object.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'radio-target
|
|
|
|
|
(org-test-with-temp-text "<<<\\alpha radio>>>"
|
2014-04-02 12:16:52 +00:00
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
;; Radio targets cannot begin or end with white space.
|
|
|
|
|
(should-not
|
|
|
|
|
(eq 'radio-target
|
|
|
|
|
(org-test-with-temp-text "<<< radio>>>"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
(should-not
|
|
|
|
|
(eq 'radio-target
|
|
|
|
|
(org-test-with-temp-text "<<<radio >>>"
|
2014-03-23 10:28:26 +00:00
|
|
|
|
(org-element-type (org-element-context))))))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
|
|
|
|
|
|
2012-05-04 17:24:51 +00:00
|
|
|
|
;;;; Section
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/section-parser ()
|
|
|
|
|
"Test `section' parser."
|
|
|
|
|
;; Standard test.
|
|
|
|
|
(should
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(org-test-with-temp-text "* Headline\nText"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'section 'identity)))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
;; There's a section before the first headline.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "Text"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'section 'identity)))
|
|
|
|
|
;; A section cannot be empty.
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "* Headline 1\n* Headline 2"
|
2012-09-01 20:52:43 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'section 'identity)))
|
|
|
|
|
;; A section doesn't contain sub-trees.
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "* Head\nText\n** Sub-Head"
|
|
|
|
|
(org-element-map
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'section 'identity nil t)
|
|
|
|
|
'headline 'identity))))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Special Block
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/special-block-parser ()
|
|
|
|
|
"Test `special-block' parser."
|
2012-05-05 17:57:37 +00:00
|
|
|
|
;; Standard test.
|
2013-06-17 15:08:53 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal "SPECIAL"
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_SPECIAL\nText\n#+END_SPECIAL"
|
|
|
|
|
(org-element-property :type (org-element-at-point)))))
|
2014-09-17 17:38:06 +00:00
|
|
|
|
;; Special blocks are case sensitive.
|
|
|
|
|
(should
|
|
|
|
|
(equal "CaSe"
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_CaSe\nText\n#+END_CaSe"
|
|
|
|
|
(org-element-property :type (org-element-at-point)))))
|
2013-06-17 15:08:53 +00:00
|
|
|
|
;; Special blocks can contain paragraphs.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'paragraph
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_SPECIAL\nText\n#+END_SPECIAL"
|
|
|
|
|
(forward-line)
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
;; Ignore incomplete block.
|
|
|
|
|
(should-not
|
2013-06-17 15:08:53 +00:00
|
|
|
|
(eq 'special-block
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_SPECIAL"
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
|
|
|
|
;; Allow special characters in type.
|
|
|
|
|
(should
|
|
|
|
|
(equal '(special-block "SPECIAL*")
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_SPECIAL*\nContents\n#+END_SPECIAL*"
|
|
|
|
|
(let ((element (org-element-at-point)))
|
|
|
|
|
(list (org-element-type element)
|
2013-11-10 10:28:14 +00:00
|
|
|
|
(org-element-property :type element))))))
|
|
|
|
|
;; Handle non-empty blank line at the end of buffer.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_SPECIAL\nC\n#+END_SPECIAL\n "
|
|
|
|
|
(= (org-element-property :end (org-element-at-point)) (point-max)))))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
|
|
|
|
|
|
2012-05-05 17:57:37 +00:00
|
|
|
|
;;;; Src Block
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/src-block-parser ()
|
|
|
|
|
"Test `src-block' parser."
|
|
|
|
|
;; Regular tests.
|
|
|
|
|
(should
|
2013-05-25 12:18:48 +00:00
|
|
|
|
(org-test-with-temp-text "#+BEGIN_SRC org\nText\n#+END_SRC"
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'src-block 'identity)))
|
|
|
|
|
;; Ignore incomplete block.
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_SRC"
|
2012-09-30 15:45:21 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'src-block 'identity)))
|
|
|
|
|
;; Properly un-escape code.
|
|
|
|
|
(should
|
|
|
|
|
(equal "* Headline\n #+keyword\nText\n"
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"#+BEGIN_SRC org\n,* Headline\n ,#+keyword\nText\n#+END_SRC"
|
2013-05-25 12:18:48 +00:00
|
|
|
|
(org-element-property :value (org-element-at-point)))))
|
2013-11-10 10:28:14 +00:00
|
|
|
|
;; Handle non-empty blank line at the end of buffer.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\nC\n#+END_SRC\n "
|
|
|
|
|
(= (org-element-property :end (org-element-at-point)) (point-max)))))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Statistics Cookie
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/statistics-cookie ()
|
|
|
|
|
"Test `statistics-cookie' parser."
|
|
|
|
|
;; With numbers.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "[1/2]"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'statistics-cookie 'identity)))
|
|
|
|
|
;; With percents.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "[33%]"
|
|
|
|
|
(org-element-map
|
|
|
|
|
(org-element-parse-buffer) 'statistics-cookie 'identity))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Strike Through
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/strike-through-parser ()
|
|
|
|
|
"Test `strike-through' parser."
|
|
|
|
|
;; Regular test.
|
|
|
|
|
(should
|
2016-12-08 08:44:26 +00:00
|
|
|
|
(org-test-with-temp-text "+strike-through+"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'strike-through #'identity)))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
;; Multi-line markup.
|
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
(org-element-contents
|
2016-12-08 08:44:26 +00:00
|
|
|
|
(org-test-with-temp-text "+first line\nsecond line+"
|
|
|
|
|
(org-element-map
|
|
|
|
|
(org-element-parse-buffer) 'strike-through #'identity nil t)))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
'("first line\nsecond line"))))
|
|
|
|
|
|
|
|
|
|
|
2012-07-10 15:21:36 +00:00
|
|
|
|
;;;; Subscript
|
2012-05-05 17:57:37 +00:00
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/subscript-parser ()
|
|
|
|
|
"Test `subscript' parser."
|
|
|
|
|
;; Without braces.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "a_b"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'subscript 'identity)))
|
|
|
|
|
;; With braces.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "a_{b}"
|
2012-10-14 19:34:22 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'subscript 'identity)))
|
2012-10-14 19:47:07 +00:00
|
|
|
|
;; Multiple subscripts in a paragraph.
|
|
|
|
|
(should
|
|
|
|
|
(= 2
|
|
|
|
|
(org-test-with-temp-text "a_b and c_d"
|
|
|
|
|
(length
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'subscript 'identity))))))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
|
|
|
|
|
|
2012-07-10 15:21:36 +00:00
|
|
|
|
;;;; Superscript
|
2012-05-05 17:57:37 +00:00
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/superscript-parser ()
|
|
|
|
|
"Test `superscript' parser."
|
|
|
|
|
;; Without braces.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "a^b"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'superscript 'identity)))
|
|
|
|
|
;; With braces.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "a^{b}"
|
2012-10-14 19:34:22 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'superscript 'identity)))
|
2012-10-14 19:47:07 +00:00
|
|
|
|
;; Multiple superscript in a paragraph.
|
|
|
|
|
(should
|
|
|
|
|
(= 2
|
|
|
|
|
(org-test-with-temp-text "a^b and c^d"
|
|
|
|
|
(length
|
|
|
|
|
(org-element-map
|
|
|
|
|
(org-element-parse-buffer) 'superscript 'identity))))))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Table
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/table-parser ()
|
|
|
|
|
"Test `table' parser."
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "| a |"
|
2012-05-11 13:17:14 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'table 'identity)))
|
|
|
|
|
;; TBLFM keyword is case insensitive.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "| a |\n#+tblfm: test"
|
|
|
|
|
(org-element-property
|
|
|
|
|
:tblfm
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'table 'identity nil t))))
|
|
|
|
|
;; Handle multiple TBLFM lines.
|
|
|
|
|
(should
|
|
|
|
|
(= 2
|
|
|
|
|
(org-test-with-temp-text "| a |\n#+TBLFM: test1\n#+TBLFM: test2"
|
|
|
|
|
(length (org-element-property
|
|
|
|
|
:tblfm
|
|
|
|
|
(org-element-map
|
2013-11-10 10:28:14 +00:00
|
|
|
|
(org-element-parse-buffer) 'table 'identity nil t))))))
|
|
|
|
|
;; Handle non-empty blank line at the end of buffer.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "| a |\n "
|
|
|
|
|
(= (org-element-property :end (org-element-at-point)) (point-max)))))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Table Cell
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/table-cell-parser ()
|
|
|
|
|
"Test `table-cell' parser."
|
2014-04-08 16:46:41 +00:00
|
|
|
|
;; Regular table cell.
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "| a |"
|
2014-04-08 16:46:41 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'table-cell 'identity)))
|
|
|
|
|
;; Last vertical bar may be omitted.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "| a "
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'table-cell 'identity))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Table Row
|
|
|
|
|
|
2012-05-11 13:17:14 +00:00
|
|
|
|
(ert-deftest test-org-element/table-row-parser ()
|
2012-05-05 17:57:37 +00:00
|
|
|
|
"Test `table-row' parser."
|
|
|
|
|
(should
|
|
|
|
|
(equal '(standard rule)
|
|
|
|
|
(org-test-with-temp-text "| a |\n|---|"
|
|
|
|
|
(org-element-map
|
|
|
|
|
(org-element-parse-buffer) 'table-row
|
|
|
|
|
(lambda (row) (org-element-property :type row)))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Target
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/target-parser ()
|
|
|
|
|
"Test `target' parser."
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "<<target>>"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'target 'identity))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Timestamp
|
|
|
|
|
|
2018-07-01 22:18:44 +00:00
|
|
|
|
(ert-deftest test-org-element/timestamp-parser ()
|
2012-05-05 17:57:37 +00:00
|
|
|
|
"Test `timestamp' parser."
|
|
|
|
|
;; Active timestamp.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "<2012-03-29 16:40>"
|
2012-09-28 12:50:21 +00:00
|
|
|
|
(eq (org-element-property :type (org-element-context)) 'active)))
|
2012-11-15 20:02:26 +00:00
|
|
|
|
(should-not
|
2012-11-15 20:46:08 +00:00
|
|
|
|
(org-test-with-temp-text "<2012-03-29 Thu>"
|
2012-11-15 20:02:26 +00:00
|
|
|
|
(let ((timestamp (org-element-context)))
|
|
|
|
|
(or (org-element-property :hour-start timestamp)
|
|
|
|
|
(org-element-property :minute-start timestamp)))))
|
2012-09-28 12:50:21 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal '(2012 3 29 16 40)
|
2012-11-15 20:46:08 +00:00
|
|
|
|
(org-test-with-temp-text "<2012-03-29 Thu 16:40>"
|
2012-09-28 12:50:21 +00:00
|
|
|
|
(let ((object (org-element-context)))
|
|
|
|
|
(list (org-element-property :year-start object)
|
|
|
|
|
(org-element-property :month-start object)
|
|
|
|
|
(org-element-property :day-start object)
|
|
|
|
|
(org-element-property :hour-start object)
|
|
|
|
|
(org-element-property :minute-start object))))))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
;; Inactive timestamp.
|
|
|
|
|
(should
|
2012-11-15 20:46:08 +00:00
|
|
|
|
(org-test-with-temp-text "[2012-03-29 Thu 16:40]"
|
2012-09-28 12:50:21 +00:00
|
|
|
|
(eq (org-element-property :type (org-element-context)) 'inactive)))
|
|
|
|
|
;; Time range.
|
|
|
|
|
(should
|
|
|
|
|
(equal '(2012 3 29 16 40 7 30)
|
2012-11-15 20:46:08 +00:00
|
|
|
|
(org-test-with-temp-text "<2012-03-29 Thu 7:30-16:40>"
|
2012-09-28 12:50:21 +00:00
|
|
|
|
(let ((object (org-element-context)))
|
|
|
|
|
(list (org-element-property :year-end object)
|
|
|
|
|
(org-element-property :month-end object)
|
|
|
|
|
(org-element-property :day-end object)
|
|
|
|
|
(org-element-property :hour-end object)
|
|
|
|
|
(org-element-property :minute-end object)
|
|
|
|
|
(org-element-property :hour-start object)
|
|
|
|
|
(org-element-property :minute-start object))))))
|
2012-11-15 20:46:08 +00:00
|
|
|
|
(should
|
|
|
|
|
(eq 'active-range
|
|
|
|
|
(org-test-with-temp-text "<2012-03-29 Thu 7:30-16:40>"
|
|
|
|
|
(org-element-property :type (org-element-context)))))
|
2012-07-17 14:33:45 +00:00
|
|
|
|
;; Date range.
|
|
|
|
|
(should
|
2012-11-15 20:46:08 +00:00
|
|
|
|
(org-test-with-temp-text "[2012-03-29 Thu 16:40]--[2012-03-29 Thu 16:41]"
|
2012-09-28 12:50:21 +00:00
|
|
|
|
(eq (org-element-property :type (org-element-context)) 'inactive-range)))
|
2012-11-15 20:02:26 +00:00
|
|
|
|
(should-not
|
2012-11-15 20:46:08 +00:00
|
|
|
|
(org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
|
2012-11-15 20:02:26 +00:00
|
|
|
|
(let ((timestamp (org-element-context)))
|
|
|
|
|
(or (org-element-property :hour-end timestamp)
|
|
|
|
|
(org-element-property :minute-end timestamp)))))
|
2013-10-13 08:17:16 +00:00
|
|
|
|
;; With repeater, warning delay and both.
|
2012-09-28 12:50:21 +00:00
|
|
|
|
(should
|
|
|
|
|
(eq 'catch-up
|
2012-11-15 20:46:08 +00:00
|
|
|
|
(org-test-with-temp-text "<2012-03-29 Thu ++1y>"
|
2012-09-28 12:50:21 +00:00
|
|
|
|
(org-element-property :repeater-type (org-element-context)))))
|
2013-10-13 08:17:16 +00:00
|
|
|
|
(should
|
|
|
|
|
(eq 'first
|
|
|
|
|
(org-test-with-temp-text "<2012-03-29 Thu --1y>"
|
|
|
|
|
(org-element-property :warning-type (org-element-context)))))
|
|
|
|
|
(should
|
|
|
|
|
(equal '(cumulate all)
|
|
|
|
|
(org-test-with-temp-text "<2012-03-29 Thu +1y -1y>"
|
|
|
|
|
(let ((ts (org-element-context)))
|
|
|
|
|
(list (org-element-property :repeater-type ts)
|
2014-08-31 13:39:35 +00:00
|
|
|
|
(org-element-property :warning-type ts)))))))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Underline
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/underline-parser ()
|
|
|
|
|
"Test `underline' parser."
|
|
|
|
|
;; Regular test.
|
|
|
|
|
(should
|
2016-12-08 08:44:26 +00:00
|
|
|
|
(org-test-with-temp-text "_underline_"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'underline #'identity)))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
;; Multi-line markup.
|
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
(org-element-contents
|
2016-12-08 08:44:26 +00:00
|
|
|
|
(org-test-with-temp-text "_first line\nsecond line_"
|
|
|
|
|
(org-element-map
|
|
|
|
|
(org-element-parse-buffer) 'underline #'identity nil t)))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
'("first line\nsecond line"))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Verbatim
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/verbatim-parser ()
|
|
|
|
|
"Test `verbatim' parser."
|
|
|
|
|
;; Regular test.
|
|
|
|
|
(should
|
2016-12-08 08:44:26 +00:00
|
|
|
|
(org-test-with-temp-text "=verbatim="
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'verbatim #'identity)))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
;; Multi-line markup.
|
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
(org-element-property
|
|
|
|
|
:value
|
2016-12-08 08:44:26 +00:00
|
|
|
|
(org-test-with-temp-text "=first line\nsecond line="
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'verbatim #'identity nil t)))
|
2012-05-05 17:57:37 +00:00
|
|
|
|
"first line\nsecond line")))
|
|
|
|
|
|
|
|
|
|
|
2012-05-04 17:24:51 +00:00
|
|
|
|
;;;; Verse Block
|
2012-04-25 20:15:29 +00:00
|
|
|
|
|
2012-05-01 13:08:08 +00:00
|
|
|
|
(ert-deftest test-org-element/verse-block-parser ()
|
2012-05-04 17:24:51 +00:00
|
|
|
|
"Test `verse-block' parser."
|
2012-04-25 20:15:29 +00:00
|
|
|
|
;; Standard test.
|
org-element: Remove folding status in parsed data
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-item-parser, org-element-quote-block-parser,
org-element-comment-block-parser, org-element-export-block-parser,
org-element-verse-block-parser, org-element-special-block-parser,
org-element-example-block-parser, org-element-headline-parser,
org-element-inlinetask-parser): Remove :hiddenp property.
* lisp/org.el (org-end-of-line, org-down-element): Use an equivalent
of :hiddenp property.
* testing/lisp/test-org-element.el: Remove tests.
The property is removed because it is buggy (e.g., when there's a link
just after a block opening line) and not really useful.
2013-10-03 20:57:02 +00:00
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_VERSE\nVerse block\n#+END_VERSE"
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'verse-block 'identity)))
|
2012-04-25 20:15:29 +00:00
|
|
|
|
;; Ignore case.
|
org-element: Remove folding status in parsed data
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-item-parser, org-element-quote-block-parser,
org-element-comment-block-parser, org-element-export-block-parser,
org-element-verse-block-parser, org-element-special-block-parser,
org-element-example-block-parser, org-element-headline-parser,
org-element-inlinetask-parser): Remove :hiddenp property.
* lisp/org.el (org-end-of-line, org-down-element): Use an equivalent
of :hiddenp property.
* testing/lisp/test-org-element.el: Remove tests.
The property is removed because it is buggy (e.g., when there's a link
just after a block opening line) and not really useful.
2013-10-03 20:57:02 +00:00
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "#+begin_verse\nVerse block\n#+end_verse"
|
2012-05-05 17:57:37 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'verse-block 'identity)))
|
2012-04-25 20:15:29 +00:00
|
|
|
|
;; Parse objects in verse blocks.
|
org-element: Remove folding status in parsed data
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-item-parser, org-element-quote-block-parser,
org-element-comment-block-parser, org-element-export-block-parser,
org-element-verse-block-parser, org-element-special-block-parser,
org-element-example-block-parser, org-element-headline-parser,
org-element-inlinetask-parser): Remove :hiddenp property.
* lisp/org.el (org-end-of-line, org-down-element): Use an equivalent
of :hiddenp property.
* testing/lisp/test-org-element.el: Remove tests.
The property is removed because it is buggy (e.g., when there's a link
just after a block opening line) and not really useful.
2013-10-03 20:57:02 +00:00
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_VERSE\nVerse \\alpha\n#+END_VERSE"
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'entity 'identity)))
|
2012-05-04 17:24:51 +00:00
|
|
|
|
;; Ignore incomplete verse block.
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_VERSE"
|
2013-11-10 10:28:14 +00:00
|
|
|
|
(org-element-map (org-element-parse-buffer) 'verse-block 'identity nil t)))
|
|
|
|
|
;; Handle non-empty blank line at the end of buffer.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_VERSE\nC\n#+END_VERSE\n "
|
|
|
|
|
(= (org-element-property :end (org-element-at-point)) (point-max)))))
|
2012-04-25 20:15:29 +00:00
|
|
|
|
|
|
|
|
|
|
2012-03-28 13:33:20 +00:00
|
|
|
|
|
2012-04-30 15:20:57 +00:00
|
|
|
|
;;; Test Interpreters.
|
2012-04-10 21:15:32 +00:00
|
|
|
|
|
2013-11-11 12:16:43 +00:00
|
|
|
|
(ert-deftest test-org-element/interpret-data ()
|
|
|
|
|
"Test `org-element-interpret-data' specifications."
|
|
|
|
|
;; Interpret simple affiliated keywords.
|
2012-04-10 21:15:32 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
(org-element-interpret-data
|
|
|
|
|
'(org-data nil (paragraph (:name "para") "Paragraph")))
|
2018-01-28 14:40:15 +00:00
|
|
|
|
"#+name: para\nParagraph\n"))
|
2013-11-11 12:16:43 +00:00
|
|
|
|
;; Interpret multiple affiliated keywords.
|
2012-04-10 21:15:32 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
(org-element-interpret-data
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 17:10:39 +00:00
|
|
|
|
'(org-data nil (paragraph (:attr_ascii ("line2" "line1")) "Paragraph")))
|
2018-01-28 14:40:15 +00:00
|
|
|
|
"#+attr_ascii: line1\n#+attr_ascii: line2\nParagraph\n"))
|
2013-11-11 12:16:43 +00:00
|
|
|
|
;; Interpret parsed affiliated keywords.
|
2012-04-10 21:15:32 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
(org-element-interpret-data
|
2012-09-13 14:51:54 +00:00
|
|
|
|
'(org-data nil (paragraph (:caption (("caption"))) "Paragraph")))
|
2018-01-28 14:40:15 +00:00
|
|
|
|
"#+caption: caption\nParagraph\n"))
|
2013-11-11 12:16:43 +00:00
|
|
|
|
;; Interpret dual affiliated keywords.
|
2012-04-10 21:15:32 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
(org-element-interpret-data
|
2012-09-13 14:51:54 +00:00
|
|
|
|
'(org-data nil (paragraph (:caption ((("long") "short"))) "Paragraph")))
|
2018-01-28 14:40:15 +00:00
|
|
|
|
"#+caption[short]: long\nParagraph\n"))
|
2012-09-13 14:51:54 +00:00
|
|
|
|
;; Interpret multiple parsed dual keywords.
|
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
(org-element-interpret-data
|
|
|
|
|
'(org-data nil (paragraph
|
org-element: Optimize affiliated keywords parsing
* lisp/org-element.el (org-element-center-block-parser,
org-element-drawer-parser, org-element-dynamic-block-parser,
org-element-footnote-definition-parser,
org-element-plain-list-parser, org-element-quote-block-parser,
org-element-special-block-parser, org-element-babel-call-parser,
org-element-comment-parser, org-element-comment-block-parser,
org-element-example-block-parser, org-element-export-block-parser,
org-element-fixed-width-parser, org-element-horizontal-rule-parser,
org-element-keyword-parser, org-element-latex-environment-parser,
org-element-paragraph-parser, org-element-property-drawer-parser,
org-element-src-block-parser, org-element-table-parser,
org-element-verse-block-parser): Change signature. Now use an
additional argument: affiliated.
(org-element--current-element): Skip affiliated keywords and pass them
as an argument to parsers. It prevents to walk through these
keywords twice: the first time to get to the first line of the
element, and a second time to collect the affiliated keywords.
* contrib/lisp/org-export.el (org-export-get-caption): Update function
since multiple affiliated keywords are now reversed.
* testing/lisp/test-org-element.el: Update tests.
2012-09-20 17:10:39 +00:00
|
|
|
|
(:caption ((("l2") "s2") (("l1") "s1"))) "Paragraph")))
|
2018-01-28 14:40:15 +00:00
|
|
|
|
"#+caption[s1]: l1\n#+caption[s2]: l2\nParagraph\n"))
|
2013-11-11 12:16:43 +00:00
|
|
|
|
;; Pseudo objects and elements are transparent.
|
|
|
|
|
(should
|
2015-02-09 11:02:16 +00:00
|
|
|
|
(equal "A B"
|
|
|
|
|
(org-trim
|
|
|
|
|
(org-element-interpret-data
|
|
|
|
|
'(paragraph nil (pseudo-object (:post-blank 1) "A") "B")))))
|
2013-11-11 12:16:43 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal "A\n\nB\n"
|
|
|
|
|
(org-element-interpret-data
|
|
|
|
|
'(center nil
|
|
|
|
|
(pseudo-element (:post-blank 1) (paragraph nil "A"))
|
2021-04-19 16:17:55 +00:00
|
|
|
|
(paragraph nil "B")))))
|
|
|
|
|
;; Obey post-blank property in strings.
|
|
|
|
|
(should
|
|
|
|
|
(equal "A "
|
|
|
|
|
(org-element-interpret-data
|
|
|
|
|
(org-element-put-property "A" :post-blank 1)))))
|
2012-04-10 21:15:32 +00:00
|
|
|
|
|
2012-04-27 15:16:17 +00:00
|
|
|
|
(ert-deftest test-org-element/center-block-interpreter ()
|
|
|
|
|
"Test center block interpreter."
|
|
|
|
|
(should
|
|
|
|
|
(equal (org-test-parse-and-interpret "#+BEGIN_CENTER\nTest\n#+END_CENTER")
|
2018-01-24 11:56:25 +00:00
|
|
|
|
"#+begin_center\nTest\n#+end_center\n")))
|
2012-04-27 15:16:17 +00:00
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/drawer-interpreter ()
|
|
|
|
|
"Test drawer interpreter."
|
|
|
|
|
(should
|
2013-10-20 12:40:09 +00:00
|
|
|
|
(equal (org-test-parse-and-interpret ":TEST:\nTest\n:END:")
|
2012-04-27 15:16:17 +00:00
|
|
|
|
":TEST:\nTest\n:END:\n")))
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/dynamic-block-interpreter ()
|
|
|
|
|
"Test dynamic block interpreter."
|
|
|
|
|
(should
|
|
|
|
|
(equal (org-test-parse-and-interpret
|
|
|
|
|
"#+BEGIN: myblock :parameter value1\nTest\n#+END:")
|
2018-01-24 11:56:25 +00:00
|
|
|
|
"#+begin: myblock :parameter value1\nTest\n#+end:\n")))
|
2012-04-27 15:16:17 +00:00
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/footnote-definition-interpreter ()
|
|
|
|
|
"Test footnote definition interpreter."
|
2017-11-09 21:47:35 +00:00
|
|
|
|
(should (equal (org-test-parse-and-interpret "[fn:1] Test") "[fn:1] Test\n"))
|
|
|
|
|
;; Handle `:pre-blank' in definitions.
|
|
|
|
|
(should
|
|
|
|
|
(equal (org-test-parse-and-interpret "[fn:1]\nparagraph")
|
|
|
|
|
"[fn:1]\nparagraph\n"))
|
|
|
|
|
(should
|
|
|
|
|
(equal (org-test-parse-and-interpret "[fn:1]\n\nparagraph")
|
|
|
|
|
"[fn:1]\n\nparagraph\n")))
|
2012-04-27 15:16:17 +00:00
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/headline-interpreter ()
|
|
|
|
|
"Test headline and section interpreters."
|
|
|
|
|
;; 1. Standard test.
|
|
|
|
|
(should (equal (org-test-parse-and-interpret "* Headline") "* Headline\n"))
|
|
|
|
|
;; 2. With TODO keywords.
|
|
|
|
|
(should
|
|
|
|
|
(equal (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
|
|
|
|
|
(org-test-parse-and-interpret "* TODO Headline"))
|
|
|
|
|
"* TODO Headline\n"))
|
|
|
|
|
;; 3. With tags...
|
|
|
|
|
;;
|
|
|
|
|
;; 3.1. ... and a positive `org-tags-column' value.
|
|
|
|
|
(should
|
|
|
|
|
(equal (let ((org-tags-column 20))
|
|
|
|
|
(org-test-parse-and-interpret "* Headline :tag:"))
|
|
|
|
|
"* Headline :tag:\n"))
|
|
|
|
|
;; 3.2. ... and a negative `org-tags-column' value.
|
|
|
|
|
(should
|
|
|
|
|
(equal (let ((org-tags-column -20))
|
|
|
|
|
(org-test-parse-and-interpret "* Headline :tag:"))
|
|
|
|
|
"* Headline :tag:\n"))
|
|
|
|
|
;; 3.3. ... and a null `org-tags-column' value.
|
|
|
|
|
(should
|
|
|
|
|
(equal (let ((org-tags-column 0))
|
|
|
|
|
(org-test-parse-and-interpret "* Headline :tag:"))
|
|
|
|
|
"* Headline :tag:\n"))
|
|
|
|
|
;; 4. With priority cookie.
|
|
|
|
|
(should
|
|
|
|
|
(equal (org-test-parse-and-interpret "* [#B] Headline")
|
|
|
|
|
"* [#B] Headline\n"))
|
|
|
|
|
;; 5. With comment keyword.
|
|
|
|
|
(should
|
|
|
|
|
(equal (let ((org-comment-string "COMMENT"))
|
|
|
|
|
(org-test-parse-and-interpret "* COMMENT Headline"))
|
|
|
|
|
"* COMMENT Headline\n"))
|
2014-01-28 20:30:48 +00:00
|
|
|
|
;; 6. Keep same number of blank lines before body.
|
2012-04-27 15:16:17 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal (org-test-parse-and-interpret
|
|
|
|
|
"* Headline\n\n\nText after two blank lines.")
|
2014-08-28 09:07:24 +00:00
|
|
|
|
"* Headline\n\n\nText after two blank lines.\n"))
|
|
|
|
|
;; 8. Preserve `org-odd-levels-only' state.
|
|
|
|
|
(should
|
|
|
|
|
(equal "* H\n*** H2\n"
|
|
|
|
|
(let ((org-odd-levels-only t))
|
|
|
|
|
(org-test-parse-and-interpret "* H\n*** H2")))))
|
2012-04-27 15:16:17 +00:00
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/inlinetask-interpreter ()
|
|
|
|
|
"Test inlinetask interpretation."
|
|
|
|
|
(when (featurep 'org-inlinetask)
|
|
|
|
|
(let ((org-inlinetask-min-level 15))
|
|
|
|
|
;; 1. Regular inlinetask.
|
|
|
|
|
(should (equal (org-test-parse-and-interpret
|
|
|
|
|
"*************** Task\nTest\n*************** END")
|
2018-01-24 11:56:25 +00:00
|
|
|
|
"*************** Task\nTest\n*************** end\n"))
|
2012-04-27 15:16:17 +00:00
|
|
|
|
;; 2. Degenerate inlinetask.
|
|
|
|
|
(should (equal (org-test-parse-and-interpret "*************** Task")
|
|
|
|
|
"*************** Task\n"))
|
|
|
|
|
;; 3. Prefer degenerate form when there are no contents.
|
|
|
|
|
(should (equal (org-test-parse-and-interpret
|
2018-01-24 11:56:25 +00:00
|
|
|
|
"*************** Task\n*************** end")
|
2012-04-27 15:16:17 +00:00
|
|
|
|
"*************** Task\n"))
|
|
|
|
|
;; 4. With TODO keywords.
|
|
|
|
|
(should
|
|
|
|
|
(equal (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
|
|
|
|
|
(org-test-parse-and-interpret "*************** TODO Task"))
|
|
|
|
|
"*************** TODO Task\n"))
|
|
|
|
|
;; 5. With tags...
|
|
|
|
|
;;
|
|
|
|
|
;; 5.1. ... and a positive `org-tags-column' value.
|
|
|
|
|
(should
|
|
|
|
|
(equal (let ((org-tags-column 30))
|
|
|
|
|
(org-test-parse-and-interpret "*************** Task :tag:"))
|
|
|
|
|
"*************** Task :tag:\n"))
|
|
|
|
|
;; 5.2. ... and a negative `org-tags-column' value.
|
|
|
|
|
(should
|
|
|
|
|
(equal (let ((org-tags-column -30))
|
|
|
|
|
(org-test-parse-and-interpret "*************** Task :tag:"))
|
|
|
|
|
"*************** Task :tag:\n"))
|
|
|
|
|
;; 5.3. ... and a null `org-tags-column' value.
|
|
|
|
|
(should
|
|
|
|
|
(equal (let ((org-tags-column 0))
|
|
|
|
|
(org-test-parse-and-interpret "*************** Task :tag:"))
|
|
|
|
|
"*************** Task :tag:\n"))
|
|
|
|
|
;; 6. With priority cookie.
|
|
|
|
|
(should
|
|
|
|
|
(equal (org-test-parse-and-interpret "*************** [#B] Task")
|
|
|
|
|
"*************** [#B] Task\n")))))
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/plain-list-interpreter ()
|
|
|
|
|
"Test plain-list and item interpreters."
|
2012-06-12 12:29:53 +00:00
|
|
|
|
(let ((org-list-two-spaces-after-bullet-regexp nil))
|
2013-07-05 19:09:23 +00:00
|
|
|
|
;; Unordered list.
|
2012-06-12 12:29:53 +00:00
|
|
|
|
(should (equal (org-test-parse-and-interpret "- item 1") "- item 1\n"))
|
2013-07-05 19:09:23 +00:00
|
|
|
|
;; Description list.
|
2012-06-12 12:29:53 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal (org-test-parse-and-interpret "- tag :: desc") "- tag :: desc\n"))
|
2013-07-05 19:09:23 +00:00
|
|
|
|
;; Ordered list.
|
2012-06-12 12:29:53 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal (let ((org-plain-list-ordered-item-terminator t))
|
|
|
|
|
(org-test-parse-and-interpret "1. Item"))
|
|
|
|
|
"1. Item\n"))
|
2013-07-05 19:09:23 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal (let ((org-plain-list-ordered-item-terminator ?\)))
|
|
|
|
|
(org-test-parse-and-interpret "1) Item"))
|
|
|
|
|
"1) Item\n"))
|
|
|
|
|
;; Ordered list with counter.
|
2012-06-12 12:29:53 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal (let ((org-plain-list-ordered-item-terminator t))
|
|
|
|
|
(org-test-parse-and-interpret "1. [@5] Item"))
|
|
|
|
|
"5. [@5] Item\n"))
|
2013-07-05 19:09:23 +00:00
|
|
|
|
;; List with check-boxes.
|
2012-06-12 12:29:53 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal (org-test-parse-and-interpret
|
|
|
|
|
"- [-] Item 1\n - [X] Item 2\n - [ ] Item 3")
|
|
|
|
|
"- [-] Item 1\n - [X] Item 2\n - [ ] Item 3\n"))
|
2013-07-05 19:09:23 +00:00
|
|
|
|
;; Item not starting with a paragraph.
|
2012-06-12 12:29:53 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal (org-test-parse-and-interpret "-\n | a | b |")
|
2013-07-05 19:09:23 +00:00
|
|
|
|
"- \n | a | b |\n"))
|
2017-11-09 21:47:35 +00:00
|
|
|
|
;; Handle `:pre-blank' in items.
|
|
|
|
|
(should
|
|
|
|
|
(equal (org-test-parse-and-interpret "-\n paragraph")
|
|
|
|
|
"- \n paragraph\n"))
|
|
|
|
|
(should
|
|
|
|
|
(equal (org-test-parse-and-interpret "-\n\n paragraph")
|
|
|
|
|
"- \n\n paragraph\n"))
|
2013-07-05 19:09:23 +00:00
|
|
|
|
;; Special case: correctly handle "*" bullets.
|
2013-07-05 22:39:28 +00:00
|
|
|
|
(should (org-test-parse-and-interpret " * item"))
|
|
|
|
|
;; Special case: correctly handle empty items.
|
|
|
|
|
(should (org-test-parse-and-interpret "-"))))
|
2012-04-27 15:16:17 +00:00
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/quote-block-interpreter ()
|
|
|
|
|
"Test quote block interpreter."
|
|
|
|
|
(should (equal (org-test-parse-and-interpret
|
|
|
|
|
"#+BEGIN_QUOTE\nTest\n#+END_QUOTE")
|
2018-01-24 11:56:25 +00:00
|
|
|
|
"#+begin_quote\nTest\n#+end_quote\n")))
|
2012-04-27 15:16:17 +00:00
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/special-block-interpreter ()
|
|
|
|
|
"Test special block interpreter."
|
|
|
|
|
(should (equal (org-test-parse-and-interpret
|
|
|
|
|
"#+BEGIN_SPECIAL\nTest\n#+END_SPECIAL")
|
2018-01-24 11:56:25 +00:00
|
|
|
|
"#+begin_SPECIAL\nTest\n#+end_SPECIAL\n")))
|
2012-04-27 15:16:17 +00:00
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/babel-call-interpreter ()
|
2015-04-21 09:54:22 +00:00
|
|
|
|
"Test Babel call interpreter."
|
|
|
|
|
;; Without argument.
|
2012-04-27 15:16:17 +00:00
|
|
|
|
(should (equal (org-test-parse-and-interpret "#+CALL: test()")
|
2018-01-24 11:56:25 +00:00
|
|
|
|
"#+call: test()\n"))
|
2015-04-21 09:54:22 +00:00
|
|
|
|
;; With argument.
|
2012-04-27 15:16:17 +00:00
|
|
|
|
(should (equal (org-test-parse-and-interpret "#+CALL: test(x=2)")
|
2018-01-24 11:56:25 +00:00
|
|
|
|
"#+call: test(x=2)\n"))
|
2015-04-21 09:54:22 +00:00
|
|
|
|
;; With header arguments.
|
2012-04-27 15:16:17 +00:00
|
|
|
|
(should (equal (org-test-parse-and-interpret
|
2015-04-21 09:54:22 +00:00
|
|
|
|
"#+CALL: test[:results output]() :results html")
|
2018-01-24 11:56:25 +00:00
|
|
|
|
"#+call: test[:results output]() :results html\n")))
|
2012-04-27 15:16:17 +00:00
|
|
|
|
|
2012-04-28 20:59:25 +00:00
|
|
|
|
(ert-deftest test-org-element/clock-interpreter ()
|
|
|
|
|
"Test clock interpreter."
|
|
|
|
|
;; Running clock.
|
|
|
|
|
(should
|
2013-11-16 09:15:28 +00:00
|
|
|
|
(string-match
|
|
|
|
|
"CLOCK: \\[2012-01-01 .* 00:01\\]"
|
2013-10-29 13:53:21 +00:00
|
|
|
|
(org-test-parse-and-interpret "CLOCK: [2012-01-01 sun. 00:01]")))
|
2012-04-28 20:59:25 +00:00
|
|
|
|
;; Closed clock.
|
|
|
|
|
(should
|
2013-11-16 09:15:28 +00:00
|
|
|
|
(string-match
|
|
|
|
|
"CLOCK: \\[2012-01-01 .* 00:01\\]--\\[2012-01-01 .* 00:02\\] => 0:01"
|
2013-10-29 13:53:21 +00:00
|
|
|
|
(org-test-parse-and-interpret "
|
|
|
|
|
CLOCK: [2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02] => 0:01"))))
|
2012-04-28 20:59:25 +00:00
|
|
|
|
|
2012-04-27 15:16:17 +00:00
|
|
|
|
(ert-deftest test-org-element/comment-interpreter ()
|
|
|
|
|
"Test comment interpreter."
|
|
|
|
|
;; Regular comment.
|
2012-08-17 13:22:36 +00:00
|
|
|
|
(should (equal (org-test-parse-and-interpret "# Comment") "# Comment\n"))
|
2012-04-27 15:16:17 +00:00
|
|
|
|
;; Inline comment.
|
2012-07-31 23:27:27 +00:00
|
|
|
|
(should (equal (org-test-parse-and-interpret " # Comment")
|
|
|
|
|
"# Comment\n"))
|
2012-05-02 15:18:14 +00:00
|
|
|
|
;; Preserve indentation.
|
2012-07-31 23:27:27 +00:00
|
|
|
|
(should (equal (org-test-parse-and-interpret " # No blank\n# One blank")
|
|
|
|
|
"# No blank\n# One blank\n")))
|
2012-04-27 15:16:17 +00:00
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/comment-block-interpreter ()
|
|
|
|
|
"Test comment block interpreter."
|
|
|
|
|
(should (equal (org-test-parse-and-interpret
|
|
|
|
|
"#+BEGIN_COMMENT\nTest\n#+END_COMMENT")
|
2018-01-24 11:56:25 +00:00
|
|
|
|
"#+begin_comment\nTest\n#+end_comment\n"))
|
2014-08-07 12:45:28 +00:00
|
|
|
|
;; Accept missing final newline in value.
|
|
|
|
|
(should
|
2018-01-24 11:56:25 +00:00
|
|
|
|
(equal "#+begin_comment\nTest\n#+end_comment\n"
|
|
|
|
|
(org-element-interpret-data '(comment-block (:value "Test"))))))
|
2012-04-27 15:16:17 +00:00
|
|
|
|
|
2012-10-27 12:23:37 +00:00
|
|
|
|
(ert-deftest test-org-element/diary-sexp ()
|
|
|
|
|
"Test diary-sexp interpreter."
|
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
(org-test-parse-and-interpret
|
|
|
|
|
"%%(org-anniversary 1956 5 14)(2) Arthur Dent is %d years old")
|
|
|
|
|
"%%(org-anniversary 1956 5 14)(2) Arthur Dent is %d years old\n")))
|
|
|
|
|
|
2012-04-27 15:16:17 +00:00
|
|
|
|
(ert-deftest test-org-element/example-block-interpreter ()
|
|
|
|
|
"Test example block interpreter."
|
2012-04-30 21:44:30 +00:00
|
|
|
|
;; Without switches.
|
2018-02-04 09:04:17 +00:00
|
|
|
|
(should (equal "#+begin_example\nTest\n#+end_example\n"
|
|
|
|
|
(let ((org-src-preserve-indentation t))
|
|
|
|
|
(org-test-parse-and-interpret
|
|
|
|
|
"#+BEGIN_EXAMPLE\nTest\n#+END_EXAMPLE"))))
|
2012-04-30 21:44:30 +00:00
|
|
|
|
;; With switches.
|
|
|
|
|
(should
|
2018-02-04 09:04:17 +00:00
|
|
|
|
(equal "#+begin_example -n -k\n(+ 1 1)\n#+end_example\n"
|
|
|
|
|
(let ((org-src-preserve-indentation t))
|
|
|
|
|
(org-test-parse-and-interpret
|
|
|
|
|
"#+BEGIN_EXAMPLE -n -k\n(+ 1 1)\n#+END_EXAMPLE"))))
|
2012-09-30 15:45:21 +00:00
|
|
|
|
;; Preserve code escaping.
|
|
|
|
|
(should
|
2018-01-24 11:56:25 +00:00
|
|
|
|
(equal
|
2018-02-04 09:04:17 +00:00
|
|
|
|
(let ((org-src-preserve-indentation t))
|
|
|
|
|
(org-test-parse-and-interpret
|
|
|
|
|
"#+BEGIN_EXAMPLE\n,* Headline\n,#+KEYWORD: value\nText\n#+END_EXAMPLE"))
|
2018-01-24 11:56:25 +00:00
|
|
|
|
"#+begin_example\n,* Headline\n,#+KEYWORD: value\nText\n#+end_example\n"))
|
2014-08-07 12:45:28 +00:00
|
|
|
|
;; Accept missing final newline in value.
|
|
|
|
|
(should
|
|
|
|
|
(equal
|
2018-01-24 11:56:25 +00:00
|
|
|
|
"#+begin_example\nTest\n#+end_example\n"
|
2018-02-04 09:04:17 +00:00
|
|
|
|
(let ((org-src-preserve-indentation t))
|
|
|
|
|
(org-element-interpret-data '(example-block (:value "Test"))))))
|
|
|
|
|
;; Handle indentation.
|
|
|
|
|
(should (equal "#+begin_example\n Test\n#+end_example\n"
|
|
|
|
|
(let ((org-src-preserve-indentation nil)
|
|
|
|
|
(org-edit-src-content-indentation 2))
|
|
|
|
|
(org-test-parse-and-interpret
|
|
|
|
|
"#+BEGIN_EXAMPLE\nTest\n#+END_EXAMPLE"))))
|
|
|
|
|
(should (equal "#+begin_example\n Test\n#+end_example\n"
|
|
|
|
|
(let ((org-src-preserve-indentation t)
|
|
|
|
|
(org-edit-src-content-indentation 2))
|
|
|
|
|
(org-test-parse-and-interpret
|
|
|
|
|
"#+BEGIN_EXAMPLE\n Test\n#+END_EXAMPLE")))))
|
2012-04-27 15:16:17 +00:00
|
|
|
|
|
2014-09-08 09:57:27 +00:00
|
|
|
|
(ert-deftest test-org-element/export-block-interpreter ()
|
|
|
|
|
"Test export block interpreter."
|
|
|
|
|
(should (equal (org-test-parse-and-interpret
|
2018-01-24 11:56:25 +00:00
|
|
|
|
"#+begin_export HTML\nTest\n#+end_export")
|
|
|
|
|
"#+begin_export HTML\nTest\n#+end_export\n")))
|
2014-09-08 09:57:27 +00:00
|
|
|
|
|
2012-04-27 15:16:17 +00:00
|
|
|
|
(ert-deftest test-org-element/fixed-width-interpreter ()
|
|
|
|
|
"Test fixed width interpreter."
|
2012-05-02 15:18:14 +00:00
|
|
|
|
;; Standard test.
|
|
|
|
|
(should (equal (org-test-parse-and-interpret ": Test") ": Test\n"))
|
|
|
|
|
;; Preserve indentation.
|
|
|
|
|
(should (equal (org-test-parse-and-interpret ": 2 blanks\n: 1 blank")
|
2013-04-26 08:38:05 +00:00
|
|
|
|
": 2 blanks\n: 1 blank\n"))
|
|
|
|
|
;; Handle empty string.
|
|
|
|
|
(should
|
|
|
|
|
(equal (org-element-fixed-width-interpreter
|
|
|
|
|
'(fixed-width (:value "")) nil)
|
|
|
|
|
""))
|
|
|
|
|
;; Handle nil value.
|
|
|
|
|
(should-not
|
|
|
|
|
(org-element-fixed-width-interpreter
|
|
|
|
|
'(fixed-width (:value nil)) nil)))
|
2012-04-27 15:16:17 +00:00
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/horizontal-rule-interpreter ()
|
|
|
|
|
"Test horizontal rule interpreter."
|
|
|
|
|
(should (equal (org-test-parse-and-interpret "-------") "-----\n")))
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/keyword-interpreter ()
|
|
|
|
|
"Test keyword interpreter."
|
|
|
|
|
(should (equal (org-test-parse-and-interpret "#+KEYWORD: value")
|
2018-01-24 11:56:25 +00:00
|
|
|
|
"#+keyword: value\n")))
|
2012-04-27 15:16:17 +00:00
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/latex-environment-interpreter ()
|
|
|
|
|
"Test latex environment interpreter."
|
|
|
|
|
(should (equal (org-test-parse-and-interpret
|
2012-04-28 20:59:25 +00:00
|
|
|
|
"\\begin{equation}\n1+1=2\n\\end{equation}")
|
2013-04-28 07:34:42 +00:00
|
|
|
|
"\\begin{equation}\n1+1=2\n\\end{equation}\n"))
|
|
|
|
|
(should (equal (org-test-parse-and-interpret
|
|
|
|
|
"\\begin{theorem}[me]\n1+1=2\n\\end{theorem}")
|
|
|
|
|
"\\begin{theorem}[me]\n1+1=2\n\\end{theorem}\n")))
|
2012-04-28 20:59:25 +00:00
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/planning-interpreter ()
|
|
|
|
|
"Test planning interpreter."
|
2013-10-29 13:53:21 +00:00
|
|
|
|
(should
|
|
|
|
|
(string-match
|
|
|
|
|
"\\* Headline
|
2013-11-16 09:15:28 +00:00
|
|
|
|
DEADLINE: <2012-03-29 .*?> SCHEDULED: <2012-03-29 .*?> CLOSED: \\[2012-03-29 .*?\\]"
|
2013-10-29 13:53:21 +00:00
|
|
|
|
(org-test-parse-and-interpret
|
|
|
|
|
"* Headline
|
|
|
|
|
DEADLINE: <2012-03-29 thu.> SCHEDULED: <2012-03-29 thu.> CLOSED: [2012-03-29 thu.]"))))
|
2012-04-27 15:16:17 +00:00
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/property-drawer-interpreter ()
|
|
|
|
|
"Test property drawer interpreter."
|
|
|
|
|
(should (equal (let ((org-property-format "%-10s %s"))
|
|
|
|
|
(org-test-parse-and-interpret
|
2014-09-13 20:43:45 +00:00
|
|
|
|
"* H\n:PROPERTIES:\n:prop: value\n:END:"))
|
|
|
|
|
"* H\n:PROPERTIES:\n:prop: value\n:END:\n")))
|
2012-04-27 15:16:17 +00:00
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/src-block-interpreter ()
|
|
|
|
|
"Test src block interpreter."
|
2012-04-30 16:21:35 +00:00
|
|
|
|
;; With arguments.
|
2012-04-27 15:16:17 +00:00
|
|
|
|
(should
|
2014-12-24 09:48:24 +00:00
|
|
|
|
(equal (let ((org-edit-src-content-indentation 2)
|
|
|
|
|
(org-src-preserve-indentation nil))
|
2012-06-07 19:41:59 +00:00
|
|
|
|
(org-test-parse-and-interpret
|
|
|
|
|
"#+BEGIN_SRC emacs-lisp :results silent\n(+ 1 1)\n#+END_SRC"))
|
2018-01-24 11:56:25 +00:00
|
|
|
|
"#+begin_src emacs-lisp :results silent\n (+ 1 1)\n#+end_src\n"))
|
2012-04-30 16:21:35 +00:00
|
|
|
|
;; With switches.
|
|
|
|
|
(should
|
2014-12-24 09:48:24 +00:00
|
|
|
|
(equal (let ((org-edit-src-content-indentation 2)
|
|
|
|
|
(org-src-preserve-indentation nil))
|
2012-06-07 19:41:59 +00:00
|
|
|
|
(org-test-parse-and-interpret
|
|
|
|
|
"#+BEGIN_SRC emacs-lisp -n -k\n(+ 1 1)\n#+END_SRC"))
|
2018-01-24 11:56:25 +00:00
|
|
|
|
"#+begin_src emacs-lisp -n -k\n (+ 1 1)\n#+end_src\n"))
|
2012-09-30 15:45:21 +00:00
|
|
|
|
;; Preserve code escaping.
|
|
|
|
|
(should
|
2018-01-24 11:56:25 +00:00
|
|
|
|
(equal
|
|
|
|
|
(let ((org-edit-src-content-indentation 2)
|
|
|
|
|
(org-src-preserve-indentation nil))
|
|
|
|
|
(org-test-parse-and-interpret
|
|
|
|
|
"#+BEGIN_SRC org\n,* Headline\n,#+KEYWORD: value\nText\n#+END_SRC"))
|
|
|
|
|
"#+begin_src org\n ,* Headline\n ,#+KEYWORD: value\n Text\n#+end_src\n"))
|
2013-05-25 12:18:48 +00:00
|
|
|
|
;; Do not apply `org-edit-src-content-indentation' when preserving
|
|
|
|
|
;; indentation.
|
|
|
|
|
(should
|
|
|
|
|
(equal (let ((org-edit-src-content-indentation 2)
|
|
|
|
|
(org-src-preserve-indentation t))
|
|
|
|
|
(org-test-parse-and-interpret
|
|
|
|
|
"#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"))
|
2018-01-24 11:56:25 +00:00
|
|
|
|
"#+begin_src emacs-lisp\n(+ 1 1)\n#+end_src\n"))
|
2013-05-25 12:18:48 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal (let ((org-edit-src-content-indentation 2)
|
|
|
|
|
(org-src-preserve-indentation nil))
|
|
|
|
|
(org-test-parse-and-interpret
|
|
|
|
|
"#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"))
|
2018-01-24 11:56:25 +00:00
|
|
|
|
"#+begin_src emacs-lisp -i\n(+ 1 1)\n#+end_src\n"))
|
2014-08-07 12:45:28 +00:00
|
|
|
|
;; Accept missing final newline in value.
|
|
|
|
|
(should
|
|
|
|
|
(equal
|
2018-01-24 11:56:25 +00:00
|
|
|
|
"#+begin_src emacs-lisp\n Test\n#+end_src\n"
|
2014-12-24 09:48:24 +00:00
|
|
|
|
(let ((org-edit-src-content-indentation 2)
|
|
|
|
|
(org-src-preserve-indentation nil))
|
2014-08-07 12:45:28 +00:00
|
|
|
|
(org-element-interpret-data
|
|
|
|
|
'(src-block (:language "emacs-lisp" :value "Test")))))))
|
2012-04-27 15:16:17 +00:00
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/table-interpreter ()
|
|
|
|
|
"Test table, table-row and table-cell interpreters."
|
|
|
|
|
;; 1. Simple table.
|
|
|
|
|
(should (equal (org-test-parse-and-interpret "| a | b |\n| c | d |")
|
|
|
|
|
"| a | b |\n| c | d |\n"))
|
2012-05-11 13:17:14 +00:00
|
|
|
|
;; 2. With horizontal rules.
|
2012-04-27 15:16:17 +00:00
|
|
|
|
(should (equal (org-test-parse-and-interpret
|
|
|
|
|
"| a | b |\n|---+---|\n| c | d |")
|
|
|
|
|
"| a | b |\n|---+---|\n| c | d |\n"))
|
2012-05-11 13:17:14 +00:00
|
|
|
|
;; 3. With meta-data.
|
2012-04-27 15:16:17 +00:00
|
|
|
|
(should (equal (org-test-parse-and-interpret "| / | < | > |\n| * | 1 | 2 |")
|
2012-05-05 17:57:37 +00:00
|
|
|
|
"| / | < | > |\n| * | 1 | 2 |\n"))
|
|
|
|
|
;; 4. With a formula.
|
|
|
|
|
(should
|
|
|
|
|
(equal (org-test-parse-and-interpret
|
|
|
|
|
"| 2 |\n| 4 |\n| 3 |\n#+TBLFM: @3=vmean(@1..@2)")
|
2012-05-11 13:17:14 +00:00
|
|
|
|
"| 2 |\n| 4 |\n| 3 |\n#+TBLFM: @3=vmean(@1..@2)\n"))
|
|
|
|
|
;; 5. With multiple formulas.
|
|
|
|
|
(should
|
|
|
|
|
(equal (org-test-parse-and-interpret
|
|
|
|
|
"| 2 |\n| 4 |\n| 3 |\n#+TBLFM: test1\n#+TBLFM: test2")
|
|
|
|
|
"| 2 |\n| 4 |\n| 3 |\n#+TBLFM: test1\n#+TBLFM: test2\n")))
|
2012-04-27 15:16:17 +00:00
|
|
|
|
|
2012-07-17 14:33:45 +00:00
|
|
|
|
(ert-deftest test-org-element/timestamp-interpreter ()
|
|
|
|
|
"Test timestamp interpreter."
|
|
|
|
|
;; Active.
|
2013-11-16 09:15:28 +00:00
|
|
|
|
(should
|
|
|
|
|
(string-match "<2012-03-29 .* 16:40>"
|
|
|
|
|
(org-test-parse-and-interpret "<2012-03-29 thu. 16:40>")))
|
2012-09-28 12:50:21 +00:00
|
|
|
|
(should
|
|
|
|
|
(string-match "<2012-03-29 .* 16:40>"
|
|
|
|
|
(org-element-timestamp-interpreter
|
|
|
|
|
'(timestamp
|
|
|
|
|
(:type active :year-start 2012 :month-start 3 :day-start 29
|
|
|
|
|
:hour-start 16 :minute-start 40)) nil)))
|
2012-07-17 14:33:45 +00:00
|
|
|
|
;; Inactive.
|
2013-11-16 09:15:28 +00:00
|
|
|
|
(should
|
|
|
|
|
(string-match "\\[2012-03-29 .* 16:40\\]"
|
|
|
|
|
(org-test-parse-and-interpret "[2012-03-29 thu. 16:40]")))
|
2012-09-28 12:50:21 +00:00
|
|
|
|
(should
|
|
|
|
|
(string-match
|
|
|
|
|
"\\[2012-03-29 .* 16:40\\]"
|
|
|
|
|
(org-element-timestamp-interpreter
|
|
|
|
|
'(timestamp
|
|
|
|
|
(:type inactive :year-start 2012 :month-start 3 :day-start 29
|
|
|
|
|
:hour-start 16 :minute-start 40)) nil)))
|
2012-07-17 14:33:45 +00:00
|
|
|
|
;; Active range.
|
2013-11-16 09:15:28 +00:00
|
|
|
|
(should
|
|
|
|
|
(string-match "<2012-03-29 .* 16:40>--<2012-03-29 .* 16:41>"
|
|
|
|
|
(org-test-parse-and-interpret
|
|
|
|
|
"<2012-03-29 thu. 16:40>--<2012-03-29 thu. 16:41>")))
|
2012-09-28 12:50:21 +00:00
|
|
|
|
(should
|
|
|
|
|
(string-match
|
|
|
|
|
"<2012-03-29 .* 16:40>--<2012-03-29 .* 16:41>"
|
|
|
|
|
(org-element-timestamp-interpreter
|
|
|
|
|
'(timestamp
|
|
|
|
|
(:type active-range :year-start 2012 :month-start 3 :day-start 29
|
|
|
|
|
:hour-start 16 :minute-start 40 :year-end 2012 :month-end 3
|
|
|
|
|
:day-end 29 :hour-end 16 :minute-end 41)) nil)))
|
2012-07-17 14:33:45 +00:00
|
|
|
|
;; Inactive range.
|
2013-11-16 09:15:28 +00:00
|
|
|
|
(should
|
|
|
|
|
(string-match "\\[2012-03-29 .* 16:40\\]--\\[2012-03-29 .* 16:41\\]"
|
|
|
|
|
(org-test-parse-and-interpret
|
|
|
|
|
"[2012-03-29 thu. 16:40]--[2012-03-29 thu. 16:41]")))
|
2012-09-28 12:50:21 +00:00
|
|
|
|
(should
|
|
|
|
|
(string-match
|
|
|
|
|
"\\[2012-03-29 .* 16:40\\]--\\[2012-03-29 .* 16:41\\]"
|
|
|
|
|
(org-element-timestamp-interpreter
|
|
|
|
|
'(timestamp
|
|
|
|
|
(:type inactive-range :year-start 2012 :month-start 3 :day-start 29
|
|
|
|
|
:hour-start 16 :minute-start 40 :year-end 2012 :month-end 3
|
|
|
|
|
:day-end 29 :hour-end 16 :minute-end 41)) nil)))
|
2012-07-17 14:33:45 +00:00
|
|
|
|
;; Diary.
|
2013-01-07 12:01:36 +00:00
|
|
|
|
(should (equal (org-test-parse-and-interpret "<%%diary-float t 4 2>")
|
|
|
|
|
"<%%diary-float t 4 2>\n"))
|
2013-10-13 16:13:35 +00:00
|
|
|
|
;; Timestamp with repeater interval, with delay, with both.
|
2013-11-16 09:15:28 +00:00
|
|
|
|
(should
|
|
|
|
|
(string-match "<2012-03-29 .* \\+1y>"
|
|
|
|
|
(org-test-parse-and-interpret "<2012-03-29 thu. +1y>")))
|
2012-09-28 12:50:21 +00:00
|
|
|
|
(should
|
|
|
|
|
(string-match
|
|
|
|
|
"<2012-03-29 .* \\+1y>"
|
|
|
|
|
(org-element-timestamp-interpreter
|
|
|
|
|
'(timestamp
|
|
|
|
|
(:type active :year-start 2012 :month-start 3 :day-start 29
|
2012-11-25 00:03:51 +00:00
|
|
|
|
:repeater-type cumulate :repeater-value 1 :repeater-unit year))
|
2013-01-10 12:57:37 +00:00
|
|
|
|
nil)))
|
2013-10-13 16:13:35 +00:00
|
|
|
|
(should
|
|
|
|
|
(string-match
|
|
|
|
|
"<2012-03-29 .* -1y>"
|
|
|
|
|
(org-element-timestamp-interpreter
|
|
|
|
|
'(timestamp
|
|
|
|
|
(:type active :year-start 2012 :month-start 3 :day-start 29
|
|
|
|
|
:warning-type all :warning-value 1 :warning-unit year))
|
|
|
|
|
nil)))
|
|
|
|
|
(should
|
|
|
|
|
(string-match
|
|
|
|
|
"<2012-03-29 .* \\+1y -1y>"
|
|
|
|
|
(org-element-timestamp-interpreter
|
|
|
|
|
'(timestamp
|
|
|
|
|
(:type active :year-start 2012 :month-start 3 :day-start 29
|
|
|
|
|
:warning-type all :warning-value 1 :warning-unit year
|
|
|
|
|
:repeater-type cumulate :repeater-value 1 :repeater-unit year))
|
|
|
|
|
nil)))
|
2013-01-10 12:57:37 +00:00
|
|
|
|
;; Timestamp range with repeater interval
|
2013-11-16 09:15:28 +00:00
|
|
|
|
(should
|
|
|
|
|
(string-match "<2012-03-29 .* \\+1y>--<2012-03-30 .* \\+1y>"
|
|
|
|
|
(org-test-parse-and-interpret
|
|
|
|
|
"<2012-03-29 Thu +1y>--<2012-03-30 Thu +1y>")))
|
2013-01-10 12:57:37 +00:00
|
|
|
|
(should
|
|
|
|
|
(string-match
|
|
|
|
|
"<2012-03-29 .* \\+1y>--<2012-03-30 .* \\+1y>"
|
|
|
|
|
(org-element-timestamp-interpreter
|
|
|
|
|
'(timestamp
|
|
|
|
|
(:type active-range :year-start 2012 :month-start 3 :day-start 29
|
|
|
|
|
:year-end 2012 :month-end 3 :day-end 30 :repeater-type cumulate
|
|
|
|
|
:repeater-value 1 :repeater-unit year))
|
2012-11-25 00:03:51 +00:00
|
|
|
|
nil))))
|
2012-07-17 14:33:45 +00:00
|
|
|
|
|
2012-04-27 15:16:17 +00:00
|
|
|
|
(ert-deftest test-org-element/verse-block-interpreter ()
|
|
|
|
|
"Test verse block interpretation."
|
|
|
|
|
(should
|
|
|
|
|
(equal (org-test-parse-and-interpret "#+BEGIN_VERSE\nTest\n#+END_VERSE")
|
2018-01-24 11:56:25 +00:00
|
|
|
|
"#+begin_verse\nTest\n#+end_verse\n")))
|
2012-04-27 15:16:17 +00:00
|
|
|
|
|
org-element: Define new objects (bold, code, italic, ...)
* contrib/lisp/org-e-ascii.el (org-e-ascii-option-alist): Fix typo.
(org-e-ascii-bold, org-e-ascii-code, org-e-ascii-strike-through,
org-e-ascii-underline): New functions.
(org-e-ascii-emphasis): Remove function.
* contrib/lisp/org-e-html.el (org-e-html-text-markup-alist): Variable
renamed from `org-e-html-emphasis-alist'. Change value type.
(org-e-html-bold, org-e-html-italic, org-e-html-strike-through,
org-e-html-underline): New functions.
(org-e-html-verbatim): Update function.
(org-e-html-emphasis): Remove function.
* contrib/lisp/org-e-latex.el (org-e-latex-text-markup-alist):
Variable renamed from `org-e-latex-emphasis-alist'. Change value
type.
(org-e-latex-center-block): Fix docstring.
(org-e-latex--text-markup, org-e-latex-bold, org-e-latex-code,
org-e-latex-italic, org-e-latex-strike-through,
org-e-latex-underline): New functions.
(org-e-latex-verbatim): Update function.
(org-e-latex-emphasis): Remove function.
* contrib/lisp/org-e-odt.el (org-e-odt-bold, org-e-odt-code,
org-e-odt-italic, org-e-odt-strike-through, org-e-odt-underline):
New functions.
(org-e-odt-verbatim): Update function.
(org-e-odt-center-block): Fix docstring.
(org-e-odt-emphasis): Remove function.
* contrib/lisp/org-element.el (org-element-bold-parser):
(org-element-bold-interpreter, org-element-code-parser,
org-element-code-interpreter, org-element-italic-parser,
org-element-italic-interpreter, org-element-strike-through-parser,
org-element-strike-through-interpreter, org-element-underline-parser,
org-element-underline-interpreter): New functions.
(org-element-emphasis-parser, org-element-emphasis-interpreter):
Remove functions.
(org-element-verbatim-parser, org-element-verbatim-interpreter,
org-element-text-markup-successor): Update function.
(org-element-object-successor-alist): Add associations for new object
types.
(org-element-recursive-objects): Add `bold', `italic',
`strike-through' and `underline' as recursive types.
(org-element-object-restrictions): Add restrictions for new recursive
object types.
* contrib/lisp/org-export.el (org-export-filters-alist): Add filters
for new object types.
(org-export-with-todo-keywords): Add missing keywords.
(org-export-filter-center-block-functions,
org-export-filter-drawer-functions,
org-export-filter-dynamic-block-functions,
org-export-filter-headline-functions,
org-export-filter-inlinetask-functions,
org-export-filter-plain-list-functions,
org-export-filter-item-functions, org-export-filter-comment-functions,
org-export-filter-comment-block-functions,
org-export-filter-example-block-functions,
org-export-filter-export-block-functions,
org-export-filter-fixed-width-functions,
org-export-filter-footnote-definition-functions,
org-export-filter-horizontal-rule-functions,
org-export-filter-keyword-functions,
org-export-filter-latex-environment-functions,
org-export-filter-babel-call-functions,
org-export-filter-paragraph-functions,
org-export-filter-property-drawer-functions,
org-export-filter-quote-section-functions,
org-export-filter-quote-block-functions,
org-export-filter-section-functions,
org-export-filter-special-block-functions,
org-export-filter-src-block-functions,
org-export-filter-table-functions,
org-export-filter-table-cell-functions,
org-export-filter-table-row-functions,
org-export-filter-verse-block-functions,
org-export-filter-entity-functions,
org-export-filter-export-snippet-functions,
org-export-filter-footnote-reference-functions,
org-export-filter-inline-babel-call-functions,
org-export-filter-inline-src-block-functions,
org-export-filter-latex-fragment-functions,
org-export-filter-line-break-functions,
org-export-filter-link-functions, org-export-filter-macro-functions,
org-export-filter-radio-target-functions,
org-export-filter-statistics-cookie-functions,
org-export-filter-subscript-functions,
org-export-filter-superscript-functions,
org-export-filter-target-functions,
org-export-filter-time-stamp-functions,
org-export-filter-verbatim-functions): Fix docstring.
(org-export-filter-bold-functions, org-export-filter-code-functions,
org-export-filter-italic-functions,
org-export-filter-strike-through-functions,
org-export-filter-underline-functions): New variables.
(org-export-filter-emphasis-functions): Remove variable.
* testing/lisp/test-org-element.el: Add tests.
2012-04-28 16:00:50 +00:00
|
|
|
|
(ert-deftest test-org-element/bold-interpreter ()
|
|
|
|
|
"Test bold interpreter."
|
|
|
|
|
(should (equal (org-test-parse-and-interpret "*text*") "*text*\n")))
|
|
|
|
|
|
2020-04-25 14:39:40 +00:00
|
|
|
|
(ert-deftest test-org-element/citation-interpreter ()
|
|
|
|
|
"Test citation interpreter."
|
|
|
|
|
(should
|
|
|
|
|
(equal "[cite:@key]\n"
|
|
|
|
|
(org-test-parse-and-interpret "[cite:@key]")))
|
|
|
|
|
(should
|
|
|
|
|
(equal "[cite:-@key]\n"
|
|
|
|
|
(org-test-parse-and-interpret "[cite:-@key]")))
|
|
|
|
|
(should
|
|
|
|
|
(equal "[cite/style:@key]\n"
|
|
|
|
|
(org-test-parse-and-interpret "[cite/style:@key]")))
|
|
|
|
|
(should
|
|
|
|
|
(equal "[cite:pre @key]\n"
|
|
|
|
|
(org-test-parse-and-interpret "[cite:pre @key]")))
|
|
|
|
|
(should
|
|
|
|
|
(equal "[cite:@key post]\n"
|
|
|
|
|
(org-test-parse-and-interpret "[cite:@key post]")))
|
|
|
|
|
(should
|
|
|
|
|
(equal "[cite:@a ;b]\n"
|
|
|
|
|
(org-test-parse-and-interpret "[cite: @a ;b]")))
|
|
|
|
|
(should
|
|
|
|
|
(equal "[cite:@a;@b;@c]\n"
|
|
|
|
|
(org-test-parse-and-interpret "[cite:@a;@b;@c]")))
|
|
|
|
|
(should
|
|
|
|
|
(equal "[cite:common-pre ; @a]\n"
|
|
|
|
|
(org-test-parse-and-interpret "[cite:common-pre ; @a]")))
|
|
|
|
|
(should
|
|
|
|
|
(equal "[cite:@a ; common-post]\n"
|
|
|
|
|
(org-test-parse-and-interpret "[cite:@a ; common-post]"))))
|
|
|
|
|
|
org-element: Define new objects (bold, code, italic, ...)
* contrib/lisp/org-e-ascii.el (org-e-ascii-option-alist): Fix typo.
(org-e-ascii-bold, org-e-ascii-code, org-e-ascii-strike-through,
org-e-ascii-underline): New functions.
(org-e-ascii-emphasis): Remove function.
* contrib/lisp/org-e-html.el (org-e-html-text-markup-alist): Variable
renamed from `org-e-html-emphasis-alist'. Change value type.
(org-e-html-bold, org-e-html-italic, org-e-html-strike-through,
org-e-html-underline): New functions.
(org-e-html-verbatim): Update function.
(org-e-html-emphasis): Remove function.
* contrib/lisp/org-e-latex.el (org-e-latex-text-markup-alist):
Variable renamed from `org-e-latex-emphasis-alist'. Change value
type.
(org-e-latex-center-block): Fix docstring.
(org-e-latex--text-markup, org-e-latex-bold, org-e-latex-code,
org-e-latex-italic, org-e-latex-strike-through,
org-e-latex-underline): New functions.
(org-e-latex-verbatim): Update function.
(org-e-latex-emphasis): Remove function.
* contrib/lisp/org-e-odt.el (org-e-odt-bold, org-e-odt-code,
org-e-odt-italic, org-e-odt-strike-through, org-e-odt-underline):
New functions.
(org-e-odt-verbatim): Update function.
(org-e-odt-center-block): Fix docstring.
(org-e-odt-emphasis): Remove function.
* contrib/lisp/org-element.el (org-element-bold-parser):
(org-element-bold-interpreter, org-element-code-parser,
org-element-code-interpreter, org-element-italic-parser,
org-element-italic-interpreter, org-element-strike-through-parser,
org-element-strike-through-interpreter, org-element-underline-parser,
org-element-underline-interpreter): New functions.
(org-element-emphasis-parser, org-element-emphasis-interpreter):
Remove functions.
(org-element-verbatim-parser, org-element-verbatim-interpreter,
org-element-text-markup-successor): Update function.
(org-element-object-successor-alist): Add associations for new object
types.
(org-element-recursive-objects): Add `bold', `italic',
`strike-through' and `underline' as recursive types.
(org-element-object-restrictions): Add restrictions for new recursive
object types.
* contrib/lisp/org-export.el (org-export-filters-alist): Add filters
for new object types.
(org-export-with-todo-keywords): Add missing keywords.
(org-export-filter-center-block-functions,
org-export-filter-drawer-functions,
org-export-filter-dynamic-block-functions,
org-export-filter-headline-functions,
org-export-filter-inlinetask-functions,
org-export-filter-plain-list-functions,
org-export-filter-item-functions, org-export-filter-comment-functions,
org-export-filter-comment-block-functions,
org-export-filter-example-block-functions,
org-export-filter-export-block-functions,
org-export-filter-fixed-width-functions,
org-export-filter-footnote-definition-functions,
org-export-filter-horizontal-rule-functions,
org-export-filter-keyword-functions,
org-export-filter-latex-environment-functions,
org-export-filter-babel-call-functions,
org-export-filter-paragraph-functions,
org-export-filter-property-drawer-functions,
org-export-filter-quote-section-functions,
org-export-filter-quote-block-functions,
org-export-filter-section-functions,
org-export-filter-special-block-functions,
org-export-filter-src-block-functions,
org-export-filter-table-functions,
org-export-filter-table-cell-functions,
org-export-filter-table-row-functions,
org-export-filter-verse-block-functions,
org-export-filter-entity-functions,
org-export-filter-export-snippet-functions,
org-export-filter-footnote-reference-functions,
org-export-filter-inline-babel-call-functions,
org-export-filter-inline-src-block-functions,
org-export-filter-latex-fragment-functions,
org-export-filter-line-break-functions,
org-export-filter-link-functions, org-export-filter-macro-functions,
org-export-filter-radio-target-functions,
org-export-filter-statistics-cookie-functions,
org-export-filter-subscript-functions,
org-export-filter-superscript-functions,
org-export-filter-target-functions,
org-export-filter-time-stamp-functions,
org-export-filter-verbatim-functions): Fix docstring.
(org-export-filter-bold-functions, org-export-filter-code-functions,
org-export-filter-italic-functions,
org-export-filter-strike-through-functions,
org-export-filter-underline-functions): New variables.
(org-export-filter-emphasis-functions): Remove variable.
* testing/lisp/test-org-element.el: Add tests.
2012-04-28 16:00:50 +00:00
|
|
|
|
(ert-deftest test-org-element/code-interpreter ()
|
|
|
|
|
"Test code interpreter."
|
|
|
|
|
(should (equal (org-test-parse-and-interpret "~text~") "~text~\n")))
|
|
|
|
|
|
2012-04-27 15:16:17 +00:00
|
|
|
|
(ert-deftest test-org-element/entity-interpreter ()
|
|
|
|
|
"Test entity interpreter."
|
|
|
|
|
;; 1. Without brackets.
|
|
|
|
|
(should
|
|
|
|
|
(equal (org-test-parse-and-interpret "\\alpha text") "\\alpha text\n"))
|
|
|
|
|
;; 2. With brackets.
|
|
|
|
|
(should
|
|
|
|
|
(equal (org-test-parse-and-interpret "\\alpha{}text") "\\alpha{}text\n")))
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/export-snippet-interpreter ()
|
|
|
|
|
"Test export snippet interpreter."
|
2012-06-30 08:01:28 +00:00
|
|
|
|
(should (equal (org-test-parse-and-interpret "@@back-end:contents@@")
|
|
|
|
|
"@@back-end:contents@@\n")))
|
2012-04-27 15:16:17 +00:00
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/footnote-reference-interpreter ()
|
|
|
|
|
"Test footnote reference interpreter."
|
2015-12-16 17:22:27 +00:00
|
|
|
|
;; Regular reference.
|
2012-04-27 15:16:17 +00:00
|
|
|
|
(should (equal (org-test-parse-and-interpret "Text[fn:1]") "Text[fn:1]\n"))
|
2015-12-16 17:22:27 +00:00
|
|
|
|
;; Named reference.
|
2012-04-27 15:16:17 +00:00
|
|
|
|
(should (equal (org-test-parse-and-interpret "Text[fn:label]")
|
|
|
|
|
"Text[fn:label]\n"))
|
2015-12-16 17:22:27 +00:00
|
|
|
|
;; Inline reference.
|
2012-04-27 15:16:17 +00:00
|
|
|
|
(should (equal (org-test-parse-and-interpret "Text[fn:label:def]")
|
|
|
|
|
"Text[fn:label:def]\n"))
|
2015-12-16 17:22:27 +00:00
|
|
|
|
;; Anonymous reference.
|
2012-04-27 15:16:17 +00:00
|
|
|
|
(should (equal (org-test-parse-and-interpret "Text[fn::def]")
|
|
|
|
|
"Text[fn::def]\n")))
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/inline-babel-call-interpreter ()
|
|
|
|
|
"Test inline babel call interpreter."
|
2015-04-21 09:54:22 +00:00
|
|
|
|
;; Without arguments.
|
2012-04-27 15:16:17 +00:00
|
|
|
|
(should (equal (org-test-parse-and-interpret "call_test()") "call_test()\n"))
|
2015-04-21 09:54:22 +00:00
|
|
|
|
;; With arguments.
|
2012-04-27 15:16:17 +00:00
|
|
|
|
(should (equal (org-test-parse-and-interpret "call_test(x=2)")
|
|
|
|
|
"call_test(x=2)\n"))
|
2015-04-21 09:54:22 +00:00
|
|
|
|
;; With header arguments.
|
2012-04-27 15:16:17 +00:00
|
|
|
|
(should (equal (org-test-parse-and-interpret
|
|
|
|
|
"call_test[:results output]()[:results html]")
|
|
|
|
|
"call_test[:results output]()[:results html]\n")))
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/inline-src-block-interpreter ()
|
|
|
|
|
"Test inline src block interpreter."
|
|
|
|
|
;; 1. Without header argument.
|
|
|
|
|
(should (equal (org-test-parse-and-interpret "src_emacs-lisp{(+ 1 1)}")
|
|
|
|
|
"src_emacs-lisp{(+ 1 1)}\n"))
|
|
|
|
|
;; 2. With header arguments.
|
|
|
|
|
(should (equal (org-test-parse-and-interpret
|
|
|
|
|
"src_emacs-lisp[:results silent]{(+ 1 1)}")
|
|
|
|
|
"src_emacs-lisp[:results silent]{(+ 1 1)}\n")))
|
|
|
|
|
|
org-element: Define new objects (bold, code, italic, ...)
* contrib/lisp/org-e-ascii.el (org-e-ascii-option-alist): Fix typo.
(org-e-ascii-bold, org-e-ascii-code, org-e-ascii-strike-through,
org-e-ascii-underline): New functions.
(org-e-ascii-emphasis): Remove function.
* contrib/lisp/org-e-html.el (org-e-html-text-markup-alist): Variable
renamed from `org-e-html-emphasis-alist'. Change value type.
(org-e-html-bold, org-e-html-italic, org-e-html-strike-through,
org-e-html-underline): New functions.
(org-e-html-verbatim): Update function.
(org-e-html-emphasis): Remove function.
* contrib/lisp/org-e-latex.el (org-e-latex-text-markup-alist):
Variable renamed from `org-e-latex-emphasis-alist'. Change value
type.
(org-e-latex-center-block): Fix docstring.
(org-e-latex--text-markup, org-e-latex-bold, org-e-latex-code,
org-e-latex-italic, org-e-latex-strike-through,
org-e-latex-underline): New functions.
(org-e-latex-verbatim): Update function.
(org-e-latex-emphasis): Remove function.
* contrib/lisp/org-e-odt.el (org-e-odt-bold, org-e-odt-code,
org-e-odt-italic, org-e-odt-strike-through, org-e-odt-underline):
New functions.
(org-e-odt-verbatim): Update function.
(org-e-odt-center-block): Fix docstring.
(org-e-odt-emphasis): Remove function.
* contrib/lisp/org-element.el (org-element-bold-parser):
(org-element-bold-interpreter, org-element-code-parser,
org-element-code-interpreter, org-element-italic-parser,
org-element-italic-interpreter, org-element-strike-through-parser,
org-element-strike-through-interpreter, org-element-underline-parser,
org-element-underline-interpreter): New functions.
(org-element-emphasis-parser, org-element-emphasis-interpreter):
Remove functions.
(org-element-verbatim-parser, org-element-verbatim-interpreter,
org-element-text-markup-successor): Update function.
(org-element-object-successor-alist): Add associations for new object
types.
(org-element-recursive-objects): Add `bold', `italic',
`strike-through' and `underline' as recursive types.
(org-element-object-restrictions): Add restrictions for new recursive
object types.
* contrib/lisp/org-export.el (org-export-filters-alist): Add filters
for new object types.
(org-export-with-todo-keywords): Add missing keywords.
(org-export-filter-center-block-functions,
org-export-filter-drawer-functions,
org-export-filter-dynamic-block-functions,
org-export-filter-headline-functions,
org-export-filter-inlinetask-functions,
org-export-filter-plain-list-functions,
org-export-filter-item-functions, org-export-filter-comment-functions,
org-export-filter-comment-block-functions,
org-export-filter-example-block-functions,
org-export-filter-export-block-functions,
org-export-filter-fixed-width-functions,
org-export-filter-footnote-definition-functions,
org-export-filter-horizontal-rule-functions,
org-export-filter-keyword-functions,
org-export-filter-latex-environment-functions,
org-export-filter-babel-call-functions,
org-export-filter-paragraph-functions,
org-export-filter-property-drawer-functions,
org-export-filter-quote-section-functions,
org-export-filter-quote-block-functions,
org-export-filter-section-functions,
org-export-filter-special-block-functions,
org-export-filter-src-block-functions,
org-export-filter-table-functions,
org-export-filter-table-cell-functions,
org-export-filter-table-row-functions,
org-export-filter-verse-block-functions,
org-export-filter-entity-functions,
org-export-filter-export-snippet-functions,
org-export-filter-footnote-reference-functions,
org-export-filter-inline-babel-call-functions,
org-export-filter-inline-src-block-functions,
org-export-filter-latex-fragment-functions,
org-export-filter-line-break-functions,
org-export-filter-link-functions, org-export-filter-macro-functions,
org-export-filter-radio-target-functions,
org-export-filter-statistics-cookie-functions,
org-export-filter-subscript-functions,
org-export-filter-superscript-functions,
org-export-filter-target-functions,
org-export-filter-time-stamp-functions,
org-export-filter-verbatim-functions): Fix docstring.
(org-export-filter-bold-functions, org-export-filter-code-functions,
org-export-filter-italic-functions,
org-export-filter-strike-through-functions,
org-export-filter-underline-functions): New variables.
(org-export-filter-emphasis-functions): Remove variable.
* testing/lisp/test-org-element.el: Add tests.
2012-04-28 16:00:50 +00:00
|
|
|
|
(ert-deftest test-org-element/italic-interpreter ()
|
|
|
|
|
"Test italic interpreter."
|
|
|
|
|
(should (equal (org-test-parse-and-interpret "/text/") "/text/\n")))
|
|
|
|
|
|
2012-04-27 15:16:17 +00:00
|
|
|
|
(ert-deftest test-org-element/latex-fragment-interpreter ()
|
|
|
|
|
"Test latex fragment interpreter."
|
2013-10-29 13:53:21 +00:00
|
|
|
|
(should (equal (org-test-parse-and-interpret "\\command{}") "\\command{}\n"))
|
|
|
|
|
(should (equal (org-test-parse-and-interpret "$x$") "$x$\n"))
|
|
|
|
|
(should (equal (org-test-parse-and-interpret "$x+y$") "$x+y$\n"))
|
|
|
|
|
(should (equal (org-test-parse-and-interpret "$$x+y$$") "$$x+y$$\n"))
|
|
|
|
|
(should (equal (org-test-parse-and-interpret "\\(x+y\\)") "\\(x+y\\)\n"))
|
|
|
|
|
(should (equal (org-test-parse-and-interpret "\\[x+y\\]") "\\[x+y\\]\n")))
|
2012-04-27 15:16:17 +00:00
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/line-break-interpreter ()
|
|
|
|
|
"Test line break interpreter."
|
|
|
|
|
(should (equal (org-test-parse-and-interpret "First line \\\\ \nSecond line")
|
|
|
|
|
"First line \\\\\nSecond line\n")))
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/link-interpreter ()
|
|
|
|
|
"Test link interpreter."
|
2015-08-19 13:12:57 +00:00
|
|
|
|
;; Links targeted from a radio target.
|
2012-04-27 15:16:17 +00:00
|
|
|
|
(should (equal (let ((org-target-link-regexp "radio-target"))
|
|
|
|
|
(org-test-parse-and-interpret "a radio-target"))
|
|
|
|
|
"a radio-target\n"))
|
2015-08-19 13:12:57 +00:00
|
|
|
|
;; Links without description.
|
2018-01-16 18:42:57 +00:00
|
|
|
|
(should (equal (org-test-parse-and-interpret "[[https://orgmode.org]]")
|
|
|
|
|
"[[https://orgmode.org]]\n"))
|
2016-10-08 22:26:45 +00:00
|
|
|
|
;; Links with a description, even one containing a link.
|
2012-04-27 15:16:17 +00:00
|
|
|
|
(should (equal (org-test-parse-and-interpret
|
2018-01-16 18:42:57 +00:00
|
|
|
|
"[[https://orgmode.org][Org mode]]")
|
|
|
|
|
"[[https://orgmode.org][Org mode]]\n"))
|
2016-10-08 22:26:45 +00:00
|
|
|
|
(should (equal (org-test-parse-and-interpret
|
2018-01-16 18:42:57 +00:00
|
|
|
|
"[[https://orgmode.org][https://orgmode.org]]")
|
|
|
|
|
"[[https://orgmode.org][https://orgmode.org]]\n"))
|
2015-08-19 13:12:57 +00:00
|
|
|
|
;; File links.
|
|
|
|
|
(should
|
|
|
|
|
(equal (org-test-parse-and-interpret "[[file+emacs:todo.org]]")
|
|
|
|
|
"[[file+emacs:todo.org]]\n"))
|
|
|
|
|
(should
|
|
|
|
|
(equal (org-test-parse-and-interpret "[[file:todo.org::*task]]")
|
|
|
|
|
"[[file:todo.org::*task]]\n"))
|
|
|
|
|
;; Id links.
|
2012-04-27 15:16:17 +00:00
|
|
|
|
(should (equal (org-test-parse-and-interpret "[[id:aaaa]]") "[[id:aaaa]]\n"))
|
2015-08-19 13:12:57 +00:00
|
|
|
|
;; Custom-id links.
|
2012-04-27 15:16:17 +00:00
|
|
|
|
(should (equal (org-test-parse-and-interpret "[[#id]]") "[[#id]]\n"))
|
2015-08-19 13:12:57 +00:00
|
|
|
|
;; Code-ref links.
|
2012-04-27 15:16:17 +00:00
|
|
|
|
(should (equal (org-test-parse-and-interpret "[[(ref)]]") "[[(ref)]]\n"))
|
2016-10-08 22:26:45 +00:00
|
|
|
|
;; Plain links.
|
2018-01-16 18:42:57 +00:00
|
|
|
|
(should (equal (org-test-parse-and-interpret "https://orgmode.org")
|
|
|
|
|
"https://orgmode.org\n"))
|
2016-10-08 22:26:45 +00:00
|
|
|
|
;; Angular links.
|
2018-01-16 18:42:57 +00:00
|
|
|
|
(should (equal (org-test-parse-and-interpret "<https://orgmode.org>")
|
|
|
|
|
"<https://orgmode.org>\n"))
|
2016-10-24 21:56:34 +00:00
|
|
|
|
;; Pathological case: link with a %-sign in description.
|
|
|
|
|
(should (equal (org-test-parse-and-interpret "[[file://path][%s]]")
|
|
|
|
|
"[[file://path][%s]]\n")))
|
2012-04-27 15:16:17 +00:00
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/macro-interpreter ()
|
|
|
|
|
"Test macro interpreter."
|
|
|
|
|
;; 1. Without argument.
|
|
|
|
|
(should (equal (org-test-parse-and-interpret "{{{test}}}") "{{{test}}}\n"))
|
|
|
|
|
;; 2. With arguments.
|
|
|
|
|
(should (equal (org-test-parse-and-interpret "{{{test(arg1,arg2)}}}")
|
|
|
|
|
"{{{test(arg1,arg2)}}}\n")))
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/radio-target-interpreter ()
|
|
|
|
|
"Test radio target interpreter."
|
|
|
|
|
(should (equal (org-test-parse-and-interpret "<<<some text>>>")
|
|
|
|
|
"<<<some text>>>\n")))
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/statistics-cookie-interpreter ()
|
|
|
|
|
"Test statistics cookie interpreter."
|
|
|
|
|
;; 1. Without percent
|
|
|
|
|
(should (equal (org-test-parse-and-interpret "[0/1]") "[0/1]\n"))
|
|
|
|
|
;; 2. With percent.
|
|
|
|
|
(should (equal (org-test-parse-and-interpret "[66%]") "[66%]\n")))
|
|
|
|
|
|
org-element: Define new objects (bold, code, italic, ...)
* contrib/lisp/org-e-ascii.el (org-e-ascii-option-alist): Fix typo.
(org-e-ascii-bold, org-e-ascii-code, org-e-ascii-strike-through,
org-e-ascii-underline): New functions.
(org-e-ascii-emphasis): Remove function.
* contrib/lisp/org-e-html.el (org-e-html-text-markup-alist): Variable
renamed from `org-e-html-emphasis-alist'. Change value type.
(org-e-html-bold, org-e-html-italic, org-e-html-strike-through,
org-e-html-underline): New functions.
(org-e-html-verbatim): Update function.
(org-e-html-emphasis): Remove function.
* contrib/lisp/org-e-latex.el (org-e-latex-text-markup-alist):
Variable renamed from `org-e-latex-emphasis-alist'. Change value
type.
(org-e-latex-center-block): Fix docstring.
(org-e-latex--text-markup, org-e-latex-bold, org-e-latex-code,
org-e-latex-italic, org-e-latex-strike-through,
org-e-latex-underline): New functions.
(org-e-latex-verbatim): Update function.
(org-e-latex-emphasis): Remove function.
* contrib/lisp/org-e-odt.el (org-e-odt-bold, org-e-odt-code,
org-e-odt-italic, org-e-odt-strike-through, org-e-odt-underline):
New functions.
(org-e-odt-verbatim): Update function.
(org-e-odt-center-block): Fix docstring.
(org-e-odt-emphasis): Remove function.
* contrib/lisp/org-element.el (org-element-bold-parser):
(org-element-bold-interpreter, org-element-code-parser,
org-element-code-interpreter, org-element-italic-parser,
org-element-italic-interpreter, org-element-strike-through-parser,
org-element-strike-through-interpreter, org-element-underline-parser,
org-element-underline-interpreter): New functions.
(org-element-emphasis-parser, org-element-emphasis-interpreter):
Remove functions.
(org-element-verbatim-parser, org-element-verbatim-interpreter,
org-element-text-markup-successor): Update function.
(org-element-object-successor-alist): Add associations for new object
types.
(org-element-recursive-objects): Add `bold', `italic',
`strike-through' and `underline' as recursive types.
(org-element-object-restrictions): Add restrictions for new recursive
object types.
* contrib/lisp/org-export.el (org-export-filters-alist): Add filters
for new object types.
(org-export-with-todo-keywords): Add missing keywords.
(org-export-filter-center-block-functions,
org-export-filter-drawer-functions,
org-export-filter-dynamic-block-functions,
org-export-filter-headline-functions,
org-export-filter-inlinetask-functions,
org-export-filter-plain-list-functions,
org-export-filter-item-functions, org-export-filter-comment-functions,
org-export-filter-comment-block-functions,
org-export-filter-example-block-functions,
org-export-filter-export-block-functions,
org-export-filter-fixed-width-functions,
org-export-filter-footnote-definition-functions,
org-export-filter-horizontal-rule-functions,
org-export-filter-keyword-functions,
org-export-filter-latex-environment-functions,
org-export-filter-babel-call-functions,
org-export-filter-paragraph-functions,
org-export-filter-property-drawer-functions,
org-export-filter-quote-section-functions,
org-export-filter-quote-block-functions,
org-export-filter-section-functions,
org-export-filter-special-block-functions,
org-export-filter-src-block-functions,
org-export-filter-table-functions,
org-export-filter-table-cell-functions,
org-export-filter-table-row-functions,
org-export-filter-verse-block-functions,
org-export-filter-entity-functions,
org-export-filter-export-snippet-functions,
org-export-filter-footnote-reference-functions,
org-export-filter-inline-babel-call-functions,
org-export-filter-inline-src-block-functions,
org-export-filter-latex-fragment-functions,
org-export-filter-line-break-functions,
org-export-filter-link-functions, org-export-filter-macro-functions,
org-export-filter-radio-target-functions,
org-export-filter-statistics-cookie-functions,
org-export-filter-subscript-functions,
org-export-filter-superscript-functions,
org-export-filter-target-functions,
org-export-filter-time-stamp-functions,
org-export-filter-verbatim-functions): Fix docstring.
(org-export-filter-bold-functions, org-export-filter-code-functions,
org-export-filter-italic-functions,
org-export-filter-strike-through-functions,
org-export-filter-underline-functions): New variables.
(org-export-filter-emphasis-functions): Remove variable.
* testing/lisp/test-org-element.el: Add tests.
2012-04-28 16:00:50 +00:00
|
|
|
|
(ert-deftest test-org-element/strike-through-interpreter ()
|
|
|
|
|
"Test strike through interpreter."
|
|
|
|
|
(should (equal (org-test-parse-and-interpret "+target+") "+target+\n")))
|
|
|
|
|
|
2012-04-27 15:16:17 +00:00
|
|
|
|
(ert-deftest test-org-element/subscript-interpreter ()
|
|
|
|
|
"Test subscript interpreter."
|
|
|
|
|
;; 1. Without brackets.
|
|
|
|
|
(should (equal (org-test-parse-and-interpret "a_b") "a_b\n"))
|
|
|
|
|
;; 2. With brackets.
|
|
|
|
|
(should (equal (org-test-parse-and-interpret "a_{b}") "a_{b}\n")))
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/superscript-interpreter ()
|
|
|
|
|
"Test superscript interpreter."
|
|
|
|
|
;; 1. Without brackets.
|
|
|
|
|
(should (equal (org-test-parse-and-interpret "a^b") "a^b\n"))
|
|
|
|
|
;; 2. With brackets.
|
|
|
|
|
(should (equal (org-test-parse-and-interpret "a^{b}") "a^{b}\n")))
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/target-interpreter ()
|
|
|
|
|
"Test target interpreter."
|
|
|
|
|
(should (equal (org-test-parse-and-interpret "<<target>>") "<<target>>\n")))
|
2012-04-25 20:15:29 +00:00
|
|
|
|
|
org-element: Define new objects (bold, code, italic, ...)
* contrib/lisp/org-e-ascii.el (org-e-ascii-option-alist): Fix typo.
(org-e-ascii-bold, org-e-ascii-code, org-e-ascii-strike-through,
org-e-ascii-underline): New functions.
(org-e-ascii-emphasis): Remove function.
* contrib/lisp/org-e-html.el (org-e-html-text-markup-alist): Variable
renamed from `org-e-html-emphasis-alist'. Change value type.
(org-e-html-bold, org-e-html-italic, org-e-html-strike-through,
org-e-html-underline): New functions.
(org-e-html-verbatim): Update function.
(org-e-html-emphasis): Remove function.
* contrib/lisp/org-e-latex.el (org-e-latex-text-markup-alist):
Variable renamed from `org-e-latex-emphasis-alist'. Change value
type.
(org-e-latex-center-block): Fix docstring.
(org-e-latex--text-markup, org-e-latex-bold, org-e-latex-code,
org-e-latex-italic, org-e-latex-strike-through,
org-e-latex-underline): New functions.
(org-e-latex-verbatim): Update function.
(org-e-latex-emphasis): Remove function.
* contrib/lisp/org-e-odt.el (org-e-odt-bold, org-e-odt-code,
org-e-odt-italic, org-e-odt-strike-through, org-e-odt-underline):
New functions.
(org-e-odt-verbatim): Update function.
(org-e-odt-center-block): Fix docstring.
(org-e-odt-emphasis): Remove function.
* contrib/lisp/org-element.el (org-element-bold-parser):
(org-element-bold-interpreter, org-element-code-parser,
org-element-code-interpreter, org-element-italic-parser,
org-element-italic-interpreter, org-element-strike-through-parser,
org-element-strike-through-interpreter, org-element-underline-parser,
org-element-underline-interpreter): New functions.
(org-element-emphasis-parser, org-element-emphasis-interpreter):
Remove functions.
(org-element-verbatim-parser, org-element-verbatim-interpreter,
org-element-text-markup-successor): Update function.
(org-element-object-successor-alist): Add associations for new object
types.
(org-element-recursive-objects): Add `bold', `italic',
`strike-through' and `underline' as recursive types.
(org-element-object-restrictions): Add restrictions for new recursive
object types.
* contrib/lisp/org-export.el (org-export-filters-alist): Add filters
for new object types.
(org-export-with-todo-keywords): Add missing keywords.
(org-export-filter-center-block-functions,
org-export-filter-drawer-functions,
org-export-filter-dynamic-block-functions,
org-export-filter-headline-functions,
org-export-filter-inlinetask-functions,
org-export-filter-plain-list-functions,
org-export-filter-item-functions, org-export-filter-comment-functions,
org-export-filter-comment-block-functions,
org-export-filter-example-block-functions,
org-export-filter-export-block-functions,
org-export-filter-fixed-width-functions,
org-export-filter-footnote-definition-functions,
org-export-filter-horizontal-rule-functions,
org-export-filter-keyword-functions,
org-export-filter-latex-environment-functions,
org-export-filter-babel-call-functions,
org-export-filter-paragraph-functions,
org-export-filter-property-drawer-functions,
org-export-filter-quote-section-functions,
org-export-filter-quote-block-functions,
org-export-filter-section-functions,
org-export-filter-special-block-functions,
org-export-filter-src-block-functions,
org-export-filter-table-functions,
org-export-filter-table-cell-functions,
org-export-filter-table-row-functions,
org-export-filter-verse-block-functions,
org-export-filter-entity-functions,
org-export-filter-export-snippet-functions,
org-export-filter-footnote-reference-functions,
org-export-filter-inline-babel-call-functions,
org-export-filter-inline-src-block-functions,
org-export-filter-latex-fragment-functions,
org-export-filter-line-break-functions,
org-export-filter-link-functions, org-export-filter-macro-functions,
org-export-filter-radio-target-functions,
org-export-filter-statistics-cookie-functions,
org-export-filter-subscript-functions,
org-export-filter-superscript-functions,
org-export-filter-target-functions,
org-export-filter-time-stamp-functions,
org-export-filter-verbatim-functions): Fix docstring.
(org-export-filter-bold-functions, org-export-filter-code-functions,
org-export-filter-italic-functions,
org-export-filter-strike-through-functions,
org-export-filter-underline-functions): New variables.
(org-export-filter-emphasis-functions): Remove variable.
* testing/lisp/test-org-element.el: Add tests.
2012-04-28 16:00:50 +00:00
|
|
|
|
(ert-deftest test-org-element/underline-interpreter ()
|
|
|
|
|
"Test underline interpreter."
|
|
|
|
|
(should (equal (org-test-parse-and-interpret "_text_") "_text_\n")))
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/verbatim-interpreter ()
|
|
|
|
|
"Test verbatim interpreter."
|
|
|
|
|
(should (equal (org-test-parse-and-interpret "=text=") "=text=\n")))
|
|
|
|
|
|
2012-04-10 21:15:32 +00:00
|
|
|
|
|
2012-04-25 18:40:13 +00:00
|
|
|
|
|
2012-04-30 15:20:57 +00:00
|
|
|
|
;;; Test Granularity
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/granularity ()
|
|
|
|
|
"Test granularity impact on buffer parsing."
|
2019-05-26 01:34:34 +00:00
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"* Head 1
|
2012-04-30 15:20:57 +00:00
|
|
|
|
** Head 2
|
|
|
|
|
#+BEGIN_CENTER
|
|
|
|
|
Centered paragraph.
|
|
|
|
|
#+END_CENTER
|
|
|
|
|
Paragraph \\alpha."
|
|
|
|
|
;; 1.1. Granularity set to `headline' should parse every headline
|
|
|
|
|
;; in buffer, and only them.
|
|
|
|
|
(let ((tree (org-element-parse-buffer 'headline)))
|
|
|
|
|
(should (= 2 (length (org-element-map tree 'headline 'identity))))
|
|
|
|
|
(should-not (org-element-map tree 'paragraph 'identity)))
|
|
|
|
|
;; 1.2. Granularity set to `greater-element' should not enter
|
|
|
|
|
;; greater elements excepted headlines and sections.
|
|
|
|
|
(let ((tree (org-element-parse-buffer 'greater-element)))
|
|
|
|
|
(should (= 1 (length (org-element-map tree 'center-block 'identity))))
|
|
|
|
|
(should (= 1 (length (org-element-map tree 'paragraph 'identity))))
|
|
|
|
|
(should-not (org-element-map tree 'entity 'identity)))
|
|
|
|
|
;; 1.3. Granularity set to `element' should enter every
|
|
|
|
|
;; greater-element.
|
|
|
|
|
(let ((tree (org-element-parse-buffer 'element)))
|
|
|
|
|
(should (= 2 (length (org-element-map tree 'paragraph 'identity))))
|
|
|
|
|
(should-not (org-element-map tree 'entity 'identity)))
|
|
|
|
|
;; 1.4. Granularity set to `object' can see everything.
|
|
|
|
|
(let ((tree (org-element-parse-buffer 'object)))
|
|
|
|
|
(should (= 1 (length (org-element-map tree 'entity 'identity)))))))
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/secondary-string-parsing ()
|
|
|
|
|
"Test if granularity correctly toggles secondary strings parsing."
|
2014-07-25 12:47:38 +00:00
|
|
|
|
;; With a granularity bigger than `object', no secondary string
|
|
|
|
|
;; should be parsed.
|
|
|
|
|
(should
|
|
|
|
|
(stringp
|
|
|
|
|
(org-test-with-temp-text "* Headline"
|
|
|
|
|
(let ((headline
|
|
|
|
|
(org-element-map (org-element-parse-buffer 'headline) 'headline
|
|
|
|
|
#'identity nil 'first-match)))
|
|
|
|
|
(org-element-property :title headline)))))
|
|
|
|
|
(should
|
|
|
|
|
(stringp
|
|
|
|
|
(org-test-with-temp-text "* Headline\n- tag :: item"
|
|
|
|
|
(let ((item (org-element-map (org-element-parse-buffer 'element) 'item
|
|
|
|
|
#'identity nil 'first-match)))
|
|
|
|
|
(org-element-property :tag item)))))
|
2012-04-30 15:20:57 +00:00
|
|
|
|
(when (featurep 'org-inlinetask)
|
2014-07-25 12:47:38 +00:00
|
|
|
|
(should
|
|
|
|
|
(stringp
|
|
|
|
|
(let ((org-inlinetask-min-level 15))
|
|
|
|
|
(org-test-with-temp-text "*************** Inlinetask"
|
|
|
|
|
(let ((inlinetask (org-element-map (org-element-parse-buffer 'element)
|
|
|
|
|
'inlinetask
|
|
|
|
|
#'identity nil 'first-match)))
|
|
|
|
|
(org-element-property :title inlinetask)))))))
|
|
|
|
|
;; With a default granularity, secondary strings should be parsed.
|
|
|
|
|
(should
|
|
|
|
|
(listp
|
|
|
|
|
(org-test-with-temp-text "* Headline"
|
|
|
|
|
(let ((headline
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'headline
|
|
|
|
|
#'identity nil 'first-match)))
|
|
|
|
|
(org-element-property :title headline)))))
|
|
|
|
|
;; `org-element-at-point' should never parse a secondary string.
|
|
|
|
|
(should-not
|
|
|
|
|
(listp
|
|
|
|
|
(org-test-with-temp-text "* Headline"
|
|
|
|
|
(org-element-property :title (org-element-at-point)))))
|
|
|
|
|
;; Preserve current local variables when parsing a secondary string.
|
|
|
|
|
(should
|
|
|
|
|
(let ((org-entities nil)
|
|
|
|
|
(org-entities-user nil))
|
|
|
|
|
(org-test-with-temp-text "
|
|
|
|
|
#+CAPTION: \\foo
|
|
|
|
|
Text
|
|
|
|
|
# Local Variables:
|
|
|
|
|
# org-entities-user: ((\"foo\"))
|
|
|
|
|
# End:"
|
|
|
|
|
(let ((safe-local-variable-values '((org-entities-user . (("foo"))))))
|
|
|
|
|
(hack-local-variables))
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'entity
|
|
|
|
|
#'identity nil nil nil t)))))
|
2012-04-30 15:20:57 +00:00
|
|
|
|
|
|
|
|
|
|
2013-05-08 07:56:26 +00:00
|
|
|
|
|
|
|
|
|
;;; Test Visible Only Parsing
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/parse-buffer-visible ()
|
|
|
|
|
"Test `org-element-parse-buffer' with visible only argument."
|
|
|
|
|
(should
|
|
|
|
|
(equal '("H1" "H3" "H5")
|
2020-01-11 19:05:07 +00:00
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"* H1\n** H2\n** H3 :visible:\n** H4\n** H5 :visible:"
|
|
|
|
|
(org-occur ":visible:")
|
|
|
|
|
(org-element-map (org-element-parse-buffer nil t) 'headline
|
|
|
|
|
(lambda (hl) (org-element-property :raw-value hl))))))
|
|
|
|
|
(should
|
|
|
|
|
(equal "Test"
|
|
|
|
|
(let ((contents "Test"))
|
|
|
|
|
(org-test-with-temp-text contents
|
|
|
|
|
(add-text-properties 0 1 '(invisible t) contents)
|
|
|
|
|
(org-element-map (org-element-parse-buffer nil t) 'plain-text
|
|
|
|
|
#'org-no-properties nil t)))))
|
|
|
|
|
(should
|
|
|
|
|
(equal "Test"
|
|
|
|
|
(let ((contents "Test"))
|
|
|
|
|
(org-test-with-temp-text (concat "- " contents)
|
|
|
|
|
(add-text-properties 0 1 '(invisible t) contents)
|
|
|
|
|
(org-element-map (org-element-parse-buffer nil t) 'plain-text
|
|
|
|
|
#'org-no-properties nil t))))))
|
2013-05-08 07:56:26 +00:00
|
|
|
|
|
|
|
|
|
|
2012-06-08 18:16:57 +00:00
|
|
|
|
|
|
|
|
|
;;; Test `:parent' Property
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/parent-property ()
|
|
|
|
|
"Test `:parent' property."
|
|
|
|
|
;; Elements.
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_CENTER\nText\n#+END_CENTER"
|
|
|
|
|
(let* ((tree (org-element-parse-buffer))
|
|
|
|
|
(parent (org-element-property
|
|
|
|
|
:parent
|
|
|
|
|
(org-element-map tree 'paragraph 'identity nil t))))
|
|
|
|
|
(should parent)
|
2012-07-18 09:25:29 +00:00
|
|
|
|
(should (eq (org-element-map tree 'center-block 'identity nil t)
|
|
|
|
|
parent))))
|
2012-06-08 18:16:57 +00:00
|
|
|
|
;; Objects.
|
|
|
|
|
(org-test-with-temp-text "a_{/b/}"
|
|
|
|
|
(let* ((tree (org-element-parse-buffer))
|
|
|
|
|
(parent (org-element-property
|
|
|
|
|
:parent
|
|
|
|
|
(org-element-map tree 'italic 'identity nil t))))
|
|
|
|
|
(should parent)
|
2012-07-18 09:25:29 +00:00
|
|
|
|
(should (eq parent
|
|
|
|
|
(org-element-map tree 'subscript 'identity nil t)))))
|
2012-06-08 18:16:57 +00:00
|
|
|
|
;; Secondary strings
|
|
|
|
|
(org-test-with-temp-text "* /italic/"
|
|
|
|
|
(let* ((tree (org-element-parse-buffer))
|
|
|
|
|
(parent (org-element-property
|
|
|
|
|
:parent (org-element-map tree 'italic 'identity nil t))))
|
|
|
|
|
(should parent)
|
2012-07-18 09:25:29 +00:00
|
|
|
|
(should (eq parent
|
|
|
|
|
(org-element-map tree 'headline 'identity nil t))))))
|
2012-06-08 18:16:57 +00:00
|
|
|
|
|
|
|
|
|
|
2012-04-30 15:20:57 +00:00
|
|
|
|
|
|
|
|
|
;;; Test Normalize Contents
|
2012-04-25 18:40:13 +00:00
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/normalize-contents ()
|
|
|
|
|
"Test `org-element-normalize-contents' specifications."
|
2014-02-07 19:00:45 +00:00
|
|
|
|
;; Remove maximum common indentation from element's contents.
|
2012-04-25 18:40:13 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
(org-element-normalize-contents
|
|
|
|
|
'(paragraph nil " Two spaces\n Three spaces"))
|
|
|
|
|
'(paragraph nil "Two spaces\n Three spaces")))
|
2017-01-12 13:33:17 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
(org-element-normalize-contents
|
|
|
|
|
'(paragraph nil " Two spaces\nNo space"))
|
|
|
|
|
'(paragraph nil " Two spaces\nNo space")))
|
2014-02-07 19:00:45 +00:00
|
|
|
|
;; Ignore objects within contents when computing maximum common
|
2015-03-07 00:52:58 +00:00
|
|
|
|
;; indentation. However, if contents start with an object, common
|
|
|
|
|
;; indentation is 0.
|
2012-04-25 18:40:13 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
(org-element-normalize-contents
|
|
|
|
|
'(paragraph nil " One " (emphasis nil "space") "\n Two spaces"))
|
|
|
|
|
'(paragraph nil "One " (emphasis nil "space") "\n Two spaces")))
|
2015-03-07 00:52:58 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
(org-element-normalize-contents
|
|
|
|
|
'(paragraph nil (verbatim nil "V") "No space\n Two\n Three"))
|
|
|
|
|
'(paragraph nil (verbatim nil "V") "No space\n Two\n Three")))
|
2014-02-07 19:00:45 +00:00
|
|
|
|
;; Ignore blank lines.
|
2012-04-25 18:40:13 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
(org-element-normalize-contents
|
|
|
|
|
'(paragraph nil " Two spaces\n\n \n Two spaces"))
|
2016-01-26 21:53:55 +00:00
|
|
|
|
'(paragraph nil "Two spaces\n\n\nTwo spaces")))
|
2014-02-07 19:00:45 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
'(paragraph nil " Two spaces\n" (verbatim nil "V") "\n Two spaces")
|
|
|
|
|
(org-element-normalize-contents
|
|
|
|
|
'(paragraph nil " Two spaces\n " (verbatim nil "V") "\n Two spaces"))))
|
2014-08-15 19:46:46 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
'(verse-block nil "line 1\n\nline 2")
|
|
|
|
|
(org-element-normalize-contents
|
|
|
|
|
'(verse-block nil " line 1\n\n line 2"))))
|
2014-02-07 19:00:45 +00:00
|
|
|
|
;; Recursively enter objects in order to compute common indentation.
|
2012-04-25 18:40:13 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
(org-element-normalize-contents
|
org-element: Define new objects (bold, code, italic, ...)
* contrib/lisp/org-e-ascii.el (org-e-ascii-option-alist): Fix typo.
(org-e-ascii-bold, org-e-ascii-code, org-e-ascii-strike-through,
org-e-ascii-underline): New functions.
(org-e-ascii-emphasis): Remove function.
* contrib/lisp/org-e-html.el (org-e-html-text-markup-alist): Variable
renamed from `org-e-html-emphasis-alist'. Change value type.
(org-e-html-bold, org-e-html-italic, org-e-html-strike-through,
org-e-html-underline): New functions.
(org-e-html-verbatim): Update function.
(org-e-html-emphasis): Remove function.
* contrib/lisp/org-e-latex.el (org-e-latex-text-markup-alist):
Variable renamed from `org-e-latex-emphasis-alist'. Change value
type.
(org-e-latex-center-block): Fix docstring.
(org-e-latex--text-markup, org-e-latex-bold, org-e-latex-code,
org-e-latex-italic, org-e-latex-strike-through,
org-e-latex-underline): New functions.
(org-e-latex-verbatim): Update function.
(org-e-latex-emphasis): Remove function.
* contrib/lisp/org-e-odt.el (org-e-odt-bold, org-e-odt-code,
org-e-odt-italic, org-e-odt-strike-through, org-e-odt-underline):
New functions.
(org-e-odt-verbatim): Update function.
(org-e-odt-center-block): Fix docstring.
(org-e-odt-emphasis): Remove function.
* contrib/lisp/org-element.el (org-element-bold-parser):
(org-element-bold-interpreter, org-element-code-parser,
org-element-code-interpreter, org-element-italic-parser,
org-element-italic-interpreter, org-element-strike-through-parser,
org-element-strike-through-interpreter, org-element-underline-parser,
org-element-underline-interpreter): New functions.
(org-element-emphasis-parser, org-element-emphasis-interpreter):
Remove functions.
(org-element-verbatim-parser, org-element-verbatim-interpreter,
org-element-text-markup-successor): Update function.
(org-element-object-successor-alist): Add associations for new object
types.
(org-element-recursive-objects): Add `bold', `italic',
`strike-through' and `underline' as recursive types.
(org-element-object-restrictions): Add restrictions for new recursive
object types.
* contrib/lisp/org-export.el (org-export-filters-alist): Add filters
for new object types.
(org-export-with-todo-keywords): Add missing keywords.
(org-export-filter-center-block-functions,
org-export-filter-drawer-functions,
org-export-filter-dynamic-block-functions,
org-export-filter-headline-functions,
org-export-filter-inlinetask-functions,
org-export-filter-plain-list-functions,
org-export-filter-item-functions, org-export-filter-comment-functions,
org-export-filter-comment-block-functions,
org-export-filter-example-block-functions,
org-export-filter-export-block-functions,
org-export-filter-fixed-width-functions,
org-export-filter-footnote-definition-functions,
org-export-filter-horizontal-rule-functions,
org-export-filter-keyword-functions,
org-export-filter-latex-environment-functions,
org-export-filter-babel-call-functions,
org-export-filter-paragraph-functions,
org-export-filter-property-drawer-functions,
org-export-filter-quote-section-functions,
org-export-filter-quote-block-functions,
org-export-filter-section-functions,
org-export-filter-special-block-functions,
org-export-filter-src-block-functions,
org-export-filter-table-functions,
org-export-filter-table-cell-functions,
org-export-filter-table-row-functions,
org-export-filter-verse-block-functions,
org-export-filter-entity-functions,
org-export-filter-export-snippet-functions,
org-export-filter-footnote-reference-functions,
org-export-filter-inline-babel-call-functions,
org-export-filter-inline-src-block-functions,
org-export-filter-latex-fragment-functions,
org-export-filter-line-break-functions,
org-export-filter-link-functions, org-export-filter-macro-functions,
org-export-filter-radio-target-functions,
org-export-filter-statistics-cookie-functions,
org-export-filter-subscript-functions,
org-export-filter-superscript-functions,
org-export-filter-target-functions,
org-export-filter-time-stamp-functions,
org-export-filter-verbatim-functions): Fix docstring.
(org-export-filter-bold-functions, org-export-filter-code-functions,
org-export-filter-italic-functions,
org-export-filter-strike-through-functions,
org-export-filter-underline-functions): New variables.
(org-export-filter-emphasis-functions): Remove variable.
* testing/lisp/test-org-element.el: Add tests.
2012-04-28 16:00:50 +00:00
|
|
|
|
'(paragraph nil " Two spaces " (bold nil " and\n One space")))
|
|
|
|
|
'(paragraph nil " Two spaces " (bold nil " and\nOne space"))))
|
2014-02-07 19:00:45 +00:00
|
|
|
|
;; When optional argument is provided, ignore first line
|
|
|
|
|
;; indentation.
|
2012-04-25 18:40:13 +00:00
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
(org-element-normalize-contents
|
|
|
|
|
'(paragraph nil "No space\n Two spaces\n Three spaces") t)
|
2015-03-07 00:52:58 +00:00
|
|
|
|
'(paragraph nil "No space\nTwo spaces\n Three spaces")))
|
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
(org-element-normalize-contents
|
|
|
|
|
'(paragraph nil (verbatim nil "V") "No space\n Two\n Three") t)
|
|
|
|
|
'(paragraph nil (verbatim nil "V") "No space\nTwo\n Three")))
|
|
|
|
|
;; Corner case: do not ignore indentation of string right after
|
|
|
|
|
;; a line break.
|
|
|
|
|
(should
|
|
|
|
|
(equal
|
|
|
|
|
(org-element-normalize-contents
|
|
|
|
|
'(paragraph nil " 1 space" (line-break) " 2 spaces"))
|
|
|
|
|
'(paragraph nil "1 space" (line-break) " 2 spaces"))))
|
2012-04-25 18:40:13 +00:00
|
|
|
|
|
2012-04-30 15:20:57 +00:00
|
|
|
|
|
2012-04-10 21:15:32 +00:00
|
|
|
|
|
2012-04-30 15:20:57 +00:00
|
|
|
|
;;; Test Navigation Tools.
|
2012-02-24 00:23:25 +00:00
|
|
|
|
|
2012-05-05 07:14:39 +00:00
|
|
|
|
(ert-deftest test-org-element/at-point ()
|
|
|
|
|
"Test `org-element-at-point' specifications."
|
2012-07-29 22:40:21 +00:00
|
|
|
|
;; Return closest element containing point.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'paragraph
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_CENTER\nA\n#+END_CENTER"
|
|
|
|
|
(progn (search-forward "A")
|
|
|
|
|
(org-element-type (org-element-at-point))))))
|
|
|
|
|
;; Correctly set `:parent' property.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'center-block
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_CENTER\nA\n#+END_CENTER"
|
|
|
|
|
(progn (search-forward "A")
|
|
|
|
|
(org-element-type
|
|
|
|
|
(org-element-property :parent (org-element-at-point)))))))
|
2013-09-11 10:22:05 +00:00
|
|
|
|
;; Special case: at a blank line just below a headline, return that
|
|
|
|
|
;; headline.
|
|
|
|
|
(should
|
|
|
|
|
(equal "H1" (org-test-with-temp-text "* H1\n \n* H2\n"
|
|
|
|
|
(forward-line)
|
|
|
|
|
(org-element-property :title (org-element-at-point)))))
|
2012-05-05 07:14:39 +00:00
|
|
|
|
;; Special case: at the very beginning of a table, return `table'
|
|
|
|
|
;; object instead of `table-row'.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'table
|
|
|
|
|
(org-test-with-temp-text "| a | b |"
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
|
|
|
|
;; Special case: at the very beginning of a list or sub-list, return
|
|
|
|
|
;; `plain-list' object instead of `item'.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'plain-list
|
|
|
|
|
(org-test-with-temp-text "- item"
|
2012-07-29 22:40:21 +00:00
|
|
|
|
(org-element-type (org-element-at-point)))))
|
2012-08-08 07:54:56 +00:00
|
|
|
|
;; Special case: at the closing line of a greater element, be sure
|
|
|
|
|
;; to return it instead of the last element in its contents.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'center-block
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_CENTER\nParagraph\n#+END_CENTER"
|
|
|
|
|
(progn (forward-line 2)
|
|
|
|
|
(org-element-type (org-element-at-point))))))
|
2012-08-11 22:48:09 +00:00
|
|
|
|
;; Special case: at a blank line between two items, be sure to
|
|
|
|
|
;; return item above instead of the last element of its contents.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'item
|
|
|
|
|
(org-test-with-temp-text "- Para1\n\n- Para2"
|
2015-08-14 14:31:16 +00:00
|
|
|
|
(forward-line)
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
2012-08-11 22:48:09 +00:00
|
|
|
|
;; Special case: at the last blank line in a plain list, return it
|
|
|
|
|
;; instead of the last item.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'plain-list
|
|
|
|
|
(org-test-with-temp-text "- Para1\n- Para2\n\nPara3"
|
|
|
|
|
(progn (forward-line 2)
|
|
|
|
|
(org-element-type (org-element-at-point))))))
|
2013-09-18 19:15:04 +00:00
|
|
|
|
;; Special case: when a list ends at the end of buffer and there's
|
|
|
|
|
;; no final newline, return last element in last item.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'paragraph
|
|
|
|
|
(org-test-with-temp-text "- a"
|
|
|
|
|
(end-of-line)
|
|
|
|
|
(org-element-type (org-element-at-point)))))
|
2012-12-15 23:37:49 +00:00
|
|
|
|
;; Parse a list within a block itself contained in a list.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'plain-list
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"- outer\n #+begin_center\n - inner\n #+end_center"
|
|
|
|
|
(search-forward "inner")
|
|
|
|
|
(beginning-of-line)
|
2013-06-25 15:32:26 +00:00
|
|
|
|
(org-element-type (org-element-at-point)))))
|
|
|
|
|
;; Do not error at eob on an empty line.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "* H\n"
|
|
|
|
|
(forward-line)
|
|
|
|
|
(or (org-element-at-point) t))))
|
2012-05-05 07:14:39 +00:00
|
|
|
|
|
2012-07-06 22:47:51 +00:00
|
|
|
|
(ert-deftest test-org-element/context ()
|
|
|
|
|
"Test `org-element-context' specifications."
|
2012-07-29 22:40:21 +00:00
|
|
|
|
;; Return closest object containing point.
|
2012-07-06 22:47:51 +00:00
|
|
|
|
(should
|
2012-07-29 22:40:21 +00:00
|
|
|
|
(eq 'underline
|
2016-02-11 08:47:54 +00:00
|
|
|
|
(org-test-with-temp-text "Some *text with _under<point>line_ text*"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
2012-07-06 22:47:51 +00:00
|
|
|
|
;; Find objects in secondary strings.
|
|
|
|
|
(should
|
2012-07-29 22:40:21 +00:00
|
|
|
|
(eq 'underline
|
2016-02-11 08:47:54 +00:00
|
|
|
|
(org-test-with-temp-text "* Headline _<point>with_ underlining"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
2012-10-05 12:24:45 +00:00
|
|
|
|
;; Find objects in objects.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'macro
|
2016-02-11 08:47:54 +00:00
|
|
|
|
(org-test-with-temp-text "| a | {<point>{{macro}}} |"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
2012-10-05 12:24:45 +00:00
|
|
|
|
(should
|
|
|
|
|
(eq 'table-cell
|
2016-02-11 08:47:54 +00:00
|
|
|
|
(org-test-with-temp-text "| a | b<point> {{{macro}}} |"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
;; Find objects in item tags.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'bold
|
|
|
|
|
(org-test-with-temp-text "- *bo<point>ld* ::"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
(should-not
|
|
|
|
|
(eq 'bold
|
|
|
|
|
(org-test-with-temp-text "- *bold* ::<point>"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
(should-not
|
|
|
|
|
(eq 'bold
|
|
|
|
|
(org-test-with-temp-text "- *bold* ::\n<point>"
|
2014-02-25 19:48:15 +00:00
|
|
|
|
(org-element-type (org-element-context)))))
|
2013-03-14 22:11:26 +00:00
|
|
|
|
;; Do not find objects in table rules.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'table-row
|
2015-06-28 19:09:16 +00:00
|
|
|
|
(org-test-with-temp-text "| a | b |\n|-<point>--|---|\n| c | d |"
|
2013-03-14 22:11:26 +00:00
|
|
|
|
(org-element-type (org-element-context)))))
|
2012-10-29 09:53:32 +00:00
|
|
|
|
;; Find objects in parsed affiliated keywords.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'macro
|
2016-02-11 08:47:54 +00:00
|
|
|
|
(org-test-with-temp-text "#+CAPTION: {<point>{{macro}}}\n| a | b |"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
2013-11-03 16:47:55 +00:00
|
|
|
|
(should
|
|
|
|
|
(eq 'bold
|
2016-02-11 08:47:54 +00:00
|
|
|
|
(org-test-with-temp-text "#+caption: *<point>bold*\nParagraph"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
2014-02-23 11:42:08 +00:00
|
|
|
|
;; Find objects at the end of buffer.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'bold
|
|
|
|
|
(org-test-with-temp-text "*bold*"
|
|
|
|
|
(goto-char (point-max))
|
|
|
|
|
(org-element-type (org-element-context)))))
|
2012-07-29 22:40:21 +00:00
|
|
|
|
;; Correctly set `:parent' property.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'paragraph
|
2016-02-11 08:47:54 +00:00
|
|
|
|
(org-test-with-temp-text "Some *bold<point>* text"
|
|
|
|
|
(org-element-type
|
|
|
|
|
(org-element-property :parent (org-element-context))))))
|
2012-11-23 22:46:52 +00:00
|
|
|
|
;; Between two objects, return the second one.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'macro
|
2016-02-11 08:47:54 +00:00
|
|
|
|
(org-test-with-temp-text "<<target>><point>{{{test}}}"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
2013-01-09 14:33:29 +00:00
|
|
|
|
;; Test optional argument.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'underline
|
2016-02-11 08:47:54 +00:00
|
|
|
|
(org-test-with-temp-text "Some *text with _under<point>line_ text*"
|
|
|
|
|
(org-element-type (org-element-context (org-element-at-point))))))
|
2014-03-12 08:05:50 +00:00
|
|
|
|
;; Special case: bold object at the beginning of a headline.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'bold
|
2016-02-11 08:47:54 +00:00
|
|
|
|
(org-test-with-temp-text "* *bo<point>ld*"
|
2014-04-17 19:37:07 +00:00
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
;; Special case: incomplete cell at the end of a table row.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'table-cell
|
2016-02-11 08:47:54 +00:00
|
|
|
|
(org-test-with-temp-text "|a|b|c<point>"
|
2014-07-06 09:08:57 +00:00
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
;; Special case: objects in inline footnotes.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'link
|
2018-01-16 18:42:57 +00:00
|
|
|
|
(org-test-with-temp-text "[fn::[[<point>https://orgmode.org]]]"
|
2016-01-16 13:50:25 +00:00
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
;; Special case: tags looking like a link.
|
|
|
|
|
(should-not
|
|
|
|
|
(eq 'link
|
|
|
|
|
(org-test-with-temp-text "* Headline :file<point>:tags:"
|
|
|
|
|
(org-element-type (org-element-context)))))
|
|
|
|
|
(should
|
|
|
|
|
(eq 'link
|
|
|
|
|
(org-test-with-temp-text "* Headline :file<point>:tags: :real:tag:"
|
2014-03-12 08:05:50 +00:00
|
|
|
|
(org-element-type (org-element-context))))))
|
2012-07-06 22:47:51 +00:00
|
|
|
|
|
2012-02-24 00:23:25 +00:00
|
|
|
|
|
2014-11-16 12:13:52 +00:00
|
|
|
|
|
|
|
|
|
;;; Test Tools
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/lineage ()
|
|
|
|
|
"Test `org-element-lineage' specifications."
|
|
|
|
|
;; Regular tests. When applied to an element or object returned by
|
|
|
|
|
;; `org-element-at-point' or `org-element-context', the list is
|
|
|
|
|
;; limited to the current section.
|
|
|
|
|
(should
|
|
|
|
|
(equal '(paragraph center-block)
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"* H1\n** H2\n#+BEGIN_CENTER\n*bold<point>*\n#+END_CENTER"
|
|
|
|
|
(mapcar #'car (org-element-lineage (org-element-context))))))
|
|
|
|
|
(should
|
|
|
|
|
(equal '(paragraph center-block section headline headline org-data)
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"* H1\n** H2\n#+BEGIN_CENTER\n*bold<point>*\n#+END_CENTER"
|
|
|
|
|
(mapcar #'car
|
|
|
|
|
(org-element-lineage
|
|
|
|
|
(org-element-map (org-element-parse-buffer) 'bold
|
|
|
|
|
#'identity nil t))))))
|
|
|
|
|
;; Test TYPES optional argument.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'center-block
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"* H1\n** H2\n#+BEGIN_CENTER\n*bold<point>*\n#+END_CENTER"
|
|
|
|
|
(org-element-type
|
|
|
|
|
(org-element-lineage (org-element-context) '(center-block))))))
|
|
|
|
|
(should-not
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"* H1\n** H2\n#+BEGIN_CENTER\n*bold<point>*\n#+END_CENTER"
|
|
|
|
|
(org-element-lineage (org-element-context) '(example-block))))
|
|
|
|
|
;; Test WITH-SELF optional argument.
|
|
|
|
|
(should
|
|
|
|
|
(equal '(bold paragraph center-block)
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"* H1\n** H2\n#+BEGIN_CENTER\n*bold<point>*\n#+END_CENTER"
|
|
|
|
|
(mapcar #'car (org-element-lineage (org-element-context) nil t)))))
|
|
|
|
|
;; When TYPES and WITH-SELF are provided, the latter is also checked
|
|
|
|
|
;; against the former.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"* H1\n** H2\n#+BEGIN_CENTER\n*bold<point>*\n#+END_CENTER"
|
|
|
|
|
(org-element-lineage (org-element-context) '(bold) t))))
|
|
|
|
|
|
|
|
|
|
|
org-element: Implement lazy cache synchronization
* lisp/org-element.el (org-element-cache-sync-idle-time): Change
default value.
(org-element-cache-sync-duration, org-element-cache-sync-break,
org-element--cache-sync-requests, org-element--cache-sync-timer,
org-element--cache-sync-keys, org-element--cache-default-key,
org-element--cache-change-warning): New variables.
(org-element-cache-merge-changes-threshold,
org-element--cache-status): Removed variables.
(org-element--cache-key, org-element--cache-generate-key,
org-element--cache-key-less-p, org-element--cache-find,
org-element--cache-set-timer, org-element--cache-process-request,
org-element--cache-submit-request, org-element--parse-to,
org-element--cache-interrupt-p, org-element--cache-put,
org-element--cache-active-p): New functions.
(org-element--cache-compare): Adapt to new keys in AVL tree.
(org-element--cache-pending-changes-p,
org-element--cache-cancel-changes, org-element--cache-mapc,
org-element-cache-get, org-element-cache-put): Removed functions.
(org-element--cache-before-change): Use new variables.
(org-element--cache-after-change): Renamed from
`org-element--cache-record-change'.
(org-element-cache-get): Change signature.
(org-element-cache-put): Rewrite function. Use new tools.
(org-element-cache-reset): Adapt to new variables.
(org-element--cache-sync): Rewrite function.
* lisp/ox.el (org-export--generate-copy-script): Do not copy through
new cache-related variables.
(org-export-ignored-local-variables): New variable.
* testing/lisp/test-org-element.el (test-org-element/cache): New test.
Now only the part of the cache that needs to be accessed is updated
synchronously. Otherwise, it happens on idle time.
2014-01-31 00:14:44 +00:00
|
|
|
|
|
|
|
|
|
;;; Test Cache.
|
|
|
|
|
|
|
|
|
|
(ert-deftest test-org-element/cache ()
|
|
|
|
|
"Test basic expectations and common pitfalls for cache."
|
|
|
|
|
;; Shift positions.
|
|
|
|
|
(should
|
|
|
|
|
(equal '(18 . 23)
|
|
|
|
|
(org-test-with-temp-text "para1\n\npara2\n\npara3"
|
|
|
|
|
(let ((org-element-use-cache t))
|
|
|
|
|
(save-excursion (goto-char (point-max)) (org-element-at-point))
|
|
|
|
|
(insert "add")
|
|
|
|
|
(forward-line 4)
|
|
|
|
|
(let ((element (org-element-at-point)))
|
|
|
|
|
(cons (org-element-property :begin element)
|
|
|
|
|
(org-element-property :end element)))))))
|
|
|
|
|
;; Partial shifting: when the contents of a greater element are
|
|
|
|
|
;; modified, only shift ending positions.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"#+BEGIN_CENTER\nPara1\n\nPara2\n\nPara3\n#+END_CENTER"
|
|
|
|
|
(let ((org-element-use-cache t))
|
|
|
|
|
(save-excursion (search-forward "3") (org-element-at-point))
|
|
|
|
|
(search-forward "Para2")
|
|
|
|
|
(insert " ")
|
|
|
|
|
(let ((element (org-element-property :parent (org-element-at-point))))
|
|
|
|
|
(equal (cons (org-element-property :begin element)
|
|
|
|
|
(org-element-property :end element))
|
|
|
|
|
(cons (point-min) (point-max)))))))
|
|
|
|
|
;; Re-parent shifted elements.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'item
|
|
|
|
|
(org-test-with-temp-text "- item\n\n\n para1\n para2"
|
|
|
|
|
(let ((org-element-use-cache t))
|
|
|
|
|
(end-of-line)
|
|
|
|
|
(org-element-at-point)
|
|
|
|
|
(save-excursion (goto-char (point-max)) (org-element-at-point))
|
|
|
|
|
(forward-line)
|
|
|
|
|
(delete-char 1)
|
|
|
|
|
(goto-char (point-max))
|
|
|
|
|
(org-element-type
|
|
|
|
|
(org-element-property :parent (org-element-at-point)))))))
|
2014-07-17 16:11:49 +00:00
|
|
|
|
;; Preserve local structures when re-parenting.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'table
|
2017-01-21 10:58:42 +00:00
|
|
|
|
(let ((org-element-use-cache t))
|
|
|
|
|
(org-test-with-temp-text
|
2021-05-15 11:19:09 +00:00
|
|
|
|
"#+begin_center\nP0\n\n<point>\n\n P1\n | a | b |\n | c | d |\n#+end_center"
|
2014-07-17 16:11:49 +00:00
|
|
|
|
(save-excursion (search-forward "| c |") (org-element-at-point))
|
|
|
|
|
(insert "- item")
|
|
|
|
|
(search-forward "| c |")
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(org-element-type
|
|
|
|
|
(org-element-property :parent (org-element-at-point)))))))
|
|
|
|
|
(should-not
|
|
|
|
|
(eq 'center-block
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"#+begin_center\nP0\n\n<point>\n\n P1\n | a | b |\n#+end_center"
|
|
|
|
|
(let ((org-element-use-cache t))
|
|
|
|
|
(save-excursion (search-forward "| a |") (org-element-at-point))
|
|
|
|
|
(insert "- item")
|
|
|
|
|
(search-forward "| a |")
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(org-element-type
|
|
|
|
|
(org-element-property :parent (org-element-at-point)))))))
|
|
|
|
|
;; When re-parenting, also propagate changes to list structures.
|
|
|
|
|
(should
|
|
|
|
|
(= 2
|
|
|
|
|
(org-test-with-temp-text "\n Para\n - item<point>"
|
|
|
|
|
(let ((org-element-use-cache t))
|
|
|
|
|
(org-element-at-point)
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(insert "- Top\n")
|
|
|
|
|
(search-forward "- item")
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(length (org-element-property :structure (org-element-at-point)))))))
|
org-element: Implement lazy cache synchronization
* lisp/org-element.el (org-element-cache-sync-idle-time): Change
default value.
(org-element-cache-sync-duration, org-element-cache-sync-break,
org-element--cache-sync-requests, org-element--cache-sync-timer,
org-element--cache-sync-keys, org-element--cache-default-key,
org-element--cache-change-warning): New variables.
(org-element-cache-merge-changes-threshold,
org-element--cache-status): Removed variables.
(org-element--cache-key, org-element--cache-generate-key,
org-element--cache-key-less-p, org-element--cache-find,
org-element--cache-set-timer, org-element--cache-process-request,
org-element--cache-submit-request, org-element--parse-to,
org-element--cache-interrupt-p, org-element--cache-put,
org-element--cache-active-p): New functions.
(org-element--cache-compare): Adapt to new keys in AVL tree.
(org-element--cache-pending-changes-p,
org-element--cache-cancel-changes, org-element--cache-mapc,
org-element-cache-get, org-element-cache-put): Removed functions.
(org-element--cache-before-change): Use new variables.
(org-element--cache-after-change): Renamed from
`org-element--cache-record-change'.
(org-element-cache-get): Change signature.
(org-element-cache-put): Rewrite function. Use new tools.
(org-element-cache-reset): Adapt to new variables.
(org-element--cache-sync): Rewrite function.
* lisp/ox.el (org-export--generate-copy-script): Do not copy through
new cache-related variables.
(org-export-ignored-local-variables): New variable.
* testing/lisp/test-org-element.el (test-org-element/cache): New test.
Now only the part of the cache that needs to be accessed is updated
synchronously. Otherwise, it happens on idle time.
2014-01-31 00:14:44 +00:00
|
|
|
|
;; Modifying the last line of an element alters the element below.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text "para1\n\npara2"
|
|
|
|
|
(let ((org-element-use-cache t))
|
|
|
|
|
(goto-char (point-max))
|
|
|
|
|
(org-element-at-point)
|
|
|
|
|
(forward-line -1)
|
|
|
|
|
(insert "merge")
|
|
|
|
|
(let ((element (org-element-at-point)))
|
|
|
|
|
(equal (cons (org-element-property :begin element)
|
|
|
|
|
(org-element-property :end element))
|
|
|
|
|
(cons (point-min) (point-max)))))))
|
|
|
|
|
;; Modifying the first line of an element alters the element above.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text ": fixed-width\n:not-fixed-width"
|
|
|
|
|
(let ((org-element-use-cache t))
|
|
|
|
|
(goto-char (point-max))
|
|
|
|
|
(org-element-at-point)
|
|
|
|
|
(search-backward ":")
|
|
|
|
|
(forward-char)
|
|
|
|
|
(insert " ")
|
|
|
|
|
(let ((element (org-element-at-point)))
|
|
|
|
|
(equal (cons (org-element-property :begin element)
|
|
|
|
|
(org-element-property :end element))
|
|
|
|
|
(cons (point-min) (point-max)))))))
|
|
|
|
|
;; Sensitive change: adding a line alters document structure both
|
|
|
|
|
;; above and below.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'example-block
|
|
|
|
|
(org-test-with-temp-text "#+BEGIN_EXAMPLE\nPara1\n\nPara2\n"
|
|
|
|
|
(let ((org-element-use-cache t))
|
|
|
|
|
(goto-char (point-max))
|
|
|
|
|
(org-element-at-point)
|
|
|
|
|
(insert "#+END_EXAMPLE")
|
|
|
|
|
(search-backward "Para1")
|
|
|
|
|
(org-element-type (org-element-at-point))))))
|
|
|
|
|
(should
|
|
|
|
|
(eq 'example-block
|
|
|
|
|
(org-test-with-temp-text "Para1\n\nPara2\n#+END_EXAMPLE"
|
|
|
|
|
(let ((org-element-use-cache t))
|
|
|
|
|
(save-excursion (goto-char (point-max)) (org-element-at-point))
|
|
|
|
|
(insert "#+BEGIN_EXAMPLE\n")
|
|
|
|
|
(search-forward "Para2")
|
|
|
|
|
(org-element-type (org-element-at-point))))))
|
|
|
|
|
;; Sensitive change: removing a line alters document structure both
|
|
|
|
|
;; above and below.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'example-block
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"# +BEGIN_EXAMPLE\nPara1\n\nPara2\n#+END_EXAMPLE"
|
|
|
|
|
(let ((org-element-use-cache t))
|
|
|
|
|
(save-excursion (goto-char (point-max)) (org-element-at-point))
|
|
|
|
|
(forward-char)
|
|
|
|
|
(delete-char 1)
|
|
|
|
|
(search-forward "Para2")
|
|
|
|
|
(org-element-type (org-element-at-point))))))
|
|
|
|
|
(should
|
|
|
|
|
(eq 'example-block
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"#+BEGIN_EXAMPLE\nPara1\n\nPara2\n# +END_EXAMPLE"
|
|
|
|
|
(let ((org-element-use-cache t))
|
|
|
|
|
(save-excursion (goto-char (point-max)) (org-element-at-point))
|
|
|
|
|
(search-forward "# ")
|
|
|
|
|
(delete-char -1)
|
|
|
|
|
(search-backward "Para1")
|
2015-04-05 22:37:49 +00:00
|
|
|
|
(org-element-type (org-element-at-point))))))
|
|
|
|
|
;; Corner case: watch out drawers named "PROPERTIES" as they are
|
|
|
|
|
;; fragile, unlike to other drawers.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'node-property
|
|
|
|
|
(org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A<point>\n:END:"
|
|
|
|
|
(let ((org-element-use-cache t))
|
|
|
|
|
(org-element-at-point)
|
|
|
|
|
(insert "+:")
|
2015-06-14 12:52:04 +00:00
|
|
|
|
(org-element-type (org-element-at-point))))))
|
|
|
|
|
;; Properly handle elements not altered by modifications but whose
|
|
|
|
|
;; parents were removed from cache.
|
|
|
|
|
(should
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"Paragraph\n\n\n\n#+begin_center\n<point>contents\n#+end_center"
|
|
|
|
|
(let ((org-element-use-cache t)
|
|
|
|
|
(parent-end (point-max)))
|
|
|
|
|
(org-element-at-point)
|
|
|
|
|
(save-excursion (search-backward "Paragraph")
|
|
|
|
|
(forward-line 2)
|
|
|
|
|
(insert "\n "))
|
|
|
|
|
(eq (org-element-property
|
|
|
|
|
:end (org-element-property :parent (org-element-at-point)))
|
|
|
|
|
(+ parent-end 3))))))
|
org-element: Implement lazy cache synchronization
* lisp/org-element.el (org-element-cache-sync-idle-time): Change
default value.
(org-element-cache-sync-duration, org-element-cache-sync-break,
org-element--cache-sync-requests, org-element--cache-sync-timer,
org-element--cache-sync-keys, org-element--cache-default-key,
org-element--cache-change-warning): New variables.
(org-element-cache-merge-changes-threshold,
org-element--cache-status): Removed variables.
(org-element--cache-key, org-element--cache-generate-key,
org-element--cache-key-less-p, org-element--cache-find,
org-element--cache-set-timer, org-element--cache-process-request,
org-element--cache-submit-request, org-element--parse-to,
org-element--cache-interrupt-p, org-element--cache-put,
org-element--cache-active-p): New functions.
(org-element--cache-compare): Adapt to new keys in AVL tree.
(org-element--cache-pending-changes-p,
org-element--cache-cancel-changes, org-element--cache-mapc,
org-element-cache-get, org-element-cache-put): Removed functions.
(org-element--cache-before-change): Use new variables.
(org-element--cache-after-change): Renamed from
`org-element--cache-record-change'.
(org-element-cache-get): Change signature.
(org-element-cache-put): Rewrite function. Use new tools.
(org-element-cache-reset): Adapt to new variables.
(org-element--cache-sync): Rewrite function.
* lisp/ox.el (org-export--generate-copy-script): Do not copy through
new cache-related variables.
(org-export-ignored-local-variables): New variable.
* testing/lisp/test-org-element.el (test-org-element/cache): New test.
Now only the part of the cache that needs to be accessed is updated
synchronously. Otherwise, it happens on idle time.
2014-01-31 00:14:44 +00:00
|
|
|
|
|
2021-05-15 12:27:20 +00:00
|
|
|
|
(ert-deftest test-org-element/cache-bugs ()
|
|
|
|
|
"Test basic expectations and common pitfalls for cache."
|
|
|
|
|
:expected-result :failed
|
|
|
|
|
;; Unindented second row of the table should not be re-parented by
|
|
|
|
|
;; inserted item.
|
|
|
|
|
(should
|
|
|
|
|
(eq 'table
|
|
|
|
|
(let ((org-element-use-cache t))
|
|
|
|
|
(org-test-with-temp-text
|
|
|
|
|
"#+begin_center\nP0\n\n<point>\n\n P1\n | a | b |\n| c | d |\n#+end_center"
|
|
|
|
|
(save-excursion (search-forward "| c |") (org-element-at-point))
|
|
|
|
|
(insert "- item")
|
|
|
|
|
(search-forward "| c |")
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(org-element-type (org-element-at-point)))))))
|
org-element: Implement lazy cache synchronization
* lisp/org-element.el (org-element-cache-sync-idle-time): Change
default value.
(org-element-cache-sync-duration, org-element-cache-sync-break,
org-element--cache-sync-requests, org-element--cache-sync-timer,
org-element--cache-sync-keys, org-element--cache-default-key,
org-element--cache-change-warning): New variables.
(org-element-cache-merge-changes-threshold,
org-element--cache-status): Removed variables.
(org-element--cache-key, org-element--cache-generate-key,
org-element--cache-key-less-p, org-element--cache-find,
org-element--cache-set-timer, org-element--cache-process-request,
org-element--cache-submit-request, org-element--parse-to,
org-element--cache-interrupt-p, org-element--cache-put,
org-element--cache-active-p): New functions.
(org-element--cache-compare): Adapt to new keys in AVL tree.
(org-element--cache-pending-changes-p,
org-element--cache-cancel-changes, org-element--cache-mapc,
org-element-cache-get, org-element-cache-put): Removed functions.
(org-element--cache-before-change): Use new variables.
(org-element--cache-after-change): Renamed from
`org-element--cache-record-change'.
(org-element-cache-get): Change signature.
(org-element-cache-put): Rewrite function. Use new tools.
(org-element-cache-reset): Adapt to new variables.
(org-element--cache-sync): Rewrite function.
* lisp/ox.el (org-export--generate-copy-script): Do not copy through
new cache-related variables.
(org-export-ignored-local-variables): New variable.
* testing/lisp/test-org-element.el (test-org-element/cache): New test.
Now only the part of the cache that needs to be accessed is updated
synchronously. Otherwise, it happens on idle time.
2014-01-31 00:14:44 +00:00
|
|
|
|
|
2012-02-23 15:28:13 +00:00
|
|
|
|
(provide 'test-org-element)
|
org-element: Implement lazy cache synchronization
* lisp/org-element.el (org-element-cache-sync-idle-time): Change
default value.
(org-element-cache-sync-duration, org-element-cache-sync-break,
org-element--cache-sync-requests, org-element--cache-sync-timer,
org-element--cache-sync-keys, org-element--cache-default-key,
org-element--cache-change-warning): New variables.
(org-element-cache-merge-changes-threshold,
org-element--cache-status): Removed variables.
(org-element--cache-key, org-element--cache-generate-key,
org-element--cache-key-less-p, org-element--cache-find,
org-element--cache-set-timer, org-element--cache-process-request,
org-element--cache-submit-request, org-element--parse-to,
org-element--cache-interrupt-p, org-element--cache-put,
org-element--cache-active-p): New functions.
(org-element--cache-compare): Adapt to new keys in AVL tree.
(org-element--cache-pending-changes-p,
org-element--cache-cancel-changes, org-element--cache-mapc,
org-element-cache-get, org-element-cache-put): Removed functions.
(org-element--cache-before-change): Use new variables.
(org-element--cache-after-change): Renamed from
`org-element--cache-record-change'.
(org-element-cache-get): Change signature.
(org-element-cache-put): Rewrite function. Use new tools.
(org-element-cache-reset): Adapt to new variables.
(org-element--cache-sync): Rewrite function.
* lisp/ox.el (org-export--generate-copy-script): Do not copy through
new cache-related variables.
(org-export-ignored-local-variables): New variable.
* testing/lisp/test-org-element.el (test-org-element/cache): New test.
Now only the part of the cache that needs to be accessed is updated
synchronously. Otherwise, it happens on idle time.
2014-01-31 00:14:44 +00:00
|
|
|
|
|
2012-02-23 15:28:13 +00:00
|
|
|
|
;;; test-org-element.el ends here
|