test-org-attach.el 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. ;;; test-org-attach.el --- tests for org-attach.el -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2017
  3. ;; Author: Marco Wahl
  4. ;; Keywords: internal
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;;
  17. ;;; Code:
  18. (require 'org-test)
  19. (require 'org-attach)
  20. (eval-and-compile (require 'cl-lib))
  21. (ert-deftest test-org-attach/dired-attach-to-next-best-subtree/1 ()
  22. "Attach file at point in dired to subtree."
  23. (should
  24. (let ((a-filename (make-temp-file "a"))) ; file is an attach candidate.
  25. (unwind-protect
  26. (org-test-with-temp-text-in-file
  27. "* foo :foo:"
  28. (split-window)
  29. (dired temporary-file-directory)
  30. (cl-assert (eq 'dired-mode major-mode))
  31. (revert-buffer)
  32. (dired-goto-file a-filename)
  33. ; action
  34. (call-interactively #'org-attach-dired-to-subtree)
  35. ; check
  36. (delete-window)
  37. (cl-assert (eq 'org-mode major-mode))
  38. (beginning-of-buffer)
  39. (search-forward "* foo")
  40. ; expectation. tag ATTACH has been appended.
  41. (cl-reduce (lambda (x y) (or x y))
  42. (mapcar (lambda (x) (string-equal "ATTACH" x))
  43. (plist-get
  44. (plist-get
  45. (org-element-at-point) 'headline) :tags))))
  46. (delete-file a-filename)))))
  47. (ert-deftest test-org-attach/dired-attach-to-next-best-subtree/2 ()
  48. "Attach 2 marked files."
  49. (should
  50. (let ((a-filename (make-temp-file "a"))
  51. (b-filename (make-temp-file "b"))) ; attach candidates.
  52. (unwind-protect
  53. (org-test-with-temp-text-in-file
  54. "* foo"
  55. (split-window)
  56. (dired temporary-file-directory)
  57. (cl-assert (eq 'dired-mode major-mode))
  58. (revert-buffer)
  59. (dired-goto-file a-filename)
  60. (dired-mark 1)
  61. (dired-goto-file b-filename)
  62. (dired-mark 1)
  63. ; action
  64. (call-interactively #'org-attach-dired-to-subtree)
  65. ; check
  66. (delete-window)
  67. (cl-assert (eq 'org-mode major-mode))
  68. (beginning-of-buffer)
  69. (search-forward "* foo")
  70. (and (file-exists-p (concat (org-attach-dir) "/"
  71. (file-name-nondirectory a-filename)))
  72. (file-exists-p (concat (org-attach-dir) "/"
  73. (file-name-nondirectory b-filename)))))
  74. (delete-file a-filename)
  75. (delete-file b-filename)))))
  76. (provide 'test-org-attach)
  77. ;;; test-org-attach.el ends here