aboutsummaryrefslogtreecommitdiff
path: root/tests/test-chime-get-tags.el
blob: aecd2ea66e324b55cbf859c9ba70b2c81673e94a (plain)
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
143
144
145
;;; test-chime-get-tags.el --- Tests for chime--get-tags and chime-done-keywords-predicate -*- lexical-binding: t; -*-

;; Copyright (C) 2026 Craig Jennings

;; Author: Craig Jennings <c@cjennings.net>

;; 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/>.

;;; Commentary:

;; Unit tests for tag extraction and done-keyword predicate:
;; - chime--get-tags: extracts org tags from a marker
;; - chime-done-keywords-predicate: checks if heading has a done keyword

;;; Code:

(require 'test-bootstrap (expand-file-name "test-bootstrap.el"))

;; Load test utilities
(require 'testutil-general (expand-file-name "testutil-general.el"))

;;;; Tests for chime--get-tags

;;; Normal Cases

(ert-deftest test-chime-get-tags-single-tag ()
  "Should extract a single tag from an org heading."
  (with-temp-buffer
    (org-mode)
    (insert "* Task                                                        :work:\n")
    (goto-char (point-min))
    (let* ((marker (point-marker))
           (tags (chime--get-tags marker)))
      (should (member "work" tags)))))

(ert-deftest test-chime-get-tags-multiple-tags ()
  "Should extract multiple tags from an org heading."
  (with-temp-buffer
    (org-mode)
    (insert "* Task                                                 :work:urgent:\n")
    (goto-char (point-min))
    (let* ((marker (point-marker))
           (tags (chime--get-tags marker)))
      (should (member "work" tags))
      (should (member "urgent" tags)))))

;;; Boundary Cases

(ert-deftest test-chime-get-tags-no-tags ()
  "Should return empty/nil list for heading with no tags."
  (with-temp-buffer
    (org-mode)
    (insert "* Task without tags\n")
    (goto-char (point-min))
    (let* ((marker (point-marker))
           (tags (chime--get-tags marker)))
      ;; Should be empty (nil or empty list)
      (should (null tags)))))

(ert-deftest test-chime-get-tags-heading-with-todo-keyword ()
  "Should extract tags correctly even with TODO keyword present."
  (with-temp-buffer
    (org-mode)
    (insert "* TODO Task                                                 :meeting:\n")
    (goto-char (point-min))
    (let* ((marker (point-marker))
           (tags (chime--get-tags marker)))
      (should (member "meeting" tags)))))

;;;; Tests for chime-done-keywords-predicate

;;; Normal Cases

(ert-deftest test-chime-done-predicate-done-keyword ()
  "DONE heading should return truthy."
  (with-temp-buffer
    (org-mode)
    (insert "* DONE Completed task\n")
    (goto-char (point-min))
    (let ((marker (point-marker)))
      (should (chime-done-keywords-predicate marker)))))

(ert-deftest test-chime-done-predicate-todo-keyword ()
  "TODO heading should return nil."
  (with-temp-buffer
    (org-mode)
    (insert "* TODO Active task\n")
    (goto-char (point-min))
    (let ((marker (point-marker)))
      (should-not (chime-done-keywords-predicate marker)))))

(ert-deftest test-chime-done-predicate-no-keyword ()
  "Heading without any TODO keyword should return nil."
  (with-temp-buffer
    (org-mode)
    (insert "* Plain heading\n")
    (goto-char (point-min))
    (let ((marker (point-marker)))
      (should-not (chime-done-keywords-predicate marker)))))

;;; Boundary Cases

(ert-deftest test-chime-done-predicate-custom-done-keywords ()
  "Custom done keywords (org-done-keywords) should be recognized."
  (with-temp-buffer
    (org-mode)
    ;; CANCELLED is a standard done keyword in many org configs,
    ;; but org-done-keywords defaults to just ("DONE").
    ;; Test with the default DONE keyword.
    (insert "* DONE Task\n")
    (goto-char (point-min))
    (let ((marker (point-marker)))
      (should (member (nth 2 (org-heading-components)) org-done-keywords)))))

(ert-deftest test-chime-done-predicate-heading-with-priority ()
  "DONE heading with priority should still be detected."
  (with-temp-buffer
    (org-mode)
    (insert "* DONE [#A] High priority done task\n")
    (goto-char (point-min))
    (let ((marker (point-marker)))
      (should (chime-done-keywords-predicate marker)))))

(ert-deftest test-chime-done-predicate-heading-with-tags ()
  "DONE heading with tags should still be detected."
  (with-temp-buffer
    (org-mode)
    (insert "* DONE Tagged task                                          :work:\n")
    (goto-char (point-min))
    (let ((marker (point-marker)))
      (should (chime-done-keywords-predicate marker)))))

(provide 'test-chime-get-tags)
;;; test-chime-get-tags.el ends here