summaryrefslogtreecommitdiff
path: root/tests/test-calendar-sync--sanitize-org-body.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-10 14:34:52 -0500
committerCraig Jennings <c@cjennings.net>2026-05-10 14:34:52 -0500
commitd75f5d2411dc3278df31398c9888825d2bc95b64 (patch)
tree59ef7d289a4b6f735bfdb4ee2e3696b8d4778cc2 /tests/test-calendar-sync--sanitize-org-body.el
parent9e4e9b322159eaf22f94a49863cf08c48c65319c (diff)
downloaddotemacs-d75f5d2411dc3278df31398c9888825d2bc95b64.tar.gz
dotemacs-d75f5d2411dc3278df31398c9888825d2bc95b64.zip
refactor(cj-org-text): extract Org-safe text sanitizers from calendar-sync
Phase 3 of utility-consolidation. Three sanitizers moved from calendar-sync.el into a new cj-org-text.el module so other consumers (web-clipper, AI conversation, mail-to-org capture) can compose Org content from external text without depending on calendar: - `calendar-sync--sanitize-org-body' -> `cj/org-sanitize-body-text' - `calendar-sync--sanitize-org-property-value' -> `cj/org-sanitize-property-value' - `calendar-sync--sanitize-org-heading' -> `cj/org-sanitize-heading' The helpers stay pure (string in, string out, nil-safe) and have no Org-mode dependency, so they work in batch and in tests without loading Org. Migrate calendar-sync.el to use the new public names: drop the three local defuns, add `(require \='cj-org-text)', update the six call sites in `calendar-sync--make-event-entry'. Move the existing 17-test file to `tests/test-cj-org-text-sanitize.el', rename test names to match the new helpers, add 1 nil-input test for `cj/org-sanitize-heading' that wasn't in the original file. Total: 18 Normal/Boundary tests across the three helpers.
Diffstat (limited to 'tests/test-calendar-sync--sanitize-org-body.el')
-rw-r--r--tests/test-calendar-sync--sanitize-org-body.el98
1 files changed, 0 insertions, 98 deletions
diff --git a/tests/test-calendar-sync--sanitize-org-body.el b/tests/test-calendar-sync--sanitize-org-body.el
deleted file mode 100644
index 636946db..00000000
--- a/tests/test-calendar-sync--sanitize-org-body.el
+++ /dev/null
@@ -1,98 +0,0 @@
-;;; test-calendar-sync--sanitize-org-body.el --- Tests for org body sanitization -*- lexical-binding: t; -*-
-
-;;; Commentary:
-;; Unit tests for calendar-sync--sanitize-org-body.
-;; Ensures description text with org-special syntax (leading asterisks)
-;; is escaped to prevent corruption of the org file structure.
-
-;;; Code:
-
-(require 'ert)
-(require 'testutil-calendar-sync)
-(require 'calendar-sync)
-
-;;; Normal Cases
-
-(ert-deftest test-calendar-sync--sanitize-org-body-normal-single-asterisk ()
- "Single leading asterisk replaced with dash."
- (should (equal "- item one" (calendar-sync--sanitize-org-body "* item one"))))
-
-(ert-deftest test-calendar-sync--sanitize-org-body-normal-double-asterisk ()
- "Double leading asterisks replaced with double dashes."
- (should (equal "-- sub-item" (calendar-sync--sanitize-org-body "** sub-item"))))
-
-(ert-deftest test-calendar-sync--sanitize-org-body-normal-triple-asterisk ()
- "Triple leading asterisks replaced with triple dashes."
- (should (equal "--- deep item" (calendar-sync--sanitize-org-body "*** deep item"))))
-
-(ert-deftest test-calendar-sync--sanitize-org-body-normal-multiline ()
- "Multiple lines with asterisks all get sanitized."
- (let ((input "Format:\n* What did you do yesterday?\n* What are you doing today?\n* Is anything in your way?")
- (expected "Format:\n- What did you do yesterday?\n- What are you doing today?\n- Is anything in your way?"))
- (should (equal expected (calendar-sync--sanitize-org-body input)))))
-
-(ert-deftest test-calendar-sync--sanitize-org-body-normal-mixed-lines ()
- "Only lines starting with asterisks are changed."
- (let ((input "Normal line\n* Bullet line\nAnother normal line"))
- (should (equal "Normal line\n- Bullet line\nAnother normal line"
- (calendar-sync--sanitize-org-body input)))))
-
-(ert-deftest test-calendar-sync--sanitize-org-body-normal-mixed-levels ()
- "Lines with different asterisk counts are each handled."
- (let ((input "* Top\n** Middle\n*** Bottom"))
- (should (equal "- Top\n-- Middle\n--- Bottom"
- (calendar-sync--sanitize-org-body input)))))
-
-;;; Boundary Cases
-
-(ert-deftest test-calendar-sync--sanitize-org-body-boundary-nil-input ()
- "Nil input returns nil."
- (should (null (calendar-sync--sanitize-org-body nil))))
-
-(ert-deftest test-calendar-sync--sanitize-org-body-boundary-empty-string ()
- "Empty string returns empty string."
- (should (equal "" (calendar-sync--sanitize-org-body ""))))
-
-(ert-deftest test-calendar-sync--sanitize-org-body-boundary-no-asterisks ()
- "Text without leading asterisks is returned unchanged."
- (let ((input "Just a normal description\nwith multiple lines"))
- (should (equal input (calendar-sync--sanitize-org-body input)))))
-
-(ert-deftest test-calendar-sync--sanitize-org-body-boundary-asterisk-mid-line ()
- "Asterisks not at line start are left alone."
- (should (equal "Use * for emphasis" (calendar-sync--sanitize-org-body "Use * for emphasis"))))
-
-(ert-deftest test-calendar-sync--sanitize-org-body-boundary-asterisk-no-space ()
- "Asterisk at line start without trailing space is not a heading — left alone."
- (should (equal "*bold text*" (calendar-sync--sanitize-org-body "*bold text*"))))
-
-(ert-deftest test-calendar-sync--sanitize-org-body-boundary-asterisk-only ()
- "Lone asterisk with space at start of line is sanitized."
- (should (equal "- " (calendar-sync--sanitize-org-body "* "))))
-
-;;; Heading and Property Sanitizers
-
-(ert-deftest test-calendar-sync--sanitize-org-heading-flattens-newlines ()
- "Heading text should stay on one Org heading line."
- (should (equal "Planning Agenda"
- (calendar-sync--sanitize-org-heading "Planning\nAgenda"))))
-
-(ert-deftest test-calendar-sync--sanitize-org-heading-replaces-leading-stars ()
- "Heading text should not start with Org heading stars."
- (should (equal "- Planning -- Hidden"
- (calendar-sync--sanitize-org-heading "* Planning\n** Hidden"))))
-
-(ert-deftest test-calendar-sync--sanitize-org-property-value-flattens-structure ()
- "Property values should not create extra property drawer lines."
- (should (equal "Room 1 :END: * Not a heading"
- (calendar-sync--sanitize-org-property-value
- "Room 1\n:END:\n* Not a heading"))))
-
-(ert-deftest test-calendar-sync--sanitize-org-property-value-trims-and-collapses ()
- "Property values should be compact single-line values."
- (should (equal "alpha beta gamma"
- (calendar-sync--sanitize-org-property-value
- " alpha\t beta\n\n gamma "))))
-
-(provide 'test-calendar-sync--sanitize-org-body)
-;;; test-calendar-sync--sanitize-org-body.el ends here