summaryrefslogtreecommitdiff
path: root/tests/test-calendar-sync--clean-text.el
blob: 86c8532b22d224e97af15307d7a1c03b0044ae1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
;;; test-calendar-sync--clean-text.el --- Tests for clean-text composition  -*- lexical-binding: t; -*-

;;; Commentary:
;; Unit tests for calendar-sync--clean-text function.
;; Composes unescape-ics-text + strip-html, trims whitespace. Returns nil for nil.
;; Covers Normal, Boundary, and Error cases.

;;; Code:

(require 'ert)
(require 'testutil-calendar-sync)
(require 'calendar-sync)

;;; Normal Cases

(ert-deftest test-calendar-sync--clean-text-normal-both-html-and-ics ()
  "Test text with both HTML tags and ICS escapes."
  (should (string= "Hello, World\nNext line"
                    (calendar-sync--clean-text "Hello\\, World<br>Next line"))))

(ert-deftest test-calendar-sync--clean-text-normal-pure-ics-escapes ()
  "Test text with only ICS escapes."
  (should (string= "a, b; c"
                    (calendar-sync--clean-text "a\\, b\\; c"))))

(ert-deftest test-calendar-sync--clean-text-normal-pure-html ()
  "Test text with only HTML."
  (should (string= "bold and italic"
                    (calendar-sync--clean-text "<b>bold</b> and <i>italic</i>"))))

;;; Boundary Cases

(ert-deftest test-calendar-sync--clean-text-boundary-already-clean ()
  "Test already-clean text passes through unchanged."
  (should (string= "no escapes here"
                    (calendar-sync--clean-text "no escapes here"))))

(ert-deftest test-calendar-sync--clean-text-boundary-empty-string ()
  "Test empty string returns empty string."
  (should (string= "" (calendar-sync--clean-text ""))))

(ert-deftest test-calendar-sync--clean-text-boundary-whitespace-only ()
  "Test whitespace-only string returns empty after trim."
  (should (string= "" (calendar-sync--clean-text "   \n  \t  "))))

(ert-deftest test-calendar-sync--clean-text-boundary-leading-trailing-whitespace ()
  "Test leading/trailing whitespace is trimmed."
  (should (string= "content"
                    (calendar-sync--clean-text "  content  "))))

;;; Error Cases

(ert-deftest test-calendar-sync--clean-text-error-nil-input ()
  "Test nil input returns nil."
  (should (null (calendar-sync--clean-text nil))))

(provide 'test-calendar-sync--clean-text)
;;; test-calendar-sync--clean-text.el ends here