From 467a6d63f44ba835a94e7580adff9ff6b2b1a1eb Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Thu, 30 Apr 2026 09:25:18 -0500 Subject: test(config-utilities): cover validate-timestamps and format-report helpers Two test files covering the extracted timestamp-validation helpers. cj/--validate-timestamps-in-buffer (8 tests): empty buffer no-op, buffer with no timestamps, buffer with all valid timestamps, DEADLINE flagged with "DEADLINE" property, SCHEDULED flagged with "SCHEDULED", inline-timestamp flagged with "inline timestamp", multiple invalid collected in document order, mixed valid+invalid returning only the invalid one. Tests use real org parsing and mock org-time-string-to-absolute at the boundary so an arbitrary timestamp can be marked invalid for a given test. cj/--format-validation-report-section (4 tests): no-entries says "No invalid timestamps found", single-entry produces the file: link + Property/Type + Invalid timestamp lines, multiple-entry preserves input order, every section ends with a trailing blank line. --- ...-utilities--format-validation-report-section.el | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 tests/test-config-utilities--format-validation-report-section.el (limited to 'tests/test-config-utilities--format-validation-report-section.el') diff --git a/tests/test-config-utilities--format-validation-report-section.el b/tests/test-config-utilities--format-validation-report-section.el new file mode 100644 index 00000000..caaaa346 --- /dev/null +++ b/tests/test-config-utilities--format-validation-report-section.el @@ -0,0 +1,60 @@ +;;; test-config-utilities--format-validation-report-section.el --- Tests for cj/--format-validation-report-section -*- lexical-binding: t; -*- + +;;; Commentary: +;; Tests for `cj/--format-validation-report-section'. Pure helper that +;; takes a FILE path and a list of invalid-entry tuples and returns +;; the per-file org-formatted string. Empty list yields a "No +;; invalid timestamps found." line; non-empty produces a bulleted +;; list with file: links, Property/Type, and the timestamp string. + +;;; Code: + +(require 'ert) + +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(require 'config-utilities) + +(ert-deftest test-config-utilities-format-validation-no-entries-says-none-found () + "Boundary: an empty entries list produces the \"No invalid\" line." + (let ((text (cj/--format-validation-report-section "/tmp/foo.org" nil))) + (should (string-match-p "^\\* /tmp/foo\\.org$" text)) + (should (string-match-p "^No invalid timestamps found\\.$" text)))) + +(ert-deftest test-config-utilities-format-validation-single-entry-formats-bullet () + "Normal: one entry produces a file-link bullet plus property and timestamp lines." + (let ((text (cj/--format-validation-report-section + "/tmp/foo.org" + '(("/tmp/foo.org" 42 "Bad heading" "DEADLINE" "<2030-13-45>"))))) + (should (string-match-p + "- \\[\\[file:/tmp/foo\\.org::42\\]\\[Bad heading\\]\\]" + text)) + (should (string-match-p "Property/Type: DEADLINE" text)) + (should (string-match-p "Invalid timestamp: \"<2030-13-45>\"" text)))) + +(ert-deftest test-config-utilities-format-validation-multiple-entries-preserves-order () + "Normal: multiple entries are formatted in input order." + (let ((text (cj/--format-validation-report-section + "/tmp/foo.org" + '(("/tmp/foo.org" 1 "First" "DEADLINE" "") + ("/tmp/foo.org" 2 "Second" "SCHEDULED" "") + ("/tmp/foo.org" 3 "Third" "inline timestamp" ""))))) + (should (string-match-p "" text)) + (should (string-match-p "" text)) + (should (string-match-p "" text)) + ;; Order is preserved. + (should (< (string-match "" text) + (string-match "" text))) + (should (< (string-match "" text) + (string-match "" text))))) + +(ert-deftest test-config-utilities-format-validation-section-ends-with-blank-line () + "Boundary: every section ends with a trailing blank line so successive +file sections are visually separated in the report." + (let ((empty-section (cj/--format-validation-report-section "/x" nil)) + (full-section (cj/--format-validation-report-section + "/x" '(("/x" 1 "h" "DEADLINE" ""))))) + (should (string-suffix-p "\n\n" empty-section)) + (should (string-suffix-p "\n\n" full-section)))) + +(provide 'test-config-utilities--format-validation-report-section) +;;; test-config-utilities--format-validation-report-section.el ends here -- cgit v1.2.3