lisp/org-table.el: fix table alignment
[org-mode/org-tableheadings.git] / testing / lisp / test-org-attach.el
blobc2f2be356ac96d9aa415ba83b59da1c9615e4f76
1 ;;; test-org-attach.el --- tests for org-attach.el -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2017, 2019
5 ;; Author: Marco Wahl
6 ;; Keywords: internal
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/>.
21 ;;; Commentary:
25 ;;; Code:
27 (require 'org-test)
28 (require 'org-attach)
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."
33 (should
34 (let ((a-filename (make-temp-file "a"))) ; file is an attach candidate.
35 (unwind-protect
36 (org-test-with-temp-text-in-file
37 "* foo :foo:"
38 (split-window)
39 (dired temporary-file-directory)
40 (cl-assert (eq 'dired-mode major-mode))
41 (revert-buffer)
42 (dired-goto-file a-filename)
43 ; action
44 (call-interactively #'org-attach-dired-to-subtree)
45 ; check
46 (delete-window)
47 (cl-assert (eq 'org-mode major-mode))
48 (beginning-of-buffer)
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))
53 (plist-get
54 (plist-get
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."
60 (should
61 (let ((a-filename (make-temp-file "a"))
62 (b-filename (make-temp-file "b"))) ; attach candidates.
63 (unwind-protect
64 (org-test-with-temp-text-in-file
65 "* foo"
66 (split-window)
67 (dired temporary-file-directory)
68 (cl-assert (eq 'dired-mode major-mode))
69 (revert-buffer)
70 (dired-goto-file a-filename)
71 (dired-mark 1)
72 (dired-goto-file b-filename)
73 (dired-mark 1)
74 ; action
75 (call-interactively #'org-attach-dired-to-subtree)
76 ; check
77 (delete-window)
78 (cl-assert (eq 'org-mode major-mode))
79 (beginning-of-buffer)
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