1 ;;; test-org-attach.el --- tests for org-attach.el -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2017, 2019
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
29 (eval-and-compile (require 'cl-lib
))
31 (ert-deftest test-org-attach
/dired-attach-to-next-best-subtree
/1 ()
32 "Attach file at point in dired to subtree."
34 (let ((a-filename (make-temp-file "a"))) ; file is an attach candidate.
36 (org-test-with-temp-text-in-file
39 (dired temporary-file-directory
)
40 (cl-assert (eq 'dired-mode major-mode
))
42 (dired-goto-file a-filename
)
44 (call-interactively #'org-attach-dired-to-subtree
)
47 (cl-assert (eq 'org-mode major-mode
))
49 (search-forward "* foo")
50 ; expectation. tag ATTACH has been appended.
51 (cl-reduce (lambda (x y
) (or x y
))
52 (mapcar (lambda (x) (string-equal "ATTACH" x
))
55 (org-element-at-point) 'headline
) :tags
))))
56 (delete-file a-filename
)))))
58 (ert-deftest test-org-attach
/dired-attach-to-next-best-subtree
/2 ()
59 "Attach 2 marked files."
61 (let ((a-filename (make-temp-file "a"))
62 (b-filename (make-temp-file "b"))) ; attach candidates.
64 (org-test-with-temp-text-in-file
67 (dired temporary-file-directory
)
68 (cl-assert (eq 'dired-mode major-mode
))
70 (dired-goto-file a-filename
)
72 (dired-goto-file b-filename
)
75 (call-interactively #'org-attach-dired-to-subtree
)
78 (cl-assert (eq 'org-mode major-mode
))
80 (search-forward "* foo")
81 (and (file-exists-p (concat (org-attach-dir) "/"
82 (file-name-nondirectory a-filename
)))
83 (file-exists-p (concat (org-attach-dir) "/"
84 (file-name-nondirectory b-filename
)))))
85 (delete-file a-filename
)
86 (delete-file b-filename
)))))
89 (provide 'test-org-attach
)
90 ;;; test-org-attach.el ends here