From 69c8deb2d7821c78475dcbb08458df6b0e56d559 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sat, 4 Apr 2026 12:40:27 -0500 Subject: Add 94 tests across 10 new test files and fix 2 bugs New test coverage for previously untested functions: - filter-day-wide-events, time utilities, day-wide time matching - make-tooltip, event-is-today, get-tags, done-keywords-predicate - extract-title, propertize-modeline-string, warn-persistent-failures - log-silently Bug fixes discovered by new tests: - Fix pluralization in no-events tooltip ("1 hours" -> "1 hour", etc.) - Fix chime--get-tags returning ("") instead of nil for untagged headings --- tests/test-chime-get-tags.el | 158 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 tests/test-chime-get-tags.el (limited to 'tests/test-chime-get-tags.el') diff --git a/tests/test-chime-get-tags.el b/tests/test-chime-get-tags.el new file mode 100644 index 0000000..75cad00 --- /dev/null +++ b/tests/test-chime-get-tags.el @@ -0,0 +1,158 @@ +;;; test-chime-get-tags.el --- Tests for chime--get-tags and chime-done-keywords-predicate -*- lexical-binding: t; -*- + +;; Copyright (C) 2024-2026 Craig Jennings + +;; Author: Craig Jennings + +;; 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 . + +;;; 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: + +;; Initialize package system for batch mode +(when noninteractive + (package-initialize)) + +(require 'ert) + +;; Load dependencies required by chime +(require 'dash) +(require 'alert) +(require 'async) +(require 'org-agenda) + +;; Load chime from parent directory +(load (expand-file-name "../chime.el") nil t) + +;; 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 -- cgit v1.2.3