aboutsummaryrefslogtreecommitdiff
path: root/tests/test-chime-sanitize-title.el
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test-chime-sanitize-title.el')
-rw-r--r--tests/test-chime-sanitize-title.el466
1 files changed, 181 insertions, 285 deletions
diff --git a/tests/test-chime-sanitize-title.el b/tests/test-chime-sanitize-title.el
index 672cf70..8856a8e 100644
--- a/tests/test-chime-sanitize-title.el
+++ b/tests/test-chime-sanitize-title.el
@@ -32,358 +32,254 @@
(require 'test-bootstrap (expand-file-name "test-bootstrap.el"))
-;; Load test utilities
-(require 'testutil-general (expand-file-name "testutil-general.el"))
-(require 'testutil-time (expand-file-name "testutil-time.el"))
-
-;;; Setup and Teardown
-
-(defun test-chime-sanitize-title-setup ()
- "Setup function run before each test."
- (chime-create-test-base-dir))
-
-(defun test-chime-sanitize-title-teardown ()
- "Teardown function run after each test."
- (chime-delete-test-base-dir))
-
;;; Normal Cases - Already Balanced
-(ert-deftest test-chime-sanitize-title-balanced-parens-unchanged ()
+(chime-deftest test-chime-sanitize-title-balanced-parens-unchanged ()
"Test that balanced parentheses are unchanged.
REFACTORED: No timestamps used"
- (test-chime-sanitize-title-setup)
- (unwind-protect
- (let* ((title "Meeting (Team Sync)")
- (result (chime--sanitize-title title)))
- (should (string-equal title result)))
- (test-chime-sanitize-title-teardown)))
-
-(ert-deftest test-chime-sanitize-title-balanced-brackets-unchanged ()
+ (let* ((title "Meeting (Team Sync)")
+ (result (chime--sanitize-title title)))
+ (should (string-equal title result))))
+
+(chime-deftest test-chime-sanitize-title-balanced-brackets-unchanged ()
"Test that balanced brackets are unchanged.
REFACTORED: No timestamps used"
- (test-chime-sanitize-title-setup)
- (unwind-protect
- (let* ((title "Review [PR #123]")
- (result (chime--sanitize-title title)))
- (should (string-equal title result)))
- (test-chime-sanitize-title-teardown)))
-
-(ert-deftest test-chime-sanitize-title-balanced-braces-unchanged ()
+ (let* ((title "Review [PR #123]")
+ (result (chime--sanitize-title title)))
+ (should (string-equal title result))))
+
+(chime-deftest test-chime-sanitize-title-balanced-braces-unchanged ()
"Test that balanced braces are unchanged.
REFACTORED: No timestamps used"
- (test-chime-sanitize-title-setup)
- (unwind-protect
- (let* ((title "Code Review {urgent}")
- (result (chime--sanitize-title title)))
- (should (string-equal title result)))
- (test-chime-sanitize-title-teardown)))
-
-(ert-deftest test-chime-sanitize-title-mixed-balanced-unchanged ()
+ (let* ((title "Code Review {urgent}")
+ (result (chime--sanitize-title title)))
+ (should (string-equal title result))))
+
+(chime-deftest test-chime-sanitize-title-mixed-balanced-unchanged ()
"Test that mixed balanced delimiters are unchanged.
REFACTORED: No timestamps used"
- (test-chime-sanitize-title-setup)
- (unwind-protect
- (let* ((title "Meeting [Team] (Sync) {Urgent}")
- (result (chime--sanitize-title title)))
- (should (string-equal title result)))
- (test-chime-sanitize-title-teardown)))
-
-(ert-deftest test-chime-sanitize-title-nested-balanced-unchanged ()
+ (let* ((title "Meeting [Team] (Sync) {Urgent}")
+ (result (chime--sanitize-title title)))
+ (should (string-equal title result))))
+
+(chime-deftest test-chime-sanitize-title-nested-balanced-unchanged ()
"Test that nested balanced delimiters are unchanged.
REFACTORED: No timestamps used"
- (test-chime-sanitize-title-setup)
- (unwind-protect
- (let* ((title "Review (PR [#123] {urgent})")
- (result (chime--sanitize-title title)))
- (should (string-equal title result)))
- (test-chime-sanitize-title-teardown)))
-
-(ert-deftest test-chime-sanitize-title-no-delimiters-unchanged ()
+ (let* ((title "Review (PR [#123] {urgent})")
+ (result (chime--sanitize-title title)))
+ (should (string-equal title result))))
+
+(chime-deftest test-chime-sanitize-title-no-delimiters-unchanged ()
"Test that titles without delimiters are unchanged.
REFACTORED: No timestamps used"
- (test-chime-sanitize-title-setup)
- (unwind-protect
- (let* ((title "Simple Meeting Title")
- (result (chime--sanitize-title title)))
- (should (string-equal title result)))
- (test-chime-sanitize-title-teardown)))
+ (let* ((title "Simple Meeting Title")
+ (result (chime--sanitize-title title)))
+ (should (string-equal title result))))
;;; Unmatched Opening Delimiters
-(ert-deftest test-chime-sanitize-title-unmatched-opening-paren ()
+(chime-deftest test-chime-sanitize-title-unmatched-opening-paren ()
"Test that unmatched opening parenthesis is closed."
- (test-chime-sanitize-title-setup)
- (unwind-protect
- (let* ((title "CTO/COO XLT (Extended Leadership")
- (result (chime--sanitize-title title)))
- (should (string-equal "CTO/COO XLT (Extended Leadership)" result)))
- (test-chime-sanitize-title-teardown)))
-
-(ert-deftest test-chime-sanitize-title-unmatched-opening-paren-at-end ()
+ (let* ((title "CTO/COO XLT (Extended Leadership")
+ (result (chime--sanitize-title title)))
+ (should (string-equal "CTO/COO XLT (Extended Leadership)" result))))
+
+(chime-deftest test-chime-sanitize-title-unmatched-opening-paren-at-end ()
"Test that unmatched opening parenthesis at end is closed."
- (test-chime-sanitize-title-setup)
- (unwind-protect
- (let* ((title "Spice Cake (")
- (result (chime--sanitize-title title)))
- (should (string-equal "Spice Cake ()" result)))
- (test-chime-sanitize-title-teardown)))
-
-(ert-deftest test-chime-sanitize-title-multiple-unmatched-opening-parens ()
+ (let* ((title "Spice Cake (")
+ (result (chime--sanitize-title title)))
+ (should (string-equal "Spice Cake ()" result))))
+
+(chime-deftest test-chime-sanitize-title-multiple-unmatched-opening-parens ()
"Test that multiple unmatched opening parentheses are closed."
- (test-chime-sanitize-title-setup)
- (unwind-protect
- (let* ((title "Meeting (Team (Sync")
- (result (chime--sanitize-title title)))
- (should (string-equal "Meeting (Team (Sync))" result)))
- (test-chime-sanitize-title-teardown)))
-
-(ert-deftest test-chime-sanitize-title-unmatched-opening-bracket ()
+ (let* ((title "Meeting (Team (Sync")
+ (result (chime--sanitize-title title)))
+ (should (string-equal "Meeting (Team (Sync))" result))))
+
+(chime-deftest test-chime-sanitize-title-unmatched-opening-bracket ()
"Test that unmatched opening bracket is closed."
- (test-chime-sanitize-title-setup)
- (unwind-protect
- (let* ((title "Review [PR #123")
- (result (chime--sanitize-title title)))
- (should (string-equal "Review [PR #123]" result)))
- (test-chime-sanitize-title-teardown)))
-
-(ert-deftest test-chime-sanitize-title-unmatched-opening-brace ()
+ (let* ((title "Review [PR #123")
+ (result (chime--sanitize-title title)))
+ (should (string-equal "Review [PR #123]" result))))
+
+(chime-deftest test-chime-sanitize-title-unmatched-opening-brace ()
"Test that unmatched opening brace is closed."
- (test-chime-sanitize-title-setup)
- (unwind-protect
- (let* ((title "Code Review {urgent")
- (result (chime--sanitize-title title)))
- (should (string-equal "Code Review {urgent}" result)))
- (test-chime-sanitize-title-teardown)))
-
-(ert-deftest test-chime-sanitize-title-mixed-unmatched-opening-delimiters ()
+ (let* ((title "Code Review {urgent")
+ (result (chime--sanitize-title title)))
+ (should (string-equal "Code Review {urgent}" result))))
+
+(chime-deftest test-chime-sanitize-title-mixed-unmatched-opening-delimiters ()
"Test that mixed unmatched opening delimiters are all closed."
- (test-chime-sanitize-title-setup)
- (unwind-protect
- (let* ((title "Meeting [Team (Sync {Urgent")
- (result (chime--sanitize-title title)))
- (should (string-equal "Meeting [Team (Sync {Urgent})]" result)))
- (test-chime-sanitize-title-teardown)))
+ (let* ((title "Meeting [Team (Sync {Urgent")
+ (result (chime--sanitize-title title)))
+ (should (string-equal "Meeting [Team (Sync {Urgent})]" result))))
;;; Unmatched Closing Delimiters
-(ert-deftest test-chime-sanitize-title-unmatched-closing-paren ()
+(chime-deftest test-chime-sanitize-title-unmatched-closing-paren ()
"Test that unmatched closing parenthesis is removed."
- (test-chime-sanitize-title-setup)
- (unwind-protect
- (let* ((title "Meeting Title)")
- (result (chime--sanitize-title title)))
- (should (string-equal "Meeting Title" result)))
- (test-chime-sanitize-title-teardown)))
-
-(ert-deftest test-chime-sanitize-title-multiple-unmatched-closing-parens ()
+ (let* ((title "Meeting Title)")
+ (result (chime--sanitize-title title)))
+ (should (string-equal "Meeting Title" result))))
+
+(chime-deftest test-chime-sanitize-title-multiple-unmatched-closing-parens ()
"Test that multiple unmatched closing parentheses are removed."
- (test-chime-sanitize-title-setup)
- (unwind-protect
- (let* ((title "Meeting Title))")
- (result (chime--sanitize-title title)))
- (should (string-equal "Meeting Title" result)))
- (test-chime-sanitize-title-teardown)))
-
-(ert-deftest test-chime-sanitize-title-unmatched-closing-bracket ()
+ (let* ((title "Meeting Title))")
+ (result (chime--sanitize-title title)))
+ (should (string-equal "Meeting Title" result))))
+
+(chime-deftest test-chime-sanitize-title-unmatched-closing-bracket ()
"Test that unmatched closing bracket is removed."
- (test-chime-sanitize-title-setup)
- (unwind-protect
- (let* ((title "Review PR]")
- (result (chime--sanitize-title title)))
- (should (string-equal "Review PR" result)))
- (test-chime-sanitize-title-teardown)))
-
-(ert-deftest test-chime-sanitize-title-unmatched-closing-brace ()
+ (let* ((title "Review PR]")
+ (result (chime--sanitize-title title)))
+ (should (string-equal "Review PR" result))))
+
+(chime-deftest test-chime-sanitize-title-unmatched-closing-brace ()
"Test that unmatched closing brace is removed."
- (test-chime-sanitize-title-setup)
- (unwind-protect
- (let* ((title "Code Review}")
- (result (chime--sanitize-title title)))
- (should (string-equal "Code Review" result)))
- (test-chime-sanitize-title-teardown)))
+ (let* ((title "Code Review}")
+ (result (chime--sanitize-title title)))
+ (should (string-equal "Code Review" result))))
;;; Complex Mixed Cases
-(ert-deftest test-chime-sanitize-title-opening-and-closing-mixed ()
+(chime-deftest test-chime-sanitize-title-opening-and-closing-mixed ()
"Test title with both unmatched opening and closing delimiters."
- (test-chime-sanitize-title-setup)
- (unwind-protect
- (let* ((title "Meeting (Team) Extra)")
- (result (chime--sanitize-title title)))
- ;; Should remove the extra closing paren
- (should (string-equal "Meeting (Team) Extra" result)))
- (test-chime-sanitize-title-teardown)))
-
-(ert-deftest test-chime-sanitize-title-complex-nesting-with-unmatched ()
+ (let* ((title "Meeting (Team) Extra)")
+ (result (chime--sanitize-title title)))
+ ;; Should remove the extra closing paren
+ (should (string-equal "Meeting (Team) Extra" result))))
+
+(chime-deftest test-chime-sanitize-title-complex-nesting-with-unmatched ()
"Test complex nested delimiters with some unmatched."
- (test-chime-sanitize-title-setup)
- (unwind-protect
- (let* ((title "Meeting [Team (Sync] Extra")
- (result (chime--sanitize-title title)))
- ;; The ']' doesn't match the '[' (because '(' is in between)
- ;; So it's removed, and we close the '(' and '[' properly: ')' and ']'
- (should (string-equal "Meeting [Team (Sync Extra)]" result)))
- (test-chime-sanitize-title-teardown)))
-
-(ert-deftest test-chime-sanitize-title-all-types-unmatched ()
+ (let* ((title "Meeting [Team (Sync] Extra")
+ (result (chime--sanitize-title title)))
+ ;; The ']' doesn't match the '[' (because '(' is in between)
+ ;; So it's removed, and we close the '(' and '[' properly: ')' and ']'
+ (should (string-equal "Meeting [Team (Sync Extra)]" result))))
+
+(chime-deftest test-chime-sanitize-title-all-types-unmatched ()
"Test with all three delimiter types unmatched."
- (test-chime-sanitize-title-setup)
- (unwind-protect
- (let* ((title "Meeting (Team [Project {Status")
- (result (chime--sanitize-title title)))
- (should (string-equal "Meeting (Team [Project {Status}])" result)))
- (test-chime-sanitize-title-teardown)))
+ (let* ((title "Meeting (Team [Project {Status")
+ (result (chime--sanitize-title title)))
+ (should (string-equal "Meeting (Team [Project {Status}])" result))))
;;; Edge Cases
-(ert-deftest test-chime-sanitize-title-nil-returns-empty-string ()
+(chime-deftest test-chime-sanitize-title-nil-returns-empty-string ()
"Test that nil title returns empty string."
- (test-chime-sanitize-title-setup)
- (unwind-protect
- (let* ((result (chime--sanitize-title nil)))
- (should (string-equal "" result)))
- (test-chime-sanitize-title-teardown)))
+ (let* ((result (chime--sanitize-title nil)))
+ (should (string-equal "" result))))
-(ert-deftest test-chime-sanitize-title-empty-string-unchanged ()
+(chime-deftest test-chime-sanitize-title-empty-string-unchanged ()
"Test that empty string is unchanged."
- (test-chime-sanitize-title-setup)
- (unwind-protect
- (let* ((title "")
- (result (chime--sanitize-title title)))
- (should (string-equal "" result)))
- (test-chime-sanitize-title-teardown)))
-
-(ert-deftest test-chime-sanitize-title-only-opening-delimiters ()
+ (let* ((title "")
+ (result (chime--sanitize-title title)))
+ (should (string-equal "" result))))
+
+(chime-deftest test-chime-sanitize-title-only-opening-delimiters ()
"Test title with only opening delimiters."
- (test-chime-sanitize-title-setup)
- (unwind-protect
- (let* ((title "([{")
- (result (chime--sanitize-title title)))
- (should (string-equal "([{}])" result)))
- (test-chime-sanitize-title-teardown)))
-
-(ert-deftest test-chime-sanitize-title-only-closing-delimiters ()
+ (let* ((title "([{")
+ (result (chime--sanitize-title title)))
+ (should (string-equal "([{}])" result))))
+
+(chime-deftest test-chime-sanitize-title-only-closing-delimiters ()
"Test title with only closing delimiters."
- (test-chime-sanitize-title-setup)
- (unwind-protect
- (let* ((title ")]}")
- (result (chime--sanitize-title title)))
- (should (string-equal "" result)))
- (test-chime-sanitize-title-teardown)))
-
-(ert-deftest test-chime-sanitize-title-very-long-title-with-unmatched ()
+ (let* ((title ")]}")
+ (result (chime--sanitize-title title)))
+ (should (string-equal "" result))))
+
+(chime-deftest test-chime-sanitize-title-very-long-title-with-unmatched ()
"Test very long title with unmatched delimiter."
- (test-chime-sanitize-title-setup)
- (unwind-protect
- (let* ((title "This is a very long meeting title that contains many words and might wrap in the notification display (Extended Info")
- (result (chime--sanitize-title title)))
- (should (string-equal "This is a very long meeting title that contains many words and might wrap in the notification display (Extended Info)" result)))
- (test-chime-sanitize-title-teardown)))
+ (let* ((title "This is a very long meeting title that contains many words and might wrap in the notification display (Extended Info")
+ (result (chime--sanitize-title title)))
+ (should (string-equal "This is a very long meeting title that contains many words and might wrap in the notification display (Extended Info)" result))))
;;; Real-World Bug Cases
-(ert-deftest test-chime-sanitize-title-bug-case-extended-leadership ()
+(chime-deftest test-chime-sanitize-title-bug-case-extended-leadership ()
"Test the actual bug case from vineti.meetings.org."
- (test-chime-sanitize-title-setup)
- (unwind-protect
- (let* ((title "1:01pm CTO/COO XLT (Extended Leadership")
- (result (chime--sanitize-title title)))
- (should (string-equal "1:01pm CTO/COO XLT (Extended Leadership)" result)))
- (test-chime-sanitize-title-teardown)))
-
-(ert-deftest test-chime-sanitize-title-bug-case-spice-cake ()
+ (let* ((title "1:01pm CTO/COO XLT (Extended Leadership")
+ (result (chime--sanitize-title title)))
+ (should (string-equal "1:01pm CTO/COO XLT (Extended Leadership)" result))))
+
+(chime-deftest test-chime-sanitize-title-bug-case-spice-cake ()
"Test the actual bug case from journal/2023-11-22.org."
- (test-chime-sanitize-title-setup)
- (unwind-protect
- (let* ((title "Spice Cake (")
- (result (chime--sanitize-title title)))
- (should (string-equal "Spice Cake ()" result)))
- (test-chime-sanitize-title-teardown)))
-
-(ert-deftest test-chime-sanitize-title-lisp-serialization-safety ()
- "Test that sanitized title can be safely read by Lisp reader."
- (test-chime-sanitize-title-setup)
- (unwind-protect
- (let* ((title "Meeting (Team Sync")
- (sanitized (chime--sanitize-title title))
- ;; Simulate what happens in async serialization
- (serialized (format "'((title . \"%s\"))" sanitized)))
- ;; This should not signal an error
- (should (listp (read serialized)))
- (should (string-equal "Meeting (Team Sync)" sanitized)))
- (test-chime-sanitize-title-teardown)))
+ (let* ((title "Spice Cake (")
+ (result (chime--sanitize-title title)))
+ (should (string-equal "Spice Cake ()" result))))
-(ert-deftest test-chime-sanitize-title-async-serialization-with-unmatched-parens ()
+(chime-deftest test-chime-sanitize-title-lisp-serialization-safety ()
+ "Test that sanitized title can be safely read by Lisp reader."
+ (let* ((title "Meeting (Team Sync")
+ (sanitized (chime--sanitize-title title))
+ ;; Simulate what happens in async serialization
+ (serialized (format "'((title . \"%s\"))" sanitized)))
+ ;; This should not signal an error
+ (should (listp (read serialized)))
+ (should (string-equal "Meeting (Team Sync)" sanitized))))
+
+(chime-deftest test-chime-sanitize-title-async-serialization-with-unmatched-parens ()
"Test that titles with unmatched parens won't break async serialization."
- (test-chime-sanitize-title-setup)
- (unwind-protect
- (let* ((problematic-titles '("Meeting (Team"
- "Review [PR"
- "Code {Status"
- "Event (("
- "Task ))")))
- (dolist (title problematic-titles)
- (let* ((sanitized (chime--sanitize-title title))
- (serialized (format "'((title . \"%s\"))" sanitized)))
- ;; Should not signal 'invalid-read-syntax error
- (should (listp (read serialized))))))
- (test-chime-sanitize-title-teardown)))
+ (let* ((problematic-titles '("Meeting (Team"
+ "Review [PR"
+ "Code {Status"
+ "Event (("
+ "Task ))")))
+ (dolist (title problematic-titles)
+ (let* ((sanitized (chime--sanitize-title title))
+ (serialized (format "'((title . \"%s\"))" sanitized)))
+ ;; Should not signal 'invalid-read-syntax error
+ (should (listp (read serialized)))))))
;;; Integration with chime--extract-title
-(ert-deftest test-chime-extract-title-sanitizes-output ()
+(chime-deftest test-chime-extract-title-sanitizes-output ()
"Test that chime--extract-title applies sanitization.
REFACTORED: Uses dynamic timestamps"
- (test-chime-sanitize-title-setup)
- (unwind-protect
- (let* ((time (test-time-tomorrow-at 14 0))
- (timestamp (test-timestamp-string time))
- (test-file (chime-create-temp-test-file-with-content
- (format "* TODO Meeting (Team Sync\n%s\n" timestamp)))
- (test-buffer (find-file-noselect test-file)))
- (with-current-buffer test-buffer
- (org-mode) ; Enable org-mode
- (goto-char (point-min))
- ;; Search for the heading
- (re-search-forward "^\\* TODO" nil t)
- (beginning-of-line)
- (let* ((marker (point-marker))
- (title (chime--extract-title marker)))
- ;; Should be sanitized with closing paren added
- (should (string-equal "Meeting (Team Sync)" title))))
- (kill-buffer test-buffer))
- (test-chime-sanitize-title-teardown)))
-
-(ert-deftest test-chime-extract-title-handles-nil ()
+ (let* ((time (test-time-tomorrow-at 14 0))
+ (timestamp (test-timestamp-string time))
+ (test-file (chime-create-temp-test-file-with-content
+ (format "* TODO Meeting (Team Sync\n%s\n" timestamp)))
+ (test-buffer (find-file-noselect test-file)))
+ (with-current-buffer test-buffer
+ (org-mode) ; Enable org-mode
+ (goto-char (point-min))
+ ;; Search for the heading
+ (re-search-forward "^\\* TODO" nil t)
+ (beginning-of-line)
+ (let* ((marker (point-marker))
+ (title (chime--extract-title marker)))
+ ;; Should be sanitized with closing paren added
+ (should (string-equal "Meeting (Team Sync)" title))))
+ (kill-buffer test-buffer)))
+
+(chime-deftest test-chime-extract-title-handles-nil ()
"Test that chime--extract-title handles nil gracefully.
REFACTORED: Uses dynamic timestamps"
- (test-chime-sanitize-title-setup)
- (unwind-protect
- (let* ((time (test-time-tomorrow-at 14 0))
- (timestamp (test-timestamp-string time))
- (test-file (chime-create-temp-test-file-with-content
- (format "* TODO\n%s\n" timestamp)))
- (test-buffer (find-file-noselect test-file)))
- (with-current-buffer test-buffer
- (org-mode) ; Enable org-mode
- (goto-char (point-min))
- ;; Search for the heading
- (re-search-forward "^\\* TODO" nil t)
- (beginning-of-line)
- (let* ((marker (point-marker))
- (title (chime--extract-title marker)))
- ;; Should return empty string for nil title
- (should (string-equal "" title))))
- (kill-buffer test-buffer))
- (test-chime-sanitize-title-teardown)))
+ (let* ((time (test-time-tomorrow-at 14 0))
+ (timestamp (test-timestamp-string time))
+ (test-file (chime-create-temp-test-file-with-content
+ (format "* TODO\n%s\n" timestamp)))
+ (test-buffer (find-file-noselect test-file)))
+ (with-current-buffer test-buffer
+ (org-mode) ; Enable org-mode
+ (goto-char (point-min))
+ ;; Search for the heading
+ (re-search-forward "^\\* TODO" nil t)
+ (beginning-of-line)
+ (let* ((marker (point-marker))
+ (title (chime--extract-title marker)))
+ ;; Should return empty string for nil title
+ (should (string-equal "" title))))
+ (kill-buffer test-buffer)))
(provide 'test-chime-sanitize-title)
;;; test-chime-sanitize-title.el ends here