aboutsummaryrefslogtreecommitdiff
path: root/tests/test-config-utilities--format-validation-report-section.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-04-30 09:25:18 -0500
committerCraig Jennings <c@cjennings.net>2026-04-30 09:25:18 -0500
commit467a6d63f44ba835a94e7580adff9ff6b2b1a1eb (patch)
tree1399981f7689280884229a96acce6225dbd2aefd /tests/test-config-utilities--format-validation-report-section.el
parentf90a087d5025952f0ca1b81d322f29891a40e540 (diff)
downloaddotemacs-467a6d63f44ba835a94e7580adff9ff6b2b1a1eb.tar.gz
dotemacs-467a6d63f44ba835a94e7580adff9ff6b2b1a1eb.zip
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.
Diffstat (limited to 'tests/test-config-utilities--format-validation-report-section.el')
-rw-r--r--tests/test-config-utilities--format-validation-report-section.el60
1 files changed, 60 insertions, 0 deletions
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" "<bad-1>")
+ ("/tmp/foo.org" 2 "Second" "SCHEDULED" "<bad-2>")
+ ("/tmp/foo.org" 3 "Third" "inline timestamp" "<bad-3>")))))
+ (should (string-match-p "<bad-1>" text))
+ (should (string-match-p "<bad-2>" text))
+ (should (string-match-p "<bad-3>" text))
+ ;; Order is preserved.
+ (should (< (string-match "<bad-1>" text)
+ (string-match "<bad-2>" text)))
+ (should (< (string-match "<bad-2>" text)
+ (string-match "<bad-3>" 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" "<bad>")))))
+ (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