summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2017-05-22 02:17:32 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2017-05-22 02:23:40 +0200
commitf335c3517de06eb74a3c3727843f276147795a84 (patch)
tree4b0dd3f825644dfba51bcb241b5c04d9ac0c0f04
parent23ac37da7c86bc30662fdd963b0206129148721a (diff)
downloadorg-mode-f335c3517de06eb74a3c3727843f276147795a84.tar.gz
Add tests for org-refile-get-targets
* testing/lisp/test-org.el (test-org/refile-get-targets): New test. Based on a patch from Sebastian Reuße <seb@wirrsal.net>.
-rw-r--r--testing/lisp/test-org.el105
1 files changed, 105 insertions, 0 deletions
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index f1033db..8162b4f 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -5341,6 +5341,111 @@ Paragraph<point>"
(org-element-type (org-element-context))))))
+;;; Refile
+
+(ert-deftest test-org/refile-get-targets ()
+ "Test `org-refile-get-targets' specifications."
+ ;; :maxlevel includes all headings above specified value.
+ (should
+ (equal '("H1" "H2" "H3")
+ (org-test-with-temp-text "* H1\n** H2\n*** H3"
+ (let ((org-refile-use-outline-path nil)
+ (org-refile-targets `((nil :maxlevel . 3))))
+ (mapcar #'car (org-refile-get-targets))))))
+ (should
+ (equal '("H1" "H2")
+ (org-test-with-temp-text "* H1\n** H2\n*** H3"
+ (let ((org-refile-use-outline-path nil)
+ (org-refile-targets `((nil :maxlevel . 2))))
+ (mapcar #'car (org-refile-get-targets))))))
+ ;; :level limits targets to headlines with the specified level.
+ (should
+ (equal '("H2")
+ (org-test-with-temp-text "* H1\n** H2\n*** H3"
+ (let ((org-refile-use-outline-path nil)
+ (org-refile-targets `((nil :level . 2))))
+ (mapcar #'car (org-refile-get-targets))))))
+ ;; :tag limits targets to headlines with specified tag.
+ (should
+ (equal '("H1")
+ (org-test-with-temp-text "* H1 :foo:\n** H2\n*** H3 :bar:"
+ (let ((org-refile-use-outline-path nil)
+ (org-refile-targets `((nil :tag . "foo"))))
+ (mapcar #'car (org-refile-get-targets))))))
+ ;; :todo limits targets to headlines with specified TODO keyword.
+ (should
+ (equal '("H2")
+ (org-test-with-temp-text "* H1\n** TODO H2\n*** DONE H3"
+ (let ((org-refile-use-outline-path nil)
+ (org-refile-targets `((nil :todo . "TODO"))))
+ (mapcar #'car (org-refile-get-targets))))))
+ ;; :regexp filters targets matching provided regexp.
+ (should
+ (equal '("F2" "F3")
+ (org-test-with-temp-text "* H1\n** F2\n*** F3"
+ (let ((org-refile-use-outline-path nil)
+ (org-refile-targets `((nil :regexp . "F"))))
+ (mapcar #'car (org-refile-get-targets))))))
+ ;; A nil `org-refile-targets' includes only top level headlines in
+ ;; current buffer.
+ (should
+ (equal '("H1" "H2")
+ (org-test-with-temp-text "* H1\n** S1\n* H2"
+ (let ((org-refile-use-outline-path nil)
+ (org-refile-targets nil))
+ (mapcar #'car (org-refile-get-targets))))))
+ ;; Return value is the union of the targets according to all the
+ ;; defined rules.
+ (should
+ (equal '("F2" "F3" "H1")
+ (org-test-with-temp-text "* TODO H1\n** F2\n*** F3"
+ (let ((org-refile-use-outline-path nil)
+ (org-refile-targets `((nil :regexp . "F")
+ (nil :todo . "TODO"))))
+ (mapcar #'car (org-refile-get-targets))))))
+ ;; When `org-refile-use-outline-path' is non-nil, provide targets as
+ ;; paths.
+ (should
+ (equal '("H1" "H1/H2" "H1/H2/H3")
+ (org-test-with-temp-text "* H1\n** H2\n*** H3"
+ (let ((org-refile-use-outline-path t)
+ (org-refile-targets `((nil :maxlevel . 3))))
+ (mapcar #'car (org-refile-get-targets))))))
+ ;; When providing targets as paths, escape forward slashes in
+ ;; headings with backslashes.
+ (should
+ (equal '("H1\\/foo")
+ (org-test-with-temp-text "* H1/foo"
+ (let ((org-refile-use-outline-path t)
+ (org-refile-targets `((nil :maxlevel . 1))))
+ (mapcar #'car (org-refile-get-targets))))))
+ ;; When `org-refile-use-outline-path' is `file', include file name
+ ;; without directory in targets.
+ (should
+ (org-test-with-temp-text-in-file "* H1"
+ (let* ((filename (buffer-file-name))
+ (org-refile-use-outline-path 'file)
+ (org-refile-targets `(((,filename) :level . 1))))
+ (member (file-name-nondirectory filename)
+ (mapcar #'car (org-refile-get-targets))))))
+ ;; When `org-refile-use-outline-path' is `full-file-path', include
+ ;; full file name.
+ (should
+ (org-test-with-temp-text-in-file "* H1"
+ (let* ((filename (buffer-file-name))
+ (org-refile-use-outline-path 'full-file-path)
+ (org-refile-targets `(((,filename) :level . 1))))
+ (member filename (mapcar #'car (org-refile-get-targets))))))
+ ;; When `org-refile-use-outline-path' is `buffer-name', include
+ ;; buffer name.
+ (should
+ (org-test-with-temp-text "* H1"
+ (let* ((org-refile-use-outline-path 'buffer-name)
+ (org-refile-targets `((nil :level . 1))))
+ (member (buffer-name) (mapcar #'car (org-refile-get-targets)))))))
+
+
+
;;; Sparse trees
(ert-deftest test-org/match-sparse-tree ()