1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
;;; test-org-archive.el --- Test for Org Archive -*- lexical-binding: t; -*-
;; Copyright (C) 2017, 2019 Jay Kamat
;; Author: Jay Kamat <jaygkamat@gmail.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
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Code:
(ert-deftest test-org-archive/update-status-cookie ()
"Test archiving properly updating status cookies."
;; Test org-archive-subtree with two children.
(should
(equal
"Top [0%]"
(org-test-with-temp-text-in-file
"* Top [%]\n** DONE One\n** TODO Two"
(forward-line)
(org-archive-subtree)
(forward-line -1)
(org-element-property :title (org-element-at-point)))))
;; Test org-archive-subtree with one child.
(should
(equal
"Top [100%]"
(org-test-with-temp-text-in-file "* Top [%]\n** TODO Two"
(forward-line)
(org-archive-subtree)
(forward-line -1)
(org-element-property :title (org-element-at-point)))))
;; Test org-archive-to-archive-sibling with two children.
(should
(equal
"Top [100%]"
(org-test-with-temp-text "* Top [%]\n<point>** TODO One\n** DONE Two"
(org-archive-to-archive-sibling)
(forward-line -1)
(org-element-property :title (org-element-at-point)))))
;; Test org-archive-to-archive-sibling with two children.
(should
(equal
"Top [0%]"
(org-test-with-temp-text "* Top [%]\n<point>** DONE Two"
(org-archive-to-archive-sibling)
(forward-line -1)
(org-element-property :title (org-element-at-point))))))
(ert-deftest test-org-archive/to-archive-sibling ()
"Test `org-archive-to-archive-sibling' specifications."
;; Archive sibling before or after archive heading.
(should
(equal "* Archive :ARCHIVE:\n** H\n"
(org-test-with-temp-text "* H\n* Archive :ARCHIVE:\n"
(let ((org-archive-sibling-heading "Archive")
(org-archive-tag "ARCHIVE"))
(org-archive-to-archive-sibling)
(goto-char (point-min))
(buffer-substring-no-properties
(point) (line-beginning-position 3))))))
(should
(equal "* Archive :ARCHIVE:\n** H\n"
(org-test-with-temp-text "* Archive :ARCHIVE:\n<point>* H\n"
(let ((org-archive-sibling-heading "Archive")
(org-archive-tag "ARCHIVE"))
(org-archive-to-archive-sibling)
(goto-char (point-min))
(buffer-substring-no-properties
(point) (line-beginning-position 3))))))
;; When there is no sibling archive heading, create it.
(should
(equal "* Archive :ARCHIVE:\n** H\n"
(org-test-with-temp-text "* H\n"
(let ((org-archive-sibling-heading "Archive")
(org-archive-tag "ARCHIVE")
(org-tags-column 1))
(org-archive-to-archive-sibling)
(goto-char (point-min))
(buffer-substring-no-properties
(point) (line-beginning-position 3))))))
;; Ignore non-sibling archive headings.
(should
(equal "* Archive :ARCHIVE:\n* Top\n** Archive :ARCHIVE:\n*** H\n"
(org-test-with-temp-text "* Archive :ARCHIVE:\n* Top\n<point>** H\n"
(let ((org-archive-sibling-heading "Archive")
(org-archive-tag "ARCHIVE")
(org-tags-column 0))
(org-archive-to-archive-sibling)
(goto-char (point-min))
(buffer-substring-no-properties
(point) (line-beginning-position 5))))))
;; When archiving a heading, leave point on next heading.
(should
(equal "* H2"
(org-test-with-temp-text "* H1\n* H2\n* Archive :ARCHIVE:\n"
(let ((org-archive-sibling-heading "Archive")
(org-archive-tag "ARCHIVE"))
(org-archive-to-archive-sibling)
(buffer-substring-no-properties (point) (line-end-position))))))
(should
(equal "* H2"
(org-test-with-temp-text "* Archive :ARCHIVE:\n<point>* H1\n* H2\n"
(let ((org-archive-sibling-heading "Archive")
(org-archive-tag "ARCHIVE"))
(org-archive-to-archive-sibling)
(buffer-substring-no-properties (point) (line-end-position))))))
;; If `org-archive-reversed-order' is nil, archive as the last
;; child. Otherwise, archive as the first one.
(should
(equal "* Archive :ARCHIVE:\n** A\n"
(org-test-with-temp-text "* H\n* Archive :ARCHIVE:\n** A\n"
(let ((org-archive-sibling-heading "Archive")
(org-archive-tag "ARCHIVE")
(org-archive-reversed-order nil))
(org-archive-to-archive-sibling)
(goto-char (point-min))
(buffer-substring-no-properties
(point) (line-beginning-position 3))))))
(should
(equal "* Archive :ARCHIVE:\n** H\n"
(org-test-with-temp-text "* H\n* Archive :ARCHIVE:\n** A\n"
(let ((org-archive-sibling-heading "Archive")
(org-archive-tag "ARCHIVE")
(org-archive-reversed-order t))
(org-archive-to-archive-sibling)
(goto-char (point-min))
(buffer-substring-no-properties
(point) (line-beginning-position 3)))))))
(provide 'test-org-archive)
;;; test-org-archive.el ends here
|